From 98a3bcd1716e06d50945883c779f59ee758f33c3 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 8 Jan 2014 13:53:14 +0000 Subject: [PATCH] refactor(client) rm custom listeners --- lib/client.js | 5 ++++- lib/client/config.js | 12 ------------ lib/client/console.js | 27 --------------------------- lib/client/dom.js | 8 -------- lib/client/edit.js | 15 +-------------- lib/client/help.js | 13 ------------- lib/client/key.js | 11 ++++++----- lib/client/listeners.js | 34 +++++++++------------------------- lib/client/menu.js | 32 ++++++++++++-------------------- lib/client/view.js | 19 ++++++++----------- 10 files changed, 40 insertions(+), 136 deletions(-) diff --git a/lib/client.js b/lib/client.js index d6a9a5b7..f082def9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -104,7 +104,7 @@ if (!isContain) lPath += '.js'; - if (!CloudCmd[lName]) + if (!CloudCmd[lName]) { CloudCmd[lName] = function(pArg) { var path = CloudCmd.LIBDIRCLIENT + lPath; @@ -118,6 +118,9 @@ CloudCmd[lName] = new Proto(pArg); }); }; + + CloudCmd[lName].show = CloudCmd[lName]; + } } } diff --git a/lib/client/config.js b/lib/client/config.js index 4f31c121..7cc36c50 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -26,9 +26,6 @@ var CloudCmd, Util, DOM; }, CloudCmd.View, ]); - - DOM.Events.addKey(listener); - DOM.setButtonKey('f10', Config.show); } this.show = function() { @@ -99,15 +96,6 @@ var CloudCmd, Util, DOM; CloudCmd.View.hide(); }; - function listener(pEvent){ - var f10 = Key.F10, - isBind = Key.isBind(), - key = pEvent.keyCode; - - /* если клавиши можно обрабатывать */ - if (isBind && key === f10) - Config.show(); - } function changeConfig(config) { var name; diff --git a/lib/client/console.js b/lib/client/console.js index 883c3d84..d68a0d2b 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -30,9 +30,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; DOM.jqueryLoad, DOM.socketLoad ]); - - DOM.Events.addKey(listener); - DOM.setButtonKey('~', Console.show); } this.show = function() { @@ -98,10 +95,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; } }; - this.hide = function() { - CloudCmd.View.hide(); - }; - this.log = function(pText) { log(pText, 'log'); }; @@ -147,26 +140,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; }); } - function listener(pEvent) { - var lTRA = Key.TRA, - lESC = Key.ESC, - lIsBind = Key.isBind(), - lKey = pEvent.keyCode; - - switch(lKey) { - case lTRA: - if (lIsBind) { - Console.show(); - DOM.preventDefault(pEvent); - } - break; - case lESC: - Console.hide(); - break; - } - - } - init(); } diff --git a/lib/client/dom.js b/lib/client/dom.js index 28b431bd..58370be4 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1188,14 +1188,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; return lRet; }; - /** - * set onclick handler on buttons f1-f10 - * @param pKey - 'f1'-'f10' - */ - this.setButtonKey = function(pKey, pFunc) { - Events.addClick(pFunc, CloudCmd.KeysPanel[pKey]); - }; - /** * set title with pName * create title element diff --git a/lib/client/edit.js b/lib/client/edit.js index cc02ca9b..c7520f1e 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -29,9 +29,6 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; load, CloudCmd.View ]); - - DOM.Events.addKey(listener); - DOM.setButtonKey('f4', Edit.show); } this.show = function(pValue) { @@ -246,17 +243,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; }); } - function listener(pEvent) { - var lF4, lKey, lIsBind = Key.isBind(); - - if (lIsBind) { - lF4 = Key.F4, - lKey = pEvent.keyCode; - - if(lKey === lF4) - Edit.show(); - } - } + function onSave(text) { var ret, diff --git a/lib/client/help.js b/lib/client/help.js index 37d13030..0d5b6c32 100644 --- a/lib/client/help.js +++ b/lib/client/help.js @@ -14,9 +14,6 @@ var CloudCmd, Util, DOM; Help.show, CloudCmd.View, ]); - - DOM.Events.addKey(listener); - DOM.setButtonKey('f1', Help.show); } this.show = function() { @@ -66,16 +63,6 @@ var CloudCmd, Util, DOM; CloudCmd.View.hide(); }; - function listener(pEvent) { - var lF1 = Key.F1, - lIsBind = Key.isBind(), - lKey = pEvent.keyCode; - - /* если клавиши можно обрабатывать */ - if (lIsBind && lKey === lF1) - Help.show(); - } - init(); } diff --git a/lib/client/key.js b/lib/client/key.js index a009cdd7..fe669f8c 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -208,7 +208,7 @@ var CloudCmd, Util, DOM; break; case Key.F1: - Util.exec(CloudCmd.Help); + Util.exec(CloudCmd.Help.show); DOM.preventDefault(pEvent); break; @@ -217,12 +217,12 @@ var CloudCmd, Util, DOM; break; case Key.F3: - Util.exec(CloudCmd.View); + Util.exec(CloudCmd.View.show); DOM.preventDefault(pEvent); break; case Key.F4: - Util.exec(CloudCmd.Edit); + Util.exec(CloudCmd.Edit.show); DOM.preventDefault(pEvent); break; @@ -251,14 +251,15 @@ var CloudCmd, Util, DOM; break; case Key.F10: - Util.exec(CloudCmd.Config); + Util.exec(CloudCmd.Config.show); DOM.preventDefault(pEvent); break; case Key.TRA: DOM.Images.showLoad({top: true}); - Util.exec(CloudCmd.Console); + Util.exec(CloudCmd.Console.show); + DOM.preventDefault(pEvent); break; diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 55e07c0f..65744d5d 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -40,29 +40,7 @@ var Util, DOM, CloudCmd; this.initKeysPanel = function() { var button, id, func, - keysElement = DOM.getByClass('keyspanel')[0], - keysPanel = {}, - - onceClickFuncs = { - 'f1' : CloudCmd.Help, - 'f3' : CloudCmd.View, - 'f4' : CloudCmd.Edit, - 'f9' : CloudCmd.Menu, - 'f10' : CloudCmd.Config, - '~' : CloudCmd.Console, - 'contact' : CloudCmd.Contact - }; - - for (id in onceClickFuncs) { - button = DOM.getById(id); - - if (button) { - func = onceClickFuncs[id]; - keysPanel[id] = button; - - Events.addOnce('click', func, button); - } - } + keysElement = DOM.getByClass('keyspanel')[0]; if (keysElement) Events.addClick(function(event) { @@ -70,6 +48,14 @@ var Util, DOM, CloudCmd; id = element.id, clickFuncs = { + 'f1' : CloudCmd.Help.show, + 'f3' : CloudCmd.View.show, + 'f4' : CloudCmd.Edit.show, + 'f9' : CloudCmd.Menu.show, + 'f10' : CloudCmd.Config.show, + '~' : CloudCmd.Console.show, + 'contact' : CloudCmd.Contact.show, + 'f2' : DOM.renameCurrent, 'f5' : DOM.copyCurrent, 'f6' : DOM.moveCurrent, @@ -82,8 +68,6 @@ var Util, DOM, CloudCmd; Util.exec(func); }, keysElement); - - return keysPanel; }; /** diff --git a/lib/client/menu.js b/lib/client/menu.js index 33e58ea5..8d7a44d1 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -34,12 +34,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; ]); Events.addKey( lListener ); - - DOM.setButtonKey('f9', function() { - var lCurrent = Info.element; - - Events.dispatch('contextmenu', lCurrent); - }); } this.show = function() { @@ -277,7 +271,8 @@ var CloudCmd, Util, DOM, CloudFunc, $; */ function clickProcessing() { var lLayer = DOM.getById('context-menu-layer'); - if (lLayer) { + + if (lLayer && Position) { DOM.hide(lLayer); var lElement = document.elementFromPoint(Position.x, Position.y), @@ -318,21 +313,18 @@ var CloudCmd, Util, DOM, CloudFunc, $; } function lListener(pEvent) { - var lCurrent, - lF9 = Key.F9, - lESC = Key.ESC, - lKey = pEvent.keyCode, - lIsBind = Key.isBind(); + var lCurrent, + lF9 = Key.F9, + lKey = pEvent.keyCode, + lIsBind = Key.isBind(); + + if (lIsBind && lKey === lF9) { + lCurrent = DOM.getCurrentFile(); + $(lCurrent).contextmenu(); - if (lIsBind && lKey === lF9) { - lCurrent = DOM.getCurrentFile(); - $(lCurrent).contextmenu(); - - DOM.preventDefault(pEvent); - } - else if (lKey === lESC) - Key.setBind(); + DOM.preventDefault(pEvent); } + } init(); } diff --git a/lib/client/view.js b/lib/client/view.js index 849b4184..a7678c11 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -8,6 +8,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; function ViewProto(CallBack) { var Name = 'View', Loading = false, + Events = DOM.Events, Info = DOM.CurrentInfo, Key = CloudCmd.Key, Images = DOM.Images, @@ -67,8 +68,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; DOM.jqueryLoad ]); - DOM.Events.addKey(listener); - DOM.setButtonKey('f3', view); + Events.addKey(listener); } /** @@ -161,18 +161,15 @@ var CloudCmd, Util, DOM, CloudFunc, $; View.show(); } - function listener(pEvent) { - var lF3 = Key.F3, - lIsBind = Key.isBind(), - lKey = pEvent.keyCode; + function listener(event) { + var keyCode = event.keyCode, + ESC = Key.ESC; - /* если клавиши можно обрабатывать */ - if (lIsBind && lKey === lF3) { - view(); - DOM.preventDefault(pEvent); - } + if (keyCode === ESC) + hide(); } + init(); return View;