diff --git a/json/modules.json b/json/modules.json index f739aaa0..5e30574f 100644 --- a/json/modules.json +++ b/json/modules.json @@ -9,6 +9,19 @@ "socket", "terminal", "console", [{ + "name": "remote", + "data": [ { + "name": "jquery", + "version": "2.1.1", + "local": "/lib/client/jquery.js", + "remote": "//ajax.googleapis.com/ajax/libs/jquery/{{ version }}/jquery.min.js" + }, { + "name": "socket", + "version": "1.0.0", + "local": "/socket.io/socket.io.js", + "remote": "//cdn.socket.io/socket.io-{{ version }}.js" + }] + }, { "name": "storage", "data": [{ "name": "DropBox", diff --git a/lib/client/dom.js b/lib/client/dom.js index 2656a45e..f4e6e3ed 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -333,16 +333,24 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; return ret; } - function loadRemote(url, callback) { - Util.checkArgs(arguments, ['url', 'callback']); + function loadRemote(name, callback) { + var getConfig = CloudCmd.getConfig, + getModules = CloudCmd.getModules; - CloudCmd.getConfig(function(config) { + Util.exec.parallel([getConfig, getModules], function(config, modules) { var load = DOM.load, + online = config.online && navigator.onLine, - local = url.local, - remote = url.remote, + remoteObj = Util.findObjByNameInArr(modules, 'remote'), + jquery = Util.findObjByNameInArr(remoteObj, name), - online = config.online && navigator.onLine, + version = jquery.version, + local = jquery.local, + remoteTmpl = jquery.remote, + + remote = Util.render(remoteTmpl, { + version: version + }), funcON = function() { load.js(remote, { @@ -366,35 +374,11 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; * @param callback */ this.loadJquery = function(callback) { - var VERSION = '2.1.1', - - local = '/lib/client/jquery.js', - remoteTemplate = '//ajax.googleapis.com/ajax/libs/jquery/{{ version }}/jquery.min.js', - - remote = Util.render(remoteTemplate, { - version: VERSION - }); - - loadRemote({ - local : local, - remote : remote - }, callback); + loadRemote('jquery', callback); }; this.loadSocket = function(callback) { - var VERSION = '1.0.0', - - local = '/socket.io/socket.io.js', - remoteTemplate = 'https://cdn.socket.io/socket.io-{{ version }}.js', - - remote = Util.render(remoteTemplate, { - version: VERSION - }); - - loadRemote({ - local : local, - remote : remote - }, callback); + loadRemote('socket', callback); }; /** function loads css and js of Menu diff --git a/lib/util.js b/lib/util.js index c64401d3..7277e6ec 100644 --- a/lib/util.js +++ b/lib/util.js @@ -886,10 +886,12 @@ if (isArray) { array.some(function(item) { - var is, + var is = item.name === name, isArray = Util.isArray(item); - if (isArray) + if (is) + ret = item; + else if (isArray) item.some(function(item) { is = item.name === name;