Commit f0d5a7aa authored by Oleg Korshul's avatar Oleg Korshul

multiplugins scheme

parent d5984bf1
...@@ -106,9 +106,8 @@ ...@@ -106,9 +106,8 @@
if (window.captureEvents) if (window.captureEvents)
window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP); window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
var _frame = document.getElementById("plugin_iframe"); if (window.g_asc_plugins)
if (_frame) window.g_asc_plugins.disablePointerEvents();
_frame.style.pointerEvents = "none";
/* /*
var parent = window; var parent = window;
...@@ -140,9 +139,8 @@ ...@@ -140,9 +139,8 @@
if (window.releaseEvents) if (window.releaseEvents)
window.releaseEvents(Event.MOUSEMOVE); window.releaseEvents(Event.MOUSEMOVE);
var _frame = document.getElementById("plugin_iframe"); if (window.g_asc_plugins)
if (_frame) window.g_asc_plugins.enablePointerEvents();
_frame.style.pointerEvents = "";
/* /*
var parent = window; var parent = window;
......
...@@ -1251,11 +1251,7 @@ ...@@ -1251,11 +1251,7 @@
if (!this.pluginsManager) if (!this.pluginsManager)
return; return;
var _pluginData = new Asc.CPluginData(); this.pluginsManager.onEnableMouseEvents(isEnable);
_pluginData.setAttribute("type", "enableMouseEvent");
_pluginData.setAttribute("isEnabled", isEnable);
this.pluginsManager.sendMessage(_pluginData);
}; };
baseEditorsApi.prototype["pluginMethod_GetFontList"] = function() baseEditorsApi.prototype["pluginMethod_GetFontList"] = function()
......
...@@ -1227,9 +1227,8 @@ ...@@ -1227,9 +1227,8 @@
} }
else if (data.type === "onExternalPluginMessage") else if (data.type === "onExternalPluginMessage")
{ {
var _iframe = document.getElementById("plugin_iframe"); if (window.g_asc_plugins)
if (_iframe) window.g_asc_plugins.sendToAllPlugins(event.data);
_iframe.contentWindow.postMessage(event.data, "*");
} }
} catch (err) } catch (err)
{ {
......
...@@ -80,18 +80,23 @@ ...@@ -80,18 +80,23 @@
function CPluginsManager(api) function CPluginsManager(api)
{ {
this.plugins = []; this.plugins = [];
this.current = null; this.systemPlugins = [];
this.currentInit = false;
this.currentVariation = 0; this.runnedPluginsMap = {}; // guid => { iframeId: "", currentVariation: 0, currentInit: false, isSystem: false, startData: {}, closeAttackTimer: -1, methodReturnAsync: false }
this.pluginsMap = {}; // guid => { isSystem: false }
this.path = "../../../../sdkjs-plugins/"; this.path = "../../../../sdkjs-plugins/";
this.api = null; this.systemPath = "";
this.api = api;
this["api"] = this.api;
this.startData = null;
this.runAndCloseData = null; this.runAndCloseData = null;
this.closeAttackTimer = -1; // защита от плагитнов, которые не закрываются this.isNoSystemPluginsOnlyOne = true;
this.guidAsyncMethod = "";
this.methodReturnAsync = false; this.sendsToInterface = {};
} }
CPluginsManager.prototype = CPluginsManager.prototype =
...@@ -99,84 +104,220 @@ ...@@ -99,84 +104,220 @@
register : function(basePath, plugins) register : function(basePath, plugins)
{ {
this.path = basePath; this.path = basePath;
for (var i = 0; i < plugins.length; i++) for (var i = 0; i < plugins.length; i++)
{
var guid = plugins[i].guid;
if (this.runnedPluginsMap[guid])
{
// не меняем запущенный
continue;
}
else if (this.pluginsMap[guid])
{
// заменяем новым
for (var j = 0; j < this.plugins.length; j++)
{
if (this.plugins[j].guid == guid)
{
this.plugins[j] = plugins[i];
break;
}
}
}
else
{
this.plugins.push(plugins[i]); this.plugins.push(plugins[i]);
this.pluginsMap[guid] = { isSystem : false };
}
}
}, },
run : function(guid, variation, data) registerSystem : function(basePath, plugins)
{ {
if (null != this.current) this.systemPath = basePath;
for (var i = 0; i < plugins.length; i++)
{ {
if (this.current.guid != guid) var guid = plugins[i].guid;
// системные не обновляем
if (this.pluginsMap[guid])
{ {
this.runAndCloseData = {}; continue;
this.runAndCloseData.guid = guid; }
this.runAndCloseData.variation = variation;
this.runAndCloseData.data = data; this.systemPlugins.push(plugins[i]);
this.pluginsMap[guid] = { isSystem : true };
}
},
// pointer events methods -------------------
enablePointerEvents : function()
{
for (var guid in this.runnedPluginsMap)
{
var _frame = document.getElementById(this.runnedPluginsMap[guid].frameId);
if (_frame)
_frame.style.pointerEvents = "";
}
},
disablePointerEvents : function()
{
for (var guid in this.runnedPluginsMap)
{
var _frame = document.getElementById(this.runnedPluginsMap[guid].frameId);
if (_frame)
_frame.style.pointerEvents = "none";
}
},
// ------------------------------------------
checkRunnedFrameId : function(id)
{
for (var guid in this.runnedPluginsMap)
{
if (this.runnedPluginsMap[guid].frameId == id)
return true;
} }
// закрываем
this.buttonClick(-1);
return false; return false;
},
sendToAllPlugins : function(data)
{
for (var guid in this.runnedPluginsMap)
{
var _frame = document.getElementById(this.runnedPluginsMap[guid].frameId);
if (_frame)
_iframe.contentWindow.postMessage(data, "*");
} }
},
getPluginByGuid : function(guid)
{
if (undefined === this.pluginsMap[guid])
return null;
for (var i = 0; i < this.plugins.length; i++) var _array = (this.pluginsMap[guid].isSystem) ? this.systemPlugins : this.plugins;
for (var i = _array.length - 1; i >= 0; i--)
{ {
if (this.plugins[i].guid == guid) if (_array[i].guid == guid)
return _array[i];
}
return null;
},
run : function(guid, variation, data, isNoUse_isNoSystemPluginsOnlyOne)
{ {
this.current = this.plugins[i]; if (this.runAndCloseData) // run only on close!!!
return;
if (this.pluginsMap[guid] === undefined)
return;
var plugin = this.getPluginByGuid(guid);
if (!plugin)
return;
var isSystem = this.pluginsMap[guid].isSystem;
var isRunned = (this.runnedPluginsMap[guid] !== undefined) ? true : false;
if (isRunned)
{
// запуск запущенного => закрытие
this.close(guid);
return false;
}
if ((isNoUse_isNoSystemPluginsOnlyOne !== true) && !isSystem && this.isNoSystemPluginsOnlyOne)
{
// смотрим, есть ли запущенный несистемный плагин
var guidOther = "";
for (var i in this.runnedPluginsMap)
{
if (this.pluginsMap[i] && !this.pluginsMap[i].isSystem)
{
guidOther = i;
break; break;
} }
} }
if (this.current == null) if (guidOther != "")
return false; {
// стопим текущий, а после закрытия - стартуем новый.
this.runAndCloseData = {};
this.runAndCloseData.guid = guid;
this.runAndCloseData.variation = variation;
this.runAndCloseData.data = data;
this.currentVariation = Math.min(variation, this.current.variations.length - 1); this.close(guidOther);
return;
}
}
var _startData = (data == null || data == "") ? new CPluginData() : data;
_startData.setAttribute("guid", guid);
this.correctData(_startData);
this.runnedPluginsMap[guid] = {
frameId: "iframe_" + guid,
currentVariation: Math.min(variation, plugin.variations.length - 1),
currentInit: false,
isSystem: isSystem,
startData: _startData,
closeAttackTimer: -1,
methodReturnAsync: false
};
this.startData = (data == null || data == "") ? new CPluginData() : data; this.show(guid);
this.startData.setAttribute("guid", guid)
this.correctData(this.startData);
this.show();
}, },
runResize : function(data) runResize : function(data)
{ {
var guid = data.getAttribute("guid"); var guid = data.getAttribute("guid");
for (var i = 0; i < this.plugins.length; i++) var plugin = this.getPluginByGuid(guid);
{ if (true !== plugin.variations[0].isUpdateOleOnResize)
if (this.plugins[i].guid == guid)
{
if (this.plugins[i].variations[0].isUpdateOleOnResize !== true)
return; return;
}
}
data.setAttribute("resize", true); data.setAttribute("resize", true);
return this.run(guid, 0, data); return this.run(guid, 0, data, true);
}, },
close : function() close : function(guid)
{ {
if (this.startData && this.startData.getAttribute("resize") === true) var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
if (!plugin || !runObject)
return;
if (runObject.startData && runObject.startData.getAttribute("resize") === true)
this.endLongAction(); this.endLongAction();
this.startData = null;
runObject.startData = null;
if (true) if (true)
{ {
this.api.sendEvent("asc_onPluginClose", this.current, this.currentVariation); if (this.sendsToInterface[plugin.guid])
var _div = document.getElementById("plugin_iframe"); {
this.api.sendEvent("asc_onPluginClose", plugin, runObject.currentVariation);
delete this.sendsToInterface[plugin.guid];
}
var _div = document.getElementById(runObject.frameId);
if (_div) if (_div)
_div.parentNode.removeChild(_div); _div.parentNode.removeChild(_div);
} }
this.current = null;
delete this.runnedPluginsMap[guid];
if (this.runAndCloseData) if (this.runAndCloseData)
{ {
this.run(this.runAndCloseData.guid, this.runAndCloseData.variation, this.runAndCloseData.data); var _tmp = this.runAndCloseData;
this.runAndCloseData = null; this.runAndCloseData = null;
this.run(_tmp.guid, _tmp.variation, _tmp.data);
} }
}, },
show : function() show : function(guid)
{ {
if (this.startData.getAttribute("resize") === true) var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
if (!plugin || !runObject)
return;
if (runObject.startData.getAttribute("resize") === true)
this.startLongAction(); this.startLongAction();
if (this.api.WordControl && this.api.WordControl.m_oTimerScrollSelect != -1) if (this.api.WordControl && this.api.WordControl.m_oTimerScrollSelect != -1)
...@@ -185,17 +326,18 @@ ...@@ -185,17 +326,18 @@
this.api.WordControl.m_oTimerScrollSelect = -1; this.api.WordControl.m_oTimerScrollSelect = -1;
} }
if (this.current.variations[this.currentVariation].isVisual && this.startData.getAttribute("resize") !== true) if (plugin.variations[runObject.currentVariation].isVisual && runObject.startData.getAttribute("resize") !== true)
{ {
this.api.sendEvent("asc_onPluginShow", this.current, this.currentVariation); this.api.sendEvent("asc_onPluginShow", plugin, runObject.currentVariation, runObject.frameId);
this.sendsToInterface[plugin.guid] = true;
} }
else else
{ {
var ifr = document.createElement("iframe"); var ifr = document.createElement("iframe");
ifr.name = "plugin_iframe"; ifr.name = runObject.frameId;
ifr.id = "plugin_iframe"; ifr.id = runObject.frameId;
var _add = this.current.baseUrl == "" ? this.path : this.current.baseUrl; var _add = plugin.baseUrl == "" ? this.path : plugin.baseUrl;
ifr.src = _add + this.current.variations[this.currentVariation].url; ifr.src = _add + plugin.variations[runObject.currentVariation].url;
ifr.style.position = AscCommon.AscBrowser.isIE ? 'fixed' : "absolute"; ifr.style.position = AscCommon.AscBrowser.isIE ? 'fixed' : "absolute";
ifr.style.top = '-100px'; ifr.style.top = '-100px';
ifr.style.left = '0px'; ifr.style.left = '0px';
...@@ -205,52 +347,79 @@ ...@@ -205,52 +347,79 @@
ifr.style.zIndex = -1000; ifr.style.zIndex = -1000;
document.body.appendChild(ifr); document.body.appendChild(ifr);
if (this.startData.getAttribute("resize") !== true) if (runObject.startData.getAttribute("resize") !== true)
this.api.sendEvent("asc_onPluginShow", this.current, this.currentVariation); {
this.api.sendEvent("asc_onPluginShow", plugin, runObject.currentVariation);
this.sendsToInterface[plugin.guid] = true;
}
} }
this.currentInit = false; runObject.currentInit = false;
}, },
buttonClick : function(id) buttonClick : function(id, guid)
{
if (guid === undefined)
{
// old version support
for (var i in this.runnedPluginsMap)
{ {
if (this.closeAttackTimer != -1) if (this.pluginsMap[i])
{ {
clearTimeout(this.closeAttackTimer); guid = i;
this.closeAttackTimer = -1; break;
}
}
}
if (undefined === guid)
return;
var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
if (!plugin || !runObject)
return;
if (runObject.closeAttackTimer != -1)
{
clearTimeout(runObject.closeAttackTimer);
runObject.closeAttackTimer = -1;
} }
if (-1 == id) if (-1 == id)
{ {
if (!this.currentInit) if (!runObject.currentInit)
{ {
window.g_asc_plugins.close(); this.close(guid);
this.close();
} }
// защита от плохого плагина // защита от плохого плагина
this.closeAttackTimer = setTimeout(function() runObject.closeAttackTimer = setTimeout(function()
{ {
window.g_asc_plugins.close(); window.g_asc_plugins.close();
}, 5000); }, 5000);
} }
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
{ {
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", this.current.guid); pluginData.setAttribute("guid", plugin.guid);
pluginData.setAttribute("type", "button"); pluginData.setAttribute("type", "button");
pluginData.setAttribute("button", "" + id); pluginData.setAttribute("button", "" + id);
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
} }
}, },
init : function() init : function(guid)
{ {
if (!this.startData) var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
if (!plugin || !runObject || !runObject.startData)
return; return;
switch (this.current.variations[this.currentVariation].initDataType) switch (plugin.variations[runObject.currentVariation].initDataType)
{ {
case Asc.EPluginDataType.text: case Asc.EPluginDataType.text:
{ {
...@@ -265,7 +434,7 @@ ...@@ -265,7 +434,7 @@
this.api.asc_CheckCopy(text_data, 1); this.api.asc_CheckCopy(text_data, 1);
if (text_data.data == null) if (text_data.data == null)
text_data.data = ""; text_data.data = "";
this.startData.setAttribute("data", text_data.data); runObject.startData.setAttribute("data", text_data.data);
break; break;
} }
case Asc.EPluginDataType.html: case Asc.EPluginDataType.html:
...@@ -281,7 +450,7 @@ ...@@ -281,7 +450,7 @@
this.api.asc_CheckCopy(text_data, 2); this.api.asc_CheckCopy(text_data, 2);
if (text_data.data == null) if (text_data.data == null)
text_data.data = ""; text_data.data = "";
this.startData.setAttribute("data", text_data.data); runObject.startData.setAttribute("data", text_data.data);
break; break;
} }
case Asc.EPluginDataType.ole: case Asc.EPluginDataType.ole:
...@@ -291,14 +460,14 @@ ...@@ -291,14 +460,14 @@
} }
} }
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
{ {
this.startData.setAttribute("type", "init"); runObject.startData.setAttribute("type", "init");
_iframe.contentWindow.postMessage(this.startData.serialize(), "*"); _iframe.contentWindow.postMessage(runObject.startData.serialize(), "*");
} }
this.currentInit = true; runObject.currentInit = true;
}, },
correctData : function(pluginData) correctData : function(pluginData)
{ {
...@@ -322,6 +491,7 @@ ...@@ -322,6 +491,7 @@
for (var i = 0; i < this.plugins.length; i++) for (var i = 0; i < this.plugins.length; i++)
_map[this.plugins[i].guid] = true; _map[this.plugins[i].guid] = true;
var _new = [];
for (var i = 0; i < _plugins.length; i++) for (var i = 0; i < _plugins.length; i++)
{ {
var _p = new Asc.CPlugin(); var _p = new Asc.CPlugin();
...@@ -330,9 +500,11 @@ ...@@ -330,9 +500,11 @@
if (_map[_p.guid] === true) if (_map[_p.guid] === true)
continue; continue;
this.plugins.push(_p); _new.push(_p);
} }
this.register(this.path, _new);
var _pluginsInstall = {"url" : this.path, "pluginsData" : []}; var _pluginsInstall = {"url" : this.path, "pluginsData" : []};
for (var i = 0; i < this.plugins.length; i++) for (var i = 0; i < this.plugins.length; i++)
{ {
...@@ -353,55 +525,80 @@ ...@@ -353,55 +525,80 @@
this.api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.SlowOperation); this.api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.SlowOperation);
}, },
sendMessage : function(pluginData) onChangedSelectionData : function()
{ {
if (!this.current) for (var guid in this.runnedPluginsMap)
return; {
var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
var _iframe = document.getElementById("plugin_iframe"); if (plugin && plugin.variations[runObject.currentVariation].initOnSelectionChanged === true)
if (_iframe)
{ {
pluginData.setAttribute("guid", this.current.guid); // re-init
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); this.init(guid);
}
} }
}, },
onChangedSelectionData : function() onExternalMouseUp : function()
{ {
if (this.current && this.current.variations[this.currentVariation].initOnSelectionChanged === true) for (var guid in this.runnedPluginsMap)
{ {
// re-init var runObject = this.runnedPluginsMap[guid];
this.init(); runObject.startData.setAttribute("type", "onExternalMouseUp");
this.correctData(runObject.startData);
var _iframe = document.getElementById(runObject.frameId);
if (_iframe)
{
runObject.startData.setAttribute("guid", guid);
_iframe.contentWindow.postMessage(runObject.startData.serialize(), "*");
}
} }
}, },
onExternalMouseUp : function() onEnableMouseEvents : function(isEnable)
{ {
if (!this.current || !this.startData) for (var guid in this.runnedPluginsMap)
return; {
var runObject = this.runnedPluginsMap[guid];
var _pluginData = new Asc.CPluginData();
_pluginData.setAttribute("type", "enableMouseEvent");
_pluginData.setAttribute("isEnabled", isEnable);
this.correctData(_pluginData);
this.startData.setAttribute("type", "onExternalMouseUp"); var _iframe = document.getElementById(runObject.frameId);
this.correctData(this.startData); if (_iframe)
this.sendMessage(this.startData); {
_pluginData.setAttribute("guid", guid);
_iframe.contentWindow.postMessage(_pluginData.serialize(), "*");
}
}
}, },
onPluginMethodReturn : function(_return) onPluginMethodReturn : function(guid, _return)
{ {
if (!this.current) var plugin = this.getPluginByGuid(guid);
var runObject = this.runnedPluginsMap[guid];
if (!plugin || !runObject)
return; return;
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", this.current.guid); pluginData.setAttribute("guid", plugin.guid);
pluginData.setAttribute("type", "onMethodReturn"); pluginData.setAttribute("type", "onMethodReturn");
pluginData.setAttribute("methodReturnData", _return); pluginData.setAttribute("methodReturnData", _return);
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
}, },
setPluginMethodReturnAsync : function() setPluginMethodReturnAsync : function()
{ {
this.methodReturnAsync = true; if (this.runnedPluginsMap[this.guidAsyncMethod])
this.runnedPluginsMap[this.guidAsyncMethod].methodReturnAsync = true;
return this.guidAsyncMethod;
} }
}; };
...@@ -410,17 +607,19 @@ ...@@ -410,17 +607,19 @@
function onMessage(event) function onMessage(event)
{ {
if (!window.g_asc_plugins || !window.g_asc_plugins.current) if (!window.g_asc_plugins)
return;
if (typeof(event.data) != "string")
return; return;
if (typeof(event.data) == "string")
{
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.deserialize(event.data); pluginData.deserialize(event.data);
var guid = pluginData.getAttribute("guid"); var guid = pluginData.getAttribute("guid");
var runObject = window.g_asc_plugins.runnedPluginsMap[guid];
if (guid != window.g_asc_plugins.current.guid) if (!runObject)
return; return;
var name = pluginData.getAttribute("type"); var name = pluginData.getAttribute("type");
...@@ -428,7 +627,7 @@ ...@@ -428,7 +627,7 @@
if ("initialize_internal" == name) if ("initialize_internal" == name)
{ {
window.g_asc_plugins.init(); window.g_asc_plugins.init(guid);
} }
else if ("initialize" == name) else if ("initialize" == name)
{ {
...@@ -436,17 +635,17 @@ ...@@ -436,17 +635,17 @@
pluginData.setAttribute("guid", guid); pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "plugin_init"); pluginData.setAttribute("type", "plugin_init");
pluginData.setAttribute("data", "!function(n,e){var i=!1;n.plugin_sendMessage=function(e){n.parent.postMessage(e,\"*\")},n.plugin_onMessage=function(t){if(n.Asc.plugin&&\"string\"==typeof t.data){var s={};try{s=JSON.parse(t.data)}catch(n){s={}}if(s.guid!=n.Asc.plugin.guid)return;var a=s.type;switch(\"init\"==a&&(n.Asc.plugin.info=s),a){case\"init\":n.Asc.plugin.executeCommand=function(e,i){n.Asc.plugin.info.type=e,n.Asc.plugin.info.data=i;var t=\"\";try{t=JSON.stringify(n.Asc.plugin.info)}catch(n){t=JSON.stringify({type:i})}n.plugin_sendMessage(t)},n.Asc.plugin.executeMethod=function(e,i){if(!0===n.Asc.plugin.isWaitMethod)return!1;n.Asc.plugin.isWaitMethod=!0,n.Asc.plugin.info.type=\"method\",n.Asc.plugin.info.methodName=e,n.Asc.plugin.info.data=i;var t=\"\";try{t=JSON.stringify(n.Asc.plugin.info)}catch(n){t=JSON.stringify({type:data})}return n.plugin_sendMessage(t),!0},n.Asc.plugin.resizeWindow=function(i,t,s,a,u,c){e==s&&(s=0),e==a&&(a=0),e==u&&(u=0),e==c&&(c=0);var g=JSON.stringify({width:i,height:t,minw:s,minh:a,maxw:u,maxh:c});n.Asc.plugin.info.type=\"resize\",n.Asc.plugin.info.data=g;var o=\"\";try{o=JSON.stringify(n.Asc.plugin.info)}catch(n){o=JSON.stringify({type:g})}n.plugin_sendMessage(o)},n.Asc.plugin.init(n.Asc.plugin.info.data);break;case\"button\":var u=parseInt(s.button);n.Asc.plugin.button||-1!=u?n.Asc.plugin.button(u):n.Asc.plugin.executeCommand(\"close\",\"\");break;case\"enableMouseEvent\":i=s.isEnabled,n.Asc.plugin.onEnableMouseEvent&&n.Asc.plugin.onEnableMouseEvent(i);break;case\"onExternalMouseUp\":n.Asc.plugin.onExternalMouseUp&&n.Asc.plugin.onExternalMouseUp();break;case\"onMethodReturn\":n.Asc.plugin.isWaitMethod=!1,n.Asc.plugin.onMethodReturn&&n.Asc.plugin.onMethodReturn(s.methodReturnData);break;case\"onCommandCallback\":n.Asc.plugin.onCommandCallback&&n.Asc.plugin.onCommandCallback();break;case\"onExternalPluginMessage\":n.Asc.plugin.onExternalPluginMessage&&s.data&&s.data.type&&n.Asc.plugin.onExternalPluginMessage(s.data)}}},n.onmousemove=function(t){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var s=e===t.clientX?t.pageX:t.clientX,a=e===t.clientY?t.pageY:t.clientY;n.Asc.plugin.executeCommand(\"onmousemove\",JSON.stringify({x:s,y:a}))}},n.onmouseup=function(t){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var s=e===t.clientX?t.pageX:t.clientX,a=e===t.clientY?t.pageY:t.clientY;n.Asc.plugin.executeCommand(\"onmouseup\",JSON.stringify({x:s,y:a}))}},n.plugin_sendMessage(JSON.stringify({guid:n.Asc.plugin.guid,type:\"initialize_internal\"}))}(window,void 0);"); pluginData.setAttribute("data", "!function(n,e){var i=!1;n.plugin_sendMessage=function(e){n.parent.postMessage(e,\"*\")},n.plugin_onMessage=function(t){if(n.Asc.plugin&&\"string\"==typeof t.data){var s={};try{s=JSON.parse(t.data)}catch(n){s={}}if(s.guid!=n.Asc.plugin.guid)return;var a=s.type;switch(\"init\"==a&&(n.Asc.plugin.info=s),a){case\"init\":n.Asc.plugin.executeCommand=function(e,i){n.Asc.plugin.info.type=e,n.Asc.plugin.info.data=i;var t=\"\";try{t=JSON.stringify(n.Asc.plugin.info)}catch(n){t=JSON.stringify({type:i})}n.plugin_sendMessage(t)},n.Asc.plugin.executeMethod=function(e,i){if(!0===n.Asc.plugin.isWaitMethod)return!1;n.Asc.plugin.isWaitMethod=!0,n.Asc.plugin.info.type=\"method\",n.Asc.plugin.info.methodName=e,n.Asc.plugin.info.data=i;var t=\"\";try{t=JSON.stringify(n.Asc.plugin.info)}catch(n){t=JSON.stringify({type:data})}return n.plugin_sendMessage(t),!0},n.Asc.plugin.resizeWindow=function(i,t,s,a,u,c){e==s&&(s=0),e==a&&(a=0),e==u&&(u=0),e==c&&(c=0);var g=JSON.stringify({width:i,height:t,minw:s,minh:a,maxw:u,maxh:c});n.Asc.plugin.info.type=\"resize\",n.Asc.plugin.info.data=g;var o=\"\";try{o=JSON.stringify(n.Asc.plugin.info)}catch(n){o=JSON.stringify({type:g})}n.plugin_sendMessage(o)},n.Asc.plugin.init(n.Asc.plugin.info.data);break;case\"button\":var u=parseInt(s.button);n.Asc.plugin.button||-1!=u?n.Asc.plugin.button(u):n.Asc.plugin.executeCommand(\"close\",\"\");break;case\"enableMouseEvent\":i=s.isEnabled,n.Asc.plugin.onEnableMouseEvent&&n.Asc.plugin.onEnableMouseEvent(i);break;case\"onExternalMouseUp\":n.Asc.plugin.onExternalMouseUp&&n.Asc.plugin.onExternalMouseUp();break;case\"onMethodReturn\":n.Asc.plugin.isWaitMethod=!1,n.Asc.plugin.onMethodReturn&&n.Asc.plugin.onMethodReturn(s.methodReturnData);break;case\"onCommandCallback\":n.Asc.plugin.onCommandCallback&&n.Asc.plugin.onCommandCallback();break;case\"onExternalPluginMessage\":n.Asc.plugin.onExternalPluginMessage&&s.data&&s.data.type&&n.Asc.plugin.onExternalPluginMessage(s.data)}}},n.onmousemove=function(t){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var s=e===t.clientX?t.pageX:t.clientX,a=e===t.clientY?t.pageY:t.clientY;n.Asc.plugin.executeCommand(\"onmousemove\",JSON.stringify({x:s,y:a}))}},n.onmouseup=function(t){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var s=e===t.clientX?t.pageX:t.clientX,a=e===t.clientY?t.pageY:t.clientY;n.Asc.plugin.executeCommand(\"onmouseup\",JSON.stringify({x:s,y:a}))}},n.plugin_sendMessage(JSON.stringify({guid:n.Asc.plugin.guid,type:\"initialize_internal\"}))}(window,void 0);");
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
return; return;
} }
else if ("close" == name || "command" == name) else if ("close" == name || "command" == name)
{ {
if (window.g_asc_plugins.closeAttackTimer != -1) if (runObject.closeAttackTimer != -1)
{ {
clearTimeout(window.g_asc_plugins.closeAttackTimer); clearTimeout(runObject.closeAttackTimer);
window.g_asc_plugins.closeAttackTimer = -1; runObject.closeAttackTimer = -1;
} }
if (value && value != "") if (value && value != "")
...@@ -515,7 +714,9 @@ ...@@ -515,7 +714,9 @@
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", guid); pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "onCommandCallback"); pluginData.setAttribute("type", "onCommandCallback");
var _iframe = document.getElementById("plugin_iframe");
var runObj = window.g_asc_plugins.runnedPluginsMap[guid];
var _iframe = document.getElementById(runObj.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
}); });
...@@ -540,7 +741,9 @@ ...@@ -540,7 +741,9 @@
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", guid); pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "onCommandCallback"); pluginData.setAttribute("type", "onCommandCallback");
var _iframe = document.getElementById("plugin_iframe");
var runObj = window.g_asc_plugins.runnedPluginsMap[guid];
var _iframe = document.getElementById(runObj.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
}); });
...@@ -561,7 +764,7 @@ ...@@ -561,7 +764,7 @@
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", guid); pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "onCommandCallback"); pluginData.setAttribute("type", "onCommandCallback");
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
} }
...@@ -569,7 +772,7 @@ ...@@ -569,7 +772,7 @@
if ("close" == name) if ("close" == name)
{ {
window.g_asc_plugins.close(); window.g_asc_plugins.close(guid);
} }
} }
else if ("resize" == name) else if ("resize" == name)
...@@ -597,24 +800,27 @@ ...@@ -597,24 +800,27 @@
{ {
var _apiMethodName = "pluginMethod_" + pluginData.getAttribute("methodName"); var _apiMethodName = "pluginMethod_" + pluginData.getAttribute("methodName");
var _return = undefined; var _return = undefined;
window.g_asc_plugins.guidAsyncMethod = guid;
if (window.g_asc_plugins.api[_apiMethodName]) if (window.g_asc_plugins.api[_apiMethodName])
_return = window.g_asc_plugins.api[_apiMethodName].apply(window.g_asc_plugins.api, value); _return = window.g_asc_plugins.api[_apiMethodName].apply(window.g_asc_plugins.api, value);
if (!window.g_asc_plugins.methodReturnAsync) if (!runObject.methodReturnAsync)
{ {
var pluginData = new CPluginData(); var pluginData = new CPluginData();
pluginData.setAttribute("guid", guid); pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "onMethodReturn"); pluginData.setAttribute("type", "onMethodReturn");
pluginData.setAttribute("methodReturnData", _return); pluginData.setAttribute("methodReturnData", _return);
var _iframe = document.getElementById("plugin_iframe"); var _iframe = document.getElementById(runObject.frameId);
if (_iframe) if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*"); _iframe.contentWindow.postMessage(pluginData.serialize(), "*");
} }
window.g_asc_plugins.methodReturnAsync = false; runObject.methodReturnAsync = false;
window.g_asc_plugins.guidAsyncMethod = "";
return; return;
} }
} }
}
if (window.addEventListener) if (window.addEventListener)
{ {
......
...@@ -3067,9 +3067,8 @@ ScrollObject.prototype = { ...@@ -3067,9 +3067,8 @@ ScrollObject.prototype = {
var evt = e || window.event; var evt = e || window.event;
// prevent pointer events on all iframes (while only plugin!) // prevent pointer events on all iframes (while only plugin!)
var _frame = document.getElementById("plugin_iframe"); if (window.g_asc_plugins)
if (_frame) window.g_asc_plugins.enablePointerEvents();
_frame.style.pointerEvents = "";
if ( evt.preventDefault ) if ( evt.preventDefault )
evt.preventDefault(); evt.preventDefault();
...@@ -3115,9 +3114,8 @@ ScrollObject.prototype = { ...@@ -3115,9 +3114,8 @@ ScrollObject.prototype = {
var evt = e || window.event; var evt = e || window.event;
// prevent pointer events on all iframes (while only plugin!) // prevent pointer events on all iframes (while only plugin!)
var _frame = document.getElementById("plugin_iframe"); if (window.g_asc_plugins)
if (_frame) window.g_asc_plugins.disablePointerEvents();
_frame.style.pointerEvents = "none";
// если сделать превент дефолт - перестанет приходить mousemove от window // если сделать превент дефолт - перестанет приходить mousemove от window
/* /*
......
...@@ -1784,7 +1784,7 @@ ...@@ -1784,7 +1784,7 @@
if (document.activeElement) if (document.activeElement)
{ {
var _id = document.activeElement.id; var _id = document.activeElement.id;
if (_id == "area_id" || _id == "plugin_iframe") if (_id == "area_id" || (window.g_asc_plugins && window.g_asc_plugins.checkRunnedFrameId(_id)))
return; return;
} }
......
...@@ -409,6 +409,7 @@ ...@@ -409,6 +409,7 @@
this.documents = _docs; this.documents = _docs;
this.returnDocuments = []; this.returnDocuments = [];
this.current = -1; this.current = -1;
this.guid = "";
this.start = function() this.start = function()
{ {
...@@ -417,14 +418,14 @@ ...@@ -417,14 +418,14 @@
this.api.incrementCounterLongAction(); this.api.incrementCounterLongAction();
if (window.g_asc_plugins) if (window.g_asc_plugins)
window.g_asc_plugins.setPluginMethodReturnAsync(); this.guid = window.g_asc_plugins.setPluginMethodReturnAsync();
this.run(); this.run();
}; };
this.end = function() this.end = function()
{ {
if (window.g_asc_plugins) if (window.g_asc_plugins)
window.g_asc_plugins.onPluginMethodReturn(this.returnDocuments); window.g_asc_plugins.onPluginMethodReturn(this.guid, this.returnDocuments);
delete this.api.__content_control_worker; delete this.api.__content_control_worker;
this.api.decrementCounterLongAction(); this.api.decrementCounterLongAction();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment