[Common] cherrypicked changes for plugins (6c427e9, 3b82dab, aceb1fe)

This commit is contained in:
Maxim Kadushkin 2017-03-01 19:19:42 +03:00
parent 52e1610b1d
commit a75065ecd6
7 changed files with 178 additions and 59 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){
@ -205,7 +204,7 @@ define([
menuContainer.css({left: showPoint[0], top: showPoint[1]}); menuContainer.css({left: showPoint[0], top: showPoint[1]});
menu.menuAlignEl = currentTarget; menu.menuAlignEl = currentTarget;
menu.setOffset(-11, -currentTarget.height()/2 + 2); menu.setOffset(-20, -currentTarget.height()/2 - 3);
menu.show(); menu.show();
_.delay(function() { _.delay(function() {
menu.cmpEl.focus(); menu.cmpEl.focus();
@ -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 = '../../../../sdkjs-plugins/';
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

@ -44,8 +44,8 @@
} }
.plugin-icon { .plugin-icon {
width: 31px; width: 40px;
height: 31px; height: 40px;
display: inline-block; display: inline-block;
.box-shadow(0 0 0 1px transparent); .box-shadow(0 0 0 1px transparent);
vertical-align: middle; vertical-align: middle;

View file

@ -865,6 +865,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);
@ -1832,6 +1833,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;
@ -1872,20 +1915,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);
}, },
@ -1896,6 +1937,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){
@ -1906,8 +1949,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,
@ -1923,8 +1965,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
})); }));
} }
}); });
@ -1941,13 +1982,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

@ -642,6 +642,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);
@ -1592,6 +1593,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;
@ -1632,20 +1676,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);
}, },
@ -1666,8 +1708,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,
@ -1683,8 +1724,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
})); }));
} }
}); });
@ -1701,13 +1741,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

@ -623,6 +623,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));
} }
@ -1817,6 +1818,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;
@ -1857,20 +1900,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);
}, },
@ -1891,8 +1932,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,
@ -1908,8 +1948,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
})); }));
} }
}); });
@ -1926,13 +1965,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) {