mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
more speedup and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a04ac505c5
commit
da5048b971
@ -479,16 +479,14 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// XXX is this the right way to go???
|
// XXX is this the right way to go???
|
||||||
['updateImage', function(_, gid, img){
|
['updateImage', function(_, gid, img){
|
||||||
// update only when ribbons are preset...
|
// NOTE: we are not using .toggleMark(..) here as this
|
||||||
if(this.ribbons != null){
|
// does not need to depend on the 'edit' feature...
|
||||||
// NOTE: we are not using .toggleMark(..) here as this
|
this.ribbons
|
||||||
// does not need to depend on the 'edit' feature...
|
&& this.ribbons
|
||||||
if(this.data.toggleTag('selected', gid, '?') == 'on'){
|
.toggleImageMark(
|
||||||
this.ribbons.toggleImageMark(gid, 'selected', 'on')
|
gid,
|
||||||
} else {
|
'selected',
|
||||||
this.ribbons.toggleImageMark(gid, 'selected', 'off')
|
this.data.hasTag(gid, 'selected') ? 'on' : 'off')
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -604,14 +602,12 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
|
|||||||
handlers: [
|
handlers: [
|
||||||
// XXX is this the right way to go???
|
// XXX is this the right way to go???
|
||||||
['updateImage', function(_, gid, img){
|
['updateImage', function(_, gid, img){
|
||||||
// update only when ribbons are preset...
|
this.ribbons
|
||||||
if(this.ribbons != null){
|
&& this.ribbons
|
||||||
if(this.data.toggleTag('bookmark', gid, '?') == 'on'){
|
.toggleImageMark(
|
||||||
this.ribbons.toggleImageMark(gid, 'bookmark', 'on')
|
gid,
|
||||||
} else {
|
'bookmark',
|
||||||
this.ribbons.toggleImageMark(gid, 'bookmark', 'off')
|
this.data.hasTag(gid, 'bookmark') ? 'on' : 'off')
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -379,11 +379,13 @@ var DataPrototype = {
|
|||||||
// NOTE: this is slow-ish...
|
// NOTE: this is slow-ish...
|
||||||
removeDuplicates: function(lst, skip_undefined){
|
removeDuplicates: function(lst, skip_undefined){
|
||||||
skip_undefined = skip_undefined == null ? true : skip_undefined
|
skip_undefined = skip_undefined == null ? true : skip_undefined
|
||||||
|
var lst_idx = lst.toKeys()
|
||||||
for(var i=0; i < lst.length; i++){
|
for(var i=0; i < lst.length; i++){
|
||||||
if(skip_undefined && lst[i] == null){
|
if(skip_undefined && lst[i] == null){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if(lst.indexOf(lst[i]) != i){
|
//if(lst.indexOf(lst[i]) != i){
|
||||||
|
if(lst_idx[lst[i]] != i){
|
||||||
lst.splice(i, 1)
|
lst.splice(i, 1)
|
||||||
i -= 1
|
i -= 1
|
||||||
}
|
}
|
||||||
@ -3126,27 +3128,26 @@ var DataWithTagsPrototype = {
|
|||||||
return gids.length > 1 ? gids.map(function(gid){ return 'off' }) : 'off'
|
return gids.length > 1 ? gids.map(function(gid){ return 'off' }) : 'off'
|
||||||
}
|
}
|
||||||
var that = this
|
var that = this
|
||||||
var tagset = this.tags
|
var tagset = this.tags || {}
|
||||||
var order = this.order
|
var order = this.order
|
||||||
var res = gids.map(function(gid){
|
var order_idx = order.toKeys()
|
||||||
gid = that.getImage(gid)
|
var res = tag in tagset ?
|
||||||
if(!(tag in tagset)){
|
gids.map(function(gid){
|
||||||
return 'off'
|
gid = that.getImage(gid)
|
||||||
}
|
return tagset[tag][order_idx[gid]] != null ? 'on' : 'off'
|
||||||
//return that.getTags(gid).indexOf(tag) != -1 ? 'on' : 'off'
|
})
|
||||||
return tagset[tag][order.indexOf(gid)] != null ? 'on' : 'off'
|
: gids.map(function(){ return 'off' })
|
||||||
})
|
|
||||||
|
|
||||||
// toggle each...
|
// toggle each...
|
||||||
} else {
|
} else {
|
||||||
var that = this
|
var that = this
|
||||||
var tagset = this.tags
|
var tagset = this.tags
|
||||||
var order = this.order
|
var order = this.order
|
||||||
|
var order_idx = order.toKeys()
|
||||||
var res = gids.map(function(gid){
|
var res = gids.map(function(gid){
|
||||||
gid = that.getImage(gid)
|
gid = that.getImage(gid)
|
||||||
//var t = that.getTags(gid).indexOf(tag) != -1 ? 'off' : 'on'
|
|
||||||
var t = tagset == null || !(tag in tagset) ? 'on'
|
var t = tagset == null || !(tag in tagset) ? 'on'
|
||||||
: tagset[tag][order.indexOf(gid)] == null ? 'on'
|
: tagset[tag][order_idx[gid]] == null ? 'on'
|
||||||
: 'off'
|
: 'off'
|
||||||
if(t == 'on'){
|
if(t == 'on'){
|
||||||
that.tag(tag, gid)
|
that.tag(tag, gid)
|
||||||
@ -3160,6 +3161,8 @@ var DataWithTagsPrototype = {
|
|||||||
return res.length == 1 ? res[0] : res
|
return res.length == 1 ? res[0] : res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
hasTag: function(gid, tag){
|
||||||
|
return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 },
|
||||||
getTags: function(gids){
|
getTags: function(gids){
|
||||||
gids = arguments.length > 1 ? [].slice.call(arguments)
|
gids = arguments.length > 1 ? [].slice.call(arguments)
|
||||||
: gids == null || gids == 'current' ? this.getImage()
|
: gids == null || gids == 'current' ? this.getImage()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user