Compare commits

..

No commits in common. "a07a69c0f5bde4ecf5b27cc861415b8612f6d573" and "801777234f051da25603bfc5937fcea4319bdf82" have entirely different histories.

2 changed files with 297 additions and 525 deletions

View File

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

File diff suppressed because it is too large Load Diff