mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
cleanup, refactoring and revision...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
906c9ff4d6
commit
69ff309718
@ -1461,23 +1461,48 @@ var BaseBrowserPrototype = {
|
|||||||
// ...keys that are numbers for some reason are first and sorted
|
// ...keys that are numbers for some reason are first and sorted
|
||||||
// by value and not by position...
|
// by value and not by position...
|
||||||
// XXX should we use .hasOwnProperty(..)???
|
// XXX should we use .hasOwnProperty(..)???
|
||||||
|
// XXX INLINED_BLOCKS_IN_LIST: do we need to include inlined blocks in .index???
|
||||||
|
// ...if yes then how??
|
||||||
__item_index_cache: null,
|
__item_index_cache: null,
|
||||||
get index(){
|
get index(){
|
||||||
|
var that = this
|
||||||
return (this.__item_index_cache =
|
return (this.__item_index_cache =
|
||||||
(this.hasOwnProperty('__item_index_cache') && this.__item_index_cache)
|
(this.hasOwnProperty('__item_index_cache') && this.__item_index_cache)
|
||||||
|| this
|
|| this
|
||||||
.reduce(function(index, e, i, p){
|
.reduce(function(index, e, i, p){
|
||||||
|
/* XXX INLINED_BLOCKS_IN_LIST
|
||||||
|
// generate a unique id if needed (inlined arrays)...
|
||||||
|
if(p[p.length-1] === undefined){
|
||||||
|
do {
|
||||||
|
var k = that.__key__(e)
|
||||||
|
} while(k in index)
|
||||||
|
p.splice(p.length-1, 1, k)
|
||||||
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
var id = p = p.join('/')
|
var id = p = p.join('/')
|
||||||
var c = 0
|
var c = 0
|
||||||
// generate a unique id...
|
|
||||||
|
/* XXX INLINED_BLOCKS_IN_LIST
|
||||||
|
// store id if not set...
|
||||||
|
!(id in e)
|
||||||
|
&& (e.id = id)
|
||||||
|
//*/
|
||||||
|
|
||||||
|
// make id unique...
|
||||||
// NOTE: no need to check if e.id is unique as we already
|
// NOTE: no need to check if e.id is unique as we already
|
||||||
// did this in make(..)...
|
// did this in make(..)...
|
||||||
while(id in index){
|
while(id in index){
|
||||||
id = this.__id__(p, ++c) }
|
id = this.__id__(p, ++c) }
|
||||||
index[id] = e
|
index[id] = e
|
||||||
|
|
||||||
return index
|
return index
|
||||||
}.bind(this), {},
|
}.bind(this), {},
|
||||||
{ iterateAll: true, includeInlinedBlocks: true })) },
|
{
|
||||||
|
iterateAll: true,
|
||||||
|
// XXX INLINED_BLOCKS_IN_LIST
|
||||||
|
//includeInlinedBlocks: true,
|
||||||
|
})) },
|
||||||
|
|
||||||
// Flat item index...
|
// Flat item index...
|
||||||
//
|
//
|
||||||
@ -1704,6 +1729,8 @@ var BaseBrowserPrototype = {
|
|||||||
// : opts)
|
// : opts)
|
||||||
// XXX revise if stage 2 is applicable to sections other than .items
|
// XXX revise if stage 2 is applicable to sections other than .items
|
||||||
// XXX INLINED_ID: generate id's for inlined items (inlined arrays)...
|
// XXX INLINED_ID: generate id's for inlined items (inlined arrays)...
|
||||||
|
// ...where do we store .id for arrays???
|
||||||
|
// ...should the id be human-readable, something like inlined<date> ???
|
||||||
make: function(options){
|
make: function(options){
|
||||||
var that = this
|
var that = this
|
||||||
options = Object.assign(
|
options = Object.assign(
|
||||||
@ -1955,7 +1982,8 @@ var BaseBrowserPrototype = {
|
|||||||
//
|
//
|
||||||
// Ignore current .children...
|
// Ignore current .children...
|
||||||
// next()
|
// next()
|
||||||
// -> children
|
// next(false)
|
||||||
|
// -> []
|
||||||
//
|
//
|
||||||
// Force children processing synchronously...
|
// Force children processing synchronously...
|
||||||
// next(true)
|
// next(true)
|
||||||
@ -3124,7 +3152,7 @@ var BaseBrowserPrototype = {
|
|||||||
root: null,
|
root: null,
|
||||||
|
|
||||||
// renderers...
|
// renderers...
|
||||||
/*/
|
//
|
||||||
// render paths...
|
// render paths...
|
||||||
elem: function(elem, index, path, options){
|
elem: function(elem, index, path, options){
|
||||||
return path.join('/') },
|
return path.join('/') },
|
||||||
@ -3178,6 +3206,8 @@ var BaseBrowserPrototype = {
|
|||||||
// XXX args parsing...
|
// XXX args parsing...
|
||||||
// XXX
|
// XXX
|
||||||
|
|
||||||
|
// NOTE: base_index and base_path only apply to the 'items'
|
||||||
|
// section...
|
||||||
var args = [...arguments]
|
var args = [...arguments]
|
||||||
var base_path = args[args.length-1] instanceof Array ?
|
var base_path = args[args.length-1] instanceof Array ?
|
||||||
args.pop()
|
args.pop()
|
||||||
@ -3214,9 +3244,21 @@ var BaseBrowserPrototype = {
|
|||||||
// ...the difference is filtering here will maintain topology...
|
// ...the difference is filtering here will maintain topology...
|
||||||
|
|
||||||
|
|
||||||
|
// used as a means to calculate lengths of nested blocks rendered
|
||||||
|
// via .render2(..)
|
||||||
var l
|
var l
|
||||||
return ((render.root === this && section instanceof Array) ?
|
return ((render.root === this && section instanceof Array) ?
|
||||||
// render list of sections...
|
// render list of sections...
|
||||||
|
//
|
||||||
|
// format:
|
||||||
|
// {
|
||||||
|
// <section-name>: [ <item>, ... ],
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// NOTE: we will only render the section list on the top
|
||||||
|
// level on all lower levels only the specific section
|
||||||
|
// is rendered for all nested browsers...
|
||||||
section
|
section
|
||||||
.reduce(function(res, name){
|
.reduce(function(res, name){
|
||||||
res[name] = that.render2(
|
res[name] = that.render2(
|
||||||
@ -3226,30 +3268,51 @@ var BaseBrowserPrototype = {
|
|||||||
section: name,
|
section: name,
|
||||||
nonFinalized: true,
|
nonFinalized: true,
|
||||||
}),
|
}),
|
||||||
render)
|
render,
|
||||||
|
// NOTE: base_index and base_path only apply
|
||||||
|
// to the 'items' section...
|
||||||
|
...(name == 'items' ?
|
||||||
|
[base_index, base_path]
|
||||||
|
: []))
|
||||||
return res }, {})
|
return res }, {})
|
||||||
|
|
||||||
// render single section...
|
// render single section...
|
||||||
: this.walk(
|
: this.walk(
|
||||||
function(e, i, p, children){
|
function(e, i, p, children){
|
||||||
|
// index...
|
||||||
// NOTE: since we let the nested browsers render sections
|
// NOTE: since we let the nested browsers render sections
|
||||||
// of the list, we also need to compensate for the
|
// of the list, we also need to compensate for the
|
||||||
// number of elements they render...
|
// number of elements they render...
|
||||||
base_index += (l || []).length
|
base_index += (l || []).length
|
||||||
l = []
|
|
||||||
i += base_index
|
i += base_index
|
||||||
|
l = []
|
||||||
|
|
||||||
|
// path...
|
||||||
// remove inlined item id from path...
|
// remove inlined item id from path...
|
||||||
// NOTE: render.inline(..) can add this back if needed...
|
// NOTE: render.inline(..) can add this back if needed...
|
||||||
;(e instanceof BaseBrowser || e instanceof Array)
|
;(e instanceof BaseBrowser || e instanceof Array)
|
||||||
&& p.pop()
|
&& p.pop()
|
||||||
|
|
||||||
p = base_path.concat(p)
|
p = base_path.concat(p)
|
||||||
|
|
||||||
|
// children...
|
||||||
// do not go down child browsers -- use their .render2(..)
|
// do not go down child browsers -- use their .render2(..)
|
||||||
;(e instanceof BaseBrowser
|
// NOTE: doing so will require us to manually handle some
|
||||||
|
// of the options that would otherwise be handled
|
||||||
|
// by .walk(..)...
|
||||||
|
var inlined = (e instanceof BaseBrowser
|
||||||
|| e.children instanceof BaseBrowser)
|
|| e.children instanceof BaseBrowser)
|
||||||
&& children(false)
|
&& !children(false)
|
||||||
|
// get children either via .walk(..) or .render2(..)
|
||||||
|
// depending on item type...
|
||||||
|
var getChildren = function(){
|
||||||
|
return inlined ?
|
||||||
|
(l = (e.children instanceof BaseBrowser ?
|
||||||
|
e.children
|
||||||
|
: e)
|
||||||
|
.render2(options, render, i+1, p))
|
||||||
|
: children(true) }
|
||||||
|
|
||||||
|
// do the actual rendering...
|
||||||
return (
|
return (
|
||||||
// skip...
|
// skip...
|
||||||
// XXX
|
// XXX
|
||||||
@ -3259,32 +3322,25 @@ var BaseBrowserPrototype = {
|
|||||||
// XXX need to maintain topology...
|
// XXX need to maintain topology...
|
||||||
|
|
||||||
// inlined...
|
// inlined...
|
||||||
: e instanceof BaseBrowser ?
|
: (e instanceof BaseBrowser || e instanceof Array) ?
|
||||||
render.inline(
|
render.inline(e,
|
||||||
e,
|
// handling non-propageted options...
|
||||||
l = e.render2(options, render, i+1, p),
|
!options.skipInlined ?
|
||||||
i, p, options)
|
getChildren()
|
||||||
: e instanceof Array ?
|
: [],
|
||||||
render.inline(
|
|
||||||
e,
|
|
||||||
children(true),
|
|
||||||
i, p, options)
|
i, p, options)
|
||||||
|
|
||||||
// nested...
|
// nested...
|
||||||
: e.children instanceof BaseBrowser ?
|
: 'children' in e ?
|
||||||
render.nest(e,
|
render.nest(e,
|
||||||
// NOTE: we handle .collapsed here as the nested
|
// handling non-propageted options...
|
||||||
// browser is one level down and knows nothing
|
(!options.skipNested
|
||||||
// of it...
|
&& (options.iterateCollapsed || !e.collapsed)) ?
|
||||||
(options.iterateCollapsed || !e.collapsed)
|
getChildren()
|
||||||
&& (l = e.children.render2(options, render, i+1, p)),
|
: [],
|
||||||
i, p, options)
|
|
||||||
: e.children instanceof Array ?
|
|
||||||
render.nest(e,
|
|
||||||
children(true),
|
|
||||||
i, p, options)
|
i, p, options)
|
||||||
|
|
||||||
// normal item...
|
// basic item...
|
||||||
: render.elem(e, i, p, options) )
|
: render.elem(e, i, p, options) )
|
||||||
}, options))
|
}, options))
|
||||||
// finalize render...
|
// finalize render...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user