From 1f6c463760831646de2ffe05fe85865fa0d874f9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 22 Jun 2015 04:00:55 +0300 Subject: [PATCH] added basic event infrastructure (piggybacked off of jQuery)... Signed-off-by: Alex A. Naanou --- ui (gen4)/experiments/browse-dialog.js | 52 ++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ui (gen4)/experiments/browse-dialog.js b/ui (gen4)/experiments/browse-dialog.js index 7b158fbf..14738b11 100755 --- a/ui (gen4)/experiments/browse-dialog.js +++ b/ui (gen4)/experiments/browse-dialog.js @@ -12,6 +12,16 @@ define(function(require){ var module = {} var object = require('../object') +/*********************************************************************/ + +function proxyToDom(name){ + return function(){ + this.dom[name].apply(this.dom, arguments) + return this + } +} + + /*********************************************************************/ // NOTE: the widget itself does not need a title, that's the job for @@ -141,6 +151,21 @@ var BrowserPrototype = { }, }, + // proxy event api... + on: proxyToDom('on'), + one: proxyToDom('one'), + off: proxyToDom('off'), + trigger: proxyToDom('trigger'), + bind: proxyToDom('bind'), + unbind: proxyToDom('unbind'), + deligate: proxyToDom('deligate'), + undeligate: proxyToDom('undeligate'), + + // specific events... + focus: proxyToDom('focus'), + blur: proxyToDom('blur'), + + // XXX should these set both the options and dom??? get flat(){ return !this.dom.hasClass('flat') || this.options.flat @@ -193,7 +218,6 @@ var BrowserPrototype = { // path due to an error, we need to be able to render the new // path both in the path and list sections... // NOTE: current behaviour is not wrong, it just not too flexible... - // XXX trigger an "update" event... update: function(path){ path = path || this.path var browser = this.dom @@ -276,6 +300,8 @@ var BrowserPrototype = { res.forEach(make) } + this.trigger('update') + return this }, @@ -577,7 +603,7 @@ var BrowserPrototype = { // NOTE: this uses .filter(..) for string and regexp matching... // // - // XXX Q: should this trigger a "select" event??? + // XXX Q: should this trigger a "deselect" event??? select: function(elem, filtering){ var pattern = '.list div:not(.disabled):not(.filtered-out)' var browser = this.dom @@ -675,6 +701,8 @@ var BrowserPrototype = { p.scrollTop(S + t - D) } + this.trigger('select', elem) + return elem.addClass('selected') } } @@ -740,12 +768,15 @@ var BrowserPrototype = { return this }, + /* focus: function(){ this.dom.focus() return this }, + */ // XXX think about the API... + // XXX need to check if openable and if not use .push() // XXX trigger an "open" event... action: function(){ var elem = this.select('!') @@ -760,11 +791,26 @@ var BrowserPrototype = { path.push(elem.text()) + /* XXX need to sort out several issues: + * - if not openable and not traversable this infinitely recurs... + if(this.isOpenable && !this.isOpenable(path)){ + return this.push() + } + */ + var res = this.open(path) + this.trigger('open', path) + return res }, + /* + isOpenable: function(path){ + return false + }, + */ + // extension methods... // Open action... @@ -792,7 +838,7 @@ var BrowserPrototype = { // // 2) non-interactive: // .list(path) -> list - // - .list(..) should return a list + // - .list(..) should return an array // - make should never get called // - the returned list will be rendered //