some cleanup and minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-06-22 18:09:37 +03:00
parent 8e755ded9f
commit 606d151b73
2 changed files with 42 additions and 35 deletions

View File

@ -191,7 +191,7 @@ requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, b)
.focus()
// Flat list demo...
// Custom flat list demo...
f = browser.Browser($('.container.flat'), {
data: [
'option 1',
@ -226,7 +226,9 @@ requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, b)
},
})
f = browser.makeList($('.container.flat2'), {
// Default flat list demo...
f2 = 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) },

View File

@ -920,42 +920,47 @@ object.makeConstructor('Browser',
BrowserPrototype)
// Construct a flat list selector...
// Flat list...
//
// makeList(<elem>, <list>)
// -> browser
//
//
// <list> format:
// {
// <text>: <callback>,
// ...
// }
//
//
// XXX should this be an object???
// This expects a data option set with the following format:
// {
// <option-text>: <callback>,
// ...
// }
//
// NOTE: this essentially a different default configuration of Browser...
var ListPrototype = Object.create(BrowserPrototype)
ListPrototype.options = {
traversable: false,
flat: true,
list: function(path, make){
var that = this
return Object.keys(this.options.data)
.map(function(k){
var e = make(k)
.on('open', function(){
return that.options.data[k].apply(this, arguments)
})
return k
})
},
}
ListPrototype.options.__proto__ = BrowserPrototype.options
var List =
module.List =
object.makeConstructor('List',
BrowserClassPrototype,
ListPrototype)
// This is a shorthand for: new List(<elem>, { data: <list> })
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
})
},
})
return List(elem, { data: list })
}