mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
refactored tag toggler constructor to use an actual toggler instead of emulating one...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
44368d9f78
commit
5a50cd04d4
@ -31,18 +31,11 @@ var base = require('features/base')
|
|||||||
// Array
|
// Array
|
||||||
//
|
//
|
||||||
// NOTE: of no data is defined this will not have any effect...
|
// NOTE: of no data is defined this will not have any effect...
|
||||||
|
// NOTE: we are not using the vanilla toggler here as it can't handle
|
||||||
|
// toggling independently multiple elements...
|
||||||
function makeTagTogglerAction(tag){
|
function makeTagTogglerAction(tag){
|
||||||
var t = function(target, action){
|
// get actual target gids...
|
||||||
if(target == '?' || target == '??'|| target == 'on' || target == 'off'){
|
var _getTarget = function(target){
|
||||||
var x = action
|
|
||||||
action = target
|
|
||||||
target = x
|
|
||||||
}
|
|
||||||
// special case: no data...
|
|
||||||
if(this.data == null){
|
|
||||||
return action == '??' ? ['on', 'off'] : 'off'
|
|
||||||
}
|
|
||||||
|
|
||||||
target = target || 'current'
|
target = target || 'current'
|
||||||
target = target == 'all'
|
target = target == 'all'
|
||||||
|| target == 'loaded'
|
|| target == 'loaded'
|
||||||
@ -50,89 +43,64 @@ function makeTagTogglerAction(tag){
|
|||||||
? this.data.getImages(target)
|
? this.data.getImages(target)
|
||||||
: target == 'ribbon' ? this.data.getImages('current')
|
: target == 'ribbon' ? this.data.getImages('current')
|
||||||
: target
|
: target
|
||||||
target = target.constructor !== Array ? [target] : target
|
return target.constructor !== Array ? [target] : target
|
||||||
|
}
|
||||||
|
|
||||||
// on...
|
// the toggler...
|
||||||
if(action == 'on'){
|
var _tagToggler = toggler.Toggler('current',
|
||||||
this.tag(tag, target)
|
function(target, action){
|
||||||
var res = 'on'
|
target = _getTarget.call(this, target)
|
||||||
|
// get state...
|
||||||
|
if(action == null){
|
||||||
|
var res = this.data.toggleTag(tag, target, '?')
|
||||||
|
return res.length == 1 ? res[0] : res
|
||||||
|
|
||||||
// off...
|
} else if(action == 'on'){
|
||||||
} else if(action == 'off'){
|
this.tag(tag, target)
|
||||||
this.untag(tag, target)
|
} else if(action == 'off'){
|
||||||
var res = 'off'
|
this.untag(tag, target)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
['off', 'on'])
|
||||||
|
|
||||||
// ?
|
// the action...
|
||||||
} else if(action == '?'){
|
var action = function(target, action){
|
||||||
var res = this.data.toggleTag(tag, target, '?')
|
// special case: no data...
|
||||||
res = res.length == 1 ? res[0] : res
|
if(this.data == null){
|
||||||
|
return action == '??' ? ['off', 'on'] : 'off'
|
||||||
|
|
||||||
// ??
|
// special case: multiple targets and toggle action...
|
||||||
} else if(action == '??'){
|
} else if((target == 'all' || target == 'loaded' || target == 'ribbon'
|
||||||
res = ['on', 'off']
|
|| target instanceof Array)
|
||||||
|
&& (action == null || action == 'next' || action == 'prev'
|
||||||
// next...
|
|| action == '!')){
|
||||||
} else {
|
|
||||||
var res = []
|
var res = []
|
||||||
var that = this
|
var that = this
|
||||||
|
target = _getTarget.call(this, target)
|
||||||
target.forEach(function(t){
|
target.forEach(function(t){
|
||||||
if(that.data.getTags(t).indexOf(tag) < 0){
|
if((that.data.getTags(t).indexOf(tag) < 0)
|
||||||
|
// invert check if action is '!'...
|
||||||
|
+ (action == '!' ? -1 : 0)){
|
||||||
that.tag(tag, t)
|
that.tag(tag, t)
|
||||||
res.push('on')
|
res.push('on')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
that.untag(tag, t)
|
that.untag(tag, t)
|
||||||
res.push('off')
|
res.push('off')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
res = res.length == 1 ? res[0] : res
|
return res.length == 1 ? res[0] : res
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
// normal case...
|
||||||
|
return _tagToggler.call(this, target, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cheating a bit...
|
// cheating a bit...
|
||||||
t.__proto__ = toggler.Toggler.prototype
|
action.__proto__ = toggler.Toggler.prototype
|
||||||
t.constructor = toggler.Toggler
|
action.constructor = toggler.Toggler
|
||||||
|
return action
|
||||||
return t
|
|
||||||
}
|
}
|
||||||
/* XXX this toggler is not fully compatible with the Toggler interface
|
|
||||||
* thus, we either need to update the Toggler to suppor multiple
|
|
||||||
* values or keep this...
|
|
||||||
function makeTagTogglerAction(tag){
|
|
||||||
return toggler.Toggler(null,
|
|
||||||
function(target, action){
|
|
||||||
// get the target...
|
|
||||||
target = target || 'current'
|
|
||||||
target = target == 'all'
|
|
||||||
|| target == 'loaded'
|
|
||||||
|| target in this.data.ribbons
|
|
||||||
? this.data.getImages(target)
|
|
||||||
: target == 'ribbon' ? this.data.getImages('current')
|
|
||||||
: target
|
|
||||||
target = target.constructor !== Array ? [target] : target
|
|
||||||
|
|
||||||
// get state...
|
|
||||||
if(action == null){
|
|
||||||
var res = this.data.toggleTag(tag, target, '?')
|
|
||||||
|
|
||||||
return res.constructor == Array ? res
|
|
||||||
: res == 'on' ? tag
|
|
||||||
: 'none'
|
|
||||||
|
|
||||||
// on...
|
|
||||||
} else if(action == tag){
|
|
||||||
this.tag(tag, target)
|
|
||||||
|
|
||||||
// off...
|
|
||||||
} else {
|
|
||||||
this.untag(tag, target)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tag)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user