[DE] Change plugins loading.

This commit is contained in:
Julia Radzhabova 2017-02-21 12:10:39 +03:00
parent be56f9e3de
commit 6c427e9229
2 changed files with 49 additions and 9 deletions

View file

@ -72,7 +72,7 @@ define([
initialize: function(options) {
_.extend(this, options);
this.pluginsPath = '../../../../sdkjs-plugins/';
this.pluginsPath = '';
this._locked = false;
this._state = {
DisabledControls: true

View file

@ -864,6 +864,7 @@ define([
pluginsController.setApi(me.api);
me.updatePlugins(me.plugins, false);
me.requestPlugins('../../../../sdkjs-plugins/config.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api);
@ -1852,6 +1853,48 @@ define([
if (url) this.iframePrint.src = url;
},
requestPlugins: function(pluginsPath) { // request plugins
if (!pluginsPath) return;
var _createXMLHTTPObject = function() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
};
var _getPluginJson = function(plugin) {
if (!plugin) return '';
try {
var xhrObj = _createXMLHTTPObject();
if (xhrObj && plugin) {
xhrObj.open('GET', plugin, false);
xhrObj.send('');
var pluginJson = eval("(" + xhrObj.responseText + ")");
return pluginJson;
}
}
catch (e) {}
return null;
};
var value = _getPluginJson(pluginsPath);
if (value)
this.updatePlugins(value, false);
},
updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return;
@ -1892,20 +1935,17 @@ define([
return null;
};
var arr = [],
baseUrl = plugins.url;
var arr = [];
pluginsData.forEach(function(item){
var url = item;
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item))
url = baseUrl + item;
var value = _getPluginJson(url);
var url = item,
value = _getPluginJson(url);
value.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
if (value) arr.push(value);
});
if (arr.length>0)
this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr
}, !!uiCustomize);
},
@ -1927,7 +1967,7 @@ define([
}
if (isSupported && (isEdit || itemVar.isViewer)) {
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url));
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? (item.baseUrl + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: variationsArr.length,