Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Side by Side Diff: pkg/polymer/lib/elements/polymer-meta/polymer-meta.html

Issue 175443005: [polymer] import all elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated from bower Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!--
2 Copyright 2013 The Polymer Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style
4 license that can be found in the LICENSE file.
5 -->
6 <!--
7 /**
8 * @module Polymer Elements
9 */
10 /**
11 * The `polymer-meta` elements provides a method of constructing a
12 * self-organizing database. It is useful to collate element meta-data for
13 * things like catalogs and for sandbox.
14 *
15 * Example, an element folder has a `metadata.html` file in it, that contains a
16 * polymer-meta, something like this:
17 *
18 * <polymer-meta id="my-element">
19 * <property name="color" type="color"></property>
20 * </polymer-meta>
21 *
22 * An application can import as many of these files as it wants, and then use
23 * polymer-meta again to access the collected data.
24 *
25 * <script>
26 * var meta = document.createElement('polymer-meta');
27 * console.log(meta.list); // dump a list of all meta-data elements that h ave been created
28 * </script>
29 *
30 * Use `byId(id)` to retrive a specific polymer-meta.
31 *
32 * <script>
33 * var meta = document.createElement('polymer-meta');
34 * console.log(meta.byId('my-element'));
35 * </script>
36 *
37 * By default all meta-data are stored in a signle databse. If your meta-data
38 * have different types and want them to be stored separately, use `type` to
39 * differentiate them.
40 *
41 * @class polymer-meta
42 */
43 -->
44 <link rel="import" href="../polymer/polymer.html">
45
46 <polymer-element name="polymer-meta" attributes="list label type">
47 <script>
48 (function() {
49 var SKIP_ID = 'meta';
50 var metaData = {}, metaArray = {};
51
52 Polymer('polymer-meta', {
53 alwaysPrepare: true,
54 /**
55 * The type of meta-data. All meta-data with the same type with be
56 * stored together.
57 *
58 * @attribute type
59 * @type string
60 * @default 'default'
61 */
62 type: 'default',
63 ready: function() {
64 this.idChanged();
65 },
66 get metaArray() {
67 var t = this.type;
68 if (!metaArray[t]) {
69 metaArray[t] = [];
70 }
71 return metaArray[t];
72 },
73 get metaData() {
74 var t = this.type;
75 if (!metaData[t]) {
76 metaData[t] = {};
77 }
78 return metaData[t];
79 },
80 idChanged: function(old) {
81 if (this.id && this.id !== SKIP_ID) {
82 this.unregister(this, old);
83 this.metaData[this.id] = this;
84 this.metaArray.push(this);
85 }
86 },
87 unregister: function(meta, id) {
88 delete this.metaData[id || meta.id];
89 var i = this.metaArray.indexOf(meta);
90 if (i >= 0) {
91 this.metaArray.splice(i, 1);
92 }
93 },
94 /**
95 * Returns a list of all meta-data elements with the same type.
96 *
97 * @attribute list
98 * @type array
99 * @default []
100 */
101 get list() {
102 return this.metaArray;
103 },
104 /**
105 * Returns the first `<template>` in the `<polymer-meta>` subtree. This
106 * is useful to store element example.
107 *
108 * <polymer-meta id="polymer-ui-toolbar" label="Polymer Toolbar">
109 * <template>
110 * <polymer-ui-toolbar theme="polymer-ui-light-theme">
111 * <polymer-ui-icon-button icon="menu"></polymer-ui-icon-butto n>
112 * <div flex>Title</div>
113 * <polymer-ui-icon-button icon="add"></polymer-ui-icon-button >
114 * </polymer-ui-toolbar>
115 * </template>
116 * </polymer-meta>
117 *
118 * @attribute archetype
119 * @type node
120 * @default null
121 */
122 get archetype() {
123 return this.querySelector('template');
124 },
125 /**
126 * Retrieves meta-data by ID.
127 *
128 * @method byId
129 * @param {String} id The ID of the meta-data to be returned.
130 * @returns Returns meta-data.
131 */
132 byId: function(id) {
133 return this.metaData[id];
134 },
135 get childMetas() {
136 return this.querySelectorAll(this.localName);
137 }
138 });
139 })();
140 </script>
141 </polymer-element>
OLDNEW
« no previous file with comments | « pkg/polymer/lib/elements/polymer-meta/index.html ('k') | pkg/polymer/lib/elements/polymer-mock-data/.bower.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698