Chromium Code Reviews| Index: tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate |
| diff --git a/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate b/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7bb57bcb19d0cbee051536ec597f2319bf22add7 |
| --- /dev/null |
| +++ b/tools/dom/templates/html/impl/impl_HTMLTemplateElement.darttemplate |
| @@ -0,0 +1,126 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// WARNING: Do not edit - generated code. |
| + |
| +part of $LIBRARYNAME; |
| + |
| +@Experimental |
| +$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| +$!MEMBERS |
| + |
| + /** |
| + * True if `<template>` element is natively supported. |
| + * |
| + * Note: this primarily affects the HTML parser. Most other features of |
| + * `<template>` work regardless of whether the parser supports template. |
| + * You can workaround the lack of parser support by using the "template" |
| + * attribute on certain nodes, see [isTemplate] for more information. |
| + * |
| + * See also: [content], [decorate], [bind], [unbind], [unbindAll]. |
| + */ |
| + static bool get supported => new Element.tag('template') is! UnknownElement; |
|
blois
2013/05/01 17:00:42
Can use Element.isTagSupported instead.
Also, can
Jennifer Messerly
2013/05/02 02:58:33
Done.
Anywhere I can put the doc comment?
I didn'
|
| + |
| + static StreamController<DocumentFragment> _instanceCreated; |
| + |
| + /** |
| + * *Warning*: This is an implementation helper for Model-Driven Views and |
| + * should not be used in your code. |
| + * |
| + * This event is fired whenever a template is instantiated via |
| + * [createInstance]. |
| + */ |
| + // TODO(rafaelw): This is a hack, and is neccesary for the polyfill |
| + // because custom elements are not upgraded during clone() |
| + @Experimental |
| + static Stream<DocumentFragment> get instanceCreated { |
|
blois
2013/05/01 17:00:42
Does this need to be public?
Jennifer Messerly
2013/05/01 17:56:34
yup! for same reason as MDV has it.
|
| + if (_instanceCreated == null) { |
| + _instanceCreated = new StreamController<DocumentFragment>(); |
| + } |
| + return _instanceCreated.stream; |
| + } |
| + |
| + /** |
| + * Ensures proper API and content model for template elements. |
| + * |
| + * [instanceRef] can be used to set the [Element.ref] property of [template], |
| + * and use the ref's content will be used as source when createInstance() is |
| + * invoked. |
| + * |
| + * Returns true if this template was just decorated, or false if it was |
| + * already decorated. |
| + */ |
| + @Experimental |
| + static bool decorate(Element template, [Element instanceRef]) { |
| + // == true check because it starts as a null field. |
| + if (template._templateIsDecorated == true) return false; |
| + |
| + template._templateIsDecorated = true; |
| + |
| + _injectStylesheet(); |
| + |
| + // Create content |
| + if (template is! TemplateElement) { |
| + var doc = _getTemplateContentsOwner(template.document); |
| + template._templateContent = doc.createDocumentFragment(); |
| + } |
| + |
| + if (instanceRef != null) { |
| + template._templateInstanceRef = instanceRef; |
| + return true; // content is empty. |
| + } |
| + |
| + if (template is TemplateElement) { |
| + _bootstrapTemplatesRecursivelyFrom(template.content); |
| + } else { |
| + _liftNonNativeTemplateChildrenIntoContent(template); |
| + } |
| + |
| + return true; |
| + } |
| + |
| + /** |
| + * This used to decorate recursively all templates from a given node. |
| + * |
| + * By default [decorate] will be called on templates lazily when certain |
| + * properties such as [model] are accessed, but it can be run eagerly to |
| + * decorate an entire tree recursively. |
| + */ |
| + // TODO(rafaelw): Review whether this is the right public API. |
| + @Experimental |
| + static void bootstrap(Node content) { |
| + _bootstrapTemplatesRecursivelyFrom(content); |
| + } |
| + |
| + static bool _initStyles; |
| + |
| + static void _injectStylesheet() { |
| + if (_initStyles == true) return; |
| + _initStyles = true; |
| + |
| + var style = new StyleElement(); |
| + style.text = r''' |
| +template, |
| +thead[template], |
| +tbody[template], |
| +tfoot[template], |
| +th[template], |
| +tr[template], |
| +td[template], |
| +caption[template], |
| +colgroup[template], |
| +col[template], |
| +option[template] { |
| + display: none; |
| +}'''; |
| + document.head.nodes.add(style); |
|
blois
2013/05/01 17:00:42
document.head.append(style) (it's faster).
Jennifer Messerly
2013/05/01 17:56:34
omg, I didn't know about .append! I'll fix that ev
|
| + } |
| + |
| + /** |
| + * A mapping of names to Custom Syntax objects. See [CustomBindingSyntax] for |
| + * more information. |
| + */ |
| + @Experimental |
| + static Map<String, CustomBindingSyntax> syntax = {}; |
| +} |