mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
35a8a69f8f
commit
f3c432c5d1
@ -1589,158 +1589,163 @@ var BaseBrowserPrototype = {
|
|||||||
|| node.walk ) }
|
|| node.walk ) }
|
||||||
|
|
||||||
return walk(
|
return walk(
|
||||||
function(state, node, next, stop){
|
function(state, node, next, stop){
|
||||||
// keep only the root stop(..) -> stop the entire call tree...
|
// keep only the root stop(..) -> stop the entire call tree...
|
||||||
stop = context.stop = context.stop || stop
|
stop = context.stop = context.stop || stop
|
||||||
|
|
||||||
// skip non-iterable items...
|
// skip non-iterable items...
|
||||||
if(!iterateNonIterable && node.noniterable){
|
if(!iterateNonIterable && node.noniterable){
|
||||||
return state }
|
return state }
|
||||||
// skip disabled branch...
|
// skip disabled branch...
|
||||||
if(skipDisabled == 'branch' && node.disabled){
|
if(skipDisabled == 'branch' && node.disabled){
|
||||||
return state }
|
return state }
|
||||||
|
|
||||||
// XXX BUG?: doNested(false) will not count any of the
|
// XXX BUG?: doNested(false) will not count any of the
|
||||||
// skipped elements thus messing up i...
|
// skipped elements thus messing up i...
|
||||||
// ...we can't just use .length as this would 1)
|
// ...we can't just use .length as this would 1)
|
||||||
// introduce a branch in the protocol + would not
|
// introduce a branch in the protocol + would not
|
||||||
// comply with the passed options in all cases but
|
// comply with the passed options in all cases but
|
||||||
// the default...
|
// the default...
|
||||||
// ...one way to do this is to set func to a dud
|
// ...one way to do this is to set func to a dud
|
||||||
// the only problem we have is the next(..) call
|
// the only problem we have is the next(..) call
|
||||||
// below that will call the parent function and
|
// below that will call the parent function and
|
||||||
// mess things up... we can go around this via
|
// mess things up... we can go around this via
|
||||||
// the context (context.skipping) but this feels
|
// the context (context.skipping) but this feels
|
||||||
// hack-ish...
|
// hack-ish...
|
||||||
var nested = false
|
var nested = false
|
||||||
var doNested = function(list){
|
var doNested = function(list){
|
||||||
// this can be called only once -> return cached results...
|
// this can be called only once -> return cached results...
|
||||||
if(nested !== false){
|
if(nested !== false){
|
||||||
return nested }
|
return nested }
|
||||||
// calling this on a node without .children is a no-op...
|
// calling this on a node without .children is a no-op...
|
||||||
if(children == null){
|
if(children == null){
|
||||||
return [] }
|
return [] }
|
||||||
|
|
||||||
// normalize...
|
// normalize...
|
||||||
list = list === true ?
|
list = list === true ?
|
||||||
children
|
children
|
||||||
: (!iterateCollapsed && node.collapsed) ?
|
: (!iterateCollapsed && node.collapsed) ?
|
||||||
[]
|
|
||||||
: list == null ?
|
|
||||||
children
|
|
||||||
: list
|
|
||||||
|
|
||||||
// call .walk(..) recursively...
|
|
||||||
var useWalk = function(){
|
|
||||||
return list.walk(
|
|
||||||
func,
|
|
||||||
recursion,
|
|
||||||
...(formArgs instanceof Function ?
|
|
||||||
[formArgs]
|
|
||||||
: [walkable]),
|
|
||||||
options, context) }
|
|
||||||
|
|
||||||
return (
|
|
||||||
// XXX BUG?: in this case we lose item indexing...
|
|
||||||
list === false || list == 'skip' ?
|
|
||||||
[]
|
[]
|
||||||
// handle arrays internally...
|
: list == null ?
|
||||||
: list instanceof Array ?
|
children
|
||||||
// NOTE: this gets the path and i from context...
|
: list
|
||||||
next('do', [],
|
|
||||||
...(reverse ?
|
// call .walk(..) recursively...
|
||||||
list.slice().reverse()
|
var useWalk = function(){
|
||||||
: list))
|
return list.walk(
|
||||||
// user-defined recursion...
|
func,
|
||||||
: recursion instanceof Function ?
|
recursion,
|
||||||
recursion.call(that,
|
...(formArgs instanceof Function ?
|
||||||
list, context.index, p,
|
[formArgs]
|
||||||
options, context,
|
: [walkable]),
|
||||||
func, useWalk)
|
options, context) }
|
||||||
// method with arg forming...
|
|
||||||
: formArgs instanceof Function
|
return (
|
||||||
&& list[recursion] ?
|
// XXX BUG?: in this case we lose item indexing...
|
||||||
list[recursion](
|
list === false || list == 'skip' ?
|
||||||
...(formArgs(
|
[]
|
||||||
|
// handle arrays internally...
|
||||||
|
: list instanceof Array ?
|
||||||
|
// NOTE: this gets the path and i from context...
|
||||||
|
next('do', [],
|
||||||
|
...(reverse ?
|
||||||
|
list.slice().reverse()
|
||||||
|
: list))
|
||||||
|
// user-defined recursion...
|
||||||
|
: recursion instanceof Function ?
|
||||||
|
recursion.call(that,
|
||||||
list, context.index, p,
|
list, context.index, p,
|
||||||
options, context,
|
options, context,
|
||||||
func, useWalk) || []))
|
func, useWalk)
|
||||||
// .walk(..)
|
// method with arg forming...
|
||||||
: useWalk())
|
: formArgs instanceof Function
|
||||||
// normalize and merge to state...
|
&& list[recursion] ?
|
||||||
.run(function(){
|
list[recursion](
|
||||||
return (nested = this instanceof Array ?
|
...(formArgs(
|
||||||
this
|
list, context.index, p,
|
||||||
: [this]) }) }
|
options, context,
|
||||||
|
func, useWalk) || []))
|
||||||
|
// .walk(..)
|
||||||
|
: useWalk())
|
||||||
|
// normalize and merge to state...
|
||||||
|
.run(function(){
|
||||||
|
return (nested = this instanceof Array ?
|
||||||
|
this
|
||||||
|
: [this]) }) }
|
||||||
|
|
||||||
// prepare context...
|
// prepare context...
|
||||||
var id = node.id
|
var id = node.id
|
||||||
var path = context.path = context.path || []
|
var path = context.path = context.path || []
|
||||||
var [inline, p, children] =
|
var [inline, p, children] =
|
||||||
// inline...
|
// inline...
|
||||||
isWalkable(node) ?
|
isWalkable(node) ?
|
||||||
[true, path.slice(), node]
|
[true, path.slice(), node]
|
||||||
// nested...
|
// nested...
|
||||||
: (!skipNested && isWalkable(node.children)) ?
|
: (!skipNested && isWalkable(node.children)) ?
|
||||||
[false,
|
[false,
|
||||||
// update context for nested items...
|
// update context for nested items...
|
||||||
path.push(id)
|
path.push(id)
|
||||||
&& path.slice(),
|
&& path.slice(),
|
||||||
node.children]
|
node.children]
|
||||||
// leaf...
|
// leaf...
|
||||||
: [false, path.concat([id]), undefined]
|
: [false, path.concat([id]), undefined]
|
||||||
|
|
||||||
if(inline && skipInlined){
|
if(inline && skipInlined){
|
||||||
return state }
|
return state }
|
||||||
|
|
||||||
// go through the elements...
|
// go through the elements...
|
||||||
state.splice(state.length, 0,
|
state.splice(state.length, 0,
|
||||||
...[
|
...[
|
||||||
// reverse -> do children...
|
// reverse -> do children...
|
||||||
reverse == 'flat'
|
reverse == 'flat'
|
||||||
&& children
|
&& children
|
||||||
&& doNested()
|
&& doNested()
|
||||||
|| [],
|
|| [],
|
||||||
// do element...
|
// do element...
|
||||||
!(skipDisabled && node.disabled) ?
|
!(skipDisabled && node.disabled) ?
|
||||||
(func ?
|
(func ?
|
||||||
(func.call(that,
|
(func.call(that,
|
||||||
...(inline ?
|
...(inline ?
|
||||||
[null, context.index]
|
[null, context.index]
|
||||||
: [node, context.index++]),
|
: [node, context.index++]),
|
||||||
p,
|
p,
|
||||||
// NOTE: when calling this it is the
|
// NOTE: when calling this it is the
|
||||||
// responsibility of the caller to return
|
// responsibility of the caller to return
|
||||||
// the result to be added to state...
|
// the result to be added to state...
|
||||||
doNested,
|
doNested,
|
||||||
stop,
|
stop,
|
||||||
children) || [])
|
children) || [])
|
||||||
: [node])
|
: [node])
|
||||||
// element is disabled -> handle children...
|
// element is disabled -> handle children...
|
||||||
: [],
|
: [],
|
||||||
// normal order -> do children...
|
// normal order -> do children...
|
||||||
children
|
children
|
||||||
&& nested === false
|
&& nested === false
|
||||||
&& doNested()
|
&& doNested()
|
||||||
|| [],
|
|| [],
|
||||||
].flat())
|
].flat())
|
||||||
|
|
||||||
// restore path context...
|
// restore path context...
|
||||||
children
|
children
|
||||||
&& context.path.pop()
|
&& context.path.pop()
|
||||||
|
|
||||||
return state
|
return state
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
// input items...
|
// input items...
|
||||||
...(sections
|
...(sections
|
||||||
.map(function(name){
|
.map(function(name){
|
||||||
return that[name] || [] })
|
return that[name] || [] })
|
||||||
.flat()
|
.flat()
|
||||||
.run(function(){
|
.run(function(){
|
||||||
return reverse ?
|
return reverse ?
|
||||||
this.reverse()
|
this.reverse()
|
||||||
: this }))) },
|
: this })))
|
||||||
|
// NOTE: walk(..) if passed to items will return a function...
|
||||||
|
.run(function(){
|
||||||
|
return this instanceof Function ?
|
||||||
|
[]
|
||||||
|
: this})},
|
||||||
|
|
||||||
|
|
||||||
// Test/Example Text renders...
|
// Test/Example Text renders...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user