Event Listeners
Event listeners allow you to automatically call any Whisk SDK basic method in response to user actions.
Click Listeners
Click listeners allow you to call any Whisk SDK basic method in response to user click on predefined DOM element. In order to create a click listener call
function, which will add an event listener to DOM element with element_id id attribute. This listener will call the method name method with method_parameters.
method_parameters supports the same parameters as a method_name does, plus one extra non-required parameter:
Here is a simple example of usage:
Add recipe to shopping list
Note: recipeUrl is optional and can be excluded. If it is not included, the URL of your page (which this code is used on) will be taken as the recipe URL.
In order to remove click listener call
whisk.listeners.removeClickListener(element_id)
with the same element_id
you used in whisk.listeners.addClickListener.
If you need to update parameters for existing click listener, you can simply call whisk.listeners.addClickListener on the same element_id with new values.
Subscriptions
Read general information about subscriptions here. Click listeners support following event types:
view - the element to which click listener is attached appeared in the viewport. Triggered once. No custom data for this event type.
click - the element to which click listener is attached has been clicked. No custom data for this event type.
Page Load Listener
Page load listeners allow you to call any Whisk SDK basic method in response to page load whenwhisk-show=1
parameter is in the page URL. In order to create a page listener call
function. This listener will call method_name
method with method_parameters
. Here is simple example of usage:
Last updated