diff --git a/gulpfile.js b/gulpfile.js index 13eaf626..0ee1ce2e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -55,8 +55,8 @@ name = 'ChangeLog'; Util.execParallel([ - Util.bind(exec, 'shell/log.sh ' + version), - Util.bind(fs.readFile, name), + Util.exec.with(exec, 'shell/log.sh ' + version), + Util.exec.with(fs.readFile, name), ], function(execParams, readParams) { var ERROR = 0, DATA = 1, diff --git a/lib/client.js b/lib/client.js index 7ca51e09..28bbaa5d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -151,7 +151,7 @@ var Util, DOM, CloudFunc; Util.exec.series([ initModules, baseInit, - Util.bind(CloudCmd.route, location.hash) + Util.exec.with(CloudCmd.route, location.hash) ]); }, diff --git a/lib/client/config.js b/lib/client/config.js index c600cc75..eb7f85da 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -35,7 +35,7 @@ var CloudCmd, Util, DOM; this.show = function() { var funcs = [ - Util.bind(CloudCmd.getTemplate, Template, 'config'), + Util.exec.with(CloudCmd.getTemplate, Template, 'config'), cssLoad ]; diff --git a/lib/client/console.js b/lib/client/console.js index b291ea0e..d484b7e8 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -13,8 +13,8 @@ var CloudCmd, Util, DOM, CloudFunc, $; Loading, jqconsole, - log = Util.bind(write, 'log'), - error = Util.bind(write, 'error'), + log = Util.exec.with(write, 'log'), + error = Util.exec.with(write, 'error'), Element, MouseBinded, diff --git a/lib/client/edit.js b/lib/client/edit.js index e65543db..9575f4a9 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -59,7 +59,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI not_append : true }); - onMenu = Util.bind(setMenu, Element); + onMenu = Util.exec.with(setMenu, Element); initAce(); @@ -272,7 +272,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI }); }); - }, Util.bind(doDiff, path)); + }, Util.exec.with(doDiff, path)); }); } diff --git a/lib/client/listeners.js b/lib/client/listeners.js index 626cec73..c4c4c5e9 100644 --- a/lib/client/listeners.js +++ b/lib/client/listeners.js @@ -12,12 +12,12 @@ var Util, DOM, CloudCmd; getConfig = CloudCmd.getConfig, OnPathLinks = [], EventsFiles = { - 'mousedown' : Util.bind(execIfNotUL, setCurrentFileByEvent), + 'mousedown' : Util.exec.with(execIfNotUL, setCurrentFileByEvent), 'contextmenu' : onContextMenu, - 'dragstart' : Util.bind(execIfNotUL, onDragStart), + 'dragstart' : Util.exec.with(execIfNotUL, onDragStart), 'click' : onClick, - 'dblclick' : Util.bind(execIfNotUL, onDblClick), - 'touchstart' : Util.bind(execIfNotUL, onTouch) + 'dblclick' : Util.exec.with(execIfNotUL, onDblClick), + 'touchstart' : Util.exec.with(execIfNotUL, onTouch) }; this.analytics = function() { @@ -101,7 +101,7 @@ var Util, DOM, CloudCmd; for (i = 0; i < n; i++) { ai = pathLinks[i]; link = Util.rmStr(ai.href, url), - load = Util.bind(loadDir, { + load = Util.exec.with(loadDir, { path : link, isRefresh : false, panel : panel @@ -359,7 +359,7 @@ var Util, DOM, CloudCmd; if (files.length) { Util.forEach(files, function(file) { - func = Util.bind(load, file, func); + func = Util.exec.with(load, file, func); }); func(); diff --git a/lib/client/markdown.js b/lib/client/markdown.js index bec2b406..fa8f9cd7 100644 --- a/lib/client/markdown.js +++ b/lib/client/markdown.js @@ -17,7 +17,7 @@ var CloudCmd, Util, DOM; Util.exec.series([ CloudCmd.View, - Util.bind(MD.show, null, null), + Util.exec.with(MD.show, null, null), ]); } diff --git a/lib/client/menu.js b/lib/client/menu.js index 3cb05e54..69cfe2a2 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -86,7 +86,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; options = { icon : true, beforeClose : Key.setBind, - beforeShow : Util.bind(beforeShow, func), + beforeShow : Util.exec.with(beforeShow, func), beforeClick : beforeClick, name : name }; @@ -114,8 +114,8 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; }, menuData = getMenuData(), menu = { - 'View' : Util.bind(show, 'View'), - 'Edit' : Util.bind(show, 'Edit'), + 'View' : Util.exec.with(show, 'View'), + 'Edit' : Util.exec.with(show, 'Edit'), 'Rename' : function() { setTimeout(DOM.renameCurrent, 100); }, @@ -169,7 +169,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; items = Util.getNamesFromObjArray(storage) || []; items.forEach(function(name) { - menu[name] = Util.bind(uploadTo, name); + menu[name] = Util.exec.with(uploadTo, name); }); callback(menu); diff --git a/lib/client/view.js b/lib/client/view.js index 2364848c..e29f38dc 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -48,7 +48,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; View.hide = hide; function init() { - var func = CallBack || Util.bind(show, null); + var func = CallBack || Util.exec.with(show, null); Loading = true; @@ -64,7 +64,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; className : 'view-overlay fancybox-overlay fancybox-overlay-fixed' }); - Events.addClick(Util.bind(onOverLayClick, Overlay), Overlay); + Events.addClick(Util.exec.with(onOverLayClick, Overlay), Overlay); Events.addKey(listener); } @@ -92,7 +92,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; if (isFunc) { func = config[name]; - config[name] = Util.bind(execParallel, [item, func]); + config[name] = Util.exec.with(execParallel, [item, func]); } else { config[name] = options[name]; } @@ -127,7 +127,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; case 'media': getMediaElement(path, function(element) { var media = DOM.getByDataName('js-media', element), - onKey = Util.bind(onMediaKey, media); + onKey = Util.exec.with(onMediaKey, media); $.fancybox.open(element, { parent : Overlay, diff --git a/lib/server.js b/lib/server.js index befb352b..fa73719a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -33,7 +33,7 @@ Rest, Route; - join = join && Util.bind(join, beforeJoin) || emptyHandler; + join = join && Util.exec.with(join, beforeJoin) || emptyHandler; /* базовая инициализация */ function init(pAppCachProcessing) { @@ -176,7 +176,7 @@ ]); funcs.map(function(func) { - return Util.bind(func, req, res); + return Util.exec.with(func, req, res); }); Util.exec.series(funcs); @@ -255,7 +255,7 @@ names[i] = minName; } - funcs.push(Util.bind(minify, name)); + funcs.push(Util.exec.with(minify, name)); } } diff --git a/lib/server/console.js b/lib/server/console.js index b05136f7..51dedf78 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -76,7 +76,7 @@ Clients[ConNum] = true; - onMessage = Util.bind(getOnMessage, ConNum, callback); + onMessage = Util.exec.with(getOnMessage, ConNum, callback); onDisconnect = function(conNum) { Clients[conNum] = ClientFuncs[conNum] = null; @@ -152,7 +152,7 @@ } if (!ClientFuncs[connNum]) - ClientFuncs[connNum] = Util.bind(setExec, function(json, error, stderr) { + ClientFuncs[connNum] = Util.exec.with(setExec, function(json, error, stderr) { log(connNum, error, 'error'); log(connNum, stderr, 'stderror'); diff --git a/lib/server/dir.js b/lib/server/dir.js index 54db8670..841dd2cd 100644 --- a/lib/server/dir.js +++ b/lib/server/dir.js @@ -57,7 +57,7 @@ fileCounter = 1; function getDirInfo(dir) { - stat(dir, Util.bind(getStat, dir)); + stat(dir, Util.exec.with(getStat, dir)); } function getStat(dir, error, stat) { diff --git a/lib/server/join.js b/lib/server/join.js index d0a3b367..d35bde68 100644 --- a/lib/server/join.js +++ b/lib/server/join.js @@ -11,16 +11,17 @@ function join(before, req, res, callback) { var names, - readFunc = Util.bind(readPipe, req, res), + exec = Util.exec, + readFunc = exec.with(readPipe, req, res), path = main.getPathName(req), isJoin = CloudFunc.isJoinURL(path); - if (!isJoin) - Util.exec(callback); - else { + if (!isJoin) { + exec(callback); + } else { names = CloudFunc.getJoinArray(path); - Util.exec.if(!before, readFunc, function(callback) { + exec.if(!before, readFunc, function(callback) { before(names, callback); }); } diff --git a/lib/server/minify.js b/lib/server/minify.js index 507afe58..b047b798 100644 --- a/lib/server/minify.js +++ b/lib/server/minify.js @@ -29,25 +29,26 @@ INDEX : HTMLDIR + 'index.html', optimize: function(name, params) { - var minifyName, isChanged, isExist; + var minifyName, isChanged, isExist, + exec = Util.exec; if (!Minify) { Util.log(COULD_NOT_MINIFY); - Util.exec(params.callback); + exec(params.callback); } else { minifyName = Minify.getName(name), - isChanged = Util.bind(IsChanged.isFileChanged, name), - isExist = Util.bind(fs.exists, minifyName); + isChanged = exec.with(IsChanged.isFileChanged, name), + isExist = exec.with(fs.exists, minifyName); if (!this.MinFolder) this.MinFolder = Minify.MinFolder; - Util.exec.parallel([isChanged, isExist], function(changed, exists) { + exec.parallel([isChanged, isExist], function(changed, exists) { if (changed || !exists) Minify.optimize(name, params); else - Util.exec(params.callback, null, { + exec(params.callback, null, { name: minifyName }); }); diff --git a/lib/server/win.js b/lib/server/win.js index a108b105..c2ab3249 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -21,14 +21,14 @@ WIN32 : 866 }, - exec = main.child_process.exec, + processExec = main.child_process.exec, Util = main.util; exports.getVolumes = function(callback) { var chcp = 'chcp ' + Charset.UNICODE, getVolumes = 'wmic logicaldisk get name'; - exec(chcp + ' && ' + getVolumes, Util.bind(processOuput, callback)); + processExec(chcp + ' && ' + getVolumes, Util.exec.with(processOuput, callback)); }; function processOuput(callback, error, stdout, stderr) { @@ -42,7 +42,7 @@ if (!error) error = stderr; - exec('chcp ' + Charset.WIN32); + processExec('chcp ' + Charset.WIN32); if(!error) { volumes = Util.rmStr(stdout, removeStr) diff --git a/lib/util.js b/lib/util.js index 7013ac95..5d927a7e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -11,21 +11,6 @@ function UtilProto() { var Util = this; - /* - * bind function to arguments without context - */ - - this.bind = function(callback) { - var result, - args = Util.slice(arguments, 1), - bind = Function.prototype.bind; - - args.unshift(null); - result = bind.apply(callback, args); - - return result; - }; - /* * apply arguemnts to constructor * @@ -690,16 +675,30 @@ return ret; }; + /* + * return function that calls callback with arguments + */ + + exec.with = function(callback) { + var result, + bind = Function.prototype.bind; + + arguments[0] = null; + result = bind.apply(callback, arguments); + + return result; + }; + /** * return save exec function * @param callback */ exec.ret = function() { var result, - args = Util.slice(arguments); + args = Util.slice(arguments) args.unshift(exec); - result = Util.bind.apply(null, args); + result = exec.with.apply(null, args); return result; };