From 5302f7962cbaba9cbfc2ca5ab5e84f947095777a Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 22 Oct 2012 05:02:24 -0400 Subject: [PATCH] rewrited with method anyLoadOnload --- lib/client/menu.js | 52 ++++++++++++++++++-------------------------- lib/client/socket.js | 14 +++++++----- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/lib/client/menu.js b/lib/client/menu.js index 320790e7..cd7d4b90 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -103,25 +103,17 @@ var CloudCommander, $; * @param pPosition - position of menu */ function load(){ - var ljsLoad_f = function(){ - var lUISrc = Menu.dir + 'ui.position.js'; - var lMenuSrc = Menu.dir + 'contextMenu.js'; - - Util.jsload(lUISrc, function(){ - Util.jsload(lMenuSrc, Menu.show()); + console.time('menu load'); + + var lDir = Menu.dir; + + Util.anyLoadOnload([ + lDir + 'contextMenu.js', + lDir + 'contextMenu.css'], + function(){ + console.timeEnd('menu load'); + Menu.show(); }); - }; - - var lSrc = Menu.dir + 'contextMenu.css'; - - Util.cssLoad({ - src : lSrc, - func : { - onload: function(){ - Util.jqueryLoad(ljsLoad_f); - } - } - }); } function set(){ @@ -193,16 +185,14 @@ var CloudCommander, $; * right away after loading */ Menu.show = function(){ - return function(){ - set(); - - Util.Images.hideLoad(); - - if(Position && Position.x && Position.y) - $('li').contextMenu(Position); - else - $('li').contextMenu(); - }; + set(); + + Util.Images.hideLoad(); + + if(Position && Position.x && Position.y) + $('li').contextMenu(Position); + else + $('li').contextMenu(); }; /* key binding function */ @@ -246,11 +236,11 @@ var CloudCommander, $; key_event(); }; - /* showing context menu preview*/ - Menu.show(); + /* showing context menu preview*/ + Menu.show(); } - load(); + Util.jqueryLoad( load ); }; cloudcmd.Menu = Menu; diff --git a/lib/client/socket.js b/lib/client/socket.js index 1623e760..8b7170b0 100644 --- a/lib/client/socket.js +++ b/lib/client/socket.js @@ -22,9 +22,11 @@ var CloudCommander, io; socket.on('connect', function () { JqueryTerminal = getJqueryTerminal(); - outToTerminal({stdout: 'socket connected'}); + if(JqueryTerminal){ + outToTerminal({stdout: 'socket connected'}); - JqueryTerminal.Term.resume(); + JqueryTerminal.Term.resume(); + } }); socket.on('message', function (msg) { @@ -37,9 +39,11 @@ var CloudCommander, io; socket.on('disconnect', function () { JqueryTerminal = getJqueryTerminal(); - outToTerminal({stderr: 'socket disconected'}); - - JqueryTerminal.Term.pause(); + if(JqueryTerminal){ + outToTerminal({stderr: 'socket disconected'}); + + JqueryTerminal.Term.pause(); + } }); },