mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
added a stub recursive iterator...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b77bbb4e52
commit
90afd124e9
@ -712,27 +712,9 @@ var BaseBrowserPrototype = {
|
||||
|
||||
// index...
|
||||
if(typeof(key) == typeof(123)){
|
||||
var i = 0
|
||||
var items = this.items
|
||||
// XXX also need to:
|
||||
// - get header by index...
|
||||
// - get N'th item of a nested browser...
|
||||
while(i < items.length){
|
||||
var item =
|
||||
items[i].value instanceof Browser ?
|
||||
items[i].value.get(key-i)
|
||||
: items[i].sublist instanceof Browser ?
|
||||
items[i].sublist.get(key-i)
|
||||
: items[i].sublist instanceof Array ?
|
||||
items[i].sublist[key-i]
|
||||
: items[i]
|
||||
|
||||
if(i >= key){
|
||||
return item
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
// XXX this needs to return as soon as we find an item and
|
||||
// not construct the whole list...
|
||||
return this.iter()[key]
|
||||
|
||||
// key...
|
||||
// XXX account for paths...
|
||||
@ -761,6 +743,33 @@ var BaseBrowserPrototype = {
|
||||
return undefined
|
||||
},
|
||||
|
||||
|
||||
iter: function(func){
|
||||
var that = this
|
||||
var doElem = function(elem){
|
||||
return [func ?
|
||||
func.call(that, elem)
|
||||
: elem] }
|
||||
return this.items
|
||||
.map(function(elem){
|
||||
return (
|
||||
// value is Browser (inline)...
|
||||
elem.value instanceof Browser ?
|
||||
elem.value.iter(func)
|
||||
// .sublist is Browser (nested)...
|
||||
: elem.sublist instanceof Browser ?
|
||||
doElem(elem)
|
||||
.concat(elem.sublist.iter(func))
|
||||
// .sublist is Array (nested)...
|
||||
: elem.sublist instanceof Array ?
|
||||
doElem(elem)
|
||||
.concat(func ?
|
||||
elem.sublist.map(func.bind(that))
|
||||
: elem.sublist.slice())
|
||||
// normal item...
|
||||
: doElem(elem) ) })
|
||||
.flat() },
|
||||
|
||||
//
|
||||
// .find(id)
|
||||
// .find(index)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user