W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: [webcomponents] Template element parser changes => Proposal for adding DocumentFragment.innerHTML

From: Scott González <scott.gonzalez@gmail.com>
Date: Wed, 9 May 2012 13:38:45 -0400
Message-ID: <CAO8i3icYxk-aD5JLMC+=Lhncjh3006u2zC8mAQJO9HGUyZ2MeQ@mail.gmail.com>
To: Ian Hickson <ian@hixie.ch>
Cc: Henri Sivonen <hsivonen@iki.fi>, Rafael Weinstein <rafaelw@google.com>, Webapps WG <public-webapps@w3.org>, Yehuda Katz <wycats@gmail.com>
Users will surely find this annoying when they know that it can be
automated. This will also result in users being tripped up on this as they
learn about this feature by looking at some other code that isn't passing a
context (because it doesn't need one) and then all of a sudden they hit a
case where they need one and it fails.

On Wed, May 9, 2012 at 1:01 PM, Ian Hickson <ian@hixie.ch> wrote:

> Quick alternative proposal that might work for both <template> parsing and
> DocumentFragment.innerHTML:
>   Have createDocumentFragment() take as an argument a context element.
>   Maybe also make it a mutable attribute of the object. Defaults to its
>   owner document's body element or root element or some such. Null means
>   no root element.
>     var df = document.createDocumentFragment(document.body);
>     df.contextElement = document.createElement('style');
>   Have innerHTML use that as the context element to the fragment parsing
>   algorithm.
>     df.innerHTML = 'p::before { content: '<hello> <world>'; }';
>   Have <template> take an argument that's the element tag name for it to
>   use to create its context element. Defaults to <body>.
>     <template context="tr"> <td> </template>
>     <template context="svg"> <g/> </template>
>   Parse <template> by creating a new Document object that's like the ones
>   you get from createDocument() (i.e. "dead"), and then creating a
>   DocumentFragment owned by that Document, and then pushing that
>   DocumentFragment onto the stack instead of the <template> element, but
>   set up to act like the <template> element for the purposes of being
>   popped off. (Except when parsing without a browsing context, then you
>   just parse normally.)
> Not sure how solid this is, but it's an idea at least. Hopefully an
> original one, though I'm sure y'all have considered it before. :-)
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 9 May 2012 17:39:15 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:34 UTC