[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) {
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){
@ -205,7 +204,7 @@ define([
menuContainer.css({left: showPoint[0], top: showPoint[1]});
menu.menuAlignEl = currentTarget;
menu.setOffset(-11, -currentTarget.height()/2 + 2);
menu.setOffset(-20, -currentTarget.height()/2 - 3);
menu.show();
_.delay(function() {
menu.cmpEl.focus();
@ -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))

View file

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

View file

@ -72,7 +72,6 @@ define([
initialize: function(options) {
_.extend(this, options);
this.pluginsPath = '../../../../sdkjs-plugins/';
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>',
'<% } %>',

View file

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

View file

@ -865,6 +865,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);
@ -1832,6 +1833,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;
@ -1872,20 +1915,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);
},
@ -1896,6 +1937,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){
@ -1906,8 +1949,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,
@ -1923,8 +1965,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: isRelativeUrl
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
}
});
@ -1941,13 +1982,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) {

View file

@ -642,6 +642,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);
@ -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
if (!plugins) return;
@ -1632,20 +1676,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);
},
@ -1666,8 +1708,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,
@ -1683,8 +1724,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: isRelativeUrl
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
}
});
@ -1701,13 +1741,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) {

View file

@ -623,6 +623,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));
}
@ -1817,6 +1818,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;
@ -1857,20 +1900,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);
},
@ -1891,8 +1932,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,
@ -1908,8 +1948,7 @@ define([
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons,
size: itemVar.size,
initOnSelectionChanged: itemVar.initOnSelectionChanged,
isRelativeUrl: isRelativeUrl
initOnSelectionChanged: itemVar.initOnSelectionChanged
}));
}
});
@ -1926,13 +1965,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) {