From 5fcd84c559cb4cf25d5f3cf20a51235f67664b7e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 23 Dec 2012 06:42:04 -0500 Subject: [PATCH] refactored --- lib/client/menu.js | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/client/menu.js b/lib/client/menu.js index eac93841..5a65ad6a 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -109,25 +109,15 @@ var CloudCommander, Util, DOM, $; * pItems = [{pName, pFunc}] */ function getAllItems(pItems){ - var lRet = {}; + var lRet = {}, + lName, + lFunc; - if( Util.isArray(pItems) ){ - var lName, - lFunc, - i, n = pItems.length; - for(i = 0; i < n; i++){ - var lItem = pItems[i]; - if(lItem){ - lName = lItem.name; - - for(var lProp in lItem){ - lName = lProp; - lFunc = lItem[lProp]; - } - lRet[lName] = getItem(lName, lFunc); - } + if(pItems) + for(lName in pItems){ + lFunc = pItems[lName]; + lRet[lName] = getItem(lName, lFunc); } - } return lRet; } @@ -148,13 +138,12 @@ var CloudCommander, Util, DOM, $; }, // define the elements of the menu - items: getAllItems([ - { 'View' : Util.retExec(showEditor, true) }, - { 'Edit' : Util.retExec(showEditor) }, - { 'Delete' : Util.retExec(DOM.promptRemoveCurrent) }, - { 'Upload to' : getUploadToItem( ['GitHub', 'GDrive', 'DropBox'] ) }, - { - 'Download' : function(key, opt){ + items: getAllItems({ + 'View' : Util.retExec(showEditor, true), + 'Edit' : Util.retExec(showEditor), + 'Delete' : Util.retExec(DOM.promptRemoveCurrent), + 'Upload to' : getUploadToItem( ['GitHub', 'GDrive', 'DropBox'] ), + 'Download' : function(key, opt){ DOM.Images.showLoad(); var lPath = DOM.getCurrentPath(), @@ -183,8 +172,7 @@ var CloudCommander, Util, DOM, $; responseText: 'Error: You trying to' + 'download same file to often'}); } - } - ]) + }) }; }