mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 10:50:08 +00:00
added .makeIndex(..) to images and some minor tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f983a7b611
commit
36c11e425a
@ -103,7 +103,14 @@ module.ImagesClassPrototype = {
|
|||||||
var ImagesPrototype =
|
var ImagesPrototype =
|
||||||
module.ImagesPrototype = {
|
module.ImagesPrototype = {
|
||||||
|
|
||||||
// Generic helpers...
|
// Generic iterators...
|
||||||
|
//
|
||||||
|
// function format:
|
||||||
|
// function(key, value, index, object)
|
||||||
|
//
|
||||||
|
// this will be set to the value...
|
||||||
|
//
|
||||||
|
//
|
||||||
// XXX are these slower than doing it manualy via Object.keys(..)
|
// XXX are these slower than doing it manualy via Object.keys(..)
|
||||||
forEach: function(func){
|
forEach: function(func){
|
||||||
var i = 0
|
var i = 0
|
||||||
@ -131,6 +138,39 @@ module.ImagesPrototype = {
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
keys: function(){
|
||||||
|
return Object.keys(this)
|
||||||
|
},
|
||||||
|
|
||||||
|
// Build an image index relative to an attribute...
|
||||||
|
//
|
||||||
|
// Format:
|
||||||
|
// {
|
||||||
|
// <attr-value> : [
|
||||||
|
// <gid>,
|
||||||
|
// ...
|
||||||
|
// ],
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// XXX test out the attr list functionality...
|
||||||
|
makeIndex: function(attr){
|
||||||
|
var res = {}
|
||||||
|
attr = attr.constructor.name != 'Array' ? [attr] : attr
|
||||||
|
|
||||||
|
// buld the index...
|
||||||
|
var that = this
|
||||||
|
this.forEach(function(key){
|
||||||
|
var n = attr.map(function(n){ return that[n] })
|
||||||
|
n = JSON.stringify(n.length == 1 ? n[0] : n)
|
||||||
|
// XXX is this the right way to go?
|
||||||
|
.replace(/^"(.*)"$/g, '$1')
|
||||||
|
res[n] = n in res ? res[n].concat(key) : [key]
|
||||||
|
})
|
||||||
|
|
||||||
|
return res
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// Image data helpers...
|
// Image data helpers...
|
||||||
|
|
||||||
@ -159,6 +199,7 @@ module.ImagesPrototype = {
|
|||||||
|
|
||||||
|
|
||||||
// Gid sorters...
|
// Gid sorters...
|
||||||
|
// XXX might be a good idea to add caching...
|
||||||
// XXX chainCmp(..) is loaded from lib/jli.js
|
// XXX chainCmp(..) is loaded from lib/jli.js
|
||||||
sortImages: function(gids, cmp, reverse){
|
sortImages: function(gids, cmp, reverse){
|
||||||
gids = gids == null ? Object.keys(this) : gids
|
gids = gids == null ? Object.keys(this) : gids
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user