Chromium Code Reviews| Index: lib/web_ui.dart |
| diff --git a/lib/web_ui.dart b/lib/web_ui.dart |
| index c899f2a93c9adb6c69075b83f9c5a55498e8afd5..d339b17121858f60cdd2491a3574f1ace86f0a94 100644 |
| --- a/lib/web_ui.dart |
| +++ b/lib/web_ui.dart |
| @@ -26,6 +26,52 @@ import 'safe_html.dart' as safe_html; |
| import 'templating.dart' as templating; |
| import 'watcher.dart' as watcher; |
| +final Map _elements = new Map<String, _CustomElementInfo>(); |
| + |
| +class _CustomElementInfo { |
| + final Element _elementElement; |
| + final DocumentFragment _template; |
| + _CustomElementInfo(this._elementElement, this._template); |
| +} |
| + |
| +/** |
| + * This API registers an `<element>` element with the runtime system, so script |
| + * code can use [getElementDefinition] and [getElementTemplate]. |
| + * |
| + * Note: normally you should not need to call this, it will be done |
| + * automatically by web_ui as part of the polyfill for the |
| + * [element HTML element](https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#the-element-element). |
| + */ |
| +void registerElementDefinition(Element element, DocumentFragment template) { |
| + var name = element.attributes['name']; |
| + if (name == null) throw new ArgumentError('custom element must have a name.'); |
| + _elements[name] = new _CustomElementInfo(element, template); |
|
Siggi Cherem (dart-lang)
2013/04/05 20:09:24
should we warn when there are conflicts on the nam
|
| +} |
| + |
| +/** |
| + * Gets the custom `<element>` corresponding to the given tag name. |
| + * These are registered automatically, or explicitly by calling |
| + * [registerElementDefinition]. |
| + * |
| + * Note that the `<template>` node's contents are not accessible from the |
| + * returned node, and should be accessed via [getElementTemplate]. |
| + */ |
| +Element getElementDefinition(String tagName) => |
| + _elements[tagName]._elementElement; |
| + |
| +/** |
| + * Gets the custom `<element>` template contents. Conceptually this is |
| + * equivalent to: |
| + * |
| + * getElementDefinition(tagName).template.content; |
| + * |
| + * However it works on browsers that don't have native support for |
| + * `<element>` and `<template>`. |
| + */ |
| +DocumentFragment getElementTemplate(String tagName) => |
| + _elements[tagName]._template; |
| + |
| + |
|
Siggi Cherem (dart-lang)
2013/04/05 20:09:24
looks like these changes below with a different ch
Jennifer Messerly
2013/04/05 20:34:36
Yes! good catch. :D
|
| /** |
| * The base class for all Dart web components. In addition to the [Element] |
| * interface, it also provides lifecycle methods: |