From 8e755ded9f573ac6ff016ac6e81a304e2f648ac5 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 22 Jun 2015 17:22:01 +0300 Subject: [PATCH] added a generic flat list constructor... Signed-off-by: Alex A. Naanou --- ui (gen4)/experiments/browse-dialog.html | 23 +++++++++++- ui (gen4)/experiments/browse-dialog.js | 47 +++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/ui (gen4)/experiments/browse-dialog.html b/ui (gen4)/experiments/browse-dialog.html index fa625456..100436fc 100755 --- a/ui (gen4)/experiments/browse-dialog.html +++ b/ui (gen4)/experiments/browse-dialog.html @@ -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:
+
+
+ diff --git a/ui (gen4)/experiments/browse-dialog.js b/ui (gen4)/experiments/browse-dialog.js index b3316806..af46a397 100755 --- a/ui (gen4)/experiments/browse-dialog.js +++ b/ui (gen4)/experiments/browse-dialog.js @@ -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(, ) +// -> browser +// +// +// format: +// { +// : , +// ... +// } +// +// +// 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 : */