Get Started
Plugins
Macros
More information

Events

The events section allows to change all the functions pertaining to the events.

Events and their description:

  • 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.

    Parameters
    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
    Example
    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.

    Parameters
    Parameter Description Type
    data Defines the data parameter that depends on the initDataType setting specified in the config.json file. string
    Example
    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.

    Parameters
    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
    Example
    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();
    };
    
  • onAddComment - the function called when a comment is added to the document with the AddComment method.

    The method takes the comment object containing the comment data in the following form:

    {
        "Id": "1_631",
        "Data": {
            "UserName": "John Smith",
            "Text": "comment",
            "Time": "1662737941471",
            "Solved": true,
            "Replies": [{"UserName": "Mark Potato", "Text": "reply 1", "Time": "1662740895892", "Solved": false}]
        }
    }
    
    Parameters
    Parameter Description Type
    Id The comment ID. string "1_631"
    Data An object which contains the comment data:
    • UserName - the comment author,
      type: string,
      example: "John Smith";
    • Text - the comment text,
      type: string,
      example: "comment";
    • Time - the time when the comment was posted (in milliseconds),
      type: string,
      example: "1662737941471";
    • Solved - specifies if the comment is resolved (true) or not (false),
      type: boolean,
      example: true;
    • Replies - an array containing the comment replies represented as the oCommentData objects,
      type: array of objects.
    object
    Example
    window.Asc.plugin.event_onAddComment = function(comment)
    {
        Comments.push(comment);
        $('#scrollable-container-id').append(makeComment(comment.Id, comment));
    };
    
  • onBlurContentControl - the function called to show which content control has been blurred.

    Parameters
    Parameter Description Type
    control Defines the content control that has been blurred:
    • Tag - a tag assigned to the content control. The same tag can be assigned to several content controls so that you can make reference to them in your code,
      type: string,
      example: "{tag}";
    • Id - a unique content control identifier. It can be used to search for a certain content control and make reference to it in your code,
      type: number,
      example: 0;
    • Lock - a value that defines if it is possible to delete and/or edit the content control or not,
      type: number,
      example: 0;
    • InternalId - a unique internal identifier of the content control,
      type: string,
      example: "5_665".
    object

    The Lock parameter can have the following values:

    Numeric value Edit Delete
    0 No Yes
    1 No No
    2 Yes No
    3 Yes Yes
    Example
    connector.attachEvent("onBlurContentControl", function(oPr)
    {
        if (oPr && "BankBIC" === oPr["Tag"])
        {
            connector.executeMethod("GetFormValue", [oPr["InternalId"]], function(value)
            {
                if ("12345678" !== value)
                    return;
    
                connector.executeMethod("GetFormsByTag", ["BankAccount"], function(forms)
                {
                    for (let i = 0; i < forms.length; ++i)
                    {
                        connector.executeMethod("SetFormValue", [forms[i]["InternalId"], "10101110100000000123"], null);
                    }
                });
    
                connector.executeMethod("GetFormsByTag", ["BankName"], function(forms)
                {
                    for (let i = 0; i < forms.length; ++i)
                    {
                        connector.executeMethod("SetFormValue", [forms[i]["InternalId"], "OnlyOffice BANK"], null);
                    }
                });
    
                connector.executeMethod("GetFormsByTag", ["BankPlace"], function(forms)
                {
                    for (let i = 0; i < forms.length; ++i)
                    {
                        connector.executeMethod("SetFormValue", [forms[i]["InternalId"], "Himalayas"], null);
                    }
                });
            });
        }
        console.log("event: onBlurContentControl");
    });
    
  • onChangeCommentData - the function called when the specified comment is changed with the ChangeComment method.

    The method takes the comment object containing the comment data in the following form:

    {
        "Id": "1_631",
        "Data": {
            "UserName": "John Smith",
            "Text": "comment",
            "Time": "1662737941471",
            "Solved": true,
            "Replies": [{"UserName": "Mark Potato", "Text": "reply 1", "Time": "1662740895892", "Solved": false}]
        }
    }
    
    Parameters
    Parameter Description Type
    Id The comment ID. string "1_631"
    Data An object which contains the updated comment data:
    • UserName - the comment author,
      type: string,
      example: "John Smith";
    • Text - the comment text,
      type: string,
      example: "comment";
    • Time - the time when the comment was posted (in milliseconds),
      type: string,
      example: "1662737941471";
    • Solved - specifies if the comment is resolved (true) or not (false),
      type: boolean,
      example: true;
    • Replies - an array containing the comment replies represented as the oCommentData objects,
      type: array of objects.
    object
    Example
    window.Asc.plugin.event_onChangeCommentData = function(comment)
    {
        changeComment(comment);
    };
    
  • onChangeContentControl - the function called to show which content control has been changed.

    Parameters
    Parameter Description Type
    control Defines the content control that has been changed:
    • Tag - a tag assigned to the content control. The same tag can be assigned to several content controls so that you can make reference to them in your code,
      type: string,
      example: "{tag}";
    • Id - a unique content control identifier. It can be used to search for a certain content control and make reference to it in your code,
      type: number,
      example: 0;
    • Lock - a value that defines if it is possible to delete and/or edit the content control or not,
      type: number,
      example: 0;
    • InternalId - a unique internal identifier of the content control,
      type: string,
      example: "5_665".
    object

    The Lock parameter can have the following values:

    Numeric value Edit Delete
    0 No Yes
    1 No No
    2 Yes No
    3 Yes Yes
    Example
    connector.attachEvent("onChangeContentControl", function()
    {
        console.log("event: onChangeContentControl");
    });
    
  • onClick - the function called when the user clicks on the element.

    Parameters
    Parameter Description Type
    isSelectionUse Defines if the selection is used or not. boolean
    Example
    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.

    Example
    window.Asc.plugin.onCommandCallback = function() {
        var plugin = window.Asc.plugin;
        plugin.executeCommand("close", "");
    };
    
  • onDocumentContentReady - the function called when the document is completely loaded.

    Example
    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.

    Parameters
    Parameter Description Type
    isEnabled Defines if the mouse or touchpad is enabled or not. boolean
    Example
    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.

    Example
    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.

    Parameters
    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
    Example
    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;
            }
        }
    };
    
  • onFocusContentControl - the function called to show which content control has been focused.

    Parameters
    Parameter Description Type
    control Defines the content control that has been focused:
    • Tag - a tag assigned to the content control. The same tag can be assigned to several content controls so that you can make reference to them in your code,
      type: string,
      example: "{tag}";
    • Id - a unique content control identifier. It can be used to search for a certain content control and make reference to it in your code,
      type: number,
      example: 0;
    • Lock - a value that defines if it is possible to delete and/or edit the content control or not,
      type: number,
      example: 0;
    • InternalId - a unique internal identifier of the content control,
      type: string,
      example: "5_665".
    object

    The Lock parameter can have the following values:

    Numeric value Edit Delete
    0 No Yes
    1 No No
    2 Yes No
    3 Yes Yes
    Example
    connector.attachEvent("onFocusContentControl", function()
    {
        console.log("event: onFocusContentControl");
    });
    
  • onInputHelperClear - the function called when the user is trying to clear the text and the input helper disappears.

    Example
    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.

    Parameters
    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
    Example
    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.

    Parameters
    Parameter Description Type
    returnValue Defines the value that will be returned.
    Example
    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)));
        } 
    };
    
  • onRemoveComment - the function called when the specified comment is removed with the RemoveComments method.

    The method takes the comment object containing the comment data in the following form:

    {
        "Id": "1_631",
        "Data": {
            "UserName": "John Smith",
            "Text": "comment",
            "Time": "1662737941471",
            "Solved": true,
            "Replies": [{"UserName": "Mark Potato", "Text": "reply 1", "Time": "1662740895892", "Solved": false}]
        }
    }
    
    Parameters
    Parameter Description Type
    Id The comment ID. string "1_631"
    Data An object which contains the comment data:
    • UserName - the comment author,
      type: string,
      example: "John Smith";
    • Text - the comment text,
      type: string,
      example: "comment";
    • Time - the time when the comment was posted (in milliseconds),
      type: string,
      example: "1662737941471";
    • Solved - specifies if the comment is resolved (true) or not (false),
      type: boolean,
      example: true;
    • Replies - an array containing the comment replies represented as the oCommentData objects,
      type: array of objects.
    object
    Example
    window.Asc.plugin.event_onRemoveComment = function(comment)
    {
        removeComments([comment.Id]);
    };
    
  • onTargetPositionChanged - the function called when the target position in the editor is changed.

    Example
    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.

    Example
    window.Asc.plugin.onTranslate = function() {
        var label = document.getElementById("button_new");
        if (label)
            label.innerHTML = window.Asc.plugin.tr("New");
    }