mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
more cleanup and some refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9ba2d231a7
commit
7f85fa4543
@ -1000,7 +1000,7 @@ var BaseBrowserPrototype = {
|
|||||||
&& doNested()
|
&& doNested()
|
||||||
// do element...
|
// do element...
|
||||||
state.splice(state.length, 0,
|
state.splice(state.length, 0,
|
||||||
...( func ?
|
...[ func ?
|
||||||
(func.call(that,
|
(func.call(that,
|
||||||
...(inline ?
|
...(inline ?
|
||||||
[null, context.index]
|
[null, context.index]
|
||||||
@ -1009,7 +1009,7 @@ var BaseBrowserPrototype = {
|
|||||||
doNested,
|
doNested,
|
||||||
stop,
|
stop,
|
||||||
children) || [])
|
children) || [])
|
||||||
: [node] ))
|
: [node] ].flat())
|
||||||
// normal order -> do children...
|
// normal order -> do children...
|
||||||
// NOTE: doNested(..) is executed only once so in reverse
|
// NOTE: doNested(..) is executed only once so in reverse
|
||||||
// the call will have no effect, but we need to
|
// the call will have no effect, but we need to
|
||||||
@ -1194,10 +1194,81 @@ var BaseBrowserPrototype = {
|
|||||||
// 'focused' - get focused items (shorthand to {focused: true})
|
// 'focused' - get focused items (shorthand to {focused: true})
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// XXX use diff
|
//
|
||||||
|
//
|
||||||
|
// __search_test_generators__ format:
|
||||||
|
// {
|
||||||
|
// // NOTE: generator order is significant as patterns are testen
|
||||||
|
// // in order the generators are defined...
|
||||||
|
// // NOTE: <key> is only used for documentation...
|
||||||
|
// <key>: testGenerator(..),
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// testGenerator(pattern)
|
||||||
|
// -> test(elem, i, path)
|
||||||
|
// -> false
|
||||||
|
//
|
||||||
|
//
|
||||||
// XXX add support for 'next'/'prev', ... keywords... (here or in .get(..)???)
|
// XXX add support for 'next'/'prev', ... keywords... (here or in .get(..)???)
|
||||||
// XXX do we actually need to stop this as soon as we find something,
|
// XXX do we actually need to stop this as soon as we find something,
|
||||||
// i.e. options.firstOnly???
|
// i.e. options.firstOnly???
|
||||||
|
// XXX add diff support...
|
||||||
|
__search_test_generators__: {
|
||||||
|
// regexp path test...
|
||||||
|
regexp: function(pattern){
|
||||||
|
return pattern instanceof RegExp
|
||||||
|
&& function(elem, i, path){
|
||||||
|
return pattern.test(elem.value)
|
||||||
|
|| pattern.test('/'+ path.join('/')) } },
|
||||||
|
// path test...
|
||||||
|
path: function(pattern){
|
||||||
|
return pattern instanceof Array
|
||||||
|
&& function(elem, i, path){
|
||||||
|
return path.length > 0
|
||||||
|
&& pattern.length == path.length
|
||||||
|
&& !pattern
|
||||||
|
// XXX add support for '**' ???
|
||||||
|
.reduce(function(res, e, i){
|
||||||
|
return res || !(
|
||||||
|
e == '*'
|
||||||
|
|| (e instanceof RegExp
|
||||||
|
&& e.test(path[i]))
|
||||||
|
|| e == path[i]) }, false) } },
|
||||||
|
// item index test...
|
||||||
|
index: function(pattern){
|
||||||
|
return typeof(pattern) == typeof(123)
|
||||||
|
&& function(elem, i, path){
|
||||||
|
return i == pattern } },
|
||||||
|
// XXX add diff support...
|
||||||
|
// object query..
|
||||||
|
// NOTE: this must be last as it will return a test unconditionally...
|
||||||
|
query: function(pattern){
|
||||||
|
return function(elem){
|
||||||
|
return Object.entries(pattern)
|
||||||
|
.reduce(function(res, [key, pattern]){
|
||||||
|
return res
|
||||||
|
&& (elem[key] == pattern
|
||||||
|
// bool...
|
||||||
|
|| ((pattern === true || pattern === false)
|
||||||
|
&& pattern === !!elem[key])
|
||||||
|
// predicate...
|
||||||
|
|| (pattern instanceof Function
|
||||||
|
&& pattern.call(that, elem[key]))
|
||||||
|
// regexp...
|
||||||
|
|| (pattern instanceof RegExp
|
||||||
|
&& pattern.test(elem[key]))
|
||||||
|
// type...
|
||||||
|
// XXX problem, we can't distinguish this
|
||||||
|
// and a predicate...
|
||||||
|
// ...so for now use:
|
||||||
|
// .search(v => v instanceof Array)
|
||||||
|
//|| (typeof(pattern) == typeof({})
|
||||||
|
// && pattern instanceof Function
|
||||||
|
// && elem[key] instanceof pattern)
|
||||||
|
) }, true) } },
|
||||||
|
},
|
||||||
search: function(pattern, func, options){
|
search: function(pattern, func, options){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
@ -1236,7 +1307,6 @@ var BaseBrowserPrototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// normalize/build the test predicate...
|
// normalize/build the test predicate...
|
||||||
// XXX add diff support...
|
|
||||||
var test = (
|
var test = (
|
||||||
// all...
|
// all...
|
||||||
pattern === true ?
|
pattern === true ?
|
||||||
@ -1244,52 +1314,15 @@ var BaseBrowserPrototype = {
|
|||||||
// predicate...
|
// predicate...
|
||||||
: pattern instanceof Function ?
|
: pattern instanceof Function ?
|
||||||
pattern
|
pattern
|
||||||
// regexp...
|
// other -> get a compatible test function...
|
||||||
: pattern instanceof RegExp ?
|
: Object.values(this.__search_test_generators__)
|
||||||
function(elem, i, path){
|
.reduce(function(res, get){
|
||||||
return pattern.test(elem.value)
|
return res
|
||||||
|| pattern.test('/'+ path.join('/')) }
|
|| get.call(this.__search_test_generators__, pattern) }, false) )
|
||||||
// path...
|
|
||||||
: pattern instanceof Array ?
|
// sanity check...
|
||||||
function(elem, i, path){
|
if(!test){
|
||||||
return path.length > 0
|
throw new Error(`.search(..): unknown pattern type: ${pattern}`) }
|
||||||
&& pattern.length == path.length
|
|
||||||
&& !pattern
|
|
||||||
// XXX add support for '**' ???
|
|
||||||
.reduce(function(res, e, i){
|
|
||||||
return res || !(
|
|
||||||
e == '*'
|
|
||||||
|| (e instanceof RegExp
|
|
||||||
&& e.test(path[i]))
|
|
||||||
|| e == path[i]) }, false) }
|
|
||||||
// index...
|
|
||||||
: typeof(pattern) == typeof(123) ?
|
|
||||||
function(elem, i, path){
|
|
||||||
return i == pattern }
|
|
||||||
// object query...
|
|
||||||
: function(elem){
|
|
||||||
return Object.entries(pattern)
|
|
||||||
.reduce(function(res, [key, pattern]){
|
|
||||||
return res
|
|
||||||
&& (elem[key] == pattern
|
|
||||||
// bool...
|
|
||||||
|| ((pattern === true || pattern === false)
|
|
||||||
&& pattern === !!elem[key])
|
|
||||||
// predicate...
|
|
||||||
|| (pattern instanceof Function
|
|
||||||
&& pattern.call(that, elem[key]))
|
|
||||||
// regexp...
|
|
||||||
|| (pattern instanceof RegExp
|
|
||||||
&& pattern.test(elem[key]))
|
|
||||||
// type...
|
|
||||||
// XXX problem, we can't distinguish this
|
|
||||||
// and a predicate...
|
|
||||||
// ...so for now use:
|
|
||||||
// .search(v => v instanceof Array)
|
|
||||||
//|| (typeof(pattern) == typeof({})
|
|
||||||
// && pattern instanceof Function
|
|
||||||
// && elem[key] instanceof pattern)
|
|
||||||
) }, true) } )
|
|
||||||
|
|
||||||
return this.walk2(
|
return this.walk2(
|
||||||
function(elem, i, path, _, stop){
|
function(elem, i, path, _, stop){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user