updated style...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2024-10-30 17:17:08 +03:00
parent f93a44bd93
commit a07a69c0f5

View File

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