type
attribute of the script
element defines the MIME type of the script.type
attribute is not defined, and the script is embedded, the script will be assumed to be a XUL Javascript scripttype
attribute is not defined, and the script is external the script will be inferred from the file extensionscript
element:<script> function clicked(){ alert('Hello World!'); } </script>or:
<script type="application/groovy"> public int getValue(){ return 10; } </script>
<script src="myScript.js" />
oncommand
, onclick
, or onchange
) must refer to a function or method defined for a script associated with the XUL script[1]
<window title="Hello" orient="horizontal" width="250" height="100" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script> function clicked() { alert('Hello World!'); } </script> <button label="Push Me!" oncommand="clicked()" /> </window>
getCurrentDocument()
and getCurrentWidget()
on the helper will return the XUL document or widget from which originates the last event. getCurrentDocument()
methodgetCurrentWidget()
methodcontext
field in your script. For example:public void clicked() { context.echo("Hello World"); }The script helper is available through the
helper
field in your script. For example:public void clicked() { XULWidget widget helper.getCurrentWidget(); }
subscribe(service)
method which will be notified for each service notification on the module. For example:<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="vboxExample" title="Example" width="200" height ="200" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script> function subscribe(service) { var value = service.getData("value").getValueAsInt(); document.getElementById("label").value = value; } </script> <hbox> <button id="button" label="Positive Step" oncommand="toggle()" /> <label id="label" value="0" /> </hbox> </window>
getService(serviceName)
method allows to get the service of a specified namegetService(serviceName, serviceURI)
method allows to get the service of a specified name and namespace<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="vboxExample" title="Example" width="200" height ="200" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script> var positive = true; function toggle() { positive = !positive; if (!positive) { document.getElementById("button").label = "Positive Step"; } else { document.getElementById("button").label = "Negative Step"; } var service = context.getService("event"); service.getData("event").setBooleanValue(positive); service.invoke(); } </script> <hbox> <button id="button" label="Positive Step" oncommand="toggle()" /> <label id="label" value="0" /> </hbox> </window>
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence