-
Notifications
You must be signed in to change notification settings - Fork 1
Examples: Execute JS
examples/execute_js
Beyond opening a specified URL, DataDocs allows a click on an overlay element to trigger an arbitrary JavaScript function with additional parameters. For the basic setup overview, refer to the instructions above for examples/launch_url. Then adjust the files as below:
-
Open
dd_execute_js.html. Towards the bottom of this file, you will find the<div id="external_content">element with some placeholder text in it. This is the div that our JavaScript function will update when the policy_text overlay is clicked. The layout styles for this div can be found indd_execute_js.css. Note that the "external_content" div is outside of the "all_info" div that we have specified as our video's fullscreen container (refer to DataDocs structural overview for more details on how the libraries organizes these divs). We have placed "external_content" outside of this because this particular content is "outside" of our main video and should not be included in fullscreen mode. >Note: Other Data Docs overlay divs can also be targeted with these functions. -
Open
main.jsand navigate to theaddCaramelentry with the target "policy_text". Instead ofurl, this instance includes two options:function_name, which is assigned the string name of the function that a click on the target div should trigger, and the optionalfunction_params, which is a JSON object containing any other information that the JavaScript function should know about. Try changing the value of thetextentry of this object. -
At the bottom of
main.jsis the particular JavaScript function this example uses; is calledpolicyClickHandler. Although we do not use it here, the actual click event will always be the first argument passed to any function triggered this way; the second argument will hold thefunction_paramsobject specified in theaddCaramelcall (if included). In this simple example, we use thetargetpart of theparamsObjectto access our "external_content" div, and then simply set its contents to the value of theparamsObject"text" property. -
Open up
dd_execute_js.htmlin Firefox or Chrome on your desktop, and watch what happens when you click the "Influence Monetary Policy" text!