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?
Copy link to clipboard
Copied
You would have to have a js file communicate that to the dom. The function would run the jsx
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.
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.
Copy link to clipboard
Copied
I have been able to add event handler through BridgeTalk
Copy link to clipboard
Copied
Were you able to call back to the dom and then do something?
Copy link to clipboard
Copied
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.
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?
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?
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.
Copy link to clipboard
Copied
It also looks like it loads twice. Which I don't understand.
Copy link to clipboard
Copied
You mean your own event handler? Have you checked if you accidentally appended the handler twice?
Copy link to clipboard
Copied
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.