mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10: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...
|
// index...
|
||||||
if(typeof(key) == typeof(123)){
|
if(typeof(key) == typeof(123)){
|
||||||
var i = 0
|
// XXX this needs to return as soon as we find an item and
|
||||||
var items = this.items
|
// not construct the whole list...
|
||||||
// XXX also need to:
|
return this.iter()[key]
|
||||||
// - 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++
|
|
||||||
}
|
|
||||||
|
|
||||||
// key...
|
// key...
|
||||||
// XXX account for paths...
|
// XXX account for paths...
|
||||||
@ -761,6 +743,33 @@ var BaseBrowserPrototype = {
|
|||||||
return undefined
|
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(id)
|
||||||
// .find(index)
|
// .find(index)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user