Index: pkg/polymer/lib/elements/polymer-meta/polymer-meta.html |
diff --git a/pkg/polymer/lib/elements/polymer-meta/polymer-meta.html b/pkg/polymer/lib/elements/polymer-meta/polymer-meta.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..163a16f2fc5fa956f52b5a04e36f7eab2fb6e589 |
--- /dev/null |
+++ b/pkg/polymer/lib/elements/polymer-meta/polymer-meta.html |
@@ -0,0 +1,141 @@ |
+<!-- |
+Copyright 2013 The Polymer Authors. All rights reserved. |
+Use of this source code is governed by a BSD-style |
+license that can be found in the LICENSE file. |
+--> |
+<!-- |
+/** |
+ * @module Polymer Elements |
+ */ |
+/** |
+ * The `polymer-meta` elements provides a method of constructing a |
+ * self-organizing database. It is useful to collate element meta-data for |
+ * things like catalogs and for sandbox. |
+ * |
+ * Example, an element folder has a `metadata.html` file in it, that contains a |
+ * polymer-meta, something like this: |
+ * |
+ * <polymer-meta id="my-element"> |
+ * <property name="color" type="color"></property> |
+ * </polymer-meta> |
+ * |
+ * An application can import as many of these files as it wants, and then use |
+ * polymer-meta again to access the collected data. |
+ * |
+ * <script> |
+ * var meta = document.createElement('polymer-meta'); |
+ * console.log(meta.list); // dump a list of all meta-data elements that have been created |
+ * </script> |
+ * |
+ * Use `byId(id)` to retrive a specific polymer-meta. |
+ * |
+ * <script> |
+ * var meta = document.createElement('polymer-meta'); |
+ * console.log(meta.byId('my-element')); |
+ * </script> |
+ * |
+ * By default all meta-data are stored in a signle databse. If your meta-data |
+ * have different types and want them to be stored separately, use `type` to |
+ * differentiate them. |
+ * |
+ * @class polymer-meta |
+ */ |
+--> |
+<link rel="import" href="../polymer/polymer.html"> |
+ |
+<polymer-element name="polymer-meta" attributes="list label type"> |
+ <script> |
+ (function() { |
+ var SKIP_ID = 'meta'; |
+ var metaData = {}, metaArray = {}; |
+ |
+ Polymer('polymer-meta', { |
+ alwaysPrepare: true, |
+ /** |
+ * The type of meta-data. All meta-data with the same type with be |
+ * stored together. |
+ * |
+ * @attribute type |
+ * @type string |
+ * @default 'default' |
+ */ |
+ type: 'default', |
+ ready: function() { |
+ this.idChanged(); |
+ }, |
+ get metaArray() { |
+ var t = this.type; |
+ if (!metaArray[t]) { |
+ metaArray[t] = []; |
+ } |
+ return metaArray[t]; |
+ }, |
+ get metaData() { |
+ var t = this.type; |
+ if (!metaData[t]) { |
+ metaData[t] = {}; |
+ } |
+ return metaData[t]; |
+ }, |
+ idChanged: function(old) { |
+ if (this.id && this.id !== SKIP_ID) { |
+ this.unregister(this, old); |
+ this.metaData[this.id] = this; |
+ this.metaArray.push(this); |
+ } |
+ }, |
+ unregister: function(meta, id) { |
+ delete this.metaData[id || meta.id]; |
+ var i = this.metaArray.indexOf(meta); |
+ if (i >= 0) { |
+ this.metaArray.splice(i, 1); |
+ } |
+ }, |
+ /** |
+ * Returns a list of all meta-data elements with the same type. |
+ * |
+ * @attribute list |
+ * @type array |
+ * @default [] |
+ */ |
+ get list() { |
+ return this.metaArray; |
+ }, |
+ /** |
+ * Returns the first `<template>` in the `<polymer-meta>` subtree. This |
+ * is useful to store element example. |
+ * |
+ * <polymer-meta id="polymer-ui-toolbar" label="Polymer Toolbar"> |
+ * <template> |
+ * <polymer-ui-toolbar theme="polymer-ui-light-theme"> |
+ * <polymer-ui-icon-button icon="menu"></polymer-ui-icon-button> |
+ * <div flex>Title</div> |
+ * <polymer-ui-icon-button icon="add"></polymer-ui-icon-button> |
+ * </polymer-ui-toolbar> |
+ * </template> |
+ * </polymer-meta> |
+ * |
+ * @attribute archetype |
+ * @type node |
+ * @default null |
+ */ |
+ get archetype() { |
+ return this.querySelector('template'); |
+ }, |
+ /** |
+ * Retrieves meta-data by ID. |
+ * |
+ * @method byId |
+ * @param {String} id The ID of the meta-data to be returned. |
+ * @returns Returns meta-data. |
+ */ |
+ byId: function(id) { |
+ return this.metaData[id]; |
+ }, |
+ get childMetas() { |
+ return this.querySelectorAll(this.localName); |
+ } |
+ }); |
+ })(); |
+ </script> |
+</polymer-element> |