From a07a69c0f5bde4ecf5b27cc861415b8612f6d573 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 30 Oct 2024 17:17:08 +0300 Subject: [PATCH] updated style... Signed-off-by: Alex A. Naanou --- Viewer/features/marks.js | 129 ++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/Viewer/features/marks.js b/Viewer/features/marks.js index 7f5f524b..948b781a 100755 --- a/Viewer/features/marks.js +++ b/Viewer/features/marks.js @@ -41,7 +41,8 @@ var ui = require('features/ui') function makeTagTogglerAction(tag){ // get actual target gids... var _getTarget = function(target){ - target = target || this.current + target = target + || this.current target = (target == 'all' || target == 'loaded' || target in this.data.ribbons) ? @@ -53,8 +54,7 @@ function makeTagTogglerAction(tag){ [] : target instanceof Array ? target - : [target] - } + : [target] } // the toggler... var _tagToggler = toggler.Toggler('current', @@ -64,14 +64,10 @@ function makeTagTogglerAction(tag){ if(action == null){ var res = this.data.toggleTag(tag, target, '?') return res.length == 1 ? res[0] : res - } else if(action == 'on'){ this.tag(tag, target) - } else if(action == 'off'){ - this.untag(tag, target) - } - }, + this.untag(tag, target) } }, ['off', 'on']) // the action... @@ -81,7 +77,8 @@ function makeTagTogglerAction(tag){ this[target] : target // reverse gid list attr... - if(typeof(target) == typeof('str') && target[0] == '!'){ + if(typeof(target) == typeof('str') + && target[0] == '!'){ var skip = new Set(this[target.slice(1)]) target = this.data.order .filter(function(gid){ @@ -89,13 +86,19 @@ function makeTagTogglerAction(tag){ // special case: no data... if(this.data == null){ - return action == '??' ? ['off', 'on'] : 'off' + return action == '??' ? + ['off', 'on'] + : 'off' // special case: multiple targets and toggle action... // XXX do we need this??? - } else if((target == 'all' || target == 'loaded' || target == 'ribbon' + } else if((target == 'all' + || target == 'loaded' + || target == 'ribbon' || target instanceof Array) - && (action == null || action == 'next' || action == 'prev' + && (action == null + || action == 'next' + || action == 'prev' || action == '!')){ var res = [] var that = this @@ -112,25 +115,22 @@ function makeTagTogglerAction(tag){ } else { off.push(gid) - res.push('off') - } - }) + res.push('off') } }) that.tag(tag, on) that.untag(tag, off) - return res.length == 1 ? res[0] : res - } + return res.length == 1 ? + res[0] + : res } // normal case... - return _tagToggler.call(this, target, action) - } + return _tagToggler.call(this, target, action) } // cheating a bit... action.__proto__ = toggler.Toggler.prototype action.constructor = toggler.Toggler - return action -} + return action } // Build a tag toggler undo set of attrs... @@ -148,30 +148,29 @@ var undoTag = function(action){ undoable: function(a){ // handle ribbon-wide operations... // NOTE: this is specific to .toggleMark(..) - if(a.args[0] == 'ribbon' && action == 'toggleMark'){ + if(a.args[0] == 'ribbon' + && action == 'toggleMark'){ a.state = this.markedInRibbon() - return true - } + return true } // skip introspection... return a.args.indexOf('?') < 0 - && a.args.indexOf('??') < 0 - }, + && a.args.indexOf('??') < 0 }, undo: function(a){ // restore state... if(a.state){ this[action]('ribbon', 'off') this[action](a.state, 'on') - // reverse state... } else { this[action].apply(this, // XXX is argument handling here too optimistic??? - a.args.map(function(e){ - return e == 'on' ? 'off' - : e == 'off' ? 'on' - : e })) - } - }, + a.args + .map(function(e){ + return e == 'on' ? + 'off' + : e == 'off' ? + 'on' + : e })) } }, } } @@ -197,26 +196,24 @@ var shiftMarked = function(direction){ var getNext = function(direction){ var next = that.data.getImage(direction) - while(next != null && marked.indexOf(next) >= 0){ - next = that.data.getImage(next, direction) - } - return next - } + while(next != null + && marked.indexOf(next) >= 0){ + next = that.data.getImage(next, direction) } + return next } next = getNext(d) - || getNext(d == 'next' ? 'prev' : 'next') + || getNext(d == 'next' ? + 'prev' + : 'next') next != null - && this.data.focusImage(next) - } + && this.data.focusImage(next) } // shift the image... this.data['shiftImage'+ direction.capitalize()](marked) // obey the shiftImage protocol... - this.shiftImage.apply(this, marked) - } -} + this.shiftImage.apply(this, marked) } } // Shift undo function constructor... @@ -225,8 +222,12 @@ var shiftMarked = function(direction){ var undoShift = function(undo){ return function(a){ this[undo](this.data.getRibbon( - undo == 'shiftMarkedUp' ? 'next' : 'prev', - a.args.length == 0 ? a.current : a.args[0])) }} + undo == 'shiftMarkedUp' ? + 'next' + : 'prev', + a.args.length == 0 ? + a.current + : a.args[0])) }} @@ -244,8 +245,9 @@ var ImageMarkActions = actions.Actions({ get marked(){ return this.data == null ? [] - : this.data.sortViaOrder(this.data.tagQuery('marked')) }, - // XXX REVISE... + : this.data.sortViaOrder( + this.data.tagQuery('marked')) }, + // NOTE: this will untag only the loaded images... set marked(gids){ gids = gids instanceof Array ? gids @@ -257,12 +259,13 @@ var ImageMarkActions = actions.Actions({ markedInRibbon: ['- Mark|Ribbon/', function(ribbon){ var ribbon = this.data.getRibbon(ribbon) - var images = this.data.makeSparseImages(this.data.getImages(ribbon)) + var images = this.data.makeSparseImages( + this.data.getImages(ribbon)) return this.data.makeSparseImages(this.marked) // NOTE: this will also filter out undefined positions... - .filter(function(img, i){ return images[i] != null }) - }], + .filter(function(img, i){ + return images[i] != null }) }], prevMarked: ['Mark|Navigate/Previous marked image', {mode: function(target){ @@ -363,22 +366,22 @@ var ImageMarkEditActions = actions.Actions({ while(i >= 0 // NOTE: we are avoiding mixing up a tag not set condition // with image i not in ribbon... - && (!ribbon[i] || !!marked[i] == state)){ + && (!ribbon[i] + || !!marked[i] == state)){ ribbon[i] && block.splice(0, 0, ribbon[i]) - i-- - } + i-- } // post block... var i = c+1 while(i < ribbon.length // NOTE: we are avoiding mixing up a tag not set condition // with image i not in ribbon... - && (!ribbon[i] || !!marked[i] == state)){ + && (!ribbon[i] + || !!marked[i] == state)){ ribbon[i] && block.push(ribbon[i]) - i++ - } + i++ } // do the marking... return this.toggleMark(block, state ? 'off' : 'on') @@ -508,8 +511,9 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({ .toggleImageMark( gid, 'marked', - this.data.hasTag(gid, 'marked') ? 'on' : 'off') - }], + this.data.hasTag(gid, 'marked') ? + 'on' + : 'off') }], ], }) @@ -530,7 +534,7 @@ var ImageBookmarkActions = actions.Actions({ return this.data == null ? [] : this.data.sortViaOrder(this.data.tagQuery('bookmark')) }, - // XXX REVISE... + // NOTE: this will untag only the loaded images... set bookmarked(gids){ gids = gids instanceof Array ? gids @@ -634,8 +638,9 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({ .toggleImageMark( gid, 'bookmark', - this.data.hasTag(gid, 'bookmark') ? 'on' : 'off') - }], + this.data.hasTag(gid, 'bookmark') ? + 'on' + : 'off') }], ], })