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

Side by Side Diff: lib/src/iron-component-page/iron-component-page.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month 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
OLDNEW
1 <!-- 1 <!--
2 @license 2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt 4 This code may only be used under the BSD style license found at http://polymer.g ithub.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/CONTRI BUTORS.txt 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.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/PATEN TS.txt 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 --> 9 -->
10 <link rel="import" href="../polymer/polymer.html"> 10 <link rel="import" href="../polymer/polymer.html">
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 <div id="docs"> 51 <div id="docs">
52 <div id="catalog-heading" catalog-only> 52 <div id="catalog-heading" catalog-only>
53 <h2><span>[[active]]</span> <span class="version" hidden$="[[!vers ion]]">[[version]]</span></h2> 53 <h2><span>[[active]]</span> <span class="version" hidden$="[[!vers ion]]">[[version]]</span></h2>
54 </div> 54 </div>
55 <iron-doc-viewer descriptor="{{_activeDescriptor}}" 55 <iron-doc-viewer descriptor="{{_activeDescriptor}}"
56 on-iron-doc-viewer-component-selected="_handleComponentSelectedEve nt"></iron-doc-viewer> 56 on-iron-doc-viewer-component-selected="_handleComponentSelectedEve nt"></iron-doc-viewer>
57 <div id="nodocs" hidden$="[[_activeDescriptor]]" class="layout fit h orizontal center-center"> 57 <div id="nodocs" hidden$="[[_activeDescriptor]]" class="layout fit h orizontal center-center">
58 No documentation found. 58 No documentation found.
59 </div> 59 </div>
60 </div> 60 </div>
61 <iframe id="demo" src="[[_frameSrc(view, base)]]"></iframe> 61 <div id="demo"></div>
62 </iron-selector> 62 </iron-selector>
63 </div> 63 </div>
64 </paper-header-panel> 64 </paper-header-panel>
65 </template> 65 </template>
66 </dom-module> 66 </dom-module>
67 67
68 <script> 68 <script>
69 (function() { 69 (function() {
70 // var hydrolysis = require('hydrolysis'); 70 // var hydrolysis = require('hydrolysis');
71 71
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return this.ownerDocument.baseURI; 128 return this.ownerDocument.baseURI;
129 } 129 }
130 }, 130 },
131 131
132 /** 132 /**
133 * The element or behavior that will be displayed on the page. Defaults 133 * The element or behavior that will be displayed on the page. Defaults
134 * to the element matching the name of the source file. 134 * to the element matching the name of the source file.
135 */ 135 */
136 active: { 136 active: {
137 type: String, 137 type: String,
138 observer: '_activeChanged', 138 notify: true,
139 notify: true 139 value: ''
140 }, 140 },
141 141
142 /** 142 /**
143 * The current view. Can be `docs` or `demo`. 143 * The current view. Can be `docs` or `demo`.
144 */ 144 */
145 view: { 145 view: {
146 type: String, 146 type: String,
147 value: 'docs', 147 value: 'docs',
148 notify: true 148 notify: true
149 }, 149 },
150 150
151 /** 151 /**
152 * Whether _all_ dependencies should be loaded and documented. 152 * Whether _all_ dependencies should be loaded and documented.
153 * 153 *
154 * Turning this on will probably slow down the load process dramatically. 154 * Turning this on will probably slow down the load process dramatically.
155 */ 155 */
156 transitive: { 156 transitive: {
157 type: Boolean, 157 type: Boolean,
158 value: false 158 value: false
159 }, 159 },
160 160
161 /** The Hydrolysis element descriptors that have been loaded. */ 161 /** The Hydrolysis element descriptors that have been loaded. */
162 docElements: { 162 docElements: {
163 type: Array, 163 type: Array,
164 observer: '_descriptorsChanged',
165 notify: true, 164 notify: true,
166 readOnly: true 165 readOnly: true,
166 value: function() {
167 return [];
168 }
167 }, 169 },
168 170
169 /** The Hydrolysis behavior descriptors that have been loaded. */ 171 /** The Hydrolysis behavior descriptors that have been loaded. */
170 docBehaviors: { 172 docBehaviors: {
171 type: Array, 173 type: Array,
172 observer: '_descriptorsChanged',
173 notify: true, 174 notify: true,
174 readOnly: true 175 readOnly: true,
176 value: function() {
177 return [];
178 }
175 }, 179 },
176 180
177 /** 181 /**
178 * Demos for the currently selected element. 182 * Demos for the currently selected element.
179 */ 183 */
180 docDemos: { 184 docDemos: {
181 type: Array, 185 type: Array,
182 notify: true, 186 notify: true,
183 readOnly: true 187 readOnly: true
184 }, 188 },
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 /** The complete URL to this component's demo. */ 243 /** The complete URL to this component's demo. */
240 _demoUrl: { 244 _demoUrl: {
241 type: String, 245 type: String,
242 value: '', 246 value: '',
243 }, 247 },
244 248
245 /** The complete URL to this component's source. */ 249 /** The complete URL to this component's source. */
246 _srcUrl: String, 250 _srcUrl: String,
247 }, 251 },
248 252
253 observers: [
254 '_updateFrameSrc(view, base)',
255 '_activeChanged(active, _analyzer)'
256 ],
257
249 ready: function() { 258 ready: function() {
250 var elements = this._loadJson(); 259 var elements = this._loadJson();
251 if (elements) { 260 if (elements) {
252 this.docElements = elements; 261 this.docElements = elements;
253 this._loading = false; 262 this._loading = false;
254 } else { 263 } else {
255 // Make sure our change handlers trigger in all cases. 264 // Make sure our change handlers trigger in all cases.
256 if (!this.src && !this._catalog) { 265 if (!this.src && !this._catalog) {
257 this._srcChanged(); 266 this._srcChanged();
258 } 267 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 var match = srcUrl.match(/([^\/\.]+)\.github\.io\/([^\/]+)\/?([^\/]*)$/); 314 var match = srcUrl.match(/([^\/\.]+)\.github\.io\/([^\/]+)\/?([^\/]*)$/);
306 if (match) { 315 if (match) {
307 srcUrl = "https://cdn.rawgit.com/" + match[1] + "/" + match[2] + "/maste r/" + match[3]; 316 srcUrl = "https://cdn.rawgit.com/" + match[1] + "/" + match[2] + "/maste r/" + match[3];
308 } 317 }
309 318
310 this._baseUrl = _baseUrl(srcUrl); 319 this._baseUrl = _baseUrl(srcUrl);
311 this._srcUrl = srcUrl; 320 this._srcUrl = srcUrl;
312 if (!this._hydroLoading) this.$.analyzer.analyze(); 321 if (!this._hydroLoading) this.$.analyzer.analyze();
313 }, 322 },
314 323
315 _frameSrc: function(view) { 324 _updateFrameSrc: function(view) {
316 if (!view || view.indexOf("demo:") !== 0) return "about:blank"; 325 if (!view || view.indexOf("demo:") !== 0) return "about:blank";
326
317 var src = view.split(':')[1]; 327 var src = view.split(':')[1];
318 return new URL(src, this.base).toString(); 328 var demoSrc = new URL(src, this.base).toString();
329
330 // If you use history.pushState with iframe.src = url, you will create 2 h istory entries,
331 // but setting the `src` attribute imperatively will not.
332
333 if (this._iframe) {
334 Polymer.dom(this.$.demo).removeChild(this._iframe);
335 }
336
337 this._iframe = document.createElement('iframe');
338 this._iframe.src = demoSrc;
339 Polymer.dom(this.$.demo).appendChild(this._iframe);
319 }, 340 },
320 341
321 _descriptorsChanged: function() { 342 _getDefaultActive: function() {
322 if (this._findDescriptor(this.active)) { 343 var matchedPage;
323 this._activeChanged(); 344 var url = this._srcUrl || this.base;
324 return; 345 var mainFile = url.replace(_baseUrl(this.base), '');
346
347 function findMatch(list) {
348 for (var item, i = 0; i < list.length; i++) {
349 item = list[i];
350 if (item && item.contentHref && item.contentHref.indexOf(mainFile) > 0 ) {
351 return item;
352 }
353 }
354 return null;
325 } 355 }
356
357 matchedPage = findMatch(this.docElements) || findMatch(this.docBehaviors);
326 358
327 if (this.docElements && this.docElements[0]) { 359 if (matchedPage) {
328 this.active = this.docElements[0].is; 360 return matchedPage.is;
329 } else if (this.docBehaviors && this.docBehaviors[0]) { 361 } else if (this.docElements.length > 0) {
330 this.active = this.docBehaviors[0].is; 362 return this.docElements[0].is;
331 } else { 363 } else if (this.docBehaviors.length > 0) {
332 this.active = null; 364 return this.docBehaviors[0].is;
333 } 365 }
366 return null;
334 }, 367 },
335 368
336 _findDescriptor: function(name) { 369 _findDescriptor: function(name) {
337 if (!this._analyzer) return null; 370 if (!this._analyzer) return null;
338 371
339 var descriptor = this._analyzer.elementsByTagName[name]; 372 var descriptor = this._analyzer.elementsByTagName[name];
340 if (descriptor) return descriptor; 373 if (descriptor) return descriptor;
341 374
342 for (var i = 0; i < this._analyzer.behaviors.length; i++) { 375 for (var i = 0; i < this._analyzer.behaviors.length; i++) {
343 if (this._analyzer.behaviors[i].is === name) { 376 if (this._analyzer.behaviors[i].is === name) {
344 return this._analyzer.behaviors[i]; 377 return this._analyzer.behaviors[i];
345 } 378 }
346 } 379 }
347 return null; 380 return null;
348 }, 381 },
349 382
350 _activeChanged: function() { 383 _activeChanged: function(active, analyzer) {
351 this.async(function() { this.$.active.value = this.active; }); 384 if (active === '') {
352 if (this._analyzer && this._analyzer.elementsByTagName) { 385 this.active = this._getDefaultActive();
386 return;
387 }
388 this.async(function() { this.$.active.value = active; });
389 if (analyzer && analyzer.elementsByTagName) {
353 this.$.headerPanel.scroller.scrollTop = 0; 390 this.$.headerPanel.scroller.scrollTop = 0;
354 this._activeDescriptor = this._findDescriptor(this.active); 391 this._activeDescriptor = this._findDescriptor(active);
355 if (this._activeDescriptor) { 392 if (this._activeDescriptor) {
356 var hasDemo; 393 var hasDemo;
357 var demos = this._activeDescriptor.demos; 394 var demos = this._activeDescriptor.demos;
358 if (this.view && demos && demos.length) { 395 if (this.view && demos && demos.length) {
359 var parts = this.view.split(':'); 396 var parts = this.view.split(':');
360 if (parts[0] == 'demo') { 397 if (parts[0] == 'demo') {
361 if (parts[1]) { 398 if (parts[1]) {
362 hasDemo = demos.some(function(d, i) { 399 hasDemo = demos.some(function(d, i) {
363 if (d.path == parts[1]) { 400 if (d.path == parts[1]) {
364 return true; 401 return true;
(...skipping 13 matching lines...) Expand all
378 document.title = this._activeDescriptor.is + " documentation"; 415 document.title = this._activeDescriptor.is + " documentation";
379 } 416 }
380 } 417 }
381 this._setDocDemos(this._activeDescriptor ? this._activeDescriptor.demos : []); 418 this._setDocDemos(this._activeDescriptor ? this._activeDescriptor.demos : []);
382 } 419 }
383 }, 420 },
384 421
385 _loadingChanged: function() { 422 _loadingChanged: function() {
386 this.toggleClass('loaded', !this._loading); 423 this.toggleClass('loaded', !this._loading);
387 }, 424 },
425
388 _detectLoading: function() { 426 _detectLoading: function() {
389 this._loading = this.docSrc ? this._ajaxLoading : this._hydroLoading; 427 this._loading = this.docSrc ? this._ajaxLoading : this._hydroLoading;
390 }, 428 },
391 429
392 _analyzerChanged: function() { 430 _analyzerChanged: function() {
393 this._setDocElements(this._analyzer ? this._analyzer.elements : []); 431 var analyzer = this._analyzer;
394 this._setDocBehaviors(this._analyzer ? this._analyzer.behaviors : []); 432 this._setDocElements(analyzer && analyzer.elements ? analyzer.elements : [ ]);
433 this._setDocBehaviors(analyzer && analyzer.behaviors ? analyzer.behaviors : []);
434
435 if (!this._findDescriptor(this.active)) {
436 this.active = this._getDefaultActive();
437 }
395 }, 438 },
396 _detectAnalyzer: function() { 439 _detectAnalyzer: function() {
397 this._analyzer = this.docSrc ? this._ajaxDesc : this._hydroDesc; 440 this._analyzer = this.docSrc ? this._ajaxDesc : this._hydroDesc;
398 }, 441 },
399 442
400 _handleAjaxResponse: function(e, req) { 443 _handleAjaxResponse: function(e, req) {
401 this._ajaxLoading = false; 444 this._ajaxLoading = false;
402 this._ajaxLastUrl = req.url; 445 this._ajaxLastUrl = req.url;
403 this._ajaxDesc = req.response; 446 this._ajaxDesc = req.response;
404 }, 447 },
(...skipping 26 matching lines...) Expand all
431 474
432 _demoView: function(path) { 475 _demoView: function(path) {
433 return "demo:" + path; 476 return "demo:" + path;
434 }, 477 },
435 _viewType: function(view) { 478 _viewType: function(view) {
436 return view ? view.split(":")[0] : null; 479 return view ? view.split(":")[0] : null;
437 } 480 }
438 }); 481 });
439 })(); 482 })();
440 </script> 483 </script>
OLDNEW
« no previous file with comments | « lib/src/iron-component-page/iron-component-page.css ('k') | lib/src/iron-doc-viewer/iron-doc-property.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698