Commit 63f3f49f authored by Oleg Korshul's avatar Oleg Korshul Committed by GitHub

Merge pull request #61 from ONLYOFFICE/hotfix/v4.1.1

Hotfix/v4.1.1
parents 0e8ae6d5 84209cec
[![License](https://img.shields.io/badge/License-GNU%20AGPL%20V3-green.svg?style=flat)](http://www.gnu.org/licenses/agpl-3.0.ru.html) ![Release](https://img.shields.io/badge/Release-v4.1.0-blue.svg?style=flat) [![License](https://img.shields.io/badge/License-GNU%20AGPL%20V3-green.svg?style=flat)](http://www.gnu.org/licenses/agpl-3.0.ru.html) ![Release](https://img.shields.io/badge/Release-v4.1.1-blue.svg?style=flat)
## Sdkjs ## Sdkjs
......
(function(window, undefined){
var g_isMouseSendEnabled = false;
// должны быть методы
// init(data);
// button(id)
window.plugin_sendMessage = function sendMessage(data)
{
window.parent.postMessage(data, "*");
};
window.plugin_onMessage = function(event)
{
if (!window.Asc.plugin)
return;
if (typeof(event.data) == "string")
{
var pluginData = {};
try
{
pluginData = JSON.parse(event.data);
}
catch(err)
{
pluginData = {};
}
if (pluginData.guid != window.Asc.plugin.guid)
return;
var type = pluginData.type;
if (type == "init")
window.Asc.plugin.info = pluginData;
switch (type)
{
case "init":
{
window.Asc.plugin.executeCommand = function(type, data)
{
window.Asc.plugin.info.type = type;
window.Asc.plugin.info.data = data;
var _message = "";
try
{
_message = JSON.stringify(window.Asc.plugin.info);
}
catch(err)
{
_message = JSON.stringify({ type : data });
}
window.plugin_sendMessage(_message);
};
window.Asc.plugin.resizeWindow = function(width, height, minW, minH, maxW, maxH)
{
if (undefined == minW)
minW = 0;
if (undefined == minH)
minH = 0;
if (undefined == maxW)
maxW = 0;
if (undefined == maxH)
maxH = 0;
var data = JSON.stringify({ width : width, height : height, minw : minW, minh : minH, maxw : maxW, maxh : maxH });
window.Asc.plugin.info.type = "resize";
window.Asc.plugin.info.data = data;
var _message = "";
try
{
_message = JSON.stringify(window.Asc.plugin.info);
}
catch(err)
{
_message = JSON.stringify({ type : data });
}
window.plugin_sendMessage(_message);
};
window.Asc.plugin.init(window.Asc.plugin.info.data);
break;
}
case "button":
{
window.Asc.plugin.button(parseInt(pluginData.button));
break;
}
case "enableMouseEvent":
{
g_isMouseSendEnabled = pluginData.isEnabled;
break;
}
case "onExternalMouseUp":
{
if (window.Asc.plugin.onExternalMouseUp)
window.Asc.plugin.onExternalMouseUp();
break;
}
default:
break;
}
}
}
window.onmousemove = function(e)
{
if (!g_isMouseSendEnabled || !window.Asc.plugin || !window.Asc.plugin.executeCommand)
return;
var _x = (undefined === e.clientX) ? e.pageX : e.clientX;
var _y = (undefined === e.clientY) ? e.pageY : e.clientY;
window.Asc.plugin.executeCommand("onmousemove", JSON.stringify({ x : _x, y : _y }));
};
window.onmouseup = function(e)
{
if (!g_isMouseSendEnabled || !window.Asc.plugin || !window.Asc.plugin.executeCommand)
return;
var _x = (undefined === e.clientX) ? e.pageX : e.clientX;
var _y = (undefined === e.clientY) ? e.pageY : e.clientY;
window.Asc.plugin.executeCommand("onmouseup", JSON.stringify({ x : _x, y : _y }));
};
window.plugin_sendMessage(JSON.stringify({ guid : window.Asc.plugin.guid, type : "initialize_internal" }));
})(window, undefined);
\ No newline at end of file
...@@ -385,9 +385,19 @@ ...@@ -385,9 +385,19 @@
var name = pluginData.getAttribute("type"); var name = pluginData.getAttribute("type");
var value = pluginData.getAttribute("data"); var value = pluginData.getAttribute("data");
if ("initialize" == name) if ("initialize_internal" == name)
{ {
window.g_asc_plugins.init(); window.g_asc_plugins.init();
}
else if ("initialize" == name)
{
var pluginData = new CPluginData();
pluginData.setAttribute("guid", guid);
pluginData.setAttribute("type", "plugin_init");
pluginData.setAttribute("data", "(function(n,t){var i=!1;n.plugin_sendMessage=function(t){n.parent.postMessage(t,\"*\")};n.plugin_onMessage=function(r){var u,f;if(n.Asc.plugin&&typeof r.data==\"string\"){u={};try{u=JSON.parse(r.data)}catch(e){u={}}if(u.guid!=n.Asc.plugin.guid)return;f=u.type;f==\"init\"&&(n.Asc.plugin.info=u);switch(f){case\"init\":n.Asc.plugin.executeCommand=function(t,i){n.Asc.plugin.info.type=t;n.Asc.plugin.info.data=i;var r=\"\";try{r=JSON.stringify(n.Asc.plugin.info)}catch(u){r=JSON.stringify({type:i})}n.plugin_sendMessage(r)};n.Asc.plugin.resizeWindow=function(i,r,u,f,e,o){var h,s;t==u&&(u=0);t==f&&(f=0);t==e&&(e=0);t==o&&(o=0);h=JSON.stringify({width:i,height:r,minw:u,minh:f,maxw:e,maxh:o});n.Asc.plugin.info.type=\"resize\";n.Asc.plugin.info.data=h;s=\"\";try{s=JSON.stringify(n.Asc.plugin.info)}catch(c){s=JSON.stringify({type:h})}n.plugin_sendMessage(s)};n.Asc.plugin.init(n.Asc.plugin.info.data);break;case\"button\":n.Asc.plugin.button(parseInt(u.button));break;case\"enableMouseEvent\":i=u.isEnabled;break;case\"onExternalMouseUp\":n.Asc.plugin.onExternalMouseUp&&n.Asc.plugin.onExternalMouseUp()}}};n.onmousemove=function(r){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var u=t===r.clientX?r.pageX:r.clientX,f=t===r.clientY?r.pageY:r.clientY;n.Asc.plugin.executeCommand(\"onmousemove\",JSON.stringify({x:u,y:f}))}};n.onmouseup=function(r){if(i&&n.Asc.plugin&&n.Asc.plugin.executeCommand){var u=t===r.clientX?r.pageX:r.clientX,f=t===r.clientY?r.pageY:r.clientY;n.Asc.plugin.executeCommand(\"onmouseup\",JSON.stringify({x:u,y:f}))}};n.plugin_sendMessage(JSON.stringify({guid:n.Asc.plugin.guid,type:\"initialize_internal\"}))})(window,undefined);");
var _iframe = document.getElementById("plugin_iframe");
if (_iframe)
_iframe.contentWindow.postMessage(pluginData.serialize(), "*");
return; return;
} }
else if ("close" == name || "command" == name) else if ("close" == name || "command" == name)
......
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