Change plugins loading. Get baseUrl from plugin's url and use all paths in plugin properties as relative.
This commit is contained in:
parent
6c427e9229
commit
3b82dab5f9
|
@ -84,7 +84,6 @@ define([
|
|||
|
||||
setMode: function(mode) {
|
||||
if (mode.canPlugins) {
|
||||
this.panelPlugins.pluginsPath = mode.pluginsPath;
|
||||
this.updatePluginsList();
|
||||
}
|
||||
},
|
||||
|
@ -143,7 +142,7 @@ define([
|
|||
item.set('pluginObj', plugin);
|
||||
arr.push(plugin);
|
||||
});
|
||||
this.api.asc_pluginsRegister(this.panelPlugins.pluginsPath, arr);
|
||||
this.api.asc_pluginsRegister('', arr);
|
||||
},
|
||||
|
||||
onSelectPlugin: function(picker, item, record, e){
|
||||
|
@ -220,8 +219,7 @@ define([
|
|||
var variation = plugin.get_Variations()[variationIndex];
|
||||
if (variation.get_Visual()) {
|
||||
var url = variation.get_Url();
|
||||
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(url))
|
||||
url = ((plugin.get_BaseUrl().length == 0) ? this.panelPlugins.pluginsPath : plugin.get_BaseUrl()) + url;
|
||||
url = ((plugin.get_BaseUrl().length == 0) ? url : plugin.get_BaseUrl()) + url;
|
||||
|
||||
if (variation.get_InsideMode()) {
|
||||
if (!this.panelPlugins.openInsideMode(plugin.get_Name(), url))
|
||||
|
|
|
@ -65,8 +65,7 @@ define([
|
|||
isUpdateOleOnResize: false,
|
||||
buttons: [],
|
||||
size: [800, 600],
|
||||
initOnSelectionChanged: false,
|
||||
isRelativeUrl: true
|
||||
initOnSelectionChanged: false
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -72,7 +72,6 @@ define([
|
|||
|
||||
initialize: function(options) {
|
||||
_.extend(this, options);
|
||||
this.pluginsPath = '';
|
||||
this._locked = false;
|
||||
this._state = {
|
||||
DisabledControls: true
|
||||
|
@ -92,7 +91,7 @@ define([
|
|||
enableKeyEvents: false,
|
||||
itemTemplate: _.template([
|
||||
'<div id="<%= id %>" class="item-plugins" style="display: block;">',
|
||||
'<div class="plugin-icon" style="background-image: url(' + '<% if (variations[currentVariation].get("isRelativeUrl")) { if (baseUrl !=="") { %>' + '<%= baseUrl %>' + '<% } else { %>' + this.pluginsPath + '<% } } %>' + '<%= variations[currentVariation].get("icons")[(window.devicePixelRatio > 1) ? 1 : 0] %>);"></div>',
|
||||
'<div class="plugin-icon" style="background-image: url(' + '<%= baseUrl %>' + '<%= variations[currentVariation].get("icons")[(window.devicePixelRatio > 1) ? 1 : 0] %>);"></div>',
|
||||
'<% if (variations.length>1) { %>',
|
||||
'<div class="plugin-caret img-commonctrl"></div>',
|
||||
'<% } %>',
|
||||
|
|
|
@ -1937,10 +1937,11 @@ define([
|
|||
|
||||
var arr = [];
|
||||
pluginsData.forEach(function(item){
|
||||
var url = item,
|
||||
value = _getPluginJson(url);
|
||||
value.baseUrl = url.substring(0, url.lastIndexOf("config.json"));
|
||||
if (value) arr.push(value);
|
||||
var value = _getPluginJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0)
|
||||
|
@ -1956,6 +1957,8 @@ define([
|
|||
if (plugins) {
|
||||
var arr = [], arrUI = [];
|
||||
plugins.pluginsData.forEach(function(item){
|
||||
if (uiCustomize!==undefined && pluginStore.findWhere({baseUrl : item.baseUrl})) return;
|
||||
|
||||
var variations = item.variations,
|
||||
variationsArr = [];
|
||||
variations.forEach(function(itemVar){
|
||||
|
@ -1966,8 +1969,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 + itemVar.url) : itemVar.url) :
|
||||
item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
|
||||
variationsArr.push(new Common.Models.PluginVariation({
|
||||
description: itemVar.description,
|
||||
index: variationsArr.length,
|
||||
|
@ -1983,8 +1985,7 @@ define([
|
|||
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
|
||||
buttons: itemVar.buttons,
|
||||
size: itemVar.size,
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged,
|
||||
isRelativeUrl: isRelativeUrl
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -2001,13 +2002,14 @@ define([
|
|||
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if (!uiCustomize) {
|
||||
if (uiCustomize === undefined) { // for desktop
|
||||
if (pluginStore) pluginStore.reset(arr);
|
||||
this.appOptions.pluginsPath = (plugins.url);
|
||||
this.appOptions.canPlugins = (arr.length>0);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
} else if (!uiCustomize) {
|
||||
if (pluginStore) pluginStore.add(arr);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.pluginsPath = '';
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (this.appOptions.canPlugins) {
|
||||
|
|
|
@ -643,6 +643,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);
|
||||
|
@ -1614,6 +1615,49 @@ define([
|
|||
}
|
||||
},
|
||||
|
||||
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;
|
||||
|
||||
|
@ -1654,20 +1698,18 @@ 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);
|
||||
if (value) arr.push(value);
|
||||
var value = _getPluginJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0)
|
||||
this.updatePluginsList({
|
||||
autoStartGuid: plugins.autoStartGuid,
|
||||
url: plugins.url,
|
||||
pluginsData: arr
|
||||
}, !!uiCustomize);
|
||||
},
|
||||
|
@ -1688,8 +1730,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(item.baseUrl + itemVar.url) :
|
||||
variationsArr.push(new Common.Models.PluginVariation({
|
||||
description: itemVar.description,
|
||||
index: variationsArr.length,
|
||||
|
@ -1705,8 +1746,7 @@ define([
|
|||
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
|
||||
buttons: itemVar.buttons,
|
||||
size: itemVar.size,
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged,
|
||||
isRelativeUrl: isRelativeUrl
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -1723,13 +1763,14 @@ define([
|
|||
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if (!uiCustomize) {
|
||||
if (uiCustomize === undefined) { // for desktop
|
||||
if (pluginStore) pluginStore.reset(arr);
|
||||
this.appOptions.pluginsPath = (plugins.url);
|
||||
this.appOptions.canPlugins = (arr.length>0);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
} else if (!uiCustomize) {
|
||||
if (pluginStore) pluginStore.add(arr);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.pluginsPath = '';
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (this.appOptions.canPlugins) {
|
||||
|
|
|
@ -624,6 +624,7 @@ define([
|
|||
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -1839,6 +1840,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;
|
||||
|
||||
|
@ -1879,20 +1922,18 @@ 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);
|
||||
if (value) arr.push(value);
|
||||
var value = _getPluginJson(item);
|
||||
if (value) {
|
||||
value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
|
||||
arr.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (arr.length>0)
|
||||
this.updatePluginsList({
|
||||
autoStartGuid: plugins.autoStartGuid,
|
||||
url: plugins.url,
|
||||
pluginsData: arr
|
||||
}, !!uiCustomize);
|
||||
},
|
||||
|
@ -1913,8 +1954,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(item.baseUrl + itemVar.url) :
|
||||
variationsArr.push(new Common.Models.PluginVariation({
|
||||
description: itemVar.description,
|
||||
index: variationsArr.length,
|
||||
|
@ -1930,8 +1970,7 @@ define([
|
|||
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
|
||||
buttons: itemVar.buttons,
|
||||
size: itemVar.size,
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged,
|
||||
isRelativeUrl: isRelativeUrl
|
||||
initOnSelectionChanged: itemVar.initOnSelectionChanged
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
@ -1948,13 +1987,14 @@ define([
|
|||
if (uiCustomize!==false) // from ui customizer in editor config or desktop event
|
||||
this.UICustomizePlugins = arrUI;
|
||||
|
||||
if (!uiCustomize) {
|
||||
if (uiCustomize === undefined) { // for desktop
|
||||
if (pluginStore) pluginStore.reset(arr);
|
||||
this.appOptions.pluginsPath = (plugins.url);
|
||||
this.appOptions.canPlugins = (arr.length>0);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
} else if (!uiCustomize) {
|
||||
if (pluginStore) pluginStore.add(arr);
|
||||
this.appOptions.canPlugins = (pluginStore.length>0);
|
||||
}
|
||||
} else if (!uiCustomize){
|
||||
this.appOptions.pluginsPath = '';
|
||||
this.appOptions.canPlugins = false;
|
||||
}
|
||||
if (this.appOptions.canPlugins) {
|
||||
|
|
Loading…
Reference in a new issue