From 3e8083d5a1c5c33d175f503bdbd181ed5f0cfc1e Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 1 May 2015 00:32:44 -0700 Subject: [PATCH] more refactoring of helpers. --- lib/widget.js | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 8eb08e4..d157739 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -564,7 +564,7 @@ Screen.prototype._listenMouse = function(el) { if (self.lockKeys) return; if (self._needsClickableSort) { - self.clickable = hsort(self.clickable); + self.clickable = helpers.hsort(self.clickable); self._needsClickableSort = false; } @@ -6540,8 +6540,8 @@ FileManager.prototype.refresh = function(cwd, callback) { } }); - dirs = asort(dirs); - files = asort(files); + dirs = helpers.asort(dirs); + files = helpers.asort(files); list = dirs.concat(files).map(function(data) { return data.text; @@ -7306,7 +7306,7 @@ Listbar.prototype.appendItem = function(item, callback) { cmd.prefix = cmd.keys[0]; } - var t = generateTags(this.style.prefix || { fg: 'lightblack' }); + var t = helpers.generateTags(this.style.prefix || { fg: 'lightblack' }); title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text; @@ -7323,7 +7323,7 @@ Listbar.prototype.appendItem = function(item, callback) { autoFocus: false, tags: true, mouse: true, - style: merge({}, this.style.item), + style: helpers.merge({}, this.style.item), noOverflow: true }; @@ -8483,9 +8483,9 @@ function Image(options) { if (fs.existsSync(Image.w3mdisplay)) { Image.hasW3MDisplay = true; } else if (options.search !== false) { - var file = findFile('/usr', 'w3mimgdisplay') - || findFile('/lib', 'w3mimgdisplay') - || findFile('/bin', 'w3mimgdisplay'); + var file = helpers.findFile('/usr', 'w3mimgdisplay') + || helpers.findFile('/lib', 'w3mimgdisplay') + || helpers.findFile('/bin', 'w3mimgdisplay'); if (file) { Image.hasW3MDisplay = true; Image.w3mdisplay = file; @@ -9049,12 +9049,13 @@ function blend(attr, attr2) { blend._cache = {}; - /** * Helpers */ -function generateTags(style, text) { +var helpers = {}; + +helpers.generateTags = function(style, text) { var open = '' , close = ''; @@ -9080,16 +9081,16 @@ function generateTags(style, text) { open: open, close: close }; -} +}; -function merge(a, b) { +helpers.merge = function(a, b) { Object.keys(b).forEach(function(key) { a[key] = b[key]; }); return a; -} +}; -function asort(obj) { +helpers.asort = function(obj) { return obj.sort(function(a, b) { a = a.name.toLowerCase(); b = b.name.toLowerCase(); @@ -9104,15 +9105,15 @@ function asort(obj) { return a > b ? 1 : (a < b ? -1 : 0); }); -} +}; -function hsort(obj) { +helpers.hsort = function(obj) { return obj.sort(function(a, b) { return b.index - a.index; }); -} +}; -function findFile(start, target) { +helpers.findFile = function(start, target) { return (function read(dir) { var files, file, stat, out; @@ -9148,13 +9149,7 @@ function findFile(start, target) { return null; })(start); -} - -/** - * Helpers - */ - -var helpers = {}; +}; // Escape text for tag-enabled elements. helpers.escape = function(text) { @@ -9168,8 +9163,6 @@ helpers.parseTags = function(text) { { parseTags: true, screen: Screen.global }, text); }; -helpers.generateTags = generateTags; - helpers.attrToBinary = function(style, element) { return Element.prototype.sattr.call(element || {}, style); }; @@ -9193,10 +9186,6 @@ helpers.dropUnicode = function(text) { .replace(unicode.chars.surrogate, '?'); }; -helpers.merge = merge; -helpers.asort = asort; -helpers.findFile = findFile; - /** * Expose */