connecting an event to function in javascript for pdf - javascript

im trying to write something in javascript to extend my adobe reader functionlaty.
i have written a function and added it to my menu item and its working fine.
im looking for a way to connecy function to specific events that happen in the file
e.g.
run the function when i click anywhere in the document.
i saw on the documention that an event object is automatically created with specifc properties.
but i dont know how to use that event in the moment it is created, and how to make it to start a function.
thx for the help.

Related

How can I wait for the create/edit entity modal window to finish rendering and execute my custom js code in 2sxc module?

When user presses either create entity button or edit entity button, there's the same modal window in an iframe that is build by js dynamically. So what I'm trying to do is to wait until it's fully rendered and then execute my custom js code. So is there a proper way to do that? Some sort of event like RenderFinished shooting or something? Don't want to use timeout since I understand that it's not a good way to do that.
What I tried so far is that I've added jquery to the page programmatically, since it's not used currently at that particular page for some reason (probably because iframe is built dynamically without jquery and I needed to add it myself).
After that I tried to access iframe via jquery selector and then on iframe.ready access element inside in the same manner (selector and even ready for that element). But iframe is accessed and element inside it is not. Console log inside ready function just outputs no elements found. When I placed breakpoint inside I saw that there's no modal window built yet and my code is executed synchronously before it. So there's nothing to find yet at that moment.
Oh and I tried to put it all inside $(document).ready, of course. But it didn't change the situation neither...
Any ideas about how to do that properly?
The final goal why am I doing all this complicated dancing: I'm trying to add validation that UrlKey for entity is unique. So I want to bind my js function to UrlKey input's onchange event and call backend api to do the validation and return new UrlKey if it wasn't unique and edit the UrlKey input accordingly. The problem that I stumbled upon is to execute my code after modal iframe window is rendered.
Any tips are highly appreciated.
You are in luck :)
2sxc added a Formula feature which will help you with this. There are videos and tutorials and more. See http://r.2sxc.org/formulas

Runtime button onclick event handler function in Symfony/Encore/Webpack

I am newbie to web page development and I had to write web page using Symfony.
My issue is that I use free-jqgrid and I have a column containing buttons which are defined in cell formatter. So there is string, which is then inserted in the corresponding cell div.
I assign onClick function to the buttons and this function is not actually defined at main scope.
The only possible solution for me is to write it directly in twig page template.
When I try to define function in separate file and use encore_entry_script_tags to source that file, it is not defined at runtime when I press the button.
For me it seems not to be the "tidy" way. I would appreciate if anyone can advice or point me to the good source of information on this topic.
Thank you very much.

Executing external JS using innerHTML and appendChild

I've been playing around with the Material Design Lite library that Google just launched a few days ago, but have some questions, specifically on how to initiate (or execute?) external JS when the HTML changes using innerHTML and appendChild.
See the first example here. As you can see, the HTML for the menu is already within the HTML file when it is first loaded so the menu works fine.
But in this example, the HTML of the document is modified using JS. However, the menu does not work anymore because the script is not executing, I think.
How can I resolve this issue? What's a better way to achieve this result? I'm a newbie when it comes to JavaScript.
You will need to attach the proper event listener from the library. With this change (adding componentHandler.upgradeAllRegistered(); after appending the item) it should work:
document.body.appendChild(menu);
componentHandler.upgradeAllRegistered();
When the menu button is inserted dynamically (when the user clicks), it doesn't get assigned the event listeners to show the menu. I'm guessing that the material design library parses the HTML when it (the library) gets loaded (since you're loading it at the bottom of your HTML document). Since it's already loaded by the time the user clicks, it doesn't check the new element that has been inserted and can't assign it the event listeners.
If this is the case, you'll need to find a way to get the library to recognize your new button.

bind function to action in pdf javascript

i wrote a function in javascript for pdf and added it as a button to my menu
the function adds a annotation to the pdf, but i want to be able to determine where the annotation will be placed. i want to use the mouse for that.
i cant find a way for connectiong a mouse click to the function i wrote,
according to what i saw in the java api documantion there is no way to bind a click event to the function.
i tried doing something which is pure java script like this.addEventListener with no success
also tried adding to my code some js libraries like KeyboardJS but also no success.
id rather have a way to bind my function to a mouse click, but a way to bind it to a specific key could also be very useful.
thank you

How to find a Javascript function if it is event handler?

I want use Chrome developer tool to add a break point to js function to debug it.
For example, a function "buttonAlert()" is binded to a button.
But I don't know where the code of such function, and I don't know where the code that bind the function to button.
So, how can I use the tool to find out the location of function and binding code?
It is actually possible to see event listeners in chrome.
Go to the elements panel, select the element in question and click on Event Listeners on the right side.
Sadly most of the time when jQuery is in use, you only see the part of the source of jQuery that bound the event, not the one that called jQuery.

Categories

Resources