W3C home > Mailing lists > Public > www-svg@w3.org > January 2008

Re: contentScriptType and type on script elements

From: Chris Lilley <chris@w3.org>
Date: Thu, 10 Jan 2008 22:31:52 +0100
Message-ID: <1758760989.20080110223152@w3.org>
To: Erik Dahlström <ed@opera.com>
Cc: "www-svg@w3.org" <www-svg@w3.org>

On Tuesday, January 8, 2008, 3:54:27 PM, Erik wrote:

(Your mail is responded to in a differnet order than how you wrote it)

ED> Spec[1] says: "The contentScriptType attribute on the 'svg' element  
ED> specifies the default scripting language for the given document fragment."
ED> which seems to be in conflict with "Identifies the default scripting  
ED> language for the given document."
ED> [1] http://www.w3.org/TR/SVG11/script.html#ScriptElement
ED> [2] http://www.w3.org/TR/SVGMobile12/script.html#ScriptElement

Its not in conflict. The wording in 1.2T is correct:

contentScriptType = "content-type"

    Identifies the default scripting language for the given document.
    This attribute sets the default scripting language for all the
    instances of script in the document fragment. This language must
    be used for all scripts that do not specify their own scripting
    language. The value content-type specifies a media type, per
    Multipurpose Internet Mail Extensions (MIME) PartTwo [RFC2046].
    The default value is "application/ecmascript".

    Animatable: no.

The wording in 1.1 differs in two details, firstly it assigns a
default of text/ecmascript to identify ECMAScript (while in practice
that language was subsequently registered as application/ecmascript)
and secondly the description fails to cover the case where there is
more than one SVG document fragment in the document.

SVGT 1.2 has a more precise definition of a conforming document
fragment.

So in this document

<foo xmlns="http://foobar.com/baz">
  <svg contentScriptType="foo/bar"
      xmlns="http://www.w3.org/2000/svg">
    <script>
      Hello, World
    </script>
  </svg>
  <svg contentScriptType="application/ecmascript"
      xmlns="http://www.w3.org/2000/svg">
    <script>
      Goodbye, World
    </script>
  </svg>      
  <svg
      xmlns="http://www.w3.org/2000/svg">
    <script>
      Goodbye, cruel World
    </script>
    <script type="foo/bar">
      Hello again, World!
    </script>    
  </svg>
</foo>

There are three SVG document fragments; in two of them the default
script language is ECMAScript. Of the four script elements, the ones
with Hello are in foo/bar and the ones with Goodbye are ECMAScript.


ED> Reading the SVG 1.1 and 1.2T specs on how 'type' works on 'script'  
ED> elements leads me to a couple of questions:

ED> 1. Given the markup below should the script element with id="s1" run?

No, because there is no script element in the SVG document fragment
(either for 1.1 or 1.2T)

ED> <svg contentScriptType="foo/bar"
ED> xmlns="http://www.w3.org/2000/svg"><foo  
ED> xmlns="http://foobar.com/baz"><script id="s1"  
ED> xmlns="http://www.w3.org/2000/svg"> alert('whee'); </script></foo></svg>

ED> The script element has to move across the unknown markup to get the  
ED> default scripttype, and if it gets that it shouldn't be executed unless it
ED> understands "foo/bar". Otherwise, one could see it such that it defaults
ED> to "text/ecmascript" even though it lacks a direct 'svg' parent. The  
ED> script is executed in ASV3, Safari 3, Firefox 3, Opera 9.x and Batik 1.7.
ED> I guess this can mean that either 'contentScriptType' is not supported, or
ED> that all viewers assume ecmascript always or that the namespace border
ED> isn't crossed and that it assumes that it is ecmascript.

Several of those reasons may be true; a simpler test will determine
whether contentScriptType and/or type are implemented. If they are
not, then the more complex test is not useful. if they both are
implemented, then your test demonstrates failure to conform to the
definition of an SVG document fragment.

ED> The spec isn't
ED> very clear on how it should work, if you are allowed to cross namespace
ED> boundaries in search of an 'svg' parent element, or what happens if there
ED> is none (although it is a required attribute in 1.1 none of the viewers
ED> seemed to respect that).

That should be an erratum for 1.1 since it can't be both required and
also have a default value :)

ED> 2. Does 'contentScriptType' work on document fragments or on documents?

Document fragments.

ED> That is does nesting 'svg' elements mean that you use the innermost or
ED> outermost 'svg' element when getting 'contentScriptType'?

Innermost.

-- 
 Chris Lilley                    mailto:chris@w3.org
 Interaction Domain Leader
 Co-Chair, W3C SVG Working Group
 W3C Graphics Activity Lead
 Co-Chair, W3C Hypertext CG
Received on Thursday, 10 January 2008 21:32:01 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:38 GMT