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() .focus()
// Flat list demo... // Custom flat list demo...
f = browser.Browser($('.container.flat'), { f = browser.Browser($('.container.flat'), {
data: [ data: [
'option 1', '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 1': function(_, p){ console.log('option:', p) },
'option 2': function(_, p){ console.log('option:', p) }, 'option 2': function(_, p){ console.log('option:', p) },
'option 3': function(_, p){ console.log('option:', p) }, 'option 3': function(_, p){ console.log('option:', p) },

View File

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