added a generic flat list constructor...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-06-22 17:22:01 +03:00
parent aaabdaed69
commit 8e755ded9f
2 changed files with 68 additions and 2 deletions

View File

@ -60,6 +60,12 @@
}
.container.flat2 {
left: 500px;
top: 400px;
}
@ -145,9 +151,10 @@ TREE.dir_c.dir_b.tree = TREE
var use_disabled = true
var show_files = false
requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, browser){
requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, b){
keyboard = k
object = o
browser = b
// Tree demo...
b = browser.Browser($('.container.tree'), {
@ -207,6 +214,10 @@ requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, br
if(use_disabled && k == 'option 4'){
e.addClass('disabled')
}
if(k == 'option 3'){
e.on('open', function(){ alert('openning: option 3!') })
}
return k
})
},
@ -214,6 +225,13 @@ requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, br
console.log('OPEN:', path)
},
})
f = browser.makeList($('.container.flat2'), {
'option 1': function(_, p){ console.log('option:', p) },
'option 2': function(_, p){ console.log('option:', p) },
'option 3': function(_, p){ console.log('option:', p) },
'option 4': function(_, p){ console.log('option:', p) },
})
})
$(function(){
@ -329,6 +347,9 @@ Files: <button id="theme" onclick="toggleFiles()">toggle</button>
<div class="container flat">
</div>
<div class="container flat2">
</div>
</body>
</html>
<!-- vim:set ts=4 sw=4 : -->

View File

@ -828,13 +828,19 @@ var BrowserPrototype = {
// Open action...
//
// XXX do we need to pass this to the event???
open: function(path){
path = path || this.path
var m = this.options.open
var res = m ? m.apply(this, arguments) : path
var elem = this.select('!')
// XXX do we need to pass this to the event???
this.trigger('open', path)
elem.trigger('open')
if(elem.length > 0){
// XXX do we need to pass this to the event???
elem.trigger('open', path)
}
return res
},
@ -914,6 +920,45 @@ object.makeConstructor('Browser',
BrowserPrototype)
// Construct a flat list selector...
//
// makeList(<elem>, <list>)
// -> browser
//
//
// <list> format:
// {
// <text>: <callback>,
// ...
// }
//
//
// XXX should this be an object???
var makeList =
module.makeList = function(elem, list){
return browser.Browser(elem, {
data: list,
traversable: false,
flat: true,
list: function(path, make){
var that = this
return Object.keys(this.options.data)
.map(function(k){
// make the element...
var e = make(k)
.on('open', function(){
return that.options.data[k].apply(this, arguments)
})
return k
})
},
})
}
/**********************************************************************
* vim:set ts=4 sw=4 : */