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...
'/dir 1': function(_, p){ console.log('dir:', 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) },
'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...
//'dynamic/*': function(path, make){
'dynamic/*': function(path, make){
console.log('listing:', path)

View File

@ -1670,6 +1670,8 @@ module.makeList = function(elem, list){
// // set traversable...
// 'dir/dir/': function(evt, path){ .. },
//
// // add a file object to two dirs...
// 'dir|other/other file': function(evt, path){ .. },
//
// // path lister...
// 'dynamic/*': function(path, make){ .. }
@ -1681,13 +1683,17 @@ module.makeList = function(elem, list){
// dir/
// file
// dir/
// other file
// file
// other/
// other file
// dynamic/
// ..
//
// Here the contents of the '/dynamic/' path are generated by the matching
// 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
// the one used is the longest match.
//
@ -1728,6 +1734,19 @@ PathListPrototype.options = {
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...
var lister = keys
.filter(function(k){ return k.trim().slice(-1) == '*' })
@ -1739,7 +1758,7 @@ PathListPrototype.options = {
// do the match...
return k.length <= path.length
&& k.filter(function(e, i){
return e != '*' && e != path[i]
return e != '*' && !match(e, path[i])
}).length == 0 })
.sort(function(a, b){ return a.length - b.length})
.pop()
@ -1763,7 +1782,7 @@ PathListPrototype.options = {
var p = kp.splice(0, path.length)
if(kp.length == 0
|| 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
}
@ -1773,24 +1792,26 @@ PathListPrototype.options = {
return false
}
if(visited.indexOf(cur) >= 0){
// set element to traversable...
if(kp.length > 0){
that.filter(cur).removeClass('not-traversable')
cur.split('|').forEach(function(cur){
if(visited.indexOf(cur) >= 0){
// set element to traversable...
if(kp.length > 0){
that.filter(cur).removeClass('not-traversable')
}
return false
}
return false
}
visited.push(cur)
visited.push(cur)
// build the element....
var e = make(cur, star || kp.length > 0)
// build the element....
var e = make(cur, star || kp.length > 0)
// setup handlers...
if(!star && data !== keys && kp.length == 0){
e.on('open', function(){
return that.options.data[k].apply(this, arguments)
})
}
// setup handlers...
if(!star && data !== keys && kp.length == 0){
e.on('open', function(){
return that.options.data[k].apply(this, arguments)
})
}
})
return cur
})