mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
working on item access...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
616d22a30f
commit
b77bbb4e52
@ -50,21 +50,23 @@ var widget = require('./widget')
|
|||||||
// and the previous item created (.prevItem()), ... etc.
|
// and the previous item created (.prevItem()), ... etc.
|
||||||
// ...this would enable us to uniquely identify the actual items
|
// ...this would enable us to uniquely identify the actual items
|
||||||
// and prevent allot of specific errors...
|
// and prevent allot of specific errors...
|
||||||
var collectItems = function(context, items){
|
var collectItems = function(make, items){
|
||||||
var made = items
|
var made = items
|
||||||
.filter(function(e){
|
.filter(function(e){
|
||||||
return e === context })
|
return e === make })
|
||||||
// constructed item list...
|
// constructed item list...
|
||||||
// ...remove each instance from .items
|
// ...remove each instance from .items
|
||||||
made = context.items.splice(
|
made = make.items.splice(
|
||||||
context.items.length - made.length,
|
make.items.length - made.length,
|
||||||
made.length)
|
made.length)
|
||||||
// get the actual item values...
|
// get the actual item values...
|
||||||
return items
|
return items
|
||||||
.map(function(e){
|
.map(function(e){
|
||||||
return e === context ?
|
return e === make ?
|
||||||
made.shift()
|
made.shift()
|
||||||
: e }) }
|
// raw item -> make(..)
|
||||||
|
: (make(e)
|
||||||
|
&& make.items.pop()) }) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -704,13 +706,33 @@ var BaseBrowserPrototype = {
|
|||||||
// -> undefined
|
// -> undefined
|
||||||
//
|
//
|
||||||
// XXX add path support...
|
// XXX add path support...
|
||||||
|
// XXX add literal item support (???)
|
||||||
get: function(key){
|
get: function(key){
|
||||||
key = key == null ? 0 : key
|
key = key == null ? 0 : key
|
||||||
|
|
||||||
// index...
|
// index...
|
||||||
if(typeof(key) == typeof(123)){
|
if(typeof(key) == typeof(123)){
|
||||||
// XXX need to account for nesting browsers and groups...
|
var i = 0
|
||||||
throw new Error('Not implemented.')
|
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++
|
||||||
|
}
|
||||||
|
|
||||||
// key...
|
// key...
|
||||||
// XXX account for paths...
|
// XXX account for paths...
|
||||||
@ -731,6 +753,7 @@ var BaseBrowserPrototype = {
|
|||||||
var n = nested.shift().sublist
|
var n = nested.shift().sublist
|
||||||
var res = n.get(key)
|
var res = n.get(key)
|
||||||
if(res !== undefined){
|
if(res !== undefined){
|
||||||
|
// return first match...
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -748,6 +771,16 @@ var BaseBrowserPrototype = {
|
|||||||
find: function(){
|
find: function(){
|
||||||
},
|
},
|
||||||
|
|
||||||
|
next: function(){},
|
||||||
|
prev: function(){},
|
||||||
|
|
||||||
|
// XXX should there return an array or a .constructor(..) instance??
|
||||||
|
forEach: function(){},
|
||||||
|
map: function(){},
|
||||||
|
filter: function(){},
|
||||||
|
reduce: function(){},
|
||||||
|
|
||||||
|
|
||||||
// XXX do we need edit ability here?
|
// XXX do we need edit ability here?
|
||||||
// i.e. .set(..), .remove(..), .sort(..), ...
|
// i.e. .set(..), .remove(..), .sort(..), ...
|
||||||
// ...if we are going to implement editing then we'll need to
|
// ...if we are going to implement editing then we'll need to
|
||||||
@ -881,13 +914,6 @@ var BaseBrowserPrototype = {
|
|||||||
|
|
||||||
close: makeEventMethod('close', function(evt, reason){}),
|
close: makeEventMethod('close', function(evt, reason){}),
|
||||||
|
|
||||||
// XXX should there return an array or a .constructor(..) instance??
|
|
||||||
forEach: function(){},
|
|
||||||
map: function(){},
|
|
||||||
filter: function(){},
|
|
||||||
reduce: function(){},
|
|
||||||
|
|
||||||
|
|
||||||
// XXX should we update on on init....
|
// XXX should we update on on init....
|
||||||
__init__: function(func, options){
|
__init__: function(func, options){
|
||||||
this.__list__ = func
|
this.__list__ = func
|
||||||
@ -1184,15 +1210,15 @@ var BrowserPrototype = {
|
|||||||
|
|
||||||
// special-case: item shorthands...
|
// special-case: item shorthands...
|
||||||
if(item.value in options.elementShorthand){
|
if(item.value in options.elementShorthand){
|
||||||
item = options.elementShorthand[item.value]
|
var template = options.elementShorthand[item.value]
|
||||||
|
|
||||||
// NOTE: this is a bit of a cheat, but it saves us from either
|
// NOTE: this is a bit of a cheat, but it saves us from either
|
||||||
// parsing or restricting the format...
|
// parsing or restricting the format...
|
||||||
var elem = $(item.html)[0]
|
var elem = item.dom = $(template.html)[0]
|
||||||
elem.classList.add(
|
elem.classList.add(
|
||||||
...(item['class'] instanceof Array ?
|
...(template['class'] instanceof Array ?
|
||||||
item['class']
|
template['class']
|
||||||
: item['class'].split(/\s+/g)))
|
: template['class'].split(/\s+/g)))
|
||||||
|
|
||||||
return elem
|
return elem
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user