The events section allows to change all the functions pertaining to the events.
-
button - the function called when any of the plugin buttons is clicked.
It defines the buttons used with the plugin and the plugin behavior when they are clicked.
Parameter |
Description |
Type |
id |
Defines the button index in the buttons array of the config.json file.
If id == -1, then the plugin considers that the Close window cross button has been clicked or its operation has been somehow interrupted.
|
number |
window.Asc.plugin.button = function (id) {
this.executeCommand("close", '');
};
-
init - the function called when the plugin is launched.
It defines the data sent to the plugin describing what actions are to be performed and how they must be performed.
Parameter |
Description |
Type |
data |
Defines the data parameter that depends on the initDataType setting specified in the config.json file.
|
string |
window.Asc.plugin.init = function () {
this.callCommand(function() {
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Hello world!");
oDocument.InsertContent([oParagraph]);
}, true);
};
-
inputHelper_onSelectItem - the function called when the user is trying to select an item from the input helper.
Parameter |
Description |
Type |
item |
Defines the selected item:
-
text - the item text,
type: string,
example: "name";
-
id - the item index,
type: string,
example: "1".
|
object |
window.Asc.plugin.inputHelper_onSelectItem = function(item) {
if (!item)
return;
window.Asc.plugin.executeMethod("InputText", [item.text, window.Asc.plugin.currentText]);
window.Asc.plugin.getInputHelper().unShow();
};
-
onClick - the function called when the user clicks on the element.
Parameter |
Description |
Type |
isSelectionUse |
Defines if the selection is used or not.
|
boolean |
window.Asc.plugin.event_onClick = function(isSelectionUse) {
window.Asc.plugin.executeMethod("GetCurrentContentControlPr", [], function(obj) {
window.Asc.plugin.currentContentControl = obj;
var controlTag = obj ? obj.Tag : "";
if (isSelectionUse)
controlTag = "";
...
});
};
-
onCommandCallback - the function called to return the result of the previously executed command.
It can be used to return data after executing the executeCommand method.
window.Asc.plugin.onCommandCallback = function() {
var plugin = window.Asc.plugin;
plugin.executeCommand("close", "");
};
-
onDocumentContentReady - the function called when the document is completely loaded.
window.Asc.plugin.event_onDocumentContentReady = function() {
var oProperties = {
"searchString" : "ONLYOFFICE",
"replaceString" : "ONLYOFFICE is cool",
"matchCase" : false
};
window.Asc.plugin.executeMethod("SearchAndReplace", [oProperties], function() {
window.Asc.plugin.executeCommand("close", "");
});
};
-
onEnableMouseEvent - the function called to turn the mouse or touchpad events on/off.
Parameter |
Description |
Type |
isEnabled |
Defines if the mouse or touchpad is enabled or not.
|
boolean |
window.Asc.plugin.onEnableMouseEvent = function(isEnabled) {
var _frames = document.getElementsByTagName("iframe");
if (_frames && _frames[0]) {
_frames[0].style.pointerEvents = isEnabled ? "none" : "";
}
};
-
onExternalMouseUp - the function called when the mouse button is released outside the plugin iframe.
window.Asc.plugin.onExternalMouseUp = function () {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("mouseup", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
document.dispatchEvent(evt);
};
-
onExternalPluginMessage - the function called to show the editor integrator message.
Parameter |
Description |
Type |
data |
Defines the editor integrator message:
-
type - the message type,
type: string,
example: "close";
-
text - the message text,
type: string,
example: "text".
|
object |
window.Asc.plugin.onExternalPluginMessage = function(data) {
switch (data.type) {
case "close": {
this.executeCommand("close", "");
break;
}
case "insertText": {
Asc.scope.text = data.text;
this.callCommand(function() {
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText(Asc.scope.text);
oDocument.InsertContent([oParagraph]);
}, false);
break;
}
}
};
-
onInputHelperClear - the function called when the user is trying to clear the text and the input helper disappears.
window.Asc.plugin.event_onInputHelperClear = function() {
window.Asc.plugin.currentText = "";
window.Asc.plugin.getInputHelper().unShow();
};
-
onInputHelperInput - the function called when the user is trying to input the text and the input helper appears.
Parameter |
Description |
Type |
data |
Defines the text which the user inputs:
-
add - defines if the text is added to the current text or this is the beginning of the text,
type: boolean,
example: true;
-
text - the text which the user inputs,
type: string,
example: "text".
|
object |
window.Asc.plugin.event_onInputHelperInput = function(data) {
if (data.add)
window.Asc.plugin.currentText += data.text;
else
window.Asc.plugin.currentText = data.text;
...
}
-
onMethodReturn - the function called to return the result of the previously executed method.
It can be used to return data after executing the executeMethod method.
Parameter |
Description |
Type |
returnValue |
Defines the value that will be returned.
|
|
window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [_obj]);
window.Asc.plugin.onMethodReturn = function(returnValue) {
if (window.Asc.plugin.info.methodName == "InsertAndReplaceContentControls") {
window.Asc.plugin.executeMethod("GetAllContentControls");
} else if ("GetAllContentControls") {
window.Asc.plugin.executeCommand("close", console.log(JSON.stringify(returnValue)));
}
};
-
onTargetPositionChanged - the function called when the target position in the editor is changed.
window.Asc.plugin.event_onTargetPositionChanged = function() {
if (!fClickLabel) {
window.Asc.plugin.executeMethod("GetCurrentContentControl");
}
fClickLabel = false;
};
-
onTranslate - the function called right after the plugin startup or later in case the plugin language is changed.
window.Asc.plugin.onTranslate = function() {
var label = document.getElementById("button_new");
if (label)
label.innerHTML = window.Asc.plugin.tr("New");
}