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
},
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(..) ???

View File

@ -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...