how do you do callbacks out of webkit into c++, objC or other bindings - e.g. "onclick" ?
pyjamas-desktop is the test-case for the glib bindings - but ignore that, i have a general question for which pyj/d is a specific case: in javascript, you can set an element's "onclick" method. how the heck do i get a callback, into c++, objc or any other binding, from an "onclick"? is there a mechanism for calling back, from javascript, into the "bindings"? so, for example, i could set an element's "onclick" method to call "hello_now_we_are_going_to_pass_all_our_arguments_to_the_binding(...)"? i've already set up an EventListener (using addWindowEventListener) but that's far from ideal, although it does take in eeeverything, which is required in a lot of instances in pyjamas, to handle e.g. mouse-move events, and to handle "event preview", thus allowing opportunities to stop event propagation... .. all that's taken care of. what _isn't_ taken care of is overriding window "onresize", element "onclick", window "onbeforeclose", window "close", element "onblur" and all the other loovely events that are usually the exclusive domain of javascript. .. how do i get em? :) tia, l.
On Aug 30, 2008, at 5:35 PM, Luke Kenneth Casson Leighton wrote:
in javascript, you can set an element's "onclick" method. how the heck do i get a callback, into c++, objc or any other binding, from an "onclick"?
is there a mechanism for calling back, from javascript, into the "bindings"?
so, for example, i could set an element's "onclick" method to call "hello_now_we_are_going_to_pass_all_our_arguments_to_the_binding (...)"?
i've already set up an EventListener (using addWindowEventListener) but that's far from ideal, although it does take in eeeverything, which is required in a lot of instances in pyjamas, to handle e.g. mouse-move events, and to handle "event preview", thus allowing opportunities to stop event propagation...
.. all that's taken care of.
what _isn't_ taken care of is overriding window "onresize", element "onclick", window "onbeforeclose", window "close", element "onblur" and all the other loovely events that are usually the exclusive domain of javascript.
You can add event listeners for any event and any event target. The name of the function to add an event listener is addEventListener. To identify the event you want to listen to, you pass the event name. Events have names like "resize", "click", "beforeclose", "blur", etc. Attributes such as "onclick" are a JavaScript-specific convenience. These attribute values are strings that are compiled as JavaScript and added as event listeners. For each attribute, such as "onclick", there's a corresponding event, such as "click". The object can have any number of event listeners listening to that particular event in addition to the single one that will be created if there's an "onclick" attribute. For example, if you have a button element in Objective-C in a variable named button, you can add a listener for clicks like this: [button addEventListener:@click" listener:clickListener useCapture:NO]; The clickListener object must be a class that implements the DOMEventListener protocol. When someone clicks the button, the handleEvent: method of the clickListener will be called. -- Dari
On Aug 30, 2008, at 7:00 PM, Darin Adler wrote:
The clickListener object must be a class that implements the DOMEventListener protocol.
What I meant to say was: The clickListener object must be an object of a class that conforms to the DOMEventListener protocol. -- Darin
i've already set up an EventListener (using addWindowEventListener) but
You can add event listeners for any event and any event target. The name of the function to add an event listener is addEventListener. To identify the event you want to listen to, you pass the event name. Events have names like "resize", "click", "beforeclose", "blur", etc.
darin - _great_. thank you very much, that was the clue that i needed, and have found the instances of addEventListener that i couldn't earlier find, not knowing what the function was called. i'm adding a simple function now to the glib bindings and copying the style of my caller to addWindowEventListener. later on i can do the other ones i've since found, based on your helpful hint, but i (personally) don't need an event listener on an XMLHTTPRequest right now so won't be adding it immediately :) l.
You can add event listeners for any event and any event target. The name of the function to add an event listener is addEventListener. To identify the event you want to listen to, you pass the event name. Events have names like "resize", "click", "beforeclose", "blur", etc.
it works. thank you!
participants (2)
-
Darin Adler
-
Luke Kenneth Casson Leighton