From 082c2bf870f743b92ea344e33f23a1b647465c57 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 2 Apr 2014 10:13:23 -0400 Subject: [PATCH] refactor(listeners) mv mousemove to listeners --- lib/client.js | 1 + lib/client/listeners.js | 26 ++++++++++++++------------ lib/client/menu.js | 29 +++++++---------------------- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/lib/client.js b/lib/client.js index 6c640936..b5fe6c10 100644 --- a/lib/client.js +++ b/lib/client.js @@ -17,6 +17,7 @@ var Util, DOM, CloudFunc; CloudCmd = this, Storage = DOM.Storage; + this.MousePosition = {}; this.LIBDIR = '/lib/'; this.LIBDIRCLIENT = '/lib/client/'; this.MIN_ONE_PANEL_WIDTH = 1155; diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 6ea2b127..1262f83e 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -45,6 +45,7 @@ var Util, DOM, CloudCmd; unload(); pop(); online(); + mousemove(); }; this.initKeysPanel = function() { @@ -160,6 +161,17 @@ var Util, DOM, CloudCmd; } }; + function mousemove() { + DOM.Events.add('mousemove', function(event) { + var position = CloudCmd.MousePosition, + x = event.clientX, + y = event.clientY; + + position.x = x; + position.y = y; + }); + } + function ifExecNotUL(callback, event) { var element = event.target, tag = element.tagName; @@ -199,13 +211,8 @@ var Util, DOM, CloudCmd; } function onContextMenu(event) { - /* getting html element - * currentTarget - DOM event - * target - jquery event - */ var element = getLIElement(event.target), isFunc = Util.isFunction(CloudCmd.Menu), - ret = true, Key = CloudCmd.Key; DOM.setCurrentFile(element); @@ -215,12 +222,7 @@ var Util, DOM, CloudCmd; x: event.clientX, y: event.clientY }); - - /* disabling browsers menu*/ - ret = false; } - - return ret; } /* @@ -286,8 +288,8 @@ var Util, DOM, CloudCmd; } function contextMenu() { - Events.addContextMenu(function(pEvent) { - CloudCmd.Menu.ENABLED || DOM.preventDefault(pEvent); + Events.addContextMenu(function(event) { + CloudCmd.Menu.ENABLED || DOM.preventDefault(event); }, document); } diff --git a/lib/client/menu.js b/lib/client/menu.js index 7650507d..571f494c 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -8,7 +8,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; CloudCmd.Menu = MenuProto; - function MenuProto(pPosition) { + function MenuProto() { var Name = 'Menu', Info = DOM.CurrentInfo, Loading = false, @@ -16,7 +16,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; Events = DOM.Events, MenuSeted = false, Menu = this, - Position, + Position = CloudCmd.MousePosition, Images = DOM.Images, UploadToItemNames; @@ -25,8 +25,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; function init() { Loading = true; - Position = pPosition; - Util.loadOnLoad([ DOM.jqueryLoad, load, @@ -41,11 +39,12 @@ var CloudCmd, Util, DOM, CloudFunc, $; Key.unsetBind(); if (!Loading) { - set(); - Images.hideLoad(); + if (!MenuSeted) { + $.contextMenu(getConfig()); + MenuSeted = true; + } - if (Position && !Position.x ) - Position = undefined; + Images.hideLoad(); $('li').contextMenu(Position); } @@ -316,20 +315,6 @@ var CloudCmd, Util, DOM, CloudFunc, $; } } - - function set() { - if (!MenuSeted) { - $.contextMenu(getConfig()); - MenuSeted = true; - DOM.Events.add('mousemove', function(pEvent) { - Position = { - x : pEvent.clientX, - y : pEvent.clientY - }; - }); - } - } - function listener(event) { var current, F9 = Key.F9,