From 5f387eda314fbed391970f0e25b23182bb40bf96 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 24 Jun 2015 18:21:49 +0300 Subject: [PATCH] added list input (no callbacks) to List constructor + some cleanup... Signed-off-by: Alex A. Naanou --- ui (gen4)/experiments/browse-dialog.html | 4 ++-- ui (gen4)/experiments/browse-dialog.js | 29 ++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ui (gen4)/experiments/browse-dialog.html b/ui (gen4)/experiments/browse-dialog.html index 2dfcad4d..b693cec8 100755 --- a/ui (gen4)/experiments/browse-dialog.html +++ b/ui (gen4)/experiments/browse-dialog.html @@ -151,10 +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, b){ +requirejs(['../lib/keyboard', '../object', './browse-dialog'], function(k, o, br){ keyboard = k object = o - browser = b + browser = br // Tree demo... b = browser.Browser($('.container.tree'), { diff --git a/ui (gen4)/experiments/browse-dialog.js b/ui (gen4)/experiments/browse-dialog.js index c8bd800b..f3707385 100755 --- a/ui (gen4)/experiments/browse-dialog.js +++ b/ui (gen4)/experiments/browse-dialog.js @@ -227,6 +227,12 @@ var BrowserPrototype = { // - build the element list // - bind to control events // + // For uniformity and ease of access from DOM, this will also set the + // 'path' html attribute on the .browse element. + // NOTE: this works one way, navigating to a different path will + // overwrite the attr but setting a new value to the html attr + // will not affect the actual path. + // // XXX do we normalize path here??? // XXX need a way to handle path errors in the extension API... // ...for example, if .list(..) can't list or lists a different @@ -329,6 +335,7 @@ var BrowserPrototype = { res.forEach(make) } + this.dom.attr('path', '/' + this.path.join('/')) this.trigger('update') return this @@ -634,6 +641,12 @@ var BrowserPrototype = { // // This will return a jQuery object. // + // For uniformity and ease of access from DOM, this will also set + // the value attr on the .browse element. + // NOTE: this is one way and setting the html attribute "value" will + // not affect the selection, but changing the selection will + // overwrite the attribute. + // // NOTE: if multiple matches occur this will select the first. // NOTE: 'none' will always return an empty jQuery object, to get // the selection state before deselecting use .select('!') @@ -737,6 +750,7 @@ var BrowserPrototype = { } elem.addClass('selected') + browser.attr('value', elem.text()) this.trigger('select', elem) @@ -932,6 +946,12 @@ object.makeConstructor('Browser', // : , // ... // } +// +// or: +// [ +// , +// ... +// ] // // NOTE: this essentially a different default configuration of Browser... var ListPrototype = Object.create(BrowserPrototype) @@ -942,12 +962,17 @@ ListPrototype.options = { list: function(path, make){ var that = this - return Object.keys(this.options.data) + var data = this.options.data + var keys = data.constructor == Array ? data : Object.keys(data) + return keys .map(function(k){ var e = make(k) - .on('open', function(){ + + if(data !== keys){ + e.on('open', function(){ return that.options.data[k].apply(this, arguments) }) + } return k })