From b94e0bf109ad9eed07d5e8716d6d5e3784b4991c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 22 Sep 2015 22:50:18 +0300 Subject: [PATCH] refactoring and minor bug fixes... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/widget/browse.js | 117 ++++++++++++++++++++------------- ui (gen4)/lib/widget/drawer.js | 2 +- ui (gen4)/lib/widget/widget.js | 1 - ui (gen4)/viewer.js | 71 +++++++++++++++++++- 4 files changed, 140 insertions(+), 51 deletions(-) diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index da3f7d75..3fa64820 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -42,7 +42,54 @@ var quoteWS = function(str){ // ...it can be implemented trivially via an attribute and a :before // CSS class... var BrowserClassPrototype = { - // construct the dom... + + // Normalize path... + // + // This converts the path into a universal absolute array + // representation, taking care of relative path constructs including + // '.' (current path) and '..' (up one level) + // + // XXX does this need to handle trailing '/'??? + // ...the problem is mainly encoding a trailing '/' into an + // array, adding a '' at the end seems both obvious and + // artificial... + // XXX is this the correct name??? + // ...should this be .normalizePath(..)??? + path2list: function(path){ + var splitter = /[\\\/]/ + + if(typeof(path) == typeof('str')){ + path = path + .split(splitter) + .filter(function(e){ return e != '' }) + } + + // we've got a relative path... + if(path[0] == '.' || path[0] == '..'){ + path = this.path.concat(path) + } + + path = path + // clear the '..'... + // NOTE: we reverse to avoid setting elements with negative + // indexes if we have a leading '..' + .reverse() + .map(function(e, i){ + if(e == '..'){ + e = '.' + path[i] = '.' + path[i+1] = '.' + } + return e + }) + .reverse() + // filter out '.'... + .filter(function(e){ return e != '.' }) + + return path + }, + + // Construct the dom... make: function(options){ var browser = $('
') .addClass('browse-widget') @@ -254,50 +301,11 @@ var BrowserPrototype = { }, - // Normalize path... + // Call the constructor's .path2list(..).. // - // This converts the path into a universal absolute array - // representation, taking care of relative path constructs including - // '.' (current path) and '..' (up one level) - // - // XXX does this need to handle trailing '/'??? - // ...the problem is mainly encoding a trailing '/' into an - // array, adding a '' at the end seems both obvious and - // artificial... - // XXX is this the correct name??? - // ...should this be .normalizePath(..)??? - path2list: function(path){ - var splitter = /[\\\/]/ - - if(typeof(path) == typeof('str')){ - path = path - .split(splitter) - .filter(function(e){ return e != '' }) - } - - // we've got a relative path... - if(path[0] == '.' || path[0] == '..'){ - path = this.path.concat(path) - } - - path = path - // clear the '..'... - // NOTE: we reverse to avoid setting elements with negative - // indexes if we have a leading '..' - .reverse() - .map(function(e, i){ - if(e == '..'){ - e = '.' - path[i] = '.' - path[i+1] = '.' - } - return e - }) - .reverse() - // filter out '.'... - .filter(function(e){ return e != '.' }) - - return path + // See: BrowserClassPrototype.path2list(..) for docs... + path2list: function(){ + return this.constructor.path2list.apply(this, arguments) }, // Trigger jQuery events on Browser... @@ -738,12 +746,21 @@ var BrowserPrototype = { // XXX support glob... } else if(typeof(pattern) == typeof('str')){ //var pl = pattern.trim().split(/\s+/) - var pl = pattern.trim().split(/[^\\]\s/).filter(function(e){ return e.trim() != '' }) + var pl = pattern.trim() + // split on whitespace but keep quoted chars... + .split(/\s*((?:\\\s|[^\s])*)\s*/g) + // remove empty strings... + .filter(function(e){ return e.trim() != '' }) + // remove '\' -- enables direct string comparison... + .map(function(e){ return e.replace(/\\(\s)/g, '$1') }) var filter = function(i, e){ e = $(e) var t = e.text() for(var p=0; p < pl.length; p++){ - var i = t.search(pl[p]) + // NOTE: we are not using search here as it treats + // the string as a regex and we need literal + // search... + var i = t.indexOf(pl[p]) if(!(i >= 0)){ if(rejected){ rejected.call(e, i, e) @@ -1629,6 +1646,10 @@ ListPrototype.options = { }) }, } +// XXX should we inherit or copy options??? +// ...inheriting might pose problems with deleting values reverting +// them to default instead of nulling them and mutable options might +// get overwritten... ListPrototype.options.__proto__ = BrowserPrototype.options var List = @@ -1838,6 +1859,10 @@ PathListPrototype.options = { } }, } +// XXX should we inherit or copy options??? +// ...inheriting might pose problems with deleting values reverting +// them to default instead of nulling them and mutable options might +// get overwritten... PathListPrototype.options.__proto__ = BrowserPrototype.options var PathList = diff --git a/ui (gen4)/lib/widget/drawer.js b/ui (gen4)/lib/widget/drawer.js index cf1fbe54..d9c4d4e2 100755 --- a/ui (gen4)/lib/widget/drawer.js +++ b/ui (gen4)/lib/widget/drawer.js @@ -41,7 +41,7 @@ var DrawerPrototype = { client: null, options: { - 'close-at': 10, + 'close-at': 40, 'fade-at': 100, 'animate': 120, diff --git a/ui (gen4)/lib/widget/widget.js b/ui (gen4)/lib/widget/widget.js index ff7f22ed..e9ef2146 100755 --- a/ui (gen4)/lib/widget/widget.js +++ b/ui (gen4)/lib/widget/widget.js @@ -119,7 +119,6 @@ var WidgetPrototype = { } - var Widget = module.Widget = object.makeConstructor('Widget', diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index 72bab146..e8b9ea22 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -2237,14 +2237,38 @@ var makeActionLister = function(list, filter, pre_order){ Object.keys(paths).forEach(function(k){ var n = paths[k][0] var k = filter ? filter(k, n) : k - actions[k] = function(){ - return a[n]() + // pass args to listers... + if(k.slice(-1) == '*'){ + actions[k] = function(){ + return a[n].apply(a, arguments) + } + // ignore args of actions... + } else { + actions[k] = function(){ + return a[n]() + } } }) + var closingPrevented = false + var o = overlay.Overlay($('body'), list(null, actions, path) - .open(function(){ o.close() })) + .open(function(evt){ + + evt.preventClosing = + event.preventClosing = + function(){ closingPrevented = true } + + setTimeout(function(){ + if(!closingPrevented){ + o.close() + } + }, 0) + })) + + // XXX DEBUG + window.LIST = o.client return this } @@ -2264,6 +2288,47 @@ var ActionTreeActions = actions.Actions({ return a +' ('+ l.join(', ') +')' })], + // XXX lister test... + embededListerTest: ['Interface/Lister test (embeded)/*', + function(path, make){ + make('a/') + make('b/') + make('c/') + }], + floatingListerTest: ['Interface/Lister test (floating)...', + function(path){ + console.log('11111111') + event + && event.preventClosing + && event.preventClosing() + + // we got an argument and can exit... + if(path){ + console.log('PATH:', path) + return + } + + // load the UI... + var that = this + var list = function(path, make){ + + make('a/') + make('b/') + make('c/') + } + + var o = overlay.Overlay($('body'), + browse.makePathList(null, { + 'a/*': list, + 'b/*': list, + 'c/*': list, + }) + .open(function(evt, path){ + o.close() + that.floatingListerTest(path) + })) + }], + // XXX this is just a test... drawerTest:['Interface/Drawer widget test', function(){