From c168b22e3861cc3649b374c2161cb5a880fb4ba4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 28 Dec 2018 06:49:05 +0300 Subject: [PATCH] some minor refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/imagegrid/data.js | 37 ++++++++++++++++--------------------- ui (gen4)/imagegrid/tags.js | 14 +++++++------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 9d70cf0e..31d2665b 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -3022,27 +3022,22 @@ var DataWithTagsPrototype = { return this }, toggleTag: function(tag, gids, action){ - gids = gids == null || gids == 'current' ? - this.current - : gids == 'ribbon' ? - this.getImages('current') - : gids == 'loaded' ? - this.getImages('loaded') - : gids == 'all' ? - this.getImages('all') - : gids - - var res = this.tags.toggle(tag, gids, action) - - return res === this.tags ? - this - : res === true ? - 'on' - : res === false ? - 'off' - : res - .map(function(r){ return r ? 'on' : 'off' }) - }, + var that = this + return this.tags.toggle(tag, + gids == null || gids == 'current' ? + this.current + : gids == 'ribbon' ? + this.getImages('current') + : gids == 'loaded' ? + this.getImages('loaded') + : gids == 'all' ? + this.getImages('all') + : gids, + action) + .run(function(){ + return this === that.tags ? + that + : this }) }, // XXX should these be .tags.query(..) ??? diff --git a/ui (gen4)/imagegrid/tags.js b/ui (gen4)/imagegrid/tags.js index 9012379f..9b91e22e 100755 --- a/ui (gen4)/imagegrid/tags.js +++ b/ui (gen4)/imagegrid/tags.js @@ -1022,7 +1022,7 @@ var BaseTagsPrototype = { // Toggle tag for each values... // .toggle(tag, value) // .toggle(tag, values) - // -> [bool|null, ..] + // -> ['on'|'off'|null, ..] // NOTE: if tag is a tag pattern (contains '*') this will toggle // matching tags values off as expected but ignore toggling // tags on in which case null will be returned for the @@ -1046,7 +1046,7 @@ var BaseTagsPrototype = { // Check if tag is set on value(s)... // .toggle(tag, value, '?') // .toggle(tag, values, '?') - // -> [bool, ..] + // -> ['on'|'off', ..] // // // NOTE: this supports tag patterns (see: ,match(..)) @@ -1061,7 +1061,7 @@ var BaseTagsPrototype = { var ntag = this.normalize(tag) // can't set pattern as tag... - if(pattern && action != 'on'){ + if(pattern && action == 'on'){ throw new TypeError(`.toggle(..): will not toggle on "${tag}": pattern and not a tag.`) } @@ -1072,19 +1072,19 @@ var BaseTagsPrototype = { : action == '?' ? values .map(function(v){ - return pattern ? + return (pattern ? // non-strict pattern search... that.tags(v, tag) // strict test... - : that.tags(v).indexOf(ntag) >= 0 }) + : that.tags(v).indexOf(ntag) >= 0) ? 'on' : 'off' }) // toggle each... : values .map(function(v){ return that.tags(v, tag) ? - (that.untag(tag, v), false) + (that.untag(tag, v), 'off') // NOTE: we set only if we are not a pattern... : (!pattern ? - (that.tag(tag, v), true) + (that.tag(tag, v), 'on') : null) }) }, // Replace tags...