some minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-28 06:49:05 +03:00
parent b7a8f1a784
commit c168b22e38
2 changed files with 23 additions and 28 deletions

View File

@ -3022,27 +3022,22 @@ var DataWithTagsPrototype = {
return this return this
}, },
toggleTag: function(tag, gids, action){ toggleTag: function(tag, gids, action){
gids = gids == null || gids == 'current' ? var that = this
this.current return this.tags.toggle(tag,
: gids == 'ribbon' ? gids == null || gids == 'current' ?
this.getImages('current') this.current
: gids == 'loaded' ? : gids == 'ribbon' ?
this.getImages('loaded') this.getImages('current')
: gids == 'all' ? : gids == 'loaded' ?
this.getImages('all') this.getImages('loaded')
: gids : gids == 'all' ?
this.getImages('all')
var res = this.tags.toggle(tag, gids, action) : gids,
action)
return res === this.tags ? .run(function(){
this return this === that.tags ?
: res === true ? that
'on' : this }) },
: res === false ?
'off'
: res
.map(function(r){ return r ? 'on' : 'off' })
},
// XXX should these be .tags.query(..) ??? // XXX should these be .tags.query(..) ???

View File

@ -1022,7 +1022,7 @@ var BaseTagsPrototype = {
// Toggle tag for each values... // Toggle tag for each values...
// .toggle(tag, value) // .toggle(tag, value)
// .toggle(tag, values) // .toggle(tag, values)
// -> [bool|null, ..] // -> ['on'|'off'|null, ..]
// NOTE: if tag is a tag pattern (contains '*') this will toggle // NOTE: if tag is a tag pattern (contains '*') this will toggle
// matching tags values off as expected but ignore toggling // matching tags values off as expected but ignore toggling
// tags on in which case null will be returned for the // 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)... // Check if tag is set on value(s)...
// .toggle(tag, value, '?') // .toggle(tag, value, '?')
// .toggle(tag, values, '?') // .toggle(tag, values, '?')
// -> [bool, ..] // -> ['on'|'off', ..]
// //
// //
// NOTE: this supports tag patterns (see: ,match(..)) // NOTE: this supports tag patterns (see: ,match(..))
@ -1061,7 +1061,7 @@ var BaseTagsPrototype = {
var ntag = this.normalize(tag) var ntag = this.normalize(tag)
// can't set pattern as 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.`) throw new TypeError(`.toggle(..): will not toggle on "${tag}": pattern and not a tag.`)
} }
@ -1072,19 +1072,19 @@ var BaseTagsPrototype = {
: action == '?' ? : action == '?' ?
values values
.map(function(v){ .map(function(v){
return pattern ? return (pattern ?
// non-strict pattern search... // non-strict pattern search...
that.tags(v, tag) that.tags(v, tag)
// strict test... // strict test...
: that.tags(v).indexOf(ntag) >= 0 }) : that.tags(v).indexOf(ntag) >= 0) ? 'on' : 'off' })
// toggle each... // toggle each...
: values : values
.map(function(v){ .map(function(v){
return that.tags(v, tag) ? 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... // NOTE: we set only if we are not a pattern...
: (!pattern ? : (!pattern ?
(that.tag(tag, v), true) (that.tag(tag, v), 'on')
: null) }) }, : null) }) },
// Replace tags... // Replace tags...