mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
adding item count to .walk(..), not yet counting correctly...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
af1a315d6e
commit
a26ba942cf
@ -115,8 +115,9 @@ requirejs([
|
|||||||
//make('e')
|
//make('e')
|
||||||
// embeded browser...
|
// embeded browser...
|
||||||
make(browser.Browser(function(make){
|
make(browser.Browser(function(make){
|
||||||
make('nested browser item 0')
|
make('inlined browser item 0')
|
||||||
make(1)
|
make(1)
|
||||||
|
make(2)
|
||||||
}))
|
}))
|
||||||
// basic nested list...
|
// basic nested list...
|
||||||
make.nest('nested', [
|
make.nest('nested', [
|
||||||
|
|||||||
@ -742,11 +742,11 @@ var BaseBrowserPrototype = {
|
|||||||
// collapsed...
|
// collapsed...
|
||||||
(item.collapsed ?
|
(item.collapsed ?
|
||||||
null
|
null
|
||||||
// renderable...
|
// renderable...
|
||||||
:item.sublist.render instanceof Function ?
|
: item.sublist.render instanceof Function ?
|
||||||
item.sublist.render(context)
|
item.sublist.render(context)
|
||||||
// list of items...
|
// list of items...
|
||||||
: item.sublist.map(_render)),
|
: item.sublist.map(_render)),
|
||||||
item,
|
item,
|
||||||
context)
|
context)
|
||||||
// basic item...
|
// basic item...
|
||||||
@ -1275,7 +1275,7 @@ var BaseBrowserPrototype = {
|
|||||||
// -> result
|
// -> result
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// item_handler(path, elem, nested, sublist)
|
// item_handler(path, elem, index, nested, sublist)
|
||||||
// -> array
|
// -> array
|
||||||
//
|
//
|
||||||
// nested(list[, options])
|
// nested(list[, options])
|
||||||
@ -1317,6 +1317,7 @@ var BaseBrowserPrototype = {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// XXX item count is broken...
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
walk: function(func, options){
|
walk: function(func, options){
|
||||||
var that = this
|
var that = this
|
||||||
@ -1330,6 +1331,9 @@ var BaseBrowserPrototype = {
|
|||||||
|| typeof(args[0]) == typeof('str')) ?
|
|| typeof(args[0]) == typeof('str')) ?
|
||||||
args.shift()
|
args.shift()
|
||||||
: undefined
|
: undefined
|
||||||
|
var i = typeof(args[0]) == typeof(123) ?
|
||||||
|
args.shift()
|
||||||
|
: 0
|
||||||
var path = (args[0] instanceof Array
|
var path = (args[0] instanceof Array
|
||||||
|| typeof(args[0]) == typeof('str')) ?
|
|| typeof(args[0]) == typeof('str')) ?
|
||||||
args.shift()
|
args.shift()
|
||||||
@ -1374,35 +1378,39 @@ var BaseBrowserPrototype = {
|
|||||||
: (list || sublist)
|
: (list || sublist)
|
||||||
list = list === true ? sublist : list
|
list = list === true ? sublist : list
|
||||||
nested_called = true
|
nested_called = true
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// request manual iteration...
|
// request manual iteration...
|
||||||
(skip || list === false) ?
|
(skip || list === false) ?
|
||||||
[]
|
[]
|
||||||
:list instanceof Array ?
|
:list instanceof Array ?
|
||||||
walk(p, list)
|
walk(p, list)
|
||||||
// user-defined recursion...
|
// user-defined recursion...
|
||||||
: recursion instanceof Function ?
|
: recursion instanceof Function ?
|
||||||
recursion.call(that, func, p, list, opts || options)
|
recursion.call(that, func, i, p, list, opts || options)
|
||||||
: list[recursion || 'walk'](func, p, opts || options)) }
|
: list[recursion || 'walk'](func, i, p, opts || options))
|
||||||
|
.run(function(){
|
||||||
|
i += this.length-1 })}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// inline browser or array...
|
// inline browser or array...
|
||||||
(elem instanceof Array
|
(elem instanceof Array
|
||||||
|| elem instanceof Browser) ?
|
|| elem instanceof Browser) ?
|
||||||
|
// XXX need to decrement i here...
|
||||||
func.call(that,
|
func.call(that,
|
||||||
p = path,
|
i, p = path,
|
||||||
null, nested,
|
null, nested,
|
||||||
sublist = elem)
|
sublist = elem)
|
||||||
// nested browser / array...
|
// nested browser / array...
|
||||||
: (elem.sublist instanceof Browser
|
: (elem.sublist instanceof Browser
|
||||||
|| elem.sublist instanceof Array) ?
|
|| elem.sublist instanceof Array) ?
|
||||||
func.call(that,
|
func.call(that,
|
||||||
p = path.concat([elem_id]),
|
i++, p = path.concat([elem_id]),
|
||||||
elem, nested,
|
elem, nested,
|
||||||
sublist = elem.sublist)
|
sublist = elem.sublist)
|
||||||
// normal element...
|
// normal element...
|
||||||
: func.call(that,
|
: func.call(that,
|
||||||
p = path.concat([elem_id]),
|
i++, p = path.concat([elem_id]),
|
||||||
elem, null,
|
elem, null,
|
||||||
sublist = null) )
|
sublist = null) )
|
||||||
// append nested elements...
|
// append nested elements...
|
||||||
@ -1433,9 +1441,12 @@ var BaseBrowserPrototype = {
|
|||||||
options = context.options
|
options = context.options
|
||||||
renderer = renderer || this
|
renderer = renderer || this
|
||||||
|
|
||||||
|
var getValue = function(item){
|
||||||
|
return item.value || item }
|
||||||
|
|
||||||
var items = this
|
var items = this
|
||||||
.walk(
|
.walk(
|
||||||
function(path, item, nested, sublist){
|
function(i, path, item, nested, sublist){
|
||||||
var indent = path.map(e => ' ').join('')
|
var indent = path.map(e => ' ').join('')
|
||||||
return (
|
return (
|
||||||
// inline...
|
// inline...
|
||||||
@ -1444,16 +1455,19 @@ var BaseBrowserPrototype = {
|
|||||||
// inline browser/list, i.e. ignoring
|
// inline browser/list, i.e. ignoring
|
||||||
// options.skipNested for inline stuff...
|
// options.skipNested for inline stuff...
|
||||||
nested(true)
|
nested(true)
|
||||||
.map(e => indent + (e.value || e))
|
.map(function(e){
|
||||||
|
return indent + getValue(e) })
|
||||||
// nested...
|
// nested...
|
||||||
: sublist ?
|
: sublist ?
|
||||||
[item.value]
|
[item.value]
|
||||||
.concat(
|
.concat(
|
||||||
nested()
|
nested()
|
||||||
.map(e => indent + (e.value || e)))
|
.map(function(e){
|
||||||
: [item.value || item]
|
return indent + getValue(e) }))
|
||||||
|
// single item...
|
||||||
|
: [getValue(item)]
|
||||||
) },
|
) },
|
||||||
function(func, path, sublist, options){
|
function(func, i, path, sublist, options){
|
||||||
return sublist.text2(context) },
|
return sublist.text2(context) },
|
||||||
options)
|
options)
|
||||||
|
|
||||||
@ -1480,10 +1494,14 @@ var BaseBrowserPrototype = {
|
|||||||
options = context.options
|
options = context.options
|
||||||
renderer = renderer || this
|
renderer = renderer || this
|
||||||
|
|
||||||
|
var getValue = function(item){
|
||||||
|
return item.value || item }
|
||||||
|
|
||||||
var items = this
|
var items = this
|
||||||
.walk(
|
.walk(
|
||||||
function(path, item, nested, sublist){
|
function(i, path, item, nested, sublist){
|
||||||
var indent = path.map(e => ' ').join('')
|
var indent = path.map(e => ' ').join('')
|
||||||
|
// XXX call renderers...
|
||||||
return (
|
return (
|
||||||
// inline...
|
// inline...
|
||||||
(item == null && sublist) ?
|
(item == null && sublist) ?
|
||||||
@ -1491,20 +1509,21 @@ var BaseBrowserPrototype = {
|
|||||||
// inline browser/list, i.e. ignoring
|
// inline browser/list, i.e. ignoring
|
||||||
// options.skipNested for inline stuff...
|
// options.skipNested for inline stuff...
|
||||||
nested(true)
|
nested(true)
|
||||||
.map(e => indent + (e.value || e))
|
|
||||||
// nested...
|
// nested...
|
||||||
: sublist ?
|
: sublist ?
|
||||||
[item.value]
|
renderer.renderNested(
|
||||||
.concat(
|
that.renderNestedHeader(item, i, context),
|
||||||
nested()
|
nested(),
|
||||||
.map(e => indent + (e.value || e)))
|
item,
|
||||||
: [item.value || item]
|
context)
|
||||||
|
// normal item...
|
||||||
|
: that.renderItem(item, i, context)
|
||||||
) },
|
) },
|
||||||
function(func, path, sublist, options){
|
function(func, path, sublist, options){
|
||||||
return sublist.render2(context) })
|
return sublist.render2(context) })
|
||||||
|
|
||||||
return context.root === this ?
|
return context.root === this ?
|
||||||
items.join('\n')
|
renderer.renderList(items, context)
|
||||||
: items
|
: items
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1521,6 +1540,9 @@ var BaseBrowserPrototype = {
|
|||||||
func = args[0] instanceof Function ?
|
func = args[0] instanceof Function ?
|
||||||
args.shift()
|
args.shift()
|
||||||
: undefined
|
: undefined
|
||||||
|
var i = typeof(args[0]) == typeof(123) ?
|
||||||
|
args.shift()
|
||||||
|
: 0
|
||||||
var path = (args[0] instanceof Array
|
var path = (args[0] instanceof Array
|
||||||
|| typeof(args[0]) == typeof('str')) ?
|
|| typeof(args[0]) == typeof('str')) ?
|
||||||
args.shift()
|
args.shift()
|
||||||
@ -1528,17 +1550,19 @@ var BaseBrowserPrototype = {
|
|||||||
var options = args.pop() || {}
|
var options = args.pop() || {}
|
||||||
|
|
||||||
return this.walk(
|
return this.walk(
|
||||||
function(path, elem){
|
function(i, path, elem){
|
||||||
return elem != null ?
|
return elem != null ?
|
||||||
[func === undefined ?
|
[func === undefined ?
|
||||||
elem
|
elem
|
||||||
: func.call(that, elem, path)]
|
: func.call(that, elem, i, path)]
|
||||||
: [] },
|
: [] },
|
||||||
function(_, path, sublist, options){
|
function(_, i, path, sublist, options){
|
||||||
// NOTE: this needs to call the actual func that the user
|
// NOTE: this needs to call the actual func that the user
|
||||||
// gave us and not the constructed function that we
|
// gave us and not the constructed function that we
|
||||||
// pass to .walk(..) above...
|
// pass to .walk(..) above...
|
||||||
return sublist.map2(func, path, options) },
|
// XXX need to get the number of items passed here into current i...
|
||||||
|
return sublist.map2(func, i, path, options) },
|
||||||
|
i,
|
||||||
path,
|
path,
|
||||||
options)
|
options)
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user