OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polym
er.github.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polym
er.github.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS
.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS
.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CO
NTRIBUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CO
NTRIBUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/P
ATENTS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/P
ATENTS.txt |
9 --> | 9 --> |
| 10 |
10 <link rel="import" href="elements/core-doc-page.html"> | 11 <link rel="import" href="elements/core-doc-page.html"> |
11 <link rel="import" href="elements/core-doc-toc.html"> | 12 <link rel="import" href="elements/core-doc-toc.html"> |
12 <link rel="import" href="../core-icon/core-icon.html"> | 13 <link rel="import" href="../core-icon/core-icon.html"> |
13 | 14 |
14 <!-- | 15 <!-- |
15 Displays formatted source documentation scraped from input urls. | 16 Displays formatted source documentation scraped from input urls. |
16 | 17 |
17 Documentation can be encoded into html comments (<!-- ... -->) or using Js
Doc notation (/** ... */). | 18 Documentation can be encoded into html comments (<!-- ... -->) or using Js
Doc notation (/** ... */). |
18 | 19 |
19 When using JsDoc notation, remember that the left-margin includes an asterisk an
d a single space. | 20 When using JsDoc notation, remember that the left-margin includes an asterisk an
d a single space. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 <context-free-parser url="{{}}" on-data-ready="{{parserDataReady}}"></cont
ext-free-parser> | 98 <context-free-parser url="{{}}" on-data-ready="{{parserDataReady}}"></cont
ext-free-parser> |
98 </template> | 99 </template> |
99 | 100 |
100 <core-doc-toc id="toc" data="{{classes}}" selected="{{selected}}"></core-doc
-toc> | 101 <core-doc-toc id="toc" data="{{classes}}" selected="{{selected}}"></core-doc
-toc> |
101 <core-doc-page flex data="{{data}}"></core-doc-page> | 102 <core-doc-page flex data="{{data}}"></core-doc-page> |
102 | 103 |
103 </template> | 104 </template> |
104 | 105 |
105 <script> | 106 <script> |
106 | 107 |
107 Polymer('core-doc-viewer', { | 108 Polymer({ |
108 /** | 109 /** |
109 * A single file to parse for docs | 110 * A single file to parse for docs |
110 * | 111 * |
111 * @attribute url | 112 * @attribute url |
112 * @type String | 113 * @type String |
113 * @default '' | 114 * @default '' |
114 */ | 115 */ |
115 | 116 |
116 /** | 117 /** |
117 * Class documentation extracted from the parser | 118 * Class documentation extracted from the parser |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 return; | 160 return; |
160 } | 161 } |
161 }, this); | 162 }, this); |
162 } | 163 } |
163 }, | 164 }, |
164 | 165 |
165 selectedChanged: function() { | 166 selectedChanged: function() { |
166 this.data = this.classes[this.selected]; | 167 this.data = this.classes[this.selected]; |
167 }, | 168 }, |
168 | 169 |
169 parserDataReady: function(event) { | 170 parserDataReady: function(event, detail, sender) { |
170 this.assimilateData(event.target.data); | 171 var path = ''; |
| 172 if (this.sources.length) { |
| 173 var path = event.target.templateInstance.model; |
| 174 var idx = path.lastIndexOf('/'); |
| 175 path = idx != -1 ? path.substr(0, idx) : '.'; |
| 176 } else { |
| 177 var parts = location.pathname.split('/'); |
| 178 parts.pop(); |
| 179 path = parts.join('/'); |
| 180 } |
| 181 |
| 182 var data = event.target.data; |
| 183 |
| 184 var xhr = new XMLHttpRequest(); |
| 185 xhr.open('GET', path + '/bower.json'); |
| 186 |
| 187 xhr.onerror = function(e) { |
| 188 this.assimilateData(data); |
| 189 }.bind(this); |
| 190 |
| 191 xhr.onloadend = function(e) { |
| 192 |
| 193 // Add package version to data. |
| 194 if (e.target.status == 200) { |
| 195 var version = JSON.parse(e.target.response).version; |
| 196 // Assumes all classes (elements) in the list are the same version. |
| 197 for (var i = 0, c; c = data.classes[i]; ++i) { |
| 198 c.version = version; |
| 199 } |
| 200 } |
| 201 |
| 202 this.assimilateData(data); |
| 203 |
| 204 }.bind(this); |
| 205 |
| 206 xhr.send(); |
171 }, | 207 }, |
172 | 208 |
173 assimilateData: function(data) { | 209 assimilateData: function(data) { |
174 this.classes = this.classes.concat(data.classes); | 210 this.classes = this.classes.concat(data.classes); |
175 this.classes.sort(function(a, b) { | 211 this.classes.sort(function(a, b) { |
176 var na = a && a.name.toLowerCase(), nb = b && b.name.toLowerCase(); | 212 var na = a && a.name.toLowerCase(), nb = b && b.name.toLowerCase(); |
177 return (na < nb) ? -1 : (na == nb) ? 0 : 1; | 213 return (na < nb) ? -1 : (na == nb) ? 0 : 1; |
178 }); | 214 }); |
179 if (!this.data && !this.route && this.classes.length) { | 215 if (!this.data && !this.route && this.classes.length) { |
180 this.data = this.classes[0]; | 216 this.data = this.classes[0]; |
181 } | 217 } |
182 if (this.classes.length > 1) { | 218 if (this.classes.length > 1) { |
183 this.$.toc.style.display = 'block'; | 219 this.$.toc.style.display = 'block'; |
184 } | 220 } |
185 this.validateRoute(); | 221 this.validateRoute(); |
186 } | 222 } |
187 | 223 |
188 }); | 224 }); |
189 | 225 |
190 </script> | 226 </script> |
191 | 227 |
192 </polymer-element> | 228 </polymer-element> |
OLD | NEW |