• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bridge CC2019 CEP Selection EventHandler

Participant ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2019 Feb 01, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 01, 2019 Feb 01, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 03, 2019 Feb 03, 2019

Copy link to clipboard

Copied

I have been able to add event handler through BridgeTalk

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

Were you able to call back to the dom and then do something?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

It also looks like it loads twice. Which I don't understand.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

You mean your own event handler? Have you checked if you accidentally appended the handler twice?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 12, 2019 Feb 12, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines