From 61eba36c6778ce25f50cf18ce5c2c09f88f62420 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 6 Feb 2017 14:59:10 +0200 Subject: [PATCH] refactor(sort) add --- client/cloudcmd.js | 3 ++- client/listeners.js | 27 +-------------------------- client/sort.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 client/sort.js diff --git a/client/cloudcmd.js b/client/cloudcmd.js index 5b158fb8..52893bc4 100644 --- a/client/cloudcmd.js +++ b/client/cloudcmd.js @@ -24,7 +24,8 @@ var CloudCmd; client + 'buffer', client + 'listeners', client + 'key', - client + 'directory' + client + 'directory', + client + 'sort' ]; var moduleFiles = [ diff --git a/client/listeners.js b/client/listeners.js index 12300687..891ea906 100644 --- a/client/listeners.js +++ b/client/listeners.js @@ -32,12 +32,6 @@ var Util, DOM, CloudFunc, CloudCmd; function header() { var fm = DOM.getFM(); - var position = Info.panelPosition; - var sortPrevious = CloudCmd.sort[position]; - - var sort = CloudCmd.sort; - var order = CloudCmd.order; - var isDataset = function(el) { return el.dataset; }; @@ -64,26 +58,7 @@ var Util, DOM, CloudFunc, CloudCmd; .filter(isPanel) .pop(); - var position = panel - .dataset - .name - .replace('js-', ''); - - if (name !== sortPrevious) { - order[position] = 'asc'; - } else { - if (order[position] === 'asc') - order[position] = 'desc'; - else - order[position] = 'asc'; - } - - sortPrevious = - sort[position] = name; - - CloudCmd.refresh(panel, { - noCurrent: position !== Info.panelPosition - }); + CloudCmd.sortPanel(name, panel); }); } diff --git a/client/sort.js b/client/sort.js new file mode 100644 index 00000000..b0014cc9 --- /dev/null +++ b/client/sort.js @@ -0,0 +1,38 @@ +/* global CloudCmd */ +/* global DOM */ + +(function() { + 'use strict'; + + var Info = DOM.CurrentInfo; + var sort = CloudCmd.sort; + var order = CloudCmd.order; + var position = DOM.getPanelPosition(); + var sortPrevious = sort[position]; + + CloudCmd.sortPanel = function(name, panel) { + panel = panel || DOM.getPanel(); + + var position = panel + .dataset + .name + .replace('js-', ''); + + if (name !== sortPrevious) { + order[position] = 'asc'; + } else { + if (order[position] === 'asc') + order[position] = 'desc'; + else + order[position] = 'asc'; + } + + sortPrevious = + sort[position] = name; + + CloudCmd.refresh(panel, { + noCurrent: position !== Info.panelPosition + }); + }; +})(); +