mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(load-remote) add
This commit is contained in:
parent
8daa190351
commit
3d9656c4c2
4 changed files with 104 additions and 84 deletions
|
|
@ -61,23 +61,6 @@ module.exports.getByClassAll = (className, element) => {
|
|||
return (element || document).getElementsByClassName(className);
|
||||
};
|
||||
|
||||
/**
|
||||
* check SVG SMIL animation support
|
||||
*/
|
||||
module.exports.isSVG = () => {
|
||||
const createNS = document.createElementNS;
|
||||
const SVG_URL = 'http://www.w3.org/2000/svg';
|
||||
|
||||
if (!createNS)
|
||||
return false;
|
||||
|
||||
const create = createNS.bind(document);
|
||||
const svgNode = create(SVG_URL, 'animate');
|
||||
const name = svgNode.toString();
|
||||
|
||||
return /SVGAnimate/.test(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* add class=hidden to element
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const DOM = require('../dom');
|
||||
const DOM = require('./');
|
||||
|
||||
const Images = module.exports;
|
||||
|
||||
|
|
@ -13,11 +13,29 @@ const ERROR = 'error';
|
|||
const LoadingImage = LOADING + getLoadingType();
|
||||
|
||||
function getLoadingType() {
|
||||
return DOM.isSVG() ? '-svg' : '-gif';
|
||||
return isSVG() ? '-svg' : '-gif';
|
||||
}
|
||||
|
||||
module.exports.get = getElement;
|
||||
|
||||
/**
|
||||
* check SVG SMIL animation support
|
||||
*/
|
||||
function isSVG() {
|
||||
const createNS = document.createElementNS;
|
||||
const SVG_URL = 'http://www.w3.org/2000/svg';
|
||||
|
||||
if (!createNS)
|
||||
return false;
|
||||
|
||||
const create = createNS.bind(document);
|
||||
const svgNode = create(SVG_URL, 'animate');
|
||||
const name = svgNode.toString();
|
||||
|
||||
return /SVGAnimate/.test(name);
|
||||
}
|
||||
|
||||
|
||||
function getElement() {
|
||||
return DOM.load({
|
||||
name : 'span',
|
||||
|
|
@ -50,15 +68,15 @@ module.exports.error = () => {
|
|||
return element;
|
||||
};
|
||||
|
||||
module.exports.show = load;
|
||||
module.exports.show.load = load;
|
||||
module.exports.show = show;
|
||||
module.exports.show.load = show;
|
||||
module.exports.show.error = error;
|
||||
|
||||
/**
|
||||
* Function shows loading spinner
|
||||
* position = {top: true};
|
||||
*/
|
||||
function load(position, panel) {
|
||||
function show(position, panel) {
|
||||
const image = Images.loading();
|
||||
const parent = image.parentElement;
|
||||
const refreshButton = DOM.getRefreshButton(panel);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
'use strict';
|
||||
|
||||
const itype = require('itype/legacy');
|
||||
const rendy = require('rendy');
|
||||
const exec = require('execon');
|
||||
const jonny = require('jonny');
|
||||
const Util = require('../../common/util');
|
||||
|
|
@ -22,89 +21,38 @@ module.exports = DOM;
|
|||
|
||||
const Images = require('./images');
|
||||
const load = require('./load');
|
||||
const Files = require('./files');
|
||||
|
||||
DOM.Images = Images;
|
||||
DOM.load = load;
|
||||
DOM.Files = Files;
|
||||
|
||||
DOM.uploadDirectory = require('./directory');
|
||||
DOM.Buffer = require('./buffer');
|
||||
DOM.Events = require('./events');
|
||||
DOM.Storage = require('./storage');
|
||||
DOM.Files = require('./files');
|
||||
DOM.RESTful = require('./rest');
|
||||
|
||||
const loadRemote = require('./load-remote');
|
||||
const selectByPattern = require('./select-by-pattern');
|
||||
|
||||
function CmdProto() {
|
||||
const Cmd = this;
|
||||
let Title;
|
||||
let CurrentInfo = {};
|
||||
|
||||
const Cmd = this;
|
||||
const CURRENT_FILE = 'current-file';
|
||||
const SELECTED_FILE = 'selected-file';
|
||||
const TITLE = 'Cloud Commander';
|
||||
var Title;
|
||||
const TabPanel = {
|
||||
'js-left' : null,
|
||||
'js-right' : null
|
||||
};
|
||||
|
||||
this.loadRemote = function(name, options, callback) {
|
||||
var o = options;
|
||||
var Files = DOM.Files;
|
||||
|
||||
if (!callback)
|
||||
callback = options;
|
||||
|
||||
if (o.name && window[o.name])
|
||||
callback();
|
||||
else
|
||||
Files.get('modules', function(error, modules) {
|
||||
var remoteTmpls, local, remote,
|
||||
load = DOM.load,
|
||||
prefix = CloudCmd.PREFIX,
|
||||
online = CloudCmd.config('online') && navigator.onLine,
|
||||
|
||||
remoteObj = Util.findObjByNameInArr(modules, 'remote'),
|
||||
module = Util.findObjByNameInArr(remoteObj, name),
|
||||
|
||||
isArray = itype.array(module.local),
|
||||
version = module.version,
|
||||
|
||||
funcOFF = () => {
|
||||
load.parallel(local, callback);
|
||||
},
|
||||
|
||||
funcON = () => {
|
||||
load.parallel(remote, (error) => {
|
||||
if (error)
|
||||
return funcOFF();
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
if (isArray) {
|
||||
remoteTmpls = module.remote;
|
||||
local = module.local;
|
||||
} else {
|
||||
remoteTmpls = [module.remote];
|
||||
local = [module.local];
|
||||
}
|
||||
|
||||
local = local.map(function(url) {
|
||||
return prefix + url;
|
||||
});
|
||||
|
||||
remote = remoteTmpls.map(function(tmpl) {
|
||||
return rendy(tmpl, {
|
||||
version: version
|
||||
});
|
||||
});
|
||||
|
||||
exec.if(online, funcON, funcOFF);
|
||||
});
|
||||
|
||||
this.loadRemote = (name, options, callback) => {
|
||||
loadRemote(name, options, callback);
|
||||
return DOM;
|
||||
};
|
||||
|
||||
/**
|
||||
* load jquery from google cdn or local copy
|
||||
* @param callback
|
||||
|
|
@ -553,7 +501,7 @@ function CmdProto() {
|
|||
return el.parentElement;
|
||||
|
||||
return el;
|
||||
}
|
||||
};
|
||||
|
||||
const el = getEl(element);
|
||||
|
||||
|
|
|
|||
71
client/dom/load-remote.js
Normal file
71
client/dom/load-remote.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
'use strict';
|
||||
|
||||
/* global CloudCmd */
|
||||
|
||||
const exec = require('execon');
|
||||
const rendy = require('rendy');
|
||||
const itype = require('itype/legacy');
|
||||
const {findObjByNameInArr} = require('../../common/util');
|
||||
|
||||
const load = require('./load');
|
||||
const Files = require('./files');
|
||||
|
||||
module.exports = (name, options, callback = options) => {
|
||||
const {PREFIX, config} = CloudCmd;
|
||||
const o = options;
|
||||
|
||||
if (o.name && window[o.name])
|
||||
return callback();
|
||||
|
||||
Files.get('modules', (error, modules) => {
|
||||
const online = config('online') && navigator.onLine;
|
||||
|
||||
const remoteObj = findObjByNameInArr(modules, 'remote');
|
||||
const module = findObjByNameInArr(remoteObj, name);
|
||||
|
||||
const isArray = itype.array(module.local);
|
||||
const version = module.version;
|
||||
|
||||
let remoteTmpls, local;
|
||||
if (isArray) {
|
||||
remoteTmpls = module.remote;
|
||||
local = module.local;
|
||||
} else {
|
||||
remoteTmpls = [module.remote];
|
||||
local = [module.local];
|
||||
}
|
||||
|
||||
const localURL = local.map((url) => {
|
||||
return PREFIX + url;
|
||||
});
|
||||
|
||||
const remoteURL = remoteTmpls.map((tmpl) => {
|
||||
return rendy(tmpl, {
|
||||
version: version
|
||||
});
|
||||
});
|
||||
|
||||
const on = funcON(localURL, remoteURL, callback);
|
||||
const off = funcOFF(localURL, callback);
|
||||
|
||||
exec.if(online, on, off);
|
||||
});
|
||||
};
|
||||
|
||||
function funcOFF(local, callback) {
|
||||
return () => {
|
||||
load.parallel(local, callback);
|
||||
};
|
||||
}
|
||||
|
||||
function funcON (local, remote,callback) {
|
||||
return () => {
|
||||
load.parallel(remote, (error) => {
|
||||
if (error)
|
||||
return funcOFF();
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue