7 Replies Latest reply on Oct 27, 2016 4:18 AM by flambert95

    InDesign HTML extension events

    flambert95

      Hey guys, for some reason when I try to add a event listerner on "afterDelete" it does not work but all my other event listeners works. I am very confused, anyone who might be able to help?

       

      heres the code:

      //doesn't work

      CSLibrary.addEventListener("afterDelete", function(e){

             alert("afterDelete worked");

        });

      //works

        CSLibrary.addEventListener("afterSelectionChanged", function(e){

             alert("afterSelectionChaged worked");

        });

        • 1. Re: InDesign HTML extension events
          Trevorׅ Adobe Community Professional

          Hi

           

          AFAIK there's only a limited range of DOM events the extensions can pick up from the HTML end.

          afterSelectionChanged is one of them and afterDelete is not.

          You set the afterDelete event from the InDesign (JSX / C++ or whatever) and send it as a custom CEP event to the HTML.

           

          It's pretty easy to do.

           

          HTH

           

          Trevor

          1 person found this helpful
          • 2. Re: InDesign HTML extension events
            flambert95 Level 1

            if it is not to much to ask coud you make a small example on how to do it?:) and thanks for the response:)

            • 3. Re: InDesign HTML extension events
              flambert95 Level 1

              If anyone is interrested here is the code:

               

              JS SIDE:

              CSLibrary.addEventListener("AfterDelete", function(e){

                alert("test");

                });

               

               

              JSX SIDE:

              var afterDelete = function(data) {

                  var x = new ExternalObject("lib:" + "PlugPlugExternalObject");

                 var eventObj = new CSXSEvent();

                  eventObj.data="test";

                  eventObj.type="AfterDelete";

                  eventObj.dispatch();

              }

              app.addEventListener(Event.AFTER_DELETE, afterDelete);

              • 4. Re: InDesign HTML extension events
                Trevorׅ Adobe Community Professional

                Glad to have helped. I wrote some code which I was going to post but you beat me to it.

                 

                Either way you might find it helpful.

                 

                // in hostcsript.jsx
                
                // loads the plugin library to the jsx engine
                function loadLib() {
                    try {
                        if (!loadLib.xLib) loadLib.xLib = new ExternalObject('lib:PlugPlugExternalObject');
                    } catch (e) {
                        alert('Drat\n' + e);
                    }
                } // end of loadLib
                
                // fires the CEP event to the CEP engine to be picked up by main.js
                function dispatchCepEvent(in_eventType, in_message) {
                    try {
                        if (loadLib.xLib) {
                            var eventObj = new CSXSEvent();
                            eventObj.type = in_eventType;
                            eventObj.data = '' + in_message;
                            eventObj.dispatch();
                            // log(eventObj.data, in_eventType + ' >>> ' + in_message);
                            return true;
                        }
                        return false;
                    } catch (e) {
                        alert(e);
                        return false;
                    }
                } // end of dispatchCepEvent
                
                loadLib();
                
                if (app.eventListeners.item('myAfterDelete').isValid) {
                    app.eventListeners.item('myAfterDelete').remove();
                }
                
                // Note AFTER_DELETE only applies to Links
                app.eventListeners.add(Event.AFTER_DELETE, doSomething).name = 'myAfterDelete';
                
                function doSomething() {
                    dispatchCepEvent('com_creative_scripts_myAfterDelete');
                }
                
                
                
                // in main.js
                
                var csInterface = new CSInterface();
                
                // Setup listener for the CSXSEvent sent from hostscript.jsx
                csInterface.addEventListener('com_creative_scripts_myAfterDelete', alertDeleted);
                
                function alertDeleted() {
                    alert('Link Deleted');
                }
                
                • 5. Re: InDesign HTML extension events
                  Trevorׅ Adobe Community Professional

                  Just one more comment as the documentation is so pathetic on the topic.

                   

                  new ExternalObject("lib:PlugPlugExternalObject");

                  is the same as

                  new ExternalObject("lib:" + "PlugPlugExternalObject");

                  • 6. Re: InDesign HTML extension events
                    flambert95 Level 1

                    Yea I know, was just a early version, since I had a variable there before (were lazy )

                    • 7. Re: InDesign HTML extension events
                      flambert95 Level 1

                      Thanks for the example anyways, I am sure others will find it usefull