Try the fastest and simplest way to install ONLYOFFICE

triggering button press with javascript

Integration questions/issues

triggering button press with javascript

Postby robertotomas » Fri Sep 29, 2017 1:41 pm

given the helloworld plugin:

Code: Select all
(function(window, undefined){

    window.Asc.plugin.init = function()
    {
        var sScript = 'var oDocument = Api.GetDocument();';
        sScript += 'var oParagraph = Api.CreateParagraph();';
        sScript += 'oParagraph.AddText(\'Hello world!\');';
        sScript += 'oDocument.InsertContent([oParagraph]);';
        window.Asc.plugin.info.recalculate = true;
        this.executeCommand("close", sScript);
    };

    window.Asc.plugin.button = function(id)
    {
    };

})(window, undefined);


How can I trigger this plugin's button press from the outer window containing the docEditor?

this is may have to be done with a postMessage and adding a listener in my plugin or editing the api.js file .. however, from there I must actually trigger the plugin to fire off. How is that done?

I want to use this to trigger an effect from the UI ..
robertotomas
 
Posts: 21
Joined: Thu Aug 31, 2017 4:05 pm

Re: triggering button press with javascript

Postby Maxim » Thu Oct 12, 2017 7:13 am

Hello!
You can use this plugin.
Maxim
 
Posts: 1237
Joined: Tue Oct 11, 2016 2:34 pm

Re: triggering button press with javascript

Postby robertotomas » Thu Oct 12, 2017 7:23 pm

Maxim, I have a plugin that works, very similar in many ways to that one. You don't have to worry about this at this point (I could still use help understanding why our server configuration doesnt seem to recongize plugins at all though).

For my custom plugin to work, I needed to alter app.js.

I can't get *your* plugin to work at all. executing the code in test.js directly in the (otherwise) working docker install on my local dev machine does nothing.
robertotomas
 
Posts: 21
Joined: Thu Aug 31, 2017 4:05 pm

Re: triggering button press with javascript

Postby Maxim » Tue Oct 17, 2017 5:59 am

Hello robertotomas!
In that case i do not worry :D :D
Maxim
 
Posts: 1237
Joined: Tue Oct 11, 2016 2:34 pm

Re: triggering button press with javascript

Postby John at O5 » Thu Dec 07, 2017 12:34 am

robertotomas, can you please tell us what you needed to alter in app.js to get this solved?
John at O5
 
Posts: 3
Joined: Thu Dec 07, 2017 12:31 am

Re: triggering button press with javascript

Postby robertotomas » Thu Dec 07, 2017 7:06 pm

Note tht there was a plugin that Maxim mentioned earlier which was designed to do this. In the particular version I was using when I built this, it did not work. It may work now though.

I just added a listener to curry messages in to the plugin, like:

Code: Select all
;
window.addEventListener("message", receiveMessage, {captive: true, passive: true})

function receiveMessage (event) {
    console.log(window.Asc, event)
   let o
   try {
      o = JSON.parse(event.data)
   } catch (e) {
      console.warn(e)
      o = {}
   }
   o.raw = event.data

   if(o.type !== 'addTag')
      return
      
   o.tag? window.Asc.addTag = o.tag: triggerAddTag()   
}

function triggerAddTag () {
   $('.item-plugins').click()
}


jQuery is already installed in the app, so there's that if you you need it (like the handy last line above).

Then you just mount onlyoffice kinda like this:
Code: Select all
<div class=onlyoffice-container><div id=onlyoffice>{{ messages.ooloading }}</div></div>


And message it like:

Code: Select all
document.querySelector('.onlyoffice-container iframe').contentWindow.postMessage(JSON.stringify({type: 'addTag', tag: 'bing'}), '*')
robertotomas
 
Posts: 21
Joined: Thu Aug 31, 2017 4:05 pm

Re: triggering button press with javascript

Postby John at O5 » Mon Dec 11, 2017 3:49 pm

thank you!
John at O5
 
Posts: 3
Joined: Thu Dec 07, 2017 12:31 am


Return to API

Who is online

Users browsing this forum: No registered users and 1 guest

cron