Change plugins loading. Get baseUrl from plugin's url and use all paths in plugin properties as relative.

This commit is contained in:
Julia Radzhabova 2017-02-21 14:20:00 +03:00
parent 6c427e9229
commit 3b82dab5f9
6 changed files with 131 additions and 52 deletions

View file

@ -84,7 +84,6 @@ define([
setMode: function(mode) { setMode: function(mode) {
if (mode.canPlugins) { if (mode.canPlugins) {
this.panelPlugins.pluginsPath = mode.pluginsPath;
this.updatePluginsList(); this.updatePluginsList();
} }
}, },
@ -143,7 +142,7 @@ define([
item.set('pluginObj', plugin); item.set('pluginObj', plugin);
arr.push(plugin); arr.push(plugin);
}); });
this.api.asc_pluginsRegister(this.panelPlugins.pluginsPath, arr); this.api.asc_pluginsRegister('', arr);
}, },
onSelectPlugin: function(picker, item, record, e){ onSelectPlugin: function(picker, item, record, e){
@ -220,8 +219,7 @@ define([
var variation = plugin.get_Variations()[variationIndex]; var variation = plugin.get_Variations()[variationIndex];
if (variation.get_Visual()) { if (variation.get_Visual()) {
var url = variation.get_Url(); var url = variation.get_Url();
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(url)) url = ((plugin.get_BaseUrl().length == 0) ? url : plugin.get_BaseUrl()) + url;
url = ((plugin.get_BaseUrl().length == 0) ? this.panelPlugins.pluginsPath : plugin.get_BaseUrl()) + url;
if (variation.get_InsideMode()) { if (variation.get_InsideMode()) {
if (!this.panelPlugins.openInsideMode(plugin.get_Name(), url)) if (!this.panelPlugins.openInsideMode(plugin.get_Name(), url))

View file

@ -65,8 +65,7 @@ define([
isUpdateOleOnResize: false, isUpdateOleOnResize: false,
buttons: [], buttons: [],
size: [800, 600], size: [800, 600],
initOnSelectionChanged: false, initOnSelectionChanged: false
isRelativeUrl: true
} }
} }
}); });

View file

@ -72,7 +72,6 @@ define([
initialize: function(options) { initialize: function(options) {
_.extend(this, options); _.extend(this, options);
this.pluginsPath = '';
this._locked = false; this._locked = false;
this._state = { this._state = {
DisabledControls: true DisabledControls: true
@ -92,7 +91,7 @@ define([
enableKeyEvents: false, enableKeyEvents: false,
itemTemplate: _.template([ itemTemplate: _.template([
'<div id="<%= id %>" class="item-plugins" style="display: block;">', '<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) { %>', '<% if (variations.length>1) { %>',
'<div class="plugin-caret img-commonctrl"></div>', '<div class="plugin-caret img-commonctrl"></div>',
'<% } %>', '<% } %>',

View file

@ -1937,10 +1937,11 @@ define([
var arr = []; var arr = [];
pluginsData.forEach(function(item){ pluginsData.forEach(function(item){
var url = item, var value = _getPluginJson(item);
value = _getPluginJson(url); if (value) {
value.baseUrl = url.substring(0, url.lastIndexOf("config.json")); value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
if (value) arr.push(value); arr.push(value);
}
}); });
if (arr.length>0) if (arr.length>0)
@ -1956,6 +1957,8 @@ define([
if (plugins) { if (plugins) {
var arr = [], arrUI = []; var arr = [], arrUI = [];
plugins.pluginsData.forEach(function(item){ plugins.pluginsData.forEach(function(item){
if (uiCustomize!==undefined && pluginStore.findWhere({baseUrl : item.baseUrl})) return;
var variations = item.variations, var variations = item.variations,
variationsArr = []; variationsArr = [];
variations.forEach(function(itemVar){ variations.forEach(function(itemVar){
@ -1966,8 +1969,7 @@ define([
} }
} }
if (isSupported && (isEdit || itemVar.isViewer)) { if (isSupported && (isEdit || itemVar.isViewer)) {
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url)); item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? (item.baseUrl + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description, description: itemVar.description,
index: variationsArr.length, index: variationsArr.length,
@ -1983,8 +1985,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize, isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons, buttons: itemVar.buttons,
size: itemVar.size, size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged, initOnSelectionChanged: itemVar.initOnSelectionChanged
isRelativeUrl: isRelativeUrl
})); }));
} }
}); });
@ -2001,13 +2002,14 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI; this.UICustomizePlugins = arrUI;
if (!uiCustomize) { if (uiCustomize === undefined) { // for desktop
if (pluginStore) pluginStore.reset(arr); if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url); this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = (arr.length>0); } else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} }
} else if (!uiCustomize){ } else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;
} }
if (this.appOptions.canPlugins) { if (this.appOptions.canPlugins) {

View file

@ -643,6 +643,7 @@ define([
pluginsController.setApi(me.api); pluginsController.setApi(me.api);
me.updatePlugins(me.plugins, false); me.updatePlugins(me.plugins, false);
me.requestPlugins('../../../../sdkjs-plugins/config.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me)); me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
documentHolderController.setApi(me.api); 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 updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return; if (!plugins) return;
@ -1654,20 +1698,18 @@ define([
return null; return null;
}; };
var arr = [], var arr = [];
baseUrl = plugins.url;
pluginsData.forEach(function(item){ pluginsData.forEach(function(item){
var url = item; var value = _getPluginJson(item);
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item)) if (value) {
url = baseUrl + item; value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
var value = _getPluginJson(url); arr.push(value);
if (value) arr.push(value); }
}); });
if (arr.length>0) if (arr.length>0)
this.updatePluginsList({ this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid, autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr pluginsData: arr
}, !!uiCustomize); }, !!uiCustomize);
}, },
@ -1688,8 +1730,7 @@ define([
} }
} }
if (isSupported && (isEdit || itemVar.isViewer)){ if (isSupported && (isEdit || itemVar.isViewer)){
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url)); item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description, description: itemVar.description,
index: variationsArr.length, index: variationsArr.length,
@ -1705,8 +1746,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize, isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons, buttons: itemVar.buttons,
size: itemVar.size, size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged, initOnSelectionChanged: itemVar.initOnSelectionChanged
isRelativeUrl: isRelativeUrl
})); }));
} }
}); });
@ -1723,13 +1763,14 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI; this.UICustomizePlugins = arrUI;
if (!uiCustomize) { if (uiCustomize === undefined) { // for desktop
if (pluginStore) pluginStore.reset(arr); if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url); this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = (arr.length>0); } else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} }
} else if (!uiCustomize){ } else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;
} }
if (this.appOptions.canPlugins) { if (this.appOptions.canPlugins) {

View file

@ -624,6 +624,7 @@ define([
if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) { if (!me.appOptions.isEditMailMerge && !me.appOptions.isEditDiagram) {
pluginsController.setApi(me.api); pluginsController.setApi(me.api);
me.updatePlugins(me.plugins, false); me.updatePlugins(me.plugins, false);
me.requestPlugins('../../../../sdkjs-plugins/config.json');
me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me)); me.api.asc_registerCallback('asc_onPluginsInit', _.bind(me.updatePluginsList, me));
} }
@ -1839,6 +1840,48 @@ define([
if (url) this.iframePrint.src = url; 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 updatePlugins: function(plugins, uiCustomize) { // plugins from config
if (!plugins) return; if (!plugins) return;
@ -1879,20 +1922,18 @@ define([
return null; return null;
}; };
var arr = [], var arr = [];
baseUrl = plugins.url;
pluginsData.forEach(function(item){ pluginsData.forEach(function(item){
var url = item; var value = _getPluginJson(item);
if (!/(^https?:\/\/)/i.test(url) && !/(^www.)/i.test(item)) if (value) {
url = baseUrl + item; value.baseUrl = item.substring(0, item.lastIndexOf("config.json"));
var value = _getPluginJson(url); arr.push(value);
if (value) arr.push(value); }
}); });
if (arr.length>0) if (arr.length>0)
this.updatePluginsList({ this.updatePluginsList({
autoStartGuid: plugins.autoStartGuid, autoStartGuid: plugins.autoStartGuid,
url: plugins.url,
pluginsData: arr pluginsData: arr
}, !!uiCustomize); }, !!uiCustomize);
}, },
@ -1913,8 +1954,7 @@ define([
} }
} }
if (isSupported && (isEdit || itemVar.isViewer)) { if (isSupported && (isEdit || itemVar.isViewer)) {
var isRelativeUrl = !(/(^https?:\/\/)/i.test(itemVar.url) || /(^www.)/i.test(itemVar.url)); item.isUICustomizer ? arrUI.push(item.baseUrl + itemVar.url) :
item.isUICustomizer ? arrUI.push((isRelativeUrl) ? ((item.baseUrl ? item.baseUrl : plugins.url) + itemVar.url) : itemVar.url) :
variationsArr.push(new Common.Models.PluginVariation({ variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description, description: itemVar.description,
index: variationsArr.length, index: variationsArr.length,
@ -1930,8 +1970,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize, isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons, buttons: itemVar.buttons,
size: itemVar.size, size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged, initOnSelectionChanged: itemVar.initOnSelectionChanged
isRelativeUrl: isRelativeUrl
})); }));
} }
}); });
@ -1948,13 +1987,14 @@ define([
if (uiCustomize!==false) // from ui customizer in editor config or desktop event if (uiCustomize!==false) // from ui customizer in editor config or desktop event
this.UICustomizePlugins = arrUI; this.UICustomizePlugins = arrUI;
if (!uiCustomize) { if (uiCustomize === undefined) { // for desktop
if (pluginStore) pluginStore.reset(arr); if (pluginStore) pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url); this.appOptions.canPlugins = (pluginStore.length>0);
this.appOptions.canPlugins = (arr.length>0); } else if (!uiCustomize) {
if (pluginStore) pluginStore.add(arr);
this.appOptions.canPlugins = (pluginStore.length>0);
} }
} else if (!uiCustomize){ } else if (!uiCustomize){
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;
} }
if (this.appOptions.canPlugins) { if (this.appOptions.canPlugins) {