mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
tweaks and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d1746ce0d0
commit
03685c643c
@ -1235,24 +1235,24 @@ var BaseBrowserPrototype = {
|
|||||||
// path test...
|
// path test...
|
||||||
// NOTE: this does not go down branches that do not match the path...
|
// NOTE: this does not go down branches that do not match the path...
|
||||||
path: function(pattern){
|
path: function(pattern){
|
||||||
// XXX add support for '**' ???
|
if(pattern instanceof Array){
|
||||||
var cmp = function(a, b){
|
// XXX add support for '**' ???
|
||||||
return a.length == b.length
|
var cmp = function(a, b){
|
||||||
&& !a
|
return a.length == b.length
|
||||||
.reduce(function(res, e, i){
|
&& !a
|
||||||
return res || !(
|
.reduce(function(res, e, i){
|
||||||
e == '*'
|
return res || !(
|
||||||
|| (e instanceof RegExp
|
e == '*'
|
||||||
&& e.test(b[i]))
|
|| (e instanceof RegExp
|
||||||
|| e == b[i]) }, false) }
|
&& e.test(b[i]))
|
||||||
var onPath = function(path){
|
|| e == b[i]) }, false) }
|
||||||
return pattern.length >= path.length
|
var onPath = function(path){
|
||||||
&& cmp(
|
return pattern.length >= path.length
|
||||||
pattern.slice(0, path.length),
|
&& cmp(
|
||||||
path) }
|
pattern.slice(0, path.length),
|
||||||
|
path) }
|
||||||
|
|
||||||
return pattern instanceof Array
|
return function(elem, i, path, next){
|
||||||
&& function(elem, i, path, next){
|
|
||||||
// do not go down branches beyond pattern length or
|
// do not go down branches beyond pattern length or
|
||||||
// ones that are not on path...
|
// ones that are not on path...
|
||||||
;(pattern.length == path.length
|
;(pattern.length == path.length
|
||||||
@ -1261,7 +1261,10 @@ var BaseBrowserPrototype = {
|
|||||||
// do the test...
|
// do the test...
|
||||||
return path.length > 0
|
return path.length > 0
|
||||||
&& pattern.length == path.length
|
&& pattern.length == path.length
|
||||||
&& cmp(pattern, path) } },
|
&& cmp(pattern, path) }
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
// item index test...
|
// item index test...
|
||||||
index: function(pattern){
|
index: function(pattern){
|
||||||
return typeof(pattern) == typeof(123)
|
return typeof(pattern) == typeof(123)
|
||||||
@ -1300,10 +1303,9 @@ var BaseBrowserPrototype = {
|
|||||||
|
|
||||||
// parse args...
|
// parse args...
|
||||||
var args = [...arguments]
|
var args = [...arguments]
|
||||||
pattern = args.shift()
|
pattern = args.length == 0 ?
|
||||||
pattern = pattern === undefined ?
|
|
||||||
true
|
true
|
||||||
: pattern
|
: args.shift()
|
||||||
func = (args[0] instanceof Function
|
func = (args[0] instanceof Function
|
||||||
|| args[0] === undefined) ?
|
|| args[0] === undefined) ?
|
||||||
args.shift()
|
args.shift()
|
||||||
@ -1314,16 +1316,18 @@ var BaseBrowserPrototype = {
|
|||||||
// pattern -- normalize and do pattern keywords...
|
// pattern -- normalize and do pattern keywords...
|
||||||
pattern = options.ignoreKeywords ?
|
pattern = options.ignoreKeywords ?
|
||||||
pattern
|
pattern
|
||||||
: (pattern === 'all' || pattern == '*') ?
|
: typeof(pattern) == typeof('str') ?
|
||||||
true
|
((pattern === 'all' || pattern == '*') ?
|
||||||
: pattern == 'first' ?
|
true
|
||||||
0
|
: pattern == 'first' ?
|
||||||
: pattern == 'last' ?
|
0
|
||||||
-1
|
: pattern == 'last' ?
|
||||||
: pattern == 'selected' ?
|
-1
|
||||||
{selected: true}
|
: pattern == 'selected' ?
|
||||||
: pattern == 'focused' ?
|
{selected: true}
|
||||||
{focused: true}
|
: pattern == 'focused' ?
|
||||||
|
{focused: true}
|
||||||
|
: pattern)
|
||||||
: pattern
|
: pattern
|
||||||
// normalize negative index...
|
// normalize negative index...
|
||||||
if(typeof(pattern) == typeof(123) && pattern < 0){
|
if(typeof(pattern) == typeof(123) && pattern < 0){
|
||||||
@ -1340,7 +1344,7 @@ var BaseBrowserPrototype = {
|
|||||||
pattern
|
pattern
|
||||||
// other -> get a compatible test function...
|
// other -> get a compatible test function...
|
||||||
: Object.entries(this.__search_test_generators__)
|
: Object.entries(this.__search_test_generators__)
|
||||||
.filter(function([key, get]){
|
.filter(function([key, _]){
|
||||||
return !(options.noQueryCheck
|
return !(options.noQueryCheck
|
||||||
&& key == 'query') })
|
&& key == 'query') })
|
||||||
.reduce(function(res, [_, get]){
|
.reduce(function(res, [_, get]){
|
||||||
@ -1349,7 +1353,6 @@ var BaseBrowserPrototype = {
|
|||||||
|
|
||||||
return this.walk2(
|
return this.walk2(
|
||||||
function(elem, i, path, next, stop){
|
function(elem, i, path, next, stop){
|
||||||
console.log('->', path.join('/'))
|
|
||||||
// match...
|
// match...
|
||||||
var res = (elem
|
var res = (elem
|
||||||
&& (test === true
|
&& (test === true
|
||||||
@ -1529,81 +1532,59 @@ var BaseBrowserPrototype = {
|
|||||||
// Like .get(.., {iterateCollapsed: true}) but will expand all the
|
// Like .get(.., {iterateCollapsed: true}) but will expand all the
|
||||||
// path items to reveal the target...
|
// path items to reveal the target...
|
||||||
// XXX should this return the item or this???
|
// XXX should this return the item or this???
|
||||||
|
// XXX make .reveal('all'/'*') only do the actual nodes that need expanding...
|
||||||
|
// ...currently for path 'a/b/c/d' we'll go through:
|
||||||
|
// 'a/b'
|
||||||
|
// 'a/b/c'
|
||||||
|
// 'a/b/c/d'
|
||||||
|
// XXX need a universal item name/value comparison / getter...
|
||||||
reveal: function(key, options){
|
reveal: function(key, options){
|
||||||
var that = this
|
var that = this
|
||||||
return this.get(key,
|
var seen = new Set()
|
||||||
function(e, i, path){
|
return this.search(key,
|
||||||
|
function(e, i, path){
|
||||||
|
return [path, e] },
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
iterateCollapsed: true,
|
||||||
|
reverse: 'flat',
|
||||||
|
},
|
||||||
|
options || {}))
|
||||||
|
// sort paths long to short...
|
||||||
|
//.sort(function(a, b){
|
||||||
|
// return b[0].length - a[0].length })
|
||||||
|
.map(function([path, e]){
|
||||||
|
// skip paths we have already seen...
|
||||||
|
if(seen.has(e.id)){
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
seen.add(e.id)
|
||||||
|
|
||||||
var cur = that
|
var cur = that
|
||||||
path.forEach(function(n){
|
path.length > 1
|
||||||
// XXX ugly
|
&& path
|
||||||
delete cur.item_key_index[n].collapsed
|
.slice(0, -1)
|
||||||
cur = cur.item_key_index[n].children
|
.forEach(function(n){
|
||||||
})
|
// array children...
|
||||||
that.render()
|
if(cur instanceof Array){
|
||||||
|
var e = cur
|
||||||
|
.filter(function(e){
|
||||||
|
// XXX need a universal item name test...
|
||||||
|
return n == (e.value || e.id) })
|
||||||
|
.pop()
|
||||||
|
delete e.collapsed
|
||||||
|
cur = e.children
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// XXX .item_key_index feels ugly...
|
||||||
|
delete cur.item_key_index[n].collapsed
|
||||||
|
cur = cur.item_key_index[n].children
|
||||||
|
}
|
||||||
|
})
|
||||||
return e
|
return e
|
||||||
},
|
})
|
||||||
Object.assign(
|
.run(function(){
|
||||||
{iterateCollapsed: true},
|
that.render() }) },
|
||||||
options)) },
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// .find(id[, options])
|
|
||||||
// .find(index[, options])
|
|
||||||
// .find(path[, options])
|
|
||||||
// .find(func[, options])
|
|
||||||
// -> list
|
|
||||||
//
|
|
||||||
// XXX add '**' patterns...
|
|
||||||
// XXX should this return item paths???
|
|
||||||
// ...one way to do this is to return an object instead of a list...
|
|
||||||
find: function(query, options){
|
|
||||||
query = typeof(query) == typeof('str') ?
|
|
||||||
query.split(/[\\\/]/g)
|
|
||||||
.filter(function(e){ return e.length > 0 })
|
|
||||||
: query
|
|
||||||
query = typeof(query) == typeof('str') ?
|
|
||||||
[query]
|
|
||||||
: query
|
|
||||||
query = query instanceof Array ?
|
|
||||||
query
|
|
||||||
.map(function(d){
|
|
||||||
return d == '*' ?
|
|
||||||
d
|
|
||||||
: d.indexOf('*') >= 0 ?
|
|
||||||
new RegExp(d
|
|
||||||
.replace(/\*/g, '.*'))
|
|
||||||
: d})
|
|
||||||
: query
|
|
||||||
|
|
||||||
var i = -1
|
|
||||||
return this
|
|
||||||
.filter(function(e, p){
|
|
||||||
i++
|
|
||||||
return (query === e
|
|
||||||
|| (
|
|
||||||
// index...
|
|
||||||
typeof(query) == typeof(123) ?
|
|
||||||
query == i
|
|
||||||
// predicate...
|
|
||||||
: query instanceof Function ?
|
|
||||||
// XXX revise signature...
|
|
||||||
query.call(this, e, p, i, this)
|
|
||||||
// regular expression...
|
|
||||||
: query instanceof RegExp ?
|
|
||||||
query.test(p.join('/'))
|
|
||||||
// direct path comparison...
|
|
||||||
: query instanceof Array ?
|
|
||||||
query.cmp(p)
|
|
||||||
|| (query.length == p.length
|
|
||||||
&& query
|
|
||||||
.filter(function(q, i){
|
|
||||||
return q == '*'
|
|
||||||
|| (q instanceof RegExp
|
|
||||||
&& q.test(p[i]))
|
|
||||||
|| q == p[i] })
|
|
||||||
.length == p.length)
|
|
||||||
: false)) }, options) },
|
|
||||||
|
|
||||||
// XXX support: up/down/left/right/first/last/next/prev
|
// XXX support: up/down/left/right/first/last/next/prev
|
||||||
// XXX extend support for screen oriented nav in a subclass...
|
// XXX extend support for screen oriented nav in a subclass...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user