mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-26 13:01:58 +00:00
more work on tags and some refactoring (Array.prototype.len now is a prop and not a function)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
22f90336ee
commit
7970a23c31
@ -355,7 +355,7 @@ var DataPrototype = {
|
|||||||
// clear empty ribbons only...
|
// clear empty ribbons only...
|
||||||
} else if(gids == 'empty'){
|
} else if(gids == 'empty'){
|
||||||
for(var r in this.ribbons){
|
for(var r in this.ribbons){
|
||||||
if(this.ribbons[r].len() == 0){
|
if(this.ribbons[r].len == 0){
|
||||||
this.clear(r)
|
this.clear(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1293,7 +1293,7 @@ var DataPrototype = {
|
|||||||
var res = this.shiftImage(gid, r-1, 'vertical')
|
var res = this.shiftImage(gid, r-1, 'vertical')
|
||||||
// clear empty ribbon...
|
// clear empty ribbon...
|
||||||
r = r == 0 ? 1 : r
|
r = r == 0 ? 1 : r
|
||||||
if(this.ribbons[this.ribbon_order[r]].len() == 0){
|
if(this.ribbons[this.ribbon_order[r]].len == 0){
|
||||||
var b = this.getRibbonOrder(this.base)-1
|
var b = this.getRibbonOrder(this.base)-1
|
||||||
|
|
||||||
r = this.ribbon_order.splice(r, 1)[0]
|
r = this.ribbon_order.splice(r, 1)[0]
|
||||||
@ -1315,7 +1315,7 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
var res = this.shiftImage(gid, r+1, 'vertical')
|
var res = this.shiftImage(gid, r+1, 'vertical')
|
||||||
// clear empty ribbon...
|
// clear empty ribbon...
|
||||||
if(this.ribbons[this.ribbon_order[r]].len() == 0){
|
if(this.ribbons[this.ribbon_order[r]].len == 0){
|
||||||
var b = this.getRibbonOrder(this.base)-1
|
var b = this.getRibbonOrder(this.base)-1
|
||||||
|
|
||||||
r = this.ribbon_order.splice(r, 1)[0]
|
r = this.ribbon_order.splice(r, 1)[0]
|
||||||
@ -1858,10 +1858,16 @@ var DataWithTagsPrototype = {
|
|||||||
|
|
||||||
if(this.tags != null){
|
if(this.tags != null){
|
||||||
var tags = this.tags
|
var tags = this.tags
|
||||||
res.tags = {}
|
var restags = {}
|
||||||
Object.keys(tags).forEach(function(tag){
|
Object.keys(tags).forEach(function(tag){
|
||||||
res.tags[tag] = tags[tag].compact()
|
var lst = tags[tag].compact()
|
||||||
|
if(lst.len > 0){
|
||||||
|
restags[tag] = lst
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
if(Object.keys(restags).length > 0){
|
||||||
|
res.tags = restags
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -1896,6 +1902,7 @@ var DataWithTagsPrototype = {
|
|||||||
var order = this.order
|
var order = this.order
|
||||||
tags.forEach(function(tag){
|
tags.forEach(function(tag){
|
||||||
gids.forEach(function(gid){
|
gids.forEach(function(gid){
|
||||||
|
gid = that.getImage(gid)
|
||||||
if(tagset[tag] == null){
|
if(tagset[tag] == null){
|
||||||
tagset[tag] = []
|
tagset[tag] = []
|
||||||
}
|
}
|
||||||
@ -1906,6 +1913,9 @@ var DataWithTagsPrototype = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
untag: function(tags, gids){
|
untag: function(tags, gids){
|
||||||
|
if(this.tags == null){
|
||||||
|
return this
|
||||||
|
}
|
||||||
tags = tags.constructor !== Array ? [tags] : tags
|
tags = tags.constructor !== Array ? [tags] : tags
|
||||||
|
|
||||||
gids = gids == null ? this.getImage() : gids
|
gids = gids == null ? this.getImage() : gids
|
||||||
@ -1915,19 +1925,69 @@ var DataWithTagsPrototype = {
|
|||||||
var tagset = this.tags
|
var tagset = this.tags
|
||||||
var order = this.order
|
var order = this.order
|
||||||
tags.forEach(function(tag){
|
tags.forEach(function(tag){
|
||||||
gids.forEach(function(gid){
|
if(tag in tagset){
|
||||||
delete tagset[tag][order.indexOf(gid)]
|
gids.forEach(function(gid){
|
||||||
})
|
if(tag in tagset){
|
||||||
if(tagset[tag].length == 0){
|
delete tagset[tag][order.indexOf(gid)]
|
||||||
delete tagset[tag]
|
}
|
||||||
|
})
|
||||||
|
if(tagset[tag].len == 0){
|
||||||
|
delete tagset[tag]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX
|
// NOTE: this does not support multiple tags at this point...
|
||||||
toggleTag: function(tags, gids, action){
|
toggleTag: function(tag, gids, action){
|
||||||
|
gids = gids == null ? this.getImage() : gids
|
||||||
|
gids = gids.constructor !== Array ? [gids] : gids
|
||||||
|
|
||||||
|
// tag all...
|
||||||
|
if(action == 'on'){
|
||||||
|
this.tag(tag, gids)
|
||||||
|
return action
|
||||||
|
|
||||||
|
// untag all...
|
||||||
|
} else if(action == 'off'){
|
||||||
|
this.untag(tag, gids)
|
||||||
|
return action
|
||||||
|
|
||||||
|
// get tag state...
|
||||||
|
} else if(action == '?'){
|
||||||
|
if(this.tags == null){
|
||||||
|
return gids.map(function(gid){ return 'off' })
|
||||||
|
}
|
||||||
|
var that = this
|
||||||
|
var tagset = this.tags
|
||||||
|
var order = this.order
|
||||||
|
var res = gids.map(function(gid){
|
||||||
|
//return that.getTags(gid).indexOf(tag) != -1 ? 'on' : 'off'
|
||||||
|
return tagset[tag][order.indexOf(gid)] != null ? 'on' : 'off'
|
||||||
|
})
|
||||||
|
|
||||||
|
// toggle each...
|
||||||
|
} else {
|
||||||
|
var that = this
|
||||||
|
var tagset = this.tags
|
||||||
|
var order = this.order
|
||||||
|
var res = gids.map(function(gid){
|
||||||
|
//var t = that.getTags(gid).indexOf(tag) != -1 ? 'off' : 'on'
|
||||||
|
var t = tagset == null ? 'on'
|
||||||
|
: tagset[tag][order.indexOf(gid)] == null ? 'on'
|
||||||
|
: 'off'
|
||||||
|
if(t == 'on'){
|
||||||
|
that.tag(tag, gid)
|
||||||
|
} else {
|
||||||
|
that.untag(tag, gid)
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.length == 1 ? res[0] : res
|
||||||
},
|
},
|
||||||
|
|
||||||
getTags: function(gids){
|
getTags: function(gids){
|
||||||
|
|||||||
@ -1044,21 +1044,21 @@ function makeDeferredPool(size, paused){
|
|||||||
// prepare to remove self from pool...
|
// prepare to remove self from pool...
|
||||||
var i = pool.indexOf(this)
|
var i = pool.indexOf(this)
|
||||||
|
|
||||||
Pool._event_handlers.progress.fire(pool.length - pool.len(), pool.length + queue.length)
|
Pool._event_handlers.progress.fire(pool.length - pool.len, pool.length + queue.length)
|
||||||
|
|
||||||
// remove self from queue...
|
// remove self from queue...
|
||||||
delete pool[i]
|
delete pool[i]
|
||||||
|
|
||||||
// shrink the pool if it's overfilled...
|
// shrink the pool if it's overfilled...
|
||||||
// i.e. do not pop another worker and let the "thread" die.
|
// i.e. do not pop another worker and let the "thread" die.
|
||||||
if(pool.len() > pool_size){
|
if(pool.len > pool_size){
|
||||||
// remove self...
|
// remove self...
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// pause the queue -- do not do anything else...
|
// pause the queue -- do not do anything else...
|
||||||
if(that._paused == true){
|
if(that._paused == true){
|
||||||
// if pool is empty fire the pause event...
|
// if pool is empty fire the pause event...
|
||||||
if(pool.len() == 0){
|
if(pool.len == 0){
|
||||||
Pool._event_handlers.pause.fire()
|
Pool._event_handlers.pause.fire()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -1072,7 +1072,7 @@ function makeDeferredPool(size, paused){
|
|||||||
run.apply(that, next)
|
run.apply(that, next)
|
||||||
|
|
||||||
// empty queue AND empty pool mean we are done...
|
// empty queue AND empty pool mean we are done...
|
||||||
} else if(pool.len() == 0){
|
} else if(pool.len == 0){
|
||||||
var l = pool.length
|
var l = pool.length
|
||||||
// NOTE: potential race condition -- something can be
|
// NOTE: potential race condition -- something can be
|
||||||
// pushed to pool just before it's "compacted"...
|
// pushed to pool just before it's "compacted"...
|
||||||
@ -1087,7 +1087,7 @@ function makeDeferredPool(size, paused){
|
|||||||
that._fill()
|
that._fill()
|
||||||
})
|
})
|
||||||
.fail(function(){
|
.fail(function(){
|
||||||
Pool._event_handlers.fail.fire(pool.length - pool.len(), pool.length + queue.length)
|
Pool._event_handlers.fail.fire(pool.length - pool.len, pool.length + queue.length)
|
||||||
deferred.reject.apply(deferred, arguments)
|
deferred.reject.apply(deferred, arguments)
|
||||||
})
|
})
|
||||||
.progress(function(){
|
.progress(function(){
|
||||||
@ -1106,7 +1106,7 @@ function makeDeferredPool(size, paused){
|
|||||||
var that = this
|
var that = this
|
||||||
var pool_size = this.size
|
var pool_size = this.size
|
||||||
var run = this._run
|
var run = this._run
|
||||||
var l = this.pool.len()
|
var l = this.pool.len
|
||||||
|
|
||||||
if(this._paused != true
|
if(this._paused != true
|
||||||
&& l < pool_size
|
&& l < pool_size
|
||||||
@ -1161,7 +1161,7 @@ function makeDeferredPool(size, paused){
|
|||||||
Pool.doneFilling = function(){
|
Pool.doneFilling = function(){
|
||||||
delete this._filling
|
delete this._filling
|
||||||
// trigger depleted if we are empty...
|
// trigger depleted if we are empty...
|
||||||
if(this.pool.len() == 0 && this.queue.length == 0){
|
if(this.pool.len == 0 && this.queue.length == 0){
|
||||||
that._event_handlers.deplete.fire(l)
|
that._event_handlers.deplete.fire(l)
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
@ -1204,7 +1204,7 @@ function makeDeferredPool(size, paused){
|
|||||||
return this._paused
|
return this._paused
|
||||||
}
|
}
|
||||||
Pool.isRunning = function(){
|
Pool.isRunning = function(){
|
||||||
return this.pool.len() > 0
|
return this.pool.len > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1337,10 +1337,19 @@ Array.prototype.compact = function(){
|
|||||||
|
|
||||||
// like .length but for sparse arrays will return the element count...
|
// like .length but for sparse arrays will return the element count...
|
||||||
// XXX make this a prop...
|
// XXX make this a prop...
|
||||||
|
/*
|
||||||
Array.prototype.len = function(){
|
Array.prototype.len = function(){
|
||||||
//return this.compact().length
|
//return this.compact().length
|
||||||
return Object.keys(this).length
|
return Object.keys(this).length
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object.defineProperty(Array.prototype, 'len', {
|
||||||
|
get : function () {
|
||||||
|
return Object.keys(this).length
|
||||||
|
},
|
||||||
|
set : function(val){},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// convert JS arguments to Array...
|
// convert JS arguments to Array...
|
||||||
|
|||||||
@ -168,6 +168,17 @@ module.GLOBAL_KEYBOARD = {
|
|||||||
ctrl: 'uncropAll',
|
ctrl: 'uncropAll',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// marking...
|
||||||
|
A: {
|
||||||
|
ctrl: 'toggleMark!: "ribbon" "on"',
|
||||||
|
},
|
||||||
|
D: {
|
||||||
|
ctrl: 'toggleMark!: "ribbon" "off"',
|
||||||
|
},
|
||||||
|
I: {
|
||||||
|
ctrl: 'toggleMark!: "ribbon"',
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1767,17 +1767,51 @@ module.GlobalStateIndicator = Feature({
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX add image updater...
|
||||||
var ImageMarkActions = actions.Actions({
|
var ImageMarkActions = actions.Actions({
|
||||||
|
// target can be:
|
||||||
|
// 'all'
|
||||||
|
// 'loaded'
|
||||||
|
// 'ribbon' - current ribbon
|
||||||
|
// ribbon - specific ribbon (gid)
|
||||||
|
// Array
|
||||||
|
//
|
||||||
|
// XXX make this a real toggler... ???
|
||||||
toggleMark: ['',
|
toggleMark: ['',
|
||||||
// XXX make this a real toggler...
|
|
||||||
function(target, action){
|
function(target, action){
|
||||||
// XXX do tagging on data and get the correct action if one is not given...
|
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
|
||||||
|
|
||||||
|
var res = this.data.toggleTag('selected', target, action)
|
||||||
|
|
||||||
if(this.ribbons != null){
|
if(this.ribbons != null){
|
||||||
this.ribbons.toggleImageMark(target, 'selected', action)
|
var that = this
|
||||||
|
target.forEach(function(t){
|
||||||
|
that.ribbons.toggleImageMark(t, 'selected', action)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return action
|
return res
|
||||||
|
}],
|
||||||
|
toggleMarkBlock: ['',
|
||||||
|
function(){
|
||||||
|
// XXX
|
||||||
|
}],
|
||||||
|
|
||||||
|
markTagged: ['',
|
||||||
|
function(tags, mode){
|
||||||
|
var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll'
|
||||||
|
|
||||||
|
var that = this
|
||||||
|
this.data[selector](tags).forEach(function(gid){
|
||||||
|
that.toggleMark(gid, 'on')
|
||||||
|
})
|
||||||
}],
|
}],
|
||||||
|
|
||||||
// XXX do we need first/last marked???
|
// XXX do we need first/last marked???
|
||||||
@ -1805,6 +1839,24 @@ module.ImageMarks = Feature({
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
var ImageBookmarkActions = actions.Actions({
|
var ImageBookmarkActions = actions.Actions({
|
||||||
|
toggleBookmark: ['',
|
||||||
|
function(){
|
||||||
|
}],
|
||||||
|
// action can be:
|
||||||
|
// 'on' - toggle all on
|
||||||
|
// 'off' - toggle all off
|
||||||
|
// 'next' - toggle each image to next state
|
||||||
|
toggleBookmarkOnMarked: ['',
|
||||||
|
function(action){
|
||||||
|
}],
|
||||||
|
|
||||||
|
prevBookmarked: ['',
|
||||||
|
function(mode){ this.prevTagged('bookmarked', mode) }],
|
||||||
|
nextBookmarked: ['',
|
||||||
|
function(mode){ this.nextTagged('bookmarked', mode) }],
|
||||||
|
|
||||||
|
cropBookmarked: ['',
|
||||||
|
function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -1817,13 +1869,6 @@ module.ImageBookmarks = Feature({
|
|||||||
|
|
||||||
actions: ImageBookmarkActions,
|
actions: ImageBookmarkActions,
|
||||||
|
|
||||||
prevBookmarked: ['',
|
|
||||||
function(mode){ this.prevTagged('bookmarked', mode) }],
|
|
||||||
nextBookmarked: ['',
|
|
||||||
function(mode){ this.nextTagged('bookmarked', mode) }],
|
|
||||||
|
|
||||||
cropBookmarked: ['',
|
|
||||||
function(flatten){ this.cropTagged('bookmarked', 'any', flatten) }],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user