From fbc7af8c05ec145c554cc5eadbc5f0255fa6cad3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 1 Sep 2023 16:15:57 +0300 Subject: [PATCH] added crops and saved crops (no GUI yet)... Signed-off-by: Alex A. Naanou --- grid-n-view.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/grid-n-view.js b/grid-n-view.js index 49387ce..069f820 100644 --- a/grid-n-view.js +++ b/grid-n-view.js @@ -1045,6 +1045,11 @@ var Gallery = { return [...gallery.dom.querySelectorAll('.images img.to-remove')] }, set toBeRemoved(lst){ this.queueRemoval(lst) }, + // XXX should this be writable... + get toBeKeept(){ + return [...gallery.dom.querySelectorAll('.images img:not(.to-remove)')] }, + set toBeKeept(lst){ + this.unqueueRemoval(lst) }, queueRemoval: function(...images){ images = images.length == 0 ? ['current'] @@ -1091,6 +1096,46 @@ var Gallery = { this.dom.querySelector('.images').innerHTML = '' return this }, + // crop... + __crop_stack: undefined, + crop: function(lst){ + var stack = this.__crop_stack ??= [] + var state = this.json() + stack.push(state) + if(lst){ + lst = this.getImages(...lst) + // XXX filter state... + // XXX + } + this.load(state) + return this }, + uncrop: function(lst){ + var state = this.__crop_stack?.pop() + state.length == 0 + && (delete this.__crop_stack) + state + && this.load(state) + return this }, + + // named crops... + // XXX add these to serilization... + // XXX TEST... + __saved_crops: undefined, + get savedCropNames(){ + return Object.keys(this.__saved_crops ?? {}) }, + saveCrop: function(name){ + var saved = this.__saved_crops ??= {} + saved[name] = this.json() + return this }, + loadCrop: function(name){ + var state = (this.__saved_crops ?? {})[name] + state + && this.load(state) + return this }, + removeCrop: function(name){ + delete (this.__saved_crops ?? {})[name] + return this }, + setup: function(dom){ var that = this this.dom = dom @@ -1320,7 +1365,6 @@ var Gallery = { // - press esc to cancel drag // ...this will leave the dragged-over classes in place... var cleanupAfterDrag = function(evt){ - console.log('11111') that.dom.classList.remove('dragged-over') dragged_over && dragged_over.classList.remove('dragged-over') }