added support for multiple insertion path elements (A|B|..)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-09-05 16:07:08 +03:00
parent baf7cd6a15
commit 65eb5b4ac4
2 changed files with 41 additions and 18 deletions

View File

@ -248,7 +248,8 @@ requirejs(['../keyboard', '../../object', './browse'], function(k, o, br){
// XXX need a way to trigger open events with touch/mouse... // XXX need a way to trigger open events with touch/mouse...
'/dir 1': function(_, p){ console.log('dir:', p) }, '/dir 1': function(_, p){ console.log('dir:', p) },
'dir 1/option 1': function(_, p){ console.log('option:', p) }, 'dir 1/option 1': function(_, p){ console.log('option:', p) },
'dir 1/option 2/': function(_, p){ console.log('option:', p) }, // add an element to two paths...
'dir 1|dir 2|dir 3/option 2/': function(_, p){ console.log('option:', p) },
'dir 2/option 3': function(_, p){ console.log('option:', p) }, 'dir 2/option 3': function(_, p){ console.log('option:', p) },
'option 4': function(_, p){ console.log('option:', p) }, 'option 4': function(_, p){ console.log('option:', p) },
@ -265,6 +266,7 @@ requirejs(['../keyboard', '../../object', './browse'], function(k, o, br){
}, },
// render a custom sub-tree... // render a custom sub-tree...
//'dynamic/*': function(path, make){
'dynamic/*': function(path, make){ 'dynamic/*': function(path, make){
console.log('listing:', path) console.log('listing:', path)

View File

@ -1670,6 +1670,8 @@ module.makeList = function(elem, list){
// // set traversable... // // set traversable...
// 'dir/dir/': function(evt, path){ .. }, // 'dir/dir/': function(evt, path){ .. },
// //
// // add a file object to two dirs...
// 'dir|other/other file': function(evt, path){ .. },
// //
// // path lister... // // path lister...
// 'dynamic/*': function(path, make){ .. } // 'dynamic/*': function(path, make){ .. }
@ -1681,13 +1683,17 @@ module.makeList = function(elem, list){
// dir/ // dir/
// file // file
// dir/ // dir/
// other file
// file // file
// other/
// other file
// dynamic/ // dynamic/
// .. // ..
// //
// Here the contents of the '/dynamic/' path are generated by the matching // Here the contents of the '/dynamic/' path are generated by the matching
// lister for that pattern path... // lister for that pattern path...
// //
// NOTE: in the A|B|C pattern, ALL of the alternatives will be created.
// NOTE: there may be multiple matching patterns/listers or a given path // NOTE: there may be multiple matching patterns/listers or a given path
// the one used is the longest match. // the one used is the longest match.
// //
@ -1728,6 +1734,19 @@ PathListPrototype.options = {
var visited = [] var visited = []
// match path elements accounting for patterns...
//
// Supported patterns:
// A - matches A exactly
// A|B - matches either A or B
var match = function(a, path){
return a
.split('|')
.filter(function(e){
return e == path
}).length > 0
}
// get the '*' listers... // get the '*' listers...
var lister = keys var lister = keys
.filter(function(k){ return k.trim().slice(-1) == '*' }) .filter(function(k){ return k.trim().slice(-1) == '*' })
@ -1739,7 +1758,7 @@ PathListPrototype.options = {
// do the match... // do the match...
return k.length <= path.length return k.length <= path.length
&& k.filter(function(e, i){ && k.filter(function(e, i){
return e != '*' && e != path[i] return e != '*' && !match(e, path[i])
}).length == 0 }) }).length == 0 })
.sort(function(a, b){ return a.length - b.length}) .sort(function(a, b){ return a.length - b.length})
.pop() .pop()
@ -1763,7 +1782,7 @@ PathListPrototype.options = {
var p = kp.splice(0, path.length) var p = kp.splice(0, path.length)
if(kp.length == 0 if(kp.length == 0
|| p.length < path.length || p.length < path.length
|| p.filter(function(e, i){ return e != path[i] }).length > 0){ || p.filter(function(e, i){ return !match(e, path[i]) }).length > 0){
return false return false
} }
@ -1773,6 +1792,7 @@ PathListPrototype.options = {
return false return false
} }
cur.split('|').forEach(function(cur){
if(visited.indexOf(cur) >= 0){ if(visited.indexOf(cur) >= 0){
// set element to traversable... // set element to traversable...
if(kp.length > 0){ if(kp.length > 0){
@ -1791,6 +1811,7 @@ PathListPrototype.options = {
return that.options.data[k].apply(this, arguments) return that.options.data[k].apply(this, arguments)
}) })
} }
})
return cur return cur
}) })