Skip to main content
Inspiring
December 13, 2018
Question

Bridge CC2019 CEP Selection EventHandler

  • December 13, 2018
  • 3 replies
  • 2085 views

Hey,

I'm currently designing a CEP app, in which I try to update the panel based on the thumb selection.

I tested my script as standalone .jsx and it works fine.

     ... run function ...

     app.eventHandlers.push( {handler: createSelectionHandler ! !} );

}

function createSelectionHandler(event)

{

     if ( event.object instanceof Document && event.type === 'selectionsChanged') {

     if (app.document.selectionLength > 0)

     {

          var thumb = app.document.selections[0];

          if(thumb.hasMetadata)

          {

               ... does important stuff...

          }

     }

}

If I run it via the CEP environment - app.eventHandlers doesn't exist (and thus the script silently fails). I can launch the regular ES after startup without issues though.

Is there another way to register an event handler / event listener for a change of the browser selection?

This topic has been closed for replies.

3 replies

bagonterman
Inspiring
February 12, 2019

So on the mac side When the buttons in my extension are pressed there is no event registered for Bridge. But on the PC side it does register an event. This breaks what I have already made because I was counting on it not firing at the time of execution. I am not sure what to do now.

bagonterman
Inspiring
February 4, 2019
function windowChange() {

   var csInterface = new CSInterface();

   const extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION);

   csInterface.evalScript('$.evalFile("' + extensionRoot + "/jsx/" + "eventWindowChange.jsx" + '")');

}

So this is the js that I am calling from the jump.

Then this calls the jsx.

function eventHandler() {

   app.eventHandlers.push({ handler: createSelectionHandler });

   // alert("after push")

   function createSelectionHandler(event) {

   //alert(event);

   if (event.object instanceof Document && event.type === 'selectionsChanged') {

   //alert("changed")

   return changed = "changed"

  }


  }

}


bt = new BridgeTalk();

bt.target = "bridge";

bt.body = "eventHandler();" + eventHandler.toString();

bt.onError = function (btErr) { result = btErr.body; alert(result) };

bt.onResult = function (btRes) { result = btRes.body };

bt.send(8);

I ended up using a bridge talk.

Now here is my problem. How do i get this value back to the dom. Because if I use a callback on this it is not going to return anything because it is just creating the eventHandler. Not handling the event. So when it handles the event. Do something. I want to change the dom but I don't know how to get it back there. Any ideas?

Inspiring
February 4, 2019

Have you tried doing this with an CSXS Event?


Like this in the JSX.

var eventObj = new CSXSEvent();

eventObj.type = "update";

eventObj.data = result

});

eventObj.dispatch();

The data payload has to be a string, otherwise it doesn't send anything.

And then you catch it in the HTML JS part like this:

csInterface.addEventListener("update", callback);

Does this work for you?

bagonterman
Inspiring
February 7, 2019

Yes that does work. My problem now is that the creation of the handler the condition of even.object and event.type these things happen everytime. if I select anything. I just need it to fire on a window change.

bagonterman
Inspiring
February 1, 2019

You would have to have a js file communicate that to the dom. The function would run the jsx

   csInterface.evalScript('var pageNumber= ' + JSON.stringify(obj) + '; $.evalFile("' + extensionRoot + "/jsx/" + "forwardPage.jsx" + '")', function (cb) {

   result = cb.toString();

   if (result == "nav") {


   document.getElementById("pageNumber").value = "";

  }

  });

On the jsx side you would have it return a value and then based on that result you could change something in the dom.

Inspiring
February 1, 2019

Hey, thanks for the answer, I'm not sure if really was the problem.

I tried to to get the selection event if the user changes the selection in the bridge browser window. In the end I solved it with an extra plugin that throws a CSXS event if the 'selectionChange' occurs (and this placed in the folder for extension that automatically start with Bridge).

I still wonder though, if there was another way of catching this event.

Inspiring
February 3, 2019

I have been able to add event handler through BridgeTalk