1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Scripting – SVG Tiny 1.2</title>
<link rel="stylesheet" href="style/svg-style.css" type="text/css"/>
<link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-REC" type="text/css"/>
<link rel="contents" href="expanded-toc.html"/>
<link rel="prev" href="linking.html"/>
<link rel="next" href="animate.html"/>
</head>
<body>
<div class="header">
SVG Tiny 1.2 – 20081222
<ul>
<li><a href="index.html">Top</a></li>
<li><a href="expanded-toc.html">Contents</a></li>
<li><a href="linking.html">Previous</a></li>
<li><a href="animate.html">Next</a></li>
<li><a href="elementTable.html">Elements</a></li>
<li><a href="attributeTable.html">Attributes</a></li>
</ul>
</div>
<h1>15 Scripting</h1>
<h2 id="toc">Contents</h2>
<ul class="toc">
<li>15.1 <a href="script.html#ScriptingLanguage">Specifying the scripting language</a>
<ul class="toc">
<li>15.1.1 <a href="script.html#DefaultScriptingLanguage">Specifying the default scripting language</a></li>
<li>15.1.2 <a href="script.html#SpecifiedScriptingLanguage">Local declaration of a scripting language</a></li>
</ul></li>
<li>15.2 <a href="script.html#ScriptElement">The 'script' element</a>
<ul class="toc">
<li>15.2.1 <a href="script.html#ScriptContentProcessing">Script processing</a></li>
</ul></li>
<li>15.3 <a href="script.html#xmlevents">XML Events</a></li>
<li>15.4 <a href="script.html#ListenerElement">The 'listener' element</a></li>
<li>15.5 <a href="script.html#HandlerElement">The 'handler' element</a>
<ul class="toc">
<li>15.5.1 <a href="script.html#handler-param">Parameters to 'handler' elements</a></li>
</ul></li>
<li>15.6 <a href="script.html#EventHandling">Event handling</a></li>
<li>15.7 <a href="script.html#InlineScript">Processing inline executable content</a></li>
</ul>
<h2 id="ScriptingLanguage">15.1 Specifying the scripting language</h2>
<h3 id="DefaultScriptingLanguage">15.1.1 Specifying the default scripting language</h3>
<p>The
<a href="struct.html#ContentScriptTypeAttribute">
<span class="attr-name">'contentScriptType'</span></a>
attribute on the <a href="struct.html#SVGElement"><span class="element-name">'svg'</span></a> element specifies the
default scripting language for the given document fragment.</p>
<h3 id="SpecifiedScriptingLanguage">15.1.2 Local declaration of a scripting language</h3>
<p>It is also possible to specify the scripting language for
each individual <a href="script.html#ScriptElement">
<span class="element-name">'script'</span></a> or
<a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
elements by specifying
a <a href="script.html#TypeAttribute"><span class="attr-name">'type'</span></a> attribute on the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> and <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> elements.</p>
<h2 id="ScriptElement">15.2 The <span class="element-name">'script'</span> element</h2>
<p>
A <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element may either contain or point to executable
content (e.g., ECMAScript [<a href="refs.html#ref-ECMA-262">ECMA-262</a>] or Java [<a href="refs.html#ref-JAVA">JAVA</a>] JAR file).
Executable content can come either in the form of a script (textual code) or in the form of compiled code. If the code is textual, it can either be
placed inline in the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element (as character data) or as
an external resource, referenced through <a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a> attribute.
Compiled code must be an external resource. If a <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element has both an <a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a> attribute and child character data,
the executable content for the script is retrieved from the IRI of the <a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a>
attribute, and the child content is not added to the scripting context.
</p>
<p>
When the executable content is inlined, it must be processed as described in
<a href="script.html#InlineScript">Processing inline executable content</a>.
</p>
<p>
Some scripting languages such as ECMAScript have a notion of a "global scope" or a "global object" such that a single global object must be associated with the document (unique for each uDOM <a href="svgudom.html#dom__Document" class="udom-interface-name">Document</a> node). This object is shared by all elements contained in that document. Thus, an ECMAScript function defined within any <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element must be in the "global" scope of the entire document to which the script belongs. The global object must implement the <a href="svgudom.html#svg__SVGGlobal" class="udom-interface-name">SVGGlobal</a> interface. In addition to being implemented on the global ECMAScript object, the <a href="svgudom.html#svg__SVGGlobal" class="udom-interface-name">SVGGlobal</a> object can also be obtained through the <a href="svgudom.html#views__DocumentView_defaultView"><code>DocumentView::defaultView</code></a> attribute on the <a href="svgudom.html#dom__Document" class="udom-interface-name">Document</a> object. Event listeners attached through event attributes and <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> elements are also evaluated using the global scope of the document in which they are defined.
</p>
<p>
For compiled languages (such as Java) that don't have a notion of "global scope", each <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element, in effect, provides a separate scope object. This scope object must perform an initialization as described in the <a href="svgudom.html">uDOM chapter</a> and serves as event listener factory for the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element.
</p>
<h3 id="ScriptContentProcessing">15.2.1 Script processing</h3>
<p>
Execution of a given <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element occurs at most once. There is a conceptual flag associated with
each <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element (referred to here as the "already processed" flag) that enforces
this behavior. When a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element is executed depends on the method by which the element was inserted
into the document.
</p>
<p>
One way for a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element to be inserted into the document is if it was inserted
while parsing the document. As mentioned in
<a href="struct.html#ProgressiveRendering">Progressive rendering</a>,
as the document is parsed if a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element is encountered then it will be processed just after its
<em>end element</em> event occurs, but before any more of the
document is parsed and further nodes inserted into the document.
(See below for a description of what it means for a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element to be processed.) Once processed, parsing of the document
resumes.
</p>
<p>
The other way a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element can be inserted into the document is if it was inserted
by something other than the parser (such as by other script executing).
In this case, as soon as one or more
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
elements are inserted into the document, they must be processed
one by one in document order.
</p>
<p>
A <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element is processed as follows:
</p>
<ol>
<li>
<p>
If the
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element's "already processed" flag is true or if the element is
not in the document tree, then no action is performed and these steps
are ended.
</p>
</li>
<li>
<p>
If the
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element references external script content, then the external script
content using the current value of the
<a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a>
attribute is fetched. Further processing of the
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element is dependent on the external script content, and will
block here until the resource has been fetched or is determined
to be an
<a href="intro.html#TermInvalidIRIReference"><span class="svg-term">invalid IRI reference</span></a>.
</p>
</li>
<li>
<p>
The
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element's "already processed" flag is set to true.
</p>
</li>
<li>
<p>
If the script content is inline, or if it is external and was
fetched successfully, then the script is executed. Note that at
this point, these steps may be re-entrant if the execution of
the script results in further
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
elements being inserted into the document.
</p>
</li>
</ol>
<p>
Note that a <a href="interact.html#EventsLoad"><code>load</code></a>
event is dispatched on a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element once it has been processed, unless it referenced external
script content with an
<a href="intro.html#TermInvalidIRIReference"><span class="svg-term">invalid IRI reference</span></a>
and
<a href="struct.html#ExternalResourcesRequiredAttribute"><span class="attr-name">'externalResourcesRequired'</span></a>
was set to <span class="attr-value">'true'</span>.
</p>
<p>
Modifying or removing the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element (or content) after the script has started its execution must have
no effect on the script execution.
</p>
<p>
Modifying a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element's <a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a>
attribute after its "already processed" flag is set to true will not
cause any new script content to be fetched or executed.
</p>
<p>
What it means to execute some script content depends on the script
content type. SVG Tiny 1.2 does not require support for any particular
programming language. However, SVG defines the behavior for two specific
script types in the case where an implementation supports it:
</p>
<dl>
<dt>
application/ecmascript</dt>
<dd>
<p>
This type of executable content must be source code for the ECMAScript programming language. This code must be executed in the context of this element's owner document's global scope as explained above.
</p>
<p>
SVG implementations that load external resources
through protocols such as HTTP that support content coding must accept
external script files that have been encoded using gzip compression
(flagged using "Content-Encoding: gzip" for HTTP).
</p>
</dd>
<dt>
application/java-archive</dt>
<dd>
<p>
This type of executable content must be an external resource that contains a Java JAR archive. The manifest file in the JAR archive must have an entry named SVG-Handler-Class. The entry's value must be a fully-qualified Java class name for a class contained in this archive. The user agent must instantiate the class from the JAR file and cast it to
the <a href="svgudom.html#svg__EventListenerInitializer2" class="udom-interface-name">EventListenerInitializer2</a> interface. Then the <a href="svgudom.html#svg__EventListenerInitializer2_initializeEventListeners"><code>initializeEventListeners</code></a> method must be called with the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element object itself as a parameter. If a class listed in SVG-Handler-Class does not implement <a href="svgudom.html#svg__EventListenerInitializer2" class="udom-interface-name">EventListenerInitializer2</a>, it is an <a href="intro.html#TermInError"><span class="svg-term">error</span></a>.
</p>
<p>
Note that the user agent may reuse classes loaded from the same URL, so the code must not assume that every <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element or every document will create its own separate class object. Thus, one cannot assume, for instance, that static fields in the class are private to a document.
</p>
</dd>
</dl>
<p>Implementations must also accept the script type <span class="attr-value">'text/ecmascript'</span> for
backwards compatibility with SVG 1.1. However, this type is deprecated
and should not be used by content authors.
</p>
<p>
Other language bindings are encouraged to adopt a similar approach to either of the two described above.
</p>
<!-- @@ fix me - use keypress -->
<p id="Example18_01"><span class="example-ref">Example 18_01</span> defines a
function <code>circle_click</code> which is called when the <a href="shapes.html#CircleElement"><span class="element-name">'circle'</span></a> element is being clicked. The drawing
below on the left is the initial image. The drawing below on
the right shows the result after clicking on the circle. The example uses the
<a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element which is described further down in this chapter.</p>
<p>Note that this example demonstrates the use of the <a href="interact.html#EventsClick"><code>click</code></a> event for
explanatory purposes. The example presupposes the presence of
an input device with the same behavioral characteristics as a
mouse, which will not always be the case. To support the widest
range of users, the <a href="interact.html#EventsActivate"><code>DOMActivate</code></a> event should be used instead
of the <a href="interact.html#EventsClick"><code>click</code></a> event.</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/18_01.svg">18_01.svg</a></div><div class="examplesource"><pre><?xml version="1.0"?>
<svg width="6cm" height="5cm" viewBox="0 0 600 500"
xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
xmlns:ev="http://www.w3.org/2001/xml-events">
<desc>Example: invoke an ECMAScript function from an click event
</desc>
<!-- ECMAScript to change the radius with each click -->
<script type="application/ecmascript"> <![CDATA[
function circle_click(evt) {
var circle = evt.target;
var currentRadius = circle.getFloatTrait("r");
if (currentRadius == 100)
circle.setFloatTrait("r", currentRadius*2);
else
circle.setFloatTrait("r", currentRadius*0.5);
}
]]> </script>
<!-- Outline the drawing area with a blue line -->
<rect x="1" y="1" width="598" height="498" fill="none" stroke="blue"/>
<!-- Act on each click event -->
<circle cx="300" cy="225" r="100" fill="red">
<handler type="application/ecmascript" ev:event="click">
circle_click(evt);
</handler>
</circle>
<text x="300" y="480" font-family="Verdana" font-size="35" text-anchor="middle">
Click on circle to change its size
</text>
</svg>
</pre></div></div>
<div class="exampleimage">
<table summary="Example 18_01">
<tr>
<td><img alt="Example 18_01 - invoke an ECMAScript function from an onclick event - before first click" src="images/script/script01.png" width="213" height="178" /></td>
<td> </td>
<td><img alt="Example 18_01 - invoke an ECMAScript function from an onclick event - after first click" src="images/script/script01-AfterClick.png" width="213" height="178" /></td>
</tr>
</table>
</div>
<p>Here the same script is invoked, this time in an external file.</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/18_02.svg">18_02.svg</a></div><div class="examplesource"><pre><?xml version="1.0"?>
<svg width="6cm" height="5cm" viewBox="0 0 600 500"
xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
xmlns:ev="http://www.w3.org/2001/xml-events">
<desc>Example: invoke an external ECMAScript function from an click event
</desc>
<!-- ECMAScript to change the radius with each click -->
<script type="application/ecmascript" xlink:href="sample.es"/>
<!-- Outline the drawing area with a blue line -->
<rect x="1" y="1" width="598" height="498" fill="none" stroke="blue"/>
<!-- Act on each click event -->
<circle cx="300" cy="225" r="100" fill="red">
<handler type="application/ecmascript" ev:event="click">
circle_click(evt);
</handler>
</circle>
<text x="300" y="480" font-family="Verdana" font-size="35" text-anchor="middle">
Click on circle to change its size
</text>
</svg>
</pre></div></div>
<div class="schema"><div class="schemaheader"><strong>Schema:</strong> script<div class="schemasource"><pre> <define name='script'>
<element name='script'>
<ref name='script.AT'/>
<ref name='script.ATCM'/>
</element>
</define>
<define name='script.AT' combine='interleave'>
<ref name='svg.CorePreserve.attr'/>
<ref name='svg.External.attr'/>
<ref name='svg.ContentType.attr'/>
</define>
<define name='script.ATCM'>
<interleave>
<choice>
<group>
<ref name='svg.XLinkRequired.attr'/>
</group>
<text/>
</choice>
<ref name='svg.Desc.group'/>
</interleave>
</define>
</pre></div></div></div>
<div class="adef-list">
<p><em>Attribute definitions:</em></p>
<dl class="definitions">
<dt id="TypeAttribute"><span class="adef">type</span> =
<span class="attr-value">"<a href="types.html#DataTypeContentType"><content-type></a>"</span></dt>
<dd><p>Identifies the programming language for the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element. The
<span class="attr-value">"<a href="types.html#DataTypeContentType"><content-type></a>"</span> value
specifies a media type, per <a href="http://www.ietf.org/rfc/rfc2046.txt"><cite>Multipurpose Internet Mail Extensions (MIME) Part Two</cite></a> [<a href="refs.html#ref-RFC2046">RFC2046</a>].
If <a href="script.html#TypeAttribute"><span class="attr-name">'type'</span></a> is not specified, the value of
<a href="struct.html#ContentScriptTypeAttribute"><span class="attr-name">'contentScriptType'</span></a> on the
<a href="struct.html#SVGElement"><span class="element-name">'svg'</span></a>
element shall be used, which in turn has a
<a href="intro.html#TermLacunaValue"><span class="svg-term">lacuna value</span></a> of
<span class="attr-value">'application/ecmascript'</span> [<a href="refs.html#ref-RFC4329">RFC4329</a>]. If a
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element is not inside an <a href="intro.html#TermSVGDocumentFragment"><span class="svg-term">SVG document fragment</span></a>,
<a href="script.html#TypeAttribute"><span class="attr-name">'type'</span></a> must default to
<span class="attr-value">'application/ecmascript'</span>.
This can happen for example if the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element is a child of some arbitrary non-SVG markup.
</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>:
no.</p></dd>
<dt><a id="ScriptElementHrefAttribute" name="ScriptElementHrefAttribute"></a> <span class="adef">xlink:href</span> = "<span class="attr-value"><a href="types.html#DataTypeIRI"><IRI></a></span>"</dt>
<dd>
<p>An <a href="linking.html#IRIReference"><span class="svg-term">IRI reference</span></a>
to an external resource containing the script code. If the attribute
contains an <a href="intro.html#TermInvalidIRIReference"><span class="svg-term">invalid IRI reference</span></a>,
the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element will not execute any script.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p></dd>
</dl>
</div>
<h2 id="xmlevents">15.3 XML Events</h2>
<p>
<a href="../../2003/REC-xml-events-20031014/index.html"><cite>XML Events</cite></a>
[<a href="refs.html#ref-XML-EVENTS">XML-EVENTS</a>] is an XML syntax for integrating
event listeners and handlers with
<a href="../../2000/REC-DOM-Level-2-Events-20001113/index.html"><cite>DOM Level 2 Events</cite></a>
[<a href="refs.html#ref-DOM2EVENTS">DOM2EVENTS</a>]. Declarative event handling in
SVG 1.1 was hardwired into the language, in that the developer was required
to embed the event handler in the element syntax (e.g. an element with an
<span class="attr-name">'onclick'</span> attribute). SVG Tiny 1.2 does not support the event attributes
(<span class="attr-name">'onload'</span>, <span class="attr-name">'onclick'</span>,
<span class="attr-name">'onactivate'</span>, etc.). Instead SVG Tiny 1.2 uses
XML Events, through the inclusion of the
<a href="script.html#ListenerElement"><span class="element-name">'listener'</span></a>
and <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
elements to provide the ability to specify the event listener separately from
the graphical content.
</p>
<p>
The <a href="interact.html#SVGEvents">list of events</a> supported by SVG Tiny 1.2
is given in the Interactivity chapter.</p>
<p>There are two ways to place a handler in SVG Tiny 1.2 content. The first method is most suitable for simple cases:</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/simplehandler.svg">simplehandler.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg"
xmlns:ev="http://www.w3.org/2001/xml-events"
version="1.2" baseProfile="tiny">
<rect x="10" y="20" width="10" height="20" fill="red">
<handler type="application/ecmascript" ev:event="click">
var theRect = evt.target;
var width = theRect.getFloatTrait("width");
theRect.setFloatTrait("width", width + 10);
</handler>
</rect>
</svg>
</pre></div></div>
<p>In this method the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element is a child element of the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-observer">observer</a> ([<a href="refs.html#ref-XML-EVENTS">XML-EVENTS</a>], section 3.1). For instance one can place a <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> as a child of a <a href="shapes.html#RectElement"><span class="element-name">'rect'</span></a> element, which becomes the observer. This causes the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element to be invoked whenever the event that it is interested in (<a href="interact.html#ClickEvent"><code>click</code></a>, in this case) occurs on the <a href="shapes.html#RectElement"><span class="element-name">'rect'</span></a>.</p>
<p>The following is an example of an SVG document using XML Events where the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element can be reused on several objects. The <a href="script.html#ListenerElement"><span class="element-name">'listener'</span></a> element from XML Events is used to specify the <a href="script.html#observer-attr"><span class="attr-name">'observer'</span></a> and <a href="script.html#handler-attr"><span class="attr-name">'handler'</span></a> for a particular <a href="script.html#event-attr"><span class="attr-name">'event'</span></a>.
</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/handler.svg">handler.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
xmlns:ev="http://www.w3.org/2001/xml-events">
<desc>An example of the handler element.</desc>
<rect xml:id="theRect1" x="10" y="20" width="10" height="20" fill="red"/>
<rect xml:id="theRect2" x="10" y="40" width="10" height="20" fill="green"/>
<ev:listener event="click" observer="theRect1" handler="#theClickHandler"/>
<ev:listener event="click" observer="theRect2" handler="#theClickHandler"/>
<handler xml:id="theClickHandler" type="application/ecmascript">
var theRect = evt.target;
var width = theRect.getFloatTrait("width");
theRect.setFloatTrait("width", (width+10));
</handler>
</svg>
</pre></div></div>
<p>
In the above example, the <a href="script.html#ListenerElement"><span class="element-name">'listener'</span></a> element registers that the "theClickHandler" element should be invoked whenever a <a href="interact.html#EventsClick"><code>click</code></a> event happens on "theRect1" or "theRect2".
</p>
<p>
The combination of the XML Events syntax and the new <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element allows event handling to be more easily processed in a compiled language. Below is an example of an event handler using the Java language:
</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/javahandler.svg">javahandler.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:foo="http://www.example.com/foo"
xmlns:xlink="http://www.w3.org/1999/xlink">
<desc>Example of a Java handler</desc>
<rect xml:id="theRect" x="10" y="20" width="200" height="300" fill="red"/>
<!-- reference a jar containing an EventListenerInitializer2 object -->
<script type="application/java-archive" xml:id="init" xlink:href="http://example.com/theJar.jar"/>
<!-- register a listener for a theRect.click event -->
<ev:listener event="click" observer="theRect" handler="#theClickHandler" />
<handler xml:id="theClickHandler" type="application/java-archive" xlink:href="#init" foo:offset="10"/>
</svg>
</pre></div></div>
<p>
In this case, the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element specifies a reference to the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element that specifies the location of compiled code that conforms to the <a href="svgudom.html#svg__EventListenerInitializer2" class="udom-interface-name">EventListenerInitializer2</a> interface. The user agent invokes the <a href="svgudom.html#svg__EventListenerInitializer2_createEventListener"><code>createEventListener</code></a> method within the targeted interface.
</p>
<p>
In this case, the <code>MyListenerInitializer</code> class referenced by the SVG-Handler-Class entry of the <code>theJar.jar</code> manifest has the following definition:
</p>
<div class="example">
<div class="exampleheader">
MyListenerInitializer
</div>
<div class="examplesource">
<pre>
package com.example;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.svg.EventListenerInitializer2;
public class MyListenerInitializer implements EventListenerInitializer2 {
Document document;
public void initializeEventListeners(Element scriptElement) {
document = scriptElement.getOwnerDocument();
}
public EventListener createEventListener(final Element handlerElement) {
return new EventListener() {
public void handleEvent(Event event) {
Element theRect = document.getElementById("theRect");
float width = Float.parseFloat(theRect.getAttributeNS(null, "width"));
float offset = Float.parseFloat(handlerElement.getAttributeNS("http://www.example.com/foo", "offset");
theRect.setAttributeNS(null, "width", "" + (width + offset));
}
};
}
}
</pre>
</div>
</div>
<p>
The <a href="svgudom.html#svg__EventListenerInitializer2" class="udom-interface-name">EventListenerInitializer2</a> interface is currently defined in the SVG package. Future specifications may move this package though it is guaranteed to always be available in the SVG package. </p>
<h2 id="ListenerElement">15.4 The <span class="element-name">'listener'</span> element</h2>
<p>
The <a href="http://www.w3.org/TR/xml-events/Overview.html#section-listener-element"><span class="element-name">'listener'</span></a> element from XML Events <a href="refs.html#ref-XML-EVENTS">[XML-EVENTS]</a> must be supported. The definition for the <a href="http://www.w3.org/TR/xml-events/Overview.html#section-listener-element"><span class="element-name">'listener'</span></a> element is provided in <a href="refs.html#ref-XML-EVENTS">[XML-EVENTS]</a>. Any additional restrictions from this specification must also apply.
</p>
<p>
Whenever the attributes of a listener element are modified, the corresponding event listener is removed and a new one is created. When listener elements are added or removed, the event listener is added or removed respectively.
</p>
<p>
Please note that the <a href="script.html#ListenerElement"><span class="element-name">'listener'</span></a> element must be
specified in the XML Events namespace, and that an element in the SVG namespace
with "listener" as its local name must not be understood as being the element
described in this chapter. Furthermore, the XML Events attributes that are
available on other elements only when they are in the XML Events namespace,
are only available on this element when they are in no namespace.
</p>
<div class="schema"><div class="schemaheader"><strong>Schema:</strong> listener<div class="schemasource"><pre> <define name='listener'>
<element name='listener'>
<ref name='listener.AT'/>
<ref name='listener.CM'/>
</element>
</define>
<define name='listener.AT' combine='interleave'>
<ref name='svg.Core.attr'/>
<optional>
<attribute name='event' svg:animatable='false' svg:inheritable='false'>
<ref name='XML-NMTOKEN.datatype'/>
</attribute>
</optional>
<optional>
<attribute name='phase' svg:animatable='false' svg:inheritable='false'>
<choice>
<value>default</value>
<value>capture</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name='propagate' svg:animatable='false' svg:inheritable='false'>
<choice>
<value>continue</value>
<value>stop</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name='defaultAction' svg:animatable='false' svg:inheritable='false'>
<choice>
<value>perform</value>
<value>cancel</value>
</choice>
</attribute>
</optional>
<optional>
<attribute name='observer' svg:animatable='false' svg:inheritable='false'>
<ref name='IDREF.datatype'/>
</attribute>
</optional>
<optional>
<attribute name='target' svg:animatable='false' svg:inheritable='false'>
<ref name='IDREF.datatype'/>
</attribute>
</optional>
<optional>
<attribute name='handler' svg:animatable='false' svg:inheritable='false'>
<ref name='IRI.datatype'/>
</attribute>
</optional>
</define>
<define name='listener.CM'>
<empty/>
</define>
</pre></div></div></div>
<div class="adef-list">
<p><em>Attribute definitions:</em></p>
<dl class="definitions">
<dt id="event-attr">
<span class="adef">event</span> =
<span class="attr-value">"<a href="types.html#DataTypeXML-NMTOKEN"><XML-NMTOKEN></a>"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-event">XML Events
<span class="attr-name">'event'</span> attribute</a> definition.
The <a href="script.html#event-attr"><span class="attr-name">'event'</span></a>
attribute must be a valid SVG Tiny 1.2 event identifier as defined in the
<a href="interact.html#SVGEvents">list of supported events</a>.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="observer-attr">
<span class="adef">observer</span> =
<span class="attr-value">"<a href="types.html#DataTypeIDREF"><IDREF></a>"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-observer">XML Events
<span class="attr-name">'observer'</span> attribute</a> definition.
Note that if the <a href="script.html#observer-attr"><span class="attr-name">'observer'</span></a>
attribute is not present, the observer is the parent of the
<a href="script.html#ListenerElement"><span class="element-name">'listener'</span></a>
element.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="target-attr">
<span class="adef">target</span> =
<span class="attr-value">"<a href="types.html#DataTypeIDREF"><IDREF></a>"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-target">XML Events
<span class="attr-name">'target'</span> attribute</a> definition.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="handler-attr">
<span class="adef">handler</span> =
<span class="attr-value">"<a href="types.html#DataTypeIRI"><IRI></a>"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-handler">XML Events
<span class="attr-name">'handler'</span> attribute</a> definition.
This attribute is an <a href="intro.html#TermIRIReference"><span class="svg-term">IRI reference</span></a>.
Restrictions specified in this chapter as to which IRIs are acceptable must be enforced.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="phase-attr">
<span class="adef">phase</span> =
<span class="attr-value">"default"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-phase">XML Events
<span class="attr-name">'phase'</span> attribute</a> definition.
Support for the capture phase is not required in SVG Tiny 1.2, and
implementations that do not support it must process this attribute as if
it had not been specified.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="propagate-attr">
<span class="adef">propagate</span> =
<span class="attr-value">"stop" | "continue"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-propagate">XML Events
<span class="attr-name">'propagate'</span> attribute</a> definition.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt id="defaultAction-attr">
<span class="adef">defaultAction</span> =
<span class="attr-value">"cancel" | "perform"</span>
</dt>
<dd>
<p>See the <a href="http://www.w3.org/TR/xml-events/Overview.html#attr-listener-defaultAction">XML Events
<span class="attr-name">'defaultAction'</span> attribute</a> definition.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
</dl>
</div>
<h2 id="HandlerElement">15.5 The <span class="element-name">'handler'</span> element</h2>
<p>
The <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element is similar to the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element: its contents, either included inline or referenced, is code that is to be executed by a scripting engine used by user agent.
</p>
<p>
However, where the <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> element executes its contents when it is loaded, the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element must only execute its contents in response to an event. This means that SVG Tiny 1.2 uses <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> to get the functionality equivalent to that provided by <a href="../../2003/REC-SVG11-20030114/script.html#EventAttributes">SVG Full event attributes</a> ([<a href="refs.html#ref-SVG11">SVG11</a>], section 18.4).
</p>
<p>
When the executable content is inlined, it must be processed as described in
<a href="script.html#InlineScript">Processing inline executable content</a>.
</p>
<p>
For example, consider the following SVG 1.1 document:
</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/nohandler.svg">nohandler.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<rect id="theRect" x="10" y="20" width="200" height="300" fill="red"
onclick="evt.target.width.baseVal.value += 10"/>
</svg>
</pre></div></div>
<p>
The above example must be rewritten, as described below, to use the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element and XML Events as shown:
</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/handler2.svg">handler2.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg"
xmlns:ev="http://www.w3.org/2001/xml-events"
version="1.2" baseProfile="tiny">
<desc>handler element example</desc>
<rect xml:id="theRect" x="10" y="20" width="200" height="300" fill="red">
<handler type="application/ecmascript" ev:event="click">
var theRect = evt.target;
var width = theRect.getFloatTrait("width");
theRect.setFloatTrait("width", width + 10);
</handler>
</rect>
</svg>
</pre></div></div>
<p>
Whenever the <a href="script.html#HandlerTypeAttribute"><span class="attr-name">'type'</span></a>
or <a href="script.html#HandlerEventAttribute"><span class="attr-name">ev:event</span></a>
attributes of a <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
element are modified, the corresponding event listener is removed and a new
one is created. When the <a href="script.html#HandlerXlinkAttribute"><span class="attr-name">'xlink:href'</span></a>
attribute is modified or the content of the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
element is modified, the existing event listener is preserved, but the user
agent must execute the updated handler logic. When <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
elements are added or removed, the corresponding event listener is added or
removed respectively.
</p>
<p>
In ECMAScript, the contents of the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element behave conceptually as if they are the contents of a new Function object, created as shown:
</p>
<pre>
function(event) {<br /> var evt = event;<br /> //contents of handler<br />}
</pre>
<p>
The 'event' parameter shown above is an <a href="svgudom.html#events__Event">Event object</a> corresponding to the event that has triggered the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>. An 'evt' variable can be used instead of 'event' ('evt' is an alias to 'event').
</p>
<div class="schema"><div class="schemaheader"><strong>Schema:</strong> handler<div class="schemasource"><pre> <define name='handler'>
<element name='handler'>
<ref name='handler.AT'/>
<ref name='handler.ATCM'/>
</element>
</define>
<define name='handler.AT' combine='interleave'>
<ref name='svg.CorePreserve.attr'/>
<ref name='svg.External.attr'/>
<optional>
<attribute name='ev:event' svg:animatable='false' svg:inheritable='false'>
<ref name='XML-NMTOKEN.datatype'/>
</attribute>
</optional>
<ref name='svg.ContentType.attr'/>
</define>
<define name='handler.ATCM'>
<interleave>
<choice>
<group>
<ref name='svg.XLinkRequired.attr'/>
</group>
<text/>
</choice>
<ref name='svg.Desc.group'/>
</interleave>
</define>
</pre></div></div></div>
<div class="adef-list">
<p><em>Attribute definitions:</em></p>
<dl class="definitions">
<dt><a id="HandlerTypeAttribute" name="HandlerTypeAttribute"></a> <span class="adef">type</span> = <span class="attr-value">"<a href="types.html#DataTypeContentType"><content-type></a>"</span></dt>
<dd>
<p>Identifies the programming language for the
<a href="script.html#ScriptElement"><span class="element-name">'handler'</span></a>
element. The <span class="attr-value">"<a href="types.html#DataTypeContentType"><content-type></a>"</span>
value specifies a media type, per <a href="http://www.ietf.org/rfc/rfc2046.txt"><cite>Multipurpose Internet Mail Extensions (MIME) Part Two</cite></a>
[<a href="refs.html#ref-RFC2046">RFC2046</a>]. If
<a href="script.html#TypeAttribute"><span class="attr-name">'type'</span></a> is not
specified, the value of <a href="struct.html#ContentScriptTypeAttribute"><span class="attr-name">'contentScriptType'</span></a>
on the <a href="struct.html#SVGElement"><span class="element-name">'svg'</span></a>
element shall be used, which in turn has a
<a href="intro.html#TermLacunaValue"><span class="svg-term">lacuna value</span></a>
of <span class="attr-value">'application/ecmascript'</span>
[<a href="refs.html#ref-RFC4329">RFC4329</a>].</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p>
</dd>
<dt><a id="HandlerXlinkAttribute" name="HandlerXlinkAttribute"></a> <span class="adef">xlink:href</span> = <span class="attr-value">"<a href="types.html#DataTypeIRI"><IRI></a>"</span></dt>
<dd><p>If this attribute is present, then the script content of the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a>
element must be loaded from this resource and what content the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element may have must not be executed.</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p></dd>
<dt><a id="HandlerEventAttribute" name="HandlerEventAttribute"></a> <span class="adef">ev:event</span> = <span class="attr-value">"<a href="types.html#DataTypeXML-NMTOKEN"><XML-NMTOKEN></a>"</span></dt>
<dd><p>The name of the event to handle. This attribute is in the XML Events namespace, <code>http://www.w3.org/2001/xml-events</code>. See <a href="interact.html#SVGEvents">event list</a> for a list of all supported events and the XML Events specification for the <a href="../../2003/REC-xml-events-20031014/index.html#attr-listener-event">definition of the <span class="attr-name">'ev:event' attribute</span></a> ([<a href="refs.html#ref-XML-EVENTS">XML-EVENTS</a>], section 3.1).</p>
<p class="anim-target"><a href="animate.html#Animatable">Animatable</a>: no.</p></dd>
</dl>
</div>
<p>
For script handlers in Java, the
<a href="script.html#ScriptElementHrefAttribute"><span class="attr-name">'xlink:href'</span></a>
attribute must reference a <a href="script.html#ScriptElement"><span class="element-name">'script'</span></a>
element that itself references a JAR archive holding a manifest with an
SVG-Handler-Class entry pointing to an
<a href="svgudom.html#svg__EventListenerInitializer2" class="udom-interface-name">EventListenerInitializer2</a>
implementation.
</p>
<h3 id="handler-param">15.5.1 Parameters to <span class="element-name">'handler'</span> elements</h3>
<p>
In many situations, the script author uses the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> as a template for calling other functions, using the content of the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element to pass parameters. However, for compiled languages the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element does not have any executable content.
</p>
<p>
In this case, the author should embed the parameters into the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> as custom content in the form of element children in a foreign namespace, or attributes on the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element also in foreign namespaces.
</p>
<p>
Below is an example of using parameters on the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element:
</p>
<div class="example"><div class="exampleheader"><strong>Example:</strong> <a href="examples/handlerparam.svg">handlerparam.svg</a></div><div class="examplesource"><pre><svg xmlns="http://www.w3.org/2000/svg"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:foo="http://www.example.com/foo"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.2" baseProfile="tiny">
<desc>An example of parameters on the handler element.</desc>
<rect xml:id="theRect" x="10" y="20" width="200" height="300" fill="red"/>
<!-- reference a jar containing an EventListenerInitializer2 object -->
<script type="application/java-archive" xml:id="init" xlink:href="http://example.com/theJar.jar"/>
<!-- register a listener for a theRect.click event -->
<ev:listener event="click" observer="theRect" handler="#theClickHandler" />
<handler xml:id="theClickHandler" type="application/java-archive" xlink:href="#init">
<foo:offset value="10"/>
<foo:person>
<foo:name>Victor Vector</foo:name>
<foo:age>42</foo:age>
</foo:person>
</handler>
</svg>
</pre></div></div>
<p>
In this case, the object referenced by the SVG-Handler-Class entry of the <code>theJar.jar</code> manifest has its <a href="svgudom.html#svg__EventListenerInitializer2_createEventListener"><code>createEventListener</code></a> method called and the returned <a href="svgudom.html#events__EventListener" class="udom-interface-name">EventListener</a> registered. Whenever a <a href="interact.html#EventsClick"><code>click</code></a> event on the "theRect" element is observed, the <a href="svgudom.html#events__EventListener_handleEvent"><code>handleEvent</code></a> method of the listener is called. The object can then access the <a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element in order to obtain its parameters from elements in the <code>http://www.example.com/foo</code> namespace.
</p>
<h2 id="EventHandling">15.6 Event handling</h2>
<p>Events must cause scripts to execute when either of the
following has occurred:</p>
<ul>
<li>Events are assigned
to particular elements and connected with script through the
<a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> element. The script is executed when the given event occurs.</li>
<li><a href="svgudom.html#Event_Listener_Registration_and_Removal">Event listeners</a>
as described in <a href="../../2000/REC-DOM-Level-2-Events-20001113/index.html"><cite>DOM Level 2 Events</cite></a>
[<a href="refs.html#ref-DOM2EVENTS">DOM2EVENTS</a>]
are defined which are invoked when a given event happens on a given object.</li>
</ul>
<p>Related sections of the spec:</p>
<ul>
<li><a href="interact.html#UIEvents">User interface
events</a> describes how an SVG user agent handles events
such as pointer movements events (e.g., mouse movement) and
activation events (e.g., mouse click).</li>
</ul>
<h2 id="InlineScript">15.7 Processing inline executable content</h2>
<p>
When executable content is inlined inside an executable element such as
<a href="script.html#ScriptElement"><span class="element-name">'script'</span></a> or
<a href="script.html#HandlerElement"><span class="element-name">'handler'</span></a> elements,
it must be processed as follows before it is parsed and executed.
</p>
<p>
If the type of the content, obtained either through the
<a href="script.html#TypeAttribute"><span class="attr-name">'type'</span></a> attribute,
the <a href="struct.html#ContentScriptTypeAttribute"><span class="attr-name">'contentScriptType'</span></a>
or its <a href="intro.html#TermLacunaValue"><span class="svg-term">lacuna value</span></a>,
attribute, or the default is not known by the user agent, then
the user agent must ignore the content and no further processing
must be performed.
</p>
<p>
If the type of the content is an XML media type [<a href="refs.html#ref-RFC3023">RFC3023</a>],
then the entire subtree of the executable element must be passed on untouched to the script engine.
</p>
<p>
Otherwise, the content that the user agent's script engine obtains must be
that which is obtained through the following steps:
</p>
<ol>
<li>Remove all descendant elements of the executable element.</li>
<li>Then, use the text content of the executable element (as defined by
<a href="../../2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent"><code>Node::textContent</code></a>
in DOM Level 3 Core ([<a href="refs.html#ref-DOM3">DOM3</a>], section
1.4) of the executable element.</li>
</ol>
<div class="footer">
SVG Tiny 1.2 – 20081222
<ul>
<li><a href="index.html">Top</a></li>
<li><a href="expanded-toc.html">Contents</a></li>
<li><a href="linking.html">Previous</a></li>
<li><a href="animate.html">Next</a></li>
<li><a href="elementTable.html">Elements</a></li>
<li><a href="attributeTable.html">Attributes</a></li>
</ul>
</div>
</body>
</html>
|