bind function to action in pdf javascript - 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

Related

How to (correctly) add JavaScript code to a Customization Project Screen in Acumatica?

I'm trying to add a button to a customization screen in Acumatica that will run a small JavaScript function when clicked.
I am able to type the function inside a JavaScript control, which will be called from the button's Click or MouseDown events. I can also directly type the function into any of these 2 button events, without the need of the JavaScript control.
Using a basic alert("test"); for testing, I can confirm the code runs, with any of the 2 methods I described above.
The problem:
Clicking on the button doesn't run the code. Instead, the message pops up right after the screen loads, and it actually does it 2 times, so it seems the function runs automatically twice on screen load.
Is this possibly a bug? or am I doing something wrong?
Is there a "correct" way or a specific set of steps to follow in order to include JavaScript code into a Customization Screen?
Notes:
Currently testing on Acumatica 2022 R1.
I have tested this prior to and after publishing the screen, getting the same results.
Add a Javascript function in Asp:Content block:
<script type="text/javascript">
function Test() {
alert("Test");
}
</script>
Put the name of the Javascript function in PXButton ClientEvents property:
<px:PXButton ID="edTest" runat="server" CommandSourceID="ds">
<ClientEvents Click="Test" />
</px:PXButton>
It's hard to tell why alert is showing many times without looking at your code.
Check the following:
is there a JS function in script block? or just JS alert statement?
are there multiple client events? perhaps you have hooked CommandPerformed
do you declare a document ready Javascript event that could execute alert?
I suggest trying on a new page to eliminate these potential mistakes. I tested code above by modifying Sales Order page directly (SO301000) and it does produce a single alert message when clicking test button.
One possible solution would be to define the function in the javascript object as you are doing. Then on the onclick event of the button you can call the function that you defined in the javascript block. A sample of this type of code can be found in the CS206020.aspx or OU201000.aspx page. It is imperative that you use the Client Events sub element of the PXButton to set the click event to the function that you defined.

Jquery detect textbox programmatic change

Long story short I am cowboying some code in which a custom framework I am using allows me to insert a script to manipulate the page to do what I want.
I want to fire a function, but only after the textbox I want to use has been populated from the webservice that gets called.
In Jquery/Javascript is there anyway to call a function like the jquery change function, but one that can detect when the textbox has been changed from javascript, and not by the user in the browser.
I currently just have:
$("#mytexbox").on('input propertychange paste change',function() {
doSomething();
});
But this does not fire when the original function in locked code sets the value of the textbox.
Note: I can not just overload the original function as most of it is built up from dynamic server side code that I can't mimic in Javascript.
I also want to avoid having to use setTimeout() as this is unreliable and not really a nice solution.
Thanks in advance!
Maybe you can use a hidden div or input and check the changes on this instead of changes on #mytextbox. Obviously, the user can not change the hidden div, but the script can. You get the trick? ;)

connecting an event to function in javascript for pdf

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.

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.

How do i turn this jQuery to javascript?

I have a facebook connect button on this site here is the code
<fb:login-button onlogin="javascript:jfbc.login.login_button_click();"
perms="email,publish_stream,user_about_me,user_hometown,user_location,user_birthday,user_religion_politics,user_interests,user_activities,user_website"
size="medium" v="2"><a class="fb_button fb_button_medium">
<span class="fb_button_text"\>Login With Facebook</span></a></fb:login-button>
and i want to trigger this button with a javascript call and doing research i found this jquery that seems that it would do the trick (havent tested though) and i was wondering if there is an equivelent javascript or mootool because jquery is not installed. I can install it if i cant find a solution. Or if anyone has another idea on how to trigger this facebook button
$("fb\:login-button").trigger("click");
There are two ways to "trigger" a listener:
call it directly (e.g. element.onclick())
dispatch an event into the DOM that the listener will respond to
The trouble with the first method is that it doesn't replicate a bubbling event so the listener may not work as intended (e.g. there is no associated event object or bubbling, the listener's this keyword may not be correctly set).
The trouble with the second is that some browsers will not allow programatically dispatched events to do certain things (click on links for example). Also, in some browsers you have to use the W3C dispatchEvent and in others the Microsoft fireEvent.
So unless the listener has been designed specifically to work with one method or the other and is called appropriately, your chances of triggering the listener successfully are quite low.
PS. Some libraries provide their own event system, with custom events and bubbling of otherwise non-bubbling events, but in that case you have to set and trigger the listener using that library, otherwise it will probably not respond to either of the above methods.
You should be able to just invoke the same code that is invoked inline:
jfbc.login.login_button_click();
I suppose it would be something like
document.getElementsByTagName("fb\:login-button")[0].click();
I'm sure that would work very well with a "normal" DOM element that handles the click event; however, I'm not entirely sure it will work in all browsers with the fb:login-button element shimmed into HTML. You'll have to let me know.
Looks like you should be able to do:
document.body.getElementsByTagName("fb\:login-button")[0].click();
It looks like you want a namespaced element selector, so you should use:
document.getElementsByTagNameNS('fb', 'login-button')[0].click();
The : is the namespace separator.
I ran into this tonight, absolutely positioned a new button image over the iframe, and was planning on using pointer-events:none to pass through and click the iframe, but I was looking for a cross-browser solution, here you go.
jQuery('.button_fb_connect').live('click', function(){ FB.login() })
Your simply running the js function FB.login() after clicking your new element, obviously you can use whatever event you want.
Thats in jQuery of course, but thats the function you want, not just a simple click event trigger.

Categories

Resources