PP.NativeDelegate(func: Function, context: Object, args: Object, params: Object)
func. Event handler.
context. The control, for which event a handler is set.
args. Event arguments.
params. Event parameters.
The NativeDelegate constructor creates an instance of the NativeDelegate class.
To execute the example, add links to PP.js scenario file and PP.css styles file to HTML page in the <head> tag, and specify the ready() value for the onload attribute in the <body> tag. Create a button and add an event handler of mouse button click:
var button;
function createButton() {
// Create a button
button = new PP.Ui.Button({
// Set a parent node
ParentNode: document.body,
// Set button's contents
Content: "Button"
});
}
// process the button click event
function onClick(sender, args) {
console.log("Button is clicked")
}
function ready() {
// Create a button
this.createButton();
// Create settings for the mouse button click event handler
var setting = {
// Specify the control, for which event the handler is set
ParentControl: button,
// Set event handler name
HandleName: button.Click.getHandleName(),
// Set name of the event, for which the handler is set
NativeEvent: button.Click.getNativeEvent(),
// Specify that the event is not fired by touching the corresponding control
IsTouchDisabled: True
};
// Create a mouse button click event handler
var delegate = new PP.NativeDelegate(onClick, this, null, setting);
// Add a button click event handler
delegate.add(onClick, button);
button.Click = delegate;
}
After the mouse button click the browser console displays the appropriate message:
Button is clicked
See also: