mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
refactored List/makeList...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
2aa5d44df0
commit
cb1870da7c
@ -269,13 +269,77 @@ function(text, options){
|
|||||||
|
|
||||||
// Make list of elements...
|
// Make list of elements...
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// data format:
|
||||||
|
// [
|
||||||
|
// // single text element...
|
||||||
|
// <item-text>,
|
||||||
|
//
|
||||||
|
// // multi-text element...
|
||||||
|
// [<item-text>, ...],
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// ]
|
||||||
|
//
|
||||||
|
// or:
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// <item-lext>: <function>,
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// options format:
|
||||||
|
// {
|
||||||
|
// disableItemPattern: <pattern>,
|
||||||
|
//
|
||||||
|
// skipDisabledItems: false,
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
Items.List =
|
Items.List =
|
||||||
function(list, options){
|
function(data, options){
|
||||||
var make = this
|
var make = this
|
||||||
var res = []
|
var res = []
|
||||||
list.forEach(function(e){
|
var keys = data instanceof Array ? data : Object.keys(data)
|
||||||
res.push(make(e, options)[0])
|
var pattern = options.disableItemPattern
|
||||||
|
&& RegExp(options.disableItemPattern)
|
||||||
|
|
||||||
|
data.forEach(function(k){
|
||||||
|
var txt = k
|
||||||
|
var opts = Object.create(options)
|
||||||
|
|
||||||
|
if(pattern){
|
||||||
|
txt = k instanceof Array ? k[0] : k
|
||||||
|
|
||||||
|
var t = txt.replace(pattern, '')
|
||||||
|
|
||||||
|
// item matches disabled pattern...
|
||||||
|
if(t != txt){
|
||||||
|
opts.disabled = true
|
||||||
|
|
||||||
|
txt = k instanceof Array ?
|
||||||
|
[t].concat(k.slice(1))
|
||||||
|
: t
|
||||||
|
|
||||||
|
if(options.skipDisabledItems){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// no match -- restore text...
|
||||||
|
} else {
|
||||||
|
txt = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var elem = make(txt, opts)
|
||||||
|
|
||||||
|
keys !== data && data[k]
|
||||||
|
&& elem.on('open', data[k])
|
||||||
|
|
||||||
|
res.push(elem[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
return $(res)
|
return $(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2997,7 +3061,7 @@ module.makeLister = function(elem, lister, options){
|
|||||||
|
|
||||||
// Flat list...
|
// Flat list...
|
||||||
//
|
//
|
||||||
// This expects a data option set with the following format:
|
// This expects a data option set with the following formats:
|
||||||
// {
|
// {
|
||||||
// <option-text>: <callback>,
|
// <option-text>: <callback>,
|
||||||
// ...
|
// ...
|
||||||
@ -3030,51 +3094,22 @@ ListPrototype.options = {
|
|||||||
list: function(path, make){
|
list: function(path, make){
|
||||||
var that = this
|
var that = this
|
||||||
var data = this.options.data
|
var data = this.options.data
|
||||||
var keys = data.constructor == Array ? data : Object.keys(data)
|
|
||||||
var pattern = this.options.disableItemPattern
|
|
||||||
&& RegExp(this.options.disableItemPattern)
|
|
||||||
|
|
||||||
return keys
|
var res = []
|
||||||
.map(function(k){
|
|
||||||
var disable = null
|
|
||||||
var n = k
|
|
||||||
|
|
||||||
// XXX make this support list args as well...
|
// this is here to get the modified titles...
|
||||||
if(pattern){
|
var _make = function(txt){
|
||||||
var t = typeof(n) == typeof('str') ? n : n[0]
|
res.push(txt)
|
||||||
|
return make.apply(make, arguments)
|
||||||
|
}
|
||||||
|
_make.__proto__ = make
|
||||||
|
|
||||||
if(typeof(t) == typeof('str')){
|
_make.List(data, {
|
||||||
var tt = t.replace(pattern, '')
|
disableItemPattern: this.options.disableItemPattern,
|
||||||
if(t != tt){
|
skipDisabledItems: this.options.skipDisabledItems,
|
||||||
disable = true
|
})
|
||||||
|
|
||||||
if(typeof(k) == typeof('str')){
|
return res
|
||||||
n = tt
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// NOTE: here we want to avoid .data contamination
|
|
||||||
// so we'll make a copy...
|
|
||||||
n = n.slice()
|
|
||||||
n[0] = tt
|
|
||||||
}
|
|
||||||
|
|
||||||
if(that.options.skipDisabledItems){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var e = make(n, {disabled: disable})
|
|
||||||
|
|
||||||
if(data !== keys && that.options.data[k] != null){
|
|
||||||
e.on('open', function(){
|
|
||||||
return that.options.data[k].apply(this, arguments)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return k
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// XXX should we inherit or copy options???
|
// XXX should we inherit or copy options???
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user