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

Side by Side Diff: pkg/web_components/lib/platform.concat.js

Issue 182073003: Update platform.js to latest. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
« no previous file with comments | « pkg/web_components/lib/platform.js ('k') | pkg/web_components/lib/platform.concat.js.map » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The Polymer Authors. All rights reserved. 2 * Copyright 2012 The Polymer Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style 3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file. 4 * license that can be found in the LICENSE file.
5 */ 5 */
6 6
7 if (typeof WeakMap === 'undefined') { 7 if (typeof WeakMap === 'undefined') {
8 (function() { 8 (function() {
9 var defineProperty = Object.defineProperty; 9 var defineProperty = Object.defineProperty;
10 var counter = Date.now() % 1e9; 10 var counter = Date.now() % 1e9;
(...skipping 3360 matching lines...) Expand 10 before | Expand all | Expand 10 after
3371 return wrapNodeList(this.impl[name].apply(this.impl, arguments)); 3371 return wrapNodeList(this.impl[name].apply(this.impl, arguments));
3372 }; 3372 };
3373 } 3373 }
3374 3374
3375 scope.wrappers.NodeList = NodeList; 3375 scope.wrappers.NodeList = NodeList;
3376 scope.addWrapNodeListMethod = addWrapNodeListMethod; 3376 scope.addWrapNodeListMethod = addWrapNodeListMethod;
3377 scope.wrapNodeList = wrapNodeList; 3377 scope.wrapNodeList = wrapNodeList;
3378 3378
3379 })(window.ShadowDOMPolyfill); 3379 })(window.ShadowDOMPolyfill);
3380 3380
3381 /*
3382 * Copyright 2014 The Polymer Authors. All rights reserved.
3383 * Use of this source code is goverened by a BSD-style
3384 * license that can be found in the LICENSE file.
3385 */
3386
3387 (function(scope) {
3388 'use strict';
3389
3390 // TODO(arv): Implement.
3391
3392 scope.wrapHTMLCollection = scope.wrapNodeList;
3393 scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
3394
3395 })(window.ShadowDOMPolyfill);
3396
3381 // Copyright 2012 The Polymer Authors. All rights reserved. 3397 // Copyright 2012 The Polymer Authors. All rights reserved.
3382 // Use of this source code is goverened by a BSD-style 3398 // Use of this source code is goverened by a BSD-style
3383 // license that can be found in the LICENSE file. 3399 // license that can be found in the LICENSE file.
3384 3400
3385 (function(scope) { 3401 (function(scope) {
3386 'use strict'; 3402 'use strict';
3387 3403
3388 var EventTarget = scope.wrappers.EventTarget; 3404 var EventTarget = scope.wrappers.EventTarget;
3389 var NodeList = scope.wrappers.NodeList; 3405 var NodeList = scope.wrappers.NodeList;
3390 var assert = scope.assert; 3406 var assert = scope.assert;
(...skipping 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after
5130 node.setAttribute('selected', ''); 5146 node.setAttribute('selected', '');
5131 node.selected = selected === true; 5147 node.selected = selected === true;
5132 } 5148 }
5133 5149
5134 Option.prototype = HTMLOptionElement.prototype; 5150 Option.prototype = HTMLOptionElement.prototype;
5135 5151
5136 scope.wrappers.HTMLOptionElement = HTMLOptionElement; 5152 scope.wrappers.HTMLOptionElement = HTMLOptionElement;
5137 scope.wrappers.Option = Option; 5153 scope.wrappers.Option = Option;
5138 })(window.ShadowDOMPolyfill); 5154 })(window.ShadowDOMPolyfill);
5139 5155
5156 // Copyright 2014 The Polymer Authors. All rights reserved.
5157 // Use of this source code is goverened by a BSD-style
5158 // license that can be found in the LICENSE file.
5159
5160 (function(scope) {
5161 'use strict';
5162
5163 var HTMLElement = scope.wrappers.HTMLElement;
5164 var mixin = scope.mixin;
5165 var registerWrapper = scope.registerWrapper;
5166 var unwrap = scope.unwrap;
5167 var wrap = scope.wrap;
5168
5169 var OriginalHTMLSelectElement = window.HTMLSelectElement;
5170
5171 function HTMLSelectElement(node) {
5172 HTMLElement.call(this, node);
5173 }
5174 HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
5175 mixin(HTMLSelectElement.prototype, {
5176 add: function(element, before) {
5177 if (typeof before === 'object') // also includes null
5178 before = unwrap(before);
5179 unwrap(this).add(unwrap(element), before);
5180 },
5181
5182 remove: function(indexOrNode) {
5183 // Spec only allows index but implementations allow index or node.
5184 // remove() is also allowed which is same as remove(undefined)
5185 if (typeof indexOrNode === 'object')
5186 indexOrNode = unwrap(indexOrNode);
5187 unwrap(this).remove(indexOrNode);
5188 },
5189
5190 get form() {
5191 return wrap(unwrap(this).form);
5192 }
5193 });
5194
5195 registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement,
5196 document.createElement('select'));
5197
5198 scope.wrappers.HTMLSelectElement = HTMLSelectElement;
5199 })(window.ShadowDOMPolyfill);
5200
5201 /*
5202 * Copyright 2014 The Polymer Authors. All rights reserved.
5203 * Use of this source code is goverened by a BSD-style
5204 * license that can be found in the LICENSE file.
5205 */
5206
5207 (function(scope) {
5208 'use strict';
5209
5210 var HTMLElement = scope.wrappers.HTMLElement;
5211 var mixin = scope.mixin;
5212 var registerWrapper = scope.registerWrapper;
5213 var unwrap = scope.unwrap;
5214 var wrap = scope.wrap;
5215 var wrapHTMLCollection = scope.wrapHTMLCollection;
5216
5217 var OriginalHTMLTableElement = window.HTMLTableElement;
5218
5219 function HTMLTableElement(node) {
5220 HTMLElement.call(this, node);
5221 }
5222 HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
5223 mixin(HTMLTableElement.prototype, {
5224 get caption() {
5225 return wrap(unwrap(this).caption);
5226 },
5227 createCaption: function() {
5228 return wrap(unwrap(this).createCaption());
5229 },
5230
5231 get tHead() {
5232 return wrap(unwrap(this).tHead);
5233 },
5234 createTHead: function() {
5235 return wrap(unwrap(this).createTHead());
5236 },
5237
5238 createTFoot: function() {
5239 return wrap(unwrap(this).createTFoot());
5240 },
5241 get tFoot() {
5242 return wrap(unwrap(this).tFoot);
5243 },
5244
5245 get tBodies() {
5246 return wrapHTMLCollection(unwrap(this).tBodies);
5247 },
5248 createTBody: function() {
5249 return wrap(unwrap(this).createTBody());
5250 },
5251
5252 get rows() {
5253 return wrapHTMLCollection(unwrap(this).rows);
5254 },
5255 insertRow: function(index) {
5256 return wrap(unwrap(this).insertRow(index));
5257 }
5258 });
5259
5260 registerWrapper(OriginalHTMLTableElement, HTMLTableElement,
5261 document.createElement('table'));
5262
5263 scope.wrappers.HTMLTableElement = HTMLTableElement;
5264 })(window.ShadowDOMPolyfill);
5265
5266 /*
5267 * Copyright 2014 The Polymer Authors. All rights reserved.
5268 * Use of this source code is goverened by a BSD-style
5269 * license that can be found in the LICENSE file.
5270 */
5271
5272 (function(scope) {
5273 'use strict';
5274
5275 var HTMLElement = scope.wrappers.HTMLElement;
5276 var mixin = scope.mixin;
5277 var registerWrapper = scope.registerWrapper;
5278 var wrapHTMLCollection = scope.wrapHTMLCollection;
5279 var unwrap = scope.unwrap;
5280 var wrap = scope.wrap;
5281
5282 var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
5283
5284 function HTMLTableSectionElement(node) {
5285 HTMLElement.call(this, node);
5286 }
5287 HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
5288 mixin(HTMLTableSectionElement.prototype, {
5289 get rows() {
5290 return wrapHTMLCollection(unwrap(this).rows);
5291 },
5292 insertRow: function(index) {
5293 return wrap(unwrap(this).insertRow(index));
5294 }
5295 });
5296
5297 registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement,
5298 document.createElement('thead'));
5299
5300 scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
5301 })(window.ShadowDOMPolyfill);
5302
5303 /*
5304 * Copyright 2014 The Polymer Authors. All rights reserved.
5305 * Use of this source code is goverened by a BSD-style
5306 * license that can be found in the LICENSE file.
5307 */
5308
5309 (function(scope) {
5310 'use strict';
5311
5312 var HTMLElement = scope.wrappers.HTMLElement;
5313 var mixin = scope.mixin;
5314 var registerWrapper = scope.registerWrapper;
5315 var wrapHTMLCollection = scope.wrapHTMLCollection;
5316 var unwrap = scope.unwrap;
5317 var wrap = scope.wrap;
5318
5319 var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
5320
5321 function HTMLTableRowElement(node) {
5322 HTMLElement.call(this, node);
5323 }
5324 HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
5325 mixin(HTMLTableRowElement.prototype, {
5326 get cells() {
5327 return wrapHTMLCollection(unwrap(this).cells);
5328 },
5329
5330 insertCell: function(index) {
5331 return wrap(unwrap(this).insertCell(index));
5332 }
5333 });
5334
5335 registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement,
5336 document.createElement('tr'));
5337
5338 scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
5339 })(window.ShadowDOMPolyfill);
5340
5140 // Copyright 2013 The Polymer Authors. All rights reserved. 5341 // Copyright 2013 The Polymer Authors. All rights reserved.
5141 // Use of this source code is goverened by a BSD-style 5342 // Use of this source code is goverened by a BSD-style
5142 // license that can be found in the LICENSE file. 5343 // license that can be found in the LICENSE file.
5143 5344
5144 (function(scope) { 5345 (function(scope) {
5145 'use strict'; 5346 'use strict';
5146 5347
5147 var HTMLContentElement = scope.wrappers.HTMLContentElement; 5348 var HTMLContentElement = scope.wrappers.HTMLContentElement;
5148 var HTMLElement = scope.wrappers.HTMLElement; 5349 var HTMLElement = scope.wrappers.HTMLElement;
5149 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; 5350 var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
5695 if (!eventParents) 5896 if (!eventParents)
5696 eventParentsTable.set(child, eventParents = []); 5897 eventParentsTable.set(child, eventParents = []);
5697 eventParents.push(insertionPoint); 5898 eventParents.push(insertionPoint);
5698 } 5899 }
5699 5900
5700 function resetDistributedChildNodes(insertionPoint) { 5901 function resetDistributedChildNodes(insertionPoint) {
5701 distributedChildNodesTable.set(insertionPoint, []); 5902 distributedChildNodesTable.set(insertionPoint, []);
5702 } 5903 }
5703 5904
5704 function getDistributedChildNodes(insertionPoint) { 5905 function getDistributedChildNodes(insertionPoint) {
5705 return distributedChildNodesTable.get(insertionPoint); 5906 var rv = distributedChildNodesTable.get(insertionPoint);
5907 if (!rv)
5908 distributedChildNodesTable.set(insertionPoint, rv = []);
5909 return rv;
5706 } 5910 }
5707 5911
5708 function getChildNodesSnapshot(node) { 5912 function getChildNodesSnapshot(node) {
5709 var result = [], i = 0; 5913 var result = [], i = 0;
5710 for (var child = node.firstChild; child; child = child.nextSibling) { 5914 for (var child = node.firstChild; child; child = child.nextSibling) {
5711 result[i++] = child; 5915 result[i++] = child;
5712 } 5916 }
5713 return result; 5917 return result;
5714 } 5918 }
5715 5919
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
5803 'requestAnimationFrame', 6007 'requestAnimationFrame',
5804 'mozRequestAnimationFrame', 6008 'mozRequestAnimationFrame',
5805 'webkitRequestAnimationFrame', 6009 'webkitRequestAnimationFrame',
5806 'setTimeout' 6010 'setTimeout'
5807 ]); 6011 ]);
5808 6012
5809 var pendingDirtyRenderers = []; 6013 var pendingDirtyRenderers = [];
5810 var renderTimer; 6014 var renderTimer;
5811 6015
5812 function renderAllPending() { 6016 function renderAllPending() {
6017 // TODO(arv): Order these in document order. That way we do not have to
6018 // render something twice.
5813 for (var i = 0; i < pendingDirtyRenderers.length; i++) { 6019 for (var i = 0; i < pendingDirtyRenderers.length; i++) {
5814 pendingDirtyRenderers[i].render(); 6020 pendingDirtyRenderers[i].render();
5815 } 6021 }
6022
5816 pendingDirtyRenderers = []; 6023 pendingDirtyRenderers = [];
5817 } 6024 }
5818 6025
5819 function handleRequestAnimationFrame() { 6026 function handleRequestAnimationFrame() {
5820 renderTimer = null; 6027 renderTimer = null;
5821 renderAllPending(); 6028 renderAllPending();
5822 } 6029 }
5823 6030
5824 /** 6031 /**
5825 * Returns existing shadow renderer for a host or creates it if it is needed. 6032 * Returns existing shadow renderer for a host or creates it if it is needed.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
5979 } else { 6186 } else {
5980 this.renderAsAnyDomTree(shadowRoot, renderNode, node, isNested); 6187 this.renderAsAnyDomTree(shadowRoot, renderNode, node, isNested);
5981 } 6188 }
5982 }, 6189 },
5983 6190
5984 renderAsAnyDomTree: function(shadowRoot, renderNode, node, isNested) { 6191 renderAsAnyDomTree: function(shadowRoot, renderNode, node, isNested) {
5985 renderNode = renderNode.append(node); 6192 renderNode = renderNode.append(node);
5986 6193
5987 if (isShadowHost(node)) { 6194 if (isShadowHost(node)) {
5988 var renderer = getRendererForHost(node); 6195 var renderer = getRendererForHost(node);
5989 renderNode.skip = !renderer.dirty; 6196 // renderNode.skip = !renderer.dirty;
6197 renderer.invalidate();
5990 renderer.render(renderNode); 6198 renderer.render(renderNode);
5991 } else { 6199 } else {
5992 for (var child = node.firstChild; child; child = child.nextSibling) { 6200 for (var child = node.firstChild; child; child = child.nextSibling) {
5993 this.renderNode(shadowRoot, renderNode, child, isNested); 6201 this.renderNode(shadowRoot, renderNode, child, isNested);
5994 } 6202 }
5995 } 6203 }
5996 }, 6204 },
5997 6205
5998 renderInsertionPoint: function(shadowRoot, renderNode, insertionPoint, 6206 renderInsertionPoint: function(shadowRoot, renderNode, insertionPoint,
5999 isNested) { 6207 isNested) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
6266 var elementsWithFormProperty = [ 6474 var elementsWithFormProperty = [
6267 'HTMLButtonElement', 6475 'HTMLButtonElement',
6268 'HTMLFieldSetElement', 6476 'HTMLFieldSetElement',
6269 'HTMLInputElement', 6477 'HTMLInputElement',
6270 'HTMLKeygenElement', 6478 'HTMLKeygenElement',
6271 'HTMLLabelElement', 6479 'HTMLLabelElement',
6272 'HTMLLegendElement', 6480 'HTMLLegendElement',
6273 'HTMLObjectElement', 6481 'HTMLObjectElement',
6274 // HTMLOptionElement is handled in HTMLOptionElement.js 6482 // HTMLOptionElement is handled in HTMLOptionElement.js
6275 'HTMLOutputElement', 6483 'HTMLOutputElement',
6276 'HTMLSelectElement', 6484 // HTMLSelectElement is handled in HTMLSelectElement.js
6277 'HTMLTextAreaElement', 6485 'HTMLTextAreaElement',
6278 ]; 6486 ];
6279 6487
6280 function createWrapperConstructor(name) { 6488 function createWrapperConstructor(name) {
6281 if (!window[name]) 6489 if (!window[name])
6282 return; 6490 return;
6283 6491
6284 // Ensure we are not overriding an already existing constructor. 6492 // Ensure we are not overriding an already existing constructor.
6285 assert(!scope.wrappers[name]); 6493 assert(!scope.wrappers[name]);
6286 6494
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
6757 6965
6758 (function(scope) { 6966 (function(scope) {
6759 'use strict'; 6967 'use strict';
6760 6968
6761 var isWrapperFor = scope.isWrapperFor; 6969 var isWrapperFor = scope.isWrapperFor;
6762 6970
6763 // This is a list of the elements we currently override the global constructor 6971 // This is a list of the elements we currently override the global constructor
6764 // for. 6972 // for.
6765 var elements = { 6973 var elements = {
6766 'a': 'HTMLAnchorElement', 6974 'a': 'HTMLAnchorElement',
6767
6768 // Do not create an applet element by default since it shows a warning in 6975 // Do not create an applet element by default since it shows a warning in
6769 // IE. 6976 // IE.
6770 // https://github.com/Polymer/polymer/issues/217 6977 // https://github.com/Polymer/polymer/issues/217
6771 // 'applet': 'HTMLAppletElement', 6978 // 'applet': 'HTMLAppletElement',
6772
6773 'area': 'HTMLAreaElement', 6979 'area': 'HTMLAreaElement',
6774 'br': 'HTMLBRElement', 6980 'audio': 'HTMLAudioElement',
6775 'base': 'HTMLBaseElement', 6981 'base': 'HTMLBaseElement',
6776 'body': 'HTMLBodyElement', 6982 'body': 'HTMLBodyElement',
6983 'br': 'HTMLBRElement',
6777 'button': 'HTMLButtonElement', 6984 'button': 'HTMLButtonElement',
6985 'canvas': 'HTMLCanvasElement',
6986 'caption': 'HTMLTableCaptionElement',
6987 'col': 'HTMLTableColElement',
6778 // 'command': 'HTMLCommandElement', // Not fully implemented in Gecko. 6988 // 'command': 'HTMLCommandElement', // Not fully implemented in Gecko.
6779 'dl': 'HTMLDListElement', 6989 'content': 'HTMLContentElement',
6990 'data': 'HTMLDataElement',
6780 'datalist': 'HTMLDataListElement', 6991 'datalist': 'HTMLDataListElement',
6781 'data': 'HTMLDataElement', 6992 'del': 'HTMLModElement',
6782 'dir': 'HTMLDirectoryElement', 6993 'dir': 'HTMLDirectoryElement',
6783 'div': 'HTMLDivElement', 6994 'div': 'HTMLDivElement',
6995 'dl': 'HTMLDListElement',
6784 'embed': 'HTMLEmbedElement', 6996 'embed': 'HTMLEmbedElement',
6785 'fieldset': 'HTMLFieldSetElement', 6997 'fieldset': 'HTMLFieldSetElement',
6786 'font': 'HTMLFontElement', 6998 'font': 'HTMLFontElement',
6787 'form': 'HTMLFormElement', 6999 'form': 'HTMLFormElement',
6788 'frame': 'HTMLFrameElement', 7000 'frame': 'HTMLFrameElement',
6789 'frameset': 'HTMLFrameSetElement', 7001 'frameset': 'HTMLFrameSetElement',
7002 'h1': 'HTMLHeadingElement',
7003 'head': 'HTMLHeadElement',
6790 'hr': 'HTMLHRElement', 7004 'hr': 'HTMLHRElement',
6791 'head': 'HTMLHeadElement',
6792 'h1': 'HTMLHeadingElement',
6793 'html': 'HTMLHtmlElement', 7005 'html': 'HTMLHtmlElement',
6794 'iframe': 'HTMLIFrameElement', 7006 'iframe': 'HTMLIFrameElement',
7007 'img': 'HTMLImageElement',
6795 'input': 'HTMLInputElement', 7008 'input': 'HTMLInputElement',
6796 'li': 'HTMLLIElement', 7009 'keygen': 'HTMLKeygenElement',
6797 'label': 'HTMLLabelElement', 7010 'label': 'HTMLLabelElement',
6798 'legend': 'HTMLLegendElement', 7011 'legend': 'HTMLLegendElement',
7012 'li': 'HTMLLIElement',
6799 'link': 'HTMLLinkElement', 7013 'link': 'HTMLLinkElement',
6800 'map': 'HTMLMapElement', 7014 'map': 'HTMLMapElement',
6801 'marquee': 'HTMLMarqueeElement', 7015 'marquee': 'HTMLMarqueeElement',
6802 'menu': 'HTMLMenuElement', 7016 'menu': 'HTMLMenuElement',
6803 'menuitem': 'HTMLMenuItemElement', 7017 'menuitem': 'HTMLMenuItemElement',
6804 'meta': 'HTMLMetaElement', 7018 'meta': 'HTMLMetaElement',
6805 'meter': 'HTMLMeterElement', 7019 'meter': 'HTMLMeterElement',
6806 'del': 'HTMLModElement', 7020 'object': 'HTMLObjectElement',
6807 'ol': 'HTMLOListElement', 7021 'ol': 'HTMLOListElement',
6808 'object': 'HTMLObjectElement',
6809 'optgroup': 'HTMLOptGroupElement', 7022 'optgroup': 'HTMLOptGroupElement',
6810 'option': 'HTMLOptionElement', 7023 'option': 'HTMLOptionElement',
6811 'output': 'HTMLOutputElement', 7024 'output': 'HTMLOutputElement',
6812 'p': 'HTMLParagraphElement', 7025 'p': 'HTMLParagraphElement',
6813 'param': 'HTMLParamElement', 7026 'param': 'HTMLParamElement',
6814 'pre': 'HTMLPreElement', 7027 'pre': 'HTMLPreElement',
6815 'progress': 'HTMLProgressElement', 7028 'progress': 'HTMLProgressElement',
6816 'q': 'HTMLQuoteElement', 7029 'q': 'HTMLQuoteElement',
6817 'script': 'HTMLScriptElement', 7030 'script': 'HTMLScriptElement',
6818 'select': 'HTMLSelectElement', 7031 'select': 'HTMLSelectElement',
7032 'shadow': 'HTMLShadowElement',
6819 'source': 'HTMLSourceElement', 7033 'source': 'HTMLSourceElement',
6820 'span': 'HTMLSpanElement', 7034 'span': 'HTMLSpanElement',
6821 'style': 'HTMLStyleElement', 7035 'style': 'HTMLStyleElement',
6822 'time': 'HTMLTimeElement', 7036 'table': 'HTMLTableElement',
6823 'caption': 'HTMLTableCaptionElement', 7037 'tbody': 'HTMLTableSectionElement',
6824 // WebKit and Moz are wrong: 7038 // WebKit and Moz are wrong:
6825 // https://bugs.webkit.org/show_bug.cgi?id=111469 7039 // https://bugs.webkit.org/show_bug.cgi?id=111469
6826 // https://bugzilla.mozilla.org/show_bug.cgi?id=848096 7040 // https://bugzilla.mozilla.org/show_bug.cgi?id=848096
6827 // 'td': 'HTMLTableCellElement', 7041 // 'td': 'HTMLTableCellElement',
6828 'col': 'HTMLTableColElement', 7042 'template': 'HTMLTemplateElement',
6829 'table': 'HTMLTableElement', 7043 'textarea': 'HTMLTextAreaElement',
7044 'thead': 'HTMLTableSectionElement',
7045 'time': 'HTMLTimeElement',
7046 'title': 'HTMLTitleElement',
6830 'tr': 'HTMLTableRowElement', 7047 'tr': 'HTMLTableRowElement',
6831 'thead': 'HTMLTableSectionElement',
6832 'tbody': 'HTMLTableSectionElement',
6833 'textarea': 'HTMLTextAreaElement',
6834 'track': 'HTMLTrackElement', 7048 'track': 'HTMLTrackElement',
6835 'title': 'HTMLTitleElement',
6836 'ul': 'HTMLUListElement', 7049 'ul': 'HTMLUListElement',
6837 'video': 'HTMLVideoElement', 7050 'video': 'HTMLVideoElement',
6838 }; 7051 };
6839 7052
6840 function overrideConstructor(tagName) { 7053 function overrideConstructor(tagName) {
6841 var nativeConstructorName = elements[tagName]; 7054 var nativeConstructorName = elements[tagName];
6842 var nativeConstructor = window[nativeConstructorName]; 7055 var nativeConstructor = window[nativeConstructorName];
6843 if (!nativeConstructor) 7056 if (!nativeConstructor)
6844 return; 7057 return;
6845 var element = document.createElement(tagName); 7058 var element = document.createElement(tagName);
6846 var wrapperConstructor = element.constructor; 7059 var wrapperConstructor = element.constructor;
6847 window[nativeConstructorName] = wrapperConstructor; 7060 window[nativeConstructorName] = wrapperConstructor;
6848 } 7061 }
6849 7062
6850 Object.keys(elements).forEach(overrideConstructor); 7063 Object.keys(elements).forEach(overrideConstructor);
6851 7064
6852 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) { 7065 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) {
6853 window[name] = scope.wrappers[name] 7066 window[name] = scope.wrappers[name]
6854 }); 7067 });
6855 7068
6856 // Export for testing.
6857 scope.knownElements = elements;
6858
6859 })(window.ShadowDOMPolyfill); 7069 })(window.ShadowDOMPolyfill);
6860 7070
6861 /* 7071 /*
6862 * Copyright 2013 The Polymer Authors. All rights reserved. 7072 * Copyright 2013 The Polymer Authors. All rights reserved.
6863 * Use of this source code is governed by a BSD-style 7073 * Use of this source code is governed by a BSD-style
6864 * license that can be found in the LICENSE file. 7074 * license that can be found in the LICENSE file.
6865 */ 7075 */
6866 (function() { 7076 (function() {
6867 7077
6868 // convenient global 7078 // convenient global
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
7021 (function(scope) { 7231 (function(scope) {
7022 7232
7023 var ShadowCSS = { 7233 var ShadowCSS = {
7024 strictStyling: false, 7234 strictStyling: false,
7025 registry: {}, 7235 registry: {},
7026 // Shim styles for a given root associated with a name and extendsName 7236 // Shim styles for a given root associated with a name and extendsName
7027 // 1. cache root styles by name 7237 // 1. cache root styles by name
7028 // 2. optionally tag root nodes with scope name 7238 // 2. optionally tag root nodes with scope name
7029 // 3. shim polyfill directives /* @polyfill */ and /* @polyfill-rule */ 7239 // 3. shim polyfill directives /* @polyfill */ and /* @polyfill-rule */
7030 // 4. shim :host and scoping 7240 // 4. shim :host and scoping
7031 shimStyling: function(root, name, extendsName) { 7241 shimStyling: function(root, name, extendsName, ownSheet) {
7032 var typeExtension = this.isTypeExtension(extendsName); 7242 var typeExtension = this.isTypeExtension(extendsName);
7033 // use caching to make working with styles nodes easier and to facilitate 7243 // use caching to make working with styles nodes easier and to facilitate
7034 // lookup of extendee 7244 // lookup of extendee
7035 var def = this.registerDefinition(root, name, extendsName); 7245 var def = this.registerDefinition(root, name, extendsName);
7036 // find styles and apply shimming... 7246 // find styles and apply shimming...
7037 if (this.strictStyling) { 7247 if (this.strictStyling) {
7038 this.applyScopeToContent(root, name); 7248 this.applyScopeToContent(root, name);
7039 } 7249 }
7040 var cssText = this.stylesToShimmedCssText(def.rootStyles, def.scopeStyles, 7250 var cssText = this.stylesToShimmedCssText(def.rootStyles, def.scopeStyles,
7041 name, typeExtension); 7251 name, typeExtension);
7042 // provide shimmedStyle for user extensibility 7252 // provide shimmedStyle for user extensibility
7043 def.shimmedStyle = cssTextToStyle(cssText); 7253 def.shimmedStyle = cssTextToStyle(cssText);
7044 if (root) { 7254 if (root) {
7045 root.shimmedStyle = def.shimmedStyle; 7255 root.shimmedStyle = def.shimmedStyle;
7046 } 7256 }
7047 // remove existing style elements 7257 // remove existing style elements
7048 for (var i=0, l=def.rootStyles.length, s; (i<l) && (s=def.rootStyles[i]); 7258 for (var i=0, l=def.rootStyles.length, s; (i<l) && (s=def.rootStyles[i]);
7049 i++) { 7259 i++) {
7050 s.parentNode.removeChild(s); 7260 s.parentNode.removeChild(s);
7051 } 7261 }
7052 // add style to document 7262 // add style to document
7053 addCssToDocument(cssText); 7263 if (ownSheet) {
7264 addOwnSheet(cssText, name);
7265 } else {
7266 addCssToDocument(cssText);
7267 }
7054 }, 7268 },
7055 // apply @polyfill rules + :host and scope shimming 7269 // apply @polyfill rules + :host and scope shimming
7056 stylesToShimmedCssText: function(rootStyles, scopeStyles, name, 7270 stylesToShimmedCssText: function(rootStyles, scopeStyles, name,
7057 typeExtension) { 7271 typeExtension) {
7058 name = name || ''; 7272 name = name || '';
7059 // insert @polyfill and @polyfill-rule rules into style elements 7273 // insert @polyfill and @polyfill-rule rules into style elements
7060 // scoping process takes care of shimming these 7274 // scoping process takes care of shimming these
7061 this.insertPolyfillDirectives(rootStyles); 7275 this.insertPolyfillDirectives(rootStyles);
7062 this.insertPolyfillRules(rootStyles); 7276 this.insertPolyfillRules(rootStyles);
7063 var cssText = this.shimScoping(scopeStyles, name, typeExtension); 7277 var cssText = this.shimScoping(scopeStyles, name, typeExtension);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
7196 return this.convertScopedStyles(styles, name, typeExtension); 7410 return this.convertScopedStyles(styles, name, typeExtension);
7197 } 7411 }
7198 }, 7412 },
7199 convertScopedStyles: function(styles, name, typeExtension) { 7413 convertScopedStyles: function(styles, name, typeExtension) {
7200 var cssText = stylesToCssText(styles); 7414 var cssText = stylesToCssText(styles);
7201 cssText = this.insertPolyfillHostInCssText(cssText); 7415 cssText = this.insertPolyfillHostInCssText(cssText);
7202 cssText = this.convertColonHost(cssText); 7416 cssText = this.convertColonHost(cssText);
7203 cssText = this.convertColonAncestor(cssText); 7417 cssText = this.convertColonAncestor(cssText);
7204 cssText = this.convertCombinators(cssText); 7418 cssText = this.convertCombinators(cssText);
7205 if (name) { 7419 if (name) {
7206 var rules = cssToRules(cssText); 7420 var self = this, cssText;
7207 cssText = this.scopeRules(rules, name, typeExtension); 7421
7422 withCssRules(cssText, function(rules) {
7423 cssText = self.scopeRules(rules, name, typeExtension);
7424 });
7425
7208 } 7426 }
7209 return cssText; 7427 return cssText;
7210 }, 7428 },
7211 /* 7429 /*
7212 * convert a rule like :host(.foo) > .bar { } 7430 * convert a rule like :host(.foo) > .bar { }
7213 * 7431 *
7214 * to 7432 * to
7215 * 7433 *
7216 * scopeName.foo > .bar 7434 * scopeName.foo > .bar
7217 */ 7435 */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 }, 7484 },
7267 /* 7485 /*
7268 * Convert ^ and ^^ combinators by replacing with space. 7486 * Convert ^ and ^^ combinators by replacing with space.
7269 */ 7487 */
7270 convertCombinators: function(cssText) { 7488 convertCombinators: function(cssText) {
7271 return cssText.replace(/\^\^/g, ' ').replace(/\^/g, ' '); 7489 return cssText.replace(/\^\^/g, ' ').replace(/\^/g, ' ');
7272 }, 7490 },
7273 // change a selector like 'div' to 'name div' 7491 // change a selector like 'div' to 'name div'
7274 scopeRules: function(cssRules, name, typeExtension) { 7492 scopeRules: function(cssRules, name, typeExtension) {
7275 var cssText = ''; 7493 var cssText = '';
7276 Array.prototype.forEach.call(cssRules, function(rule) { 7494 if (cssRules) {
7277 if (rule.selectorText && (rule.style && rule.style.cssText)) { 7495 Array.prototype.forEach.call(cssRules, function(rule) {
7278 cssText += this.scopeSelector(rule.selectorText, name, typeExtension, 7496 if (rule.selectorText && (rule.style && rule.style.cssText)) {
7279 this.strictStyling) + ' {\n\t'; 7497 cssText += this.scopeSelector(rule.selectorText, name, typeExtension,
7280 cssText += this.propertiesFromRule(rule) + '\n}\n\n'; 7498 this.strictStyling) + ' {\n\t';
7281 } else if (rule.media) { 7499 cssText += this.propertiesFromRule(rule) + '\n}\n\n';
7282 cssText += '@media ' + rule.media.mediaText + ' {\n'; 7500 } else if (rule.type === CSSRule.MEDIA_RULE) {
7283 cssText += this.scopeRules(rule.cssRules, name, typeExtension); 7501 cssText += '@media ' + rule.media.mediaText + ' {\n';
7284 cssText += '\n}\n\n'; 7502 cssText += this.scopeRules(rule.cssRules, name, typeExtension);
7285 } else if (rule.cssText) { 7503 cssText += '\n}\n\n';
7286 cssText += rule.cssText + '\n\n'; 7504 } else if (rule.cssText) {
7287 } 7505 cssText += rule.cssText + '\n\n';
7288 }, this); 7506 }
7507 }, this);
7508 }
7289 return cssText; 7509 return cssText;
7290 }, 7510 },
7291 scopeSelector: function(selector, name, typeExtension, strict) { 7511 scopeSelector: function(selector, name, typeExtension, strict) {
7292 var r = [], parts = selector.split(','); 7512 var r = [], parts = selector.split(',');
7293 parts.forEach(function(p) { 7513 parts.forEach(function(p) {
7294 p = p.trim(); 7514 p = p.trim();
7295 if (this.selectorNeedsScoping(p, name, typeExtension)) { 7515 if (this.selectorNeedsScoping(p, name, typeExtension)) {
7296 p = (strict && !p.match(polyfillHostNoCombinator)) ? 7516 p = (strict && !p.match(polyfillHostNoCombinator)) ?
7297 this.applyStrictSelectorScope(p, name) : 7517 this.applyStrictSelectorScope(p, name) :
7298 this.applySimpleSelectorScope(p, name, typeExtension); 7518 this.applySimpleSelectorScope(p, name, typeExtension);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
7392 7612
7393 function cssTextToStyle(cssText) { 7613 function cssTextToStyle(cssText) {
7394 var style = document.createElement('style'); 7614 var style = document.createElement('style');
7395 style.textContent = cssText; 7615 style.textContent = cssText;
7396 return style; 7616 return style;
7397 } 7617 }
7398 7618
7399 function cssToRules(cssText) { 7619 function cssToRules(cssText) {
7400 var style = cssTextToStyle(cssText); 7620 var style = cssTextToStyle(cssText);
7401 document.head.appendChild(style); 7621 document.head.appendChild(style);
7402 var rules = style.sheet.cssRules; 7622 var rules = [];
7623 if (style.sheet) {
7624 // TODO(sorvell): Firefox throws when accessing the rules of a stylesheet
7625 // with an @import
7626 // https://bugzilla.mozilla.org/show_bug.cgi?id=625013
7627 try {
7628 rules = style.sheet.cssRules;
7629 } catch(e) {
7630 //
7631 }
7632 } else {
7633 console.warn('sheet not found', style);
7634 }
7403 style.parentNode.removeChild(style); 7635 style.parentNode.removeChild(style);
7404 return rules; 7636 return rules;
7405 } 7637 }
7406 7638
7639 var frame = document.createElement('iframe');
7640 frame.style.display = 'none';
7641
7642 function initFrame() {
7643 frame.initialized = true;
7644 document.body.appendChild(frame);
7645 var doc = frame.contentDocument;
7646 var base = doc.createElement('base');
7647 base.href = document.baseURI;
7648 doc.head.appendChild(base);
7649 }
7650
7651 function inFrame(fn) {
7652 if (!frame.initialized) {
7653 initFrame();
7654 }
7655 document.body.appendChild(frame);
7656 fn(frame.contentDocument);
7657 document.body.removeChild(frame);
7658 }
7659
7660 // TODO(sorvell): use an iframe if the cssText contains an @import to workaround
7661 // https://code.google.com/p/chromium/issues/detail?id=345114
7662 var isChrome = navigator.userAgent.match('Chrome');
7663 function withCssRules(cssText, callback) {
7664 if (!callback) {
7665 return;
7666 }
7667 var rules;
7668 if (cssText.match('@import') && isChrome) {
7669 var style = cssTextToStyle(cssText);
7670 inFrame(function(doc) {
7671 doc.head.appendChild(style.impl);
7672 rules = style.sheet.cssRules;
7673 callback(rules);
7674 });
7675 } else {
7676 rules = cssToRules(cssText);
7677 callback(rules);
7678 }
7679 }
7680
7407 function rulesToCss(cssRules) { 7681 function rulesToCss(cssRules) {
7408 for (var i=0, css=[]; i < cssRules.length; i++) { 7682 for (var i=0, css=[]; i < cssRules.length; i++) {
7409 css.push(cssRules[i].cssText); 7683 css.push(cssRules[i].cssText);
7410 } 7684 }
7411 return css.join('\n\n'); 7685 return css.join('\n\n');
7412 } 7686 }
7413 7687
7414 function addCssToDocument(cssText) { 7688 function addCssToDocument(cssText) {
7415 if (cssText) { 7689 if (cssText) {
7416 getSheet().appendChild(document.createTextNode(cssText)); 7690 getSheet().appendChild(document.createTextNode(cssText));
7417 } 7691 }
7418 } 7692 }
7419 7693
7694 function addOwnSheet(cssText, name) {
7695 var style = cssTextToStyle(cssText);
7696 style.setAttribute(name, '');
7697 style.setAttribute(SHIMMED_ATTRIBUTE, '');
7698 document.head.appendChild(style);
7699 }
7700
7420 var SHIM_ATTRIBUTE = 'shim-shadowdom'; 7701 var SHIM_ATTRIBUTE = 'shim-shadowdom';
7421 var SHIMMED_ATTRIBUTE = 'shim-shadowdom-css'; 7702 var SHIMMED_ATTRIBUTE = 'shim-shadowdom-css';
7422 7703
7423 var sheet; 7704 var sheet;
7424 function getSheet() { 7705 function getSheet() {
7425 if (!sheet) { 7706 if (!sheet) {
7426 sheet = document.createElement("style"); 7707 sheet = document.createElement("style");
7427 sheet.setAttribute(SHIMMED_ATTRIBUTE, ''); 7708 sheet.setAttribute(SHIMMED_ATTRIBUTE, '');
7428 sheet[SHIMMED_ATTRIBUTE] = true; 7709 sheet[SHIMMED_ATTRIBUTE] = true;
7429 } 7710 }
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
8283 if (!window.cancelAnimationFrame) { 8564 if (!window.cancelAnimationFrame) {
8284 window.cancelAnimationFrame = (function() { 8565 window.cancelAnimationFrame = (function() {
8285 return window.webkitCancelAnimationFrame || 8566 return window.webkitCancelAnimationFrame ||
8286 window.mozCancelAnimationFrame || 8567 window.mozCancelAnimationFrame ||
8287 function(id) { 8568 function(id) {
8288 clearTimeout(id); 8569 clearTimeout(id);
8289 }; 8570 };
8290 })(); 8571 })();
8291 } 8572 }
8292 8573
8293 // TODO(sorvell): workaround for bug:
8294 // https://code.google.com/p/chromium/issues/detail?id=229142
8295 // remove when this bug is addressed
8296 // give main document templates a base that allows them to fetch eagerly
8297 // resolved paths relative to the main document
8298 var template = document.createElement('template');
8299 var base = document.createElement('base');
8300 base.href = document.baseURI;
8301 template.content.ownerDocument.appendChild(base);
8302
8303
8304 // utility 8574 // utility
8305 8575
8306 function createDOM(inTagOrNode, inHTML, inAttrs) { 8576 function createDOM(inTagOrNode, inHTML, inAttrs) {
8307 var dom = typeof inTagOrNode == 'string' ? 8577 var dom = typeof inTagOrNode == 'string' ?
8308 document.createElement(inTagOrNode) : inTagOrNode.cloneNode(true); 8578 document.createElement(inTagOrNode) : inTagOrNode.cloneNode(true);
8309 dom.innerHTML = inHTML; 8579 dom.innerHTML = inHTML;
8310 if (inAttrs) { 8580 if (inAttrs) {
8311 for (var n in inAttrs) { 8581 for (var n in inAttrs) {
8312 dom.setAttribute(n, inAttrs[n]); 8582 dom.setAttribute(n, inAttrs[n]);
8313 } 8583 }
8314 } 8584 }
8315 return dom; 8585 return dom;
8316 } 8586 }
8317 // Make a stub for Polymer() for polyfill purposes; under the HTMLImports 8587 // Make a stub for Polymer() for polyfill purposes; under the HTMLImports
8318 // polyfill, scripts in the main document run before imports. That means 8588 // polyfill, scripts in the main document run before imports. That means
8319 // if (1) polymer is imported and (2) Polymer() is called in the main document 8589 // if (1) polymer is imported and (2) Polymer() is called in the main document
8320 // in a script after the import, 2 occurs before 1. We correct this here 8590 // in a script after the import, 2 occurs before 1. We correct this here
8321 // by specfiically patching Polymer(); this is not necessary under native 8591 // by specfiically patching Polymer(); this is not necessary under native
8322 // HTMLImports. 8592 // HTMLImports.
8323 var elementDeclarations = []; 8593 var elementDeclarations = [];
8324 8594
8325 var polymerStub = function(name, dictionary) { 8595 var polymerStub = function(name, dictionary) {
8326 elementDeclarations.push(arguments); 8596 elementDeclarations.push(arguments);
8327 } 8597 }
8328 window.Polymer = polymerStub; 8598 window.Polymer = polymerStub;
8329 8599
8330 // deliver queued delcarations 8600 // deliver queued delcarations
8331 scope.deliverDeclarations = function() { 8601 scope.deliverDeclarations = function() {
8332 scope.deliverDeclarations = null; 8602 scope.deliverDeclarations = function() {
8603 throw 'Possible attempt to load Polymer twice';
8604 };
8333 return elementDeclarations; 8605 return elementDeclarations;
8334 } 8606 }
8335 8607
8336 // Once DOMContent has loaded, any main document scripts that depend on 8608 // Once DOMContent has loaded, any main document scripts that depend on
8337 // Polymer() should have run. Calling Polymer() now is an error until 8609 // Polymer() should have run. Calling Polymer() now is an error until
8338 // polymer is imported. 8610 // polymer is imported.
8339 window.addEventListener('DOMContentLoaded', function() { 8611 window.addEventListener('DOMContentLoaded', function() {
8340 if (window.Polymer === polymerStub) { 8612 if (window.Polymer === polymerStub) {
8341 window.Polymer = function() { 8613 window.Polymer = function() {
8342 console.error('You tried to use polymer without loading it first. To ' + 8614 console.error('You tried to use polymer without loading it first. To ' +
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
8676 // handle template.content 8948 // handle template.content
8677 var templates = root.querySelectorAll('template'); 8949 var templates = root.querySelectorAll('template');
8678 if (templates) { 8950 if (templates) {
8679 for (var i = 0, l = templates.length, t; (i < l) && (t = templates[i]); i+ +) { 8951 for (var i = 0, l = templates.length, t; (i < l) && (t = templates[i]); i+ +) {
8680 if (t.content) { 8952 if (t.content) {
8681 this.resolveDom(t.content, url); 8953 this.resolveDom(t.content, url);
8682 } 8954 }
8683 } 8955 }
8684 } 8956 }
8685 }, 8957 },
8958 resolveTemplate: function(template) {
8959 this.resolveDom(template.content, template.ownerDocument.baseURI);
8960 },
8686 resolveStyles: function(root, url) { 8961 resolveStyles: function(root, url) {
8687 var styles = root.querySelectorAll('style'); 8962 var styles = root.querySelectorAll('style');
8688 if (styles) { 8963 if (styles) {
8689 for (var i = 0, l = styles.length, s; (i < l) && (s = styles[i]); i++) { 8964 for (var i = 0, l = styles.length, s; (i < l) && (s = styles[i]); i++) {
8690 this.resolveStyle(s, url); 8965 this.resolveStyle(s, url);
8691 } 8966 }
8692 } 8967 }
8693 }, 8968 },
8694 resolveStyle: function(style, url) { 8969 resolveStyle: function(style, url) {
8695 url = url || style.ownerDocument.baseURI; 8970 url = url || style.ownerDocument.baseURI;
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
9591 var src = elt; 9866 var src = elt;
9592 elt = cloneStyle(elt); 9867 elt = cloneStyle(elt);
9593 elt.__importElement = src; 9868 elt.__importElement = src;
9594 this.parseGeneric(elt); 9869 this.parseGeneric(elt);
9595 }, 9870 },
9596 parseGeneric: function(elt) { 9871 parseGeneric: function(elt) {
9597 this.trackElement(elt); 9872 this.trackElement(elt);
9598 document.head.appendChild(elt); 9873 document.head.appendChild(elt);
9599 }, 9874 },
9600 // tracks when a loadable element has loaded 9875 // tracks when a loadable element has loaded
9601 trackElement: function(elt) { 9876 trackElement: function(elt, callback) {
9602 var self = this; 9877 var self = this;
9603 var done = function() { 9878 var done = function(e) {
9879 if (callback) {
9880 callback(e);
9881 }
9604 self.markParsingComplete(elt); 9882 self.markParsingComplete(elt);
9605 }; 9883 };
9606 elt.addEventListener('load', done); 9884 elt.addEventListener('load', done);
9607 elt.addEventListener('error', done); 9885 elt.addEventListener('error', done);
9608 9886
9609 // NOTE: IE does not fire "load" event for styles that have already loaded 9887 // NOTE: IE does not fire "load" event for styles that have already loaded
9610 // This is in violation of the spec, so we try our hardest to work around it 9888 // This is in violation of the spec, so we try our hardest to work around it
9611 if (isIe && elt.localName === 'style') { 9889 if (isIe && elt.localName === 'style') {
9612 var fakeLoad = false; 9890 var fakeLoad = false;
9613 // If there's not @import in the textContent, assume it has loaded 9891 // If there's not @import in the textContent, assume it has loaded
(...skipping 11 matching lines...) Expand all
9625 fakeLoad = fakeLoad && Boolean(r.styleSheet); 9903 fakeLoad = fakeLoad && Boolean(r.styleSheet);
9626 } 9904 }
9627 } 9905 }
9628 } 9906 }
9629 // dispatch a fake load event and continue parsing 9907 // dispatch a fake load event and continue parsing
9630 if (fakeLoad) { 9908 if (fakeLoad) {
9631 elt.dispatchEvent(new CustomEvent('load', {bubbles: false})); 9909 elt.dispatchEvent(new CustomEvent('load', {bubbles: false}));
9632 } 9910 }
9633 } 9911 }
9634 }, 9912 },
9913 // NOTE: execute scripts by injecting them and watching for the load/error
9914 // event. Inline scripts are handled via dataURL's because browsers tend to
9915 // provide correct parsing errors in this case. If this has any compatibility
9916 // issues, we can switch to injecting the inline script with textContent.
9917 // Scripts with dataURL's do not appear to generate load events and therefore
9918 // we assume they execute synchronously.
9635 parseScript: function(scriptElt) { 9919 parseScript: function(scriptElt) {
9636 // acquire code to execute 9920 var script = document.createElement('script');
9637 var code = (scriptElt.__resource || scriptElt.textContent).trim(); 9921 script.__importElement = scriptElt;
9638 if (code) { 9922 script.src = scriptElt.src ? scriptElt.src :
9639 // calculate source map hint 9923 generateScriptDataUrl(scriptElt);
9640 var moniker = scriptElt.__nodeUrl; 9924 scope.currentScript = scriptElt;
9641 if (!moniker) { 9925 this.trackElement(script, function(e) {
9642 moniker = scriptElt.ownerDocument.baseURI; 9926 script.parentNode.removeChild(script);
9643 // there could be more than one script this url 9927 scope.currentScript = null;
9644 var tag = '[' + Math.floor((Math.random()+1)*1000) + ']'; 9928 });
9645 // TODO(sjmiles): Polymer hack, should be pluggable if we need to allow 9929 document.head.appendChild(script);
9646 // this sort of thing
9647 var matches = code.match(/Polymer\(['"]([^'"]*)/);
9648 tag = matches && matches[1] || tag;
9649 // tag the moniker
9650 moniker += '/' + tag + '.js';
9651 }
9652 // source map hint
9653 code += "\n//# sourceURL=" + moniker + "\n";
9654 // evaluate the code
9655 scope.currentScript = scriptElt;
9656 eval.call(window, code);
9657 scope.currentScript = null;
9658 }
9659 this.markParsingComplete(scriptElt);
9660 }, 9930 },
9661 // determine the next element in the tree which should be parsed 9931 // determine the next element in the tree which should be parsed
9662 nextToParse: function() { 9932 nextToParse: function() {
9663 return !this.parsingElement && this.nextToParseInDoc(mainDoc); 9933 return !this.parsingElement && this.nextToParseInDoc(mainDoc);
9664 }, 9934 },
9665 nextToParseInDoc: function(doc, link) { 9935 nextToParseInDoc: function(doc, link) {
9666 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc)); 9936 var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
9667 for (var i=0, l=nodes.length, p=0, n; (i<l) && (n=nodes[i]); i++) { 9937 for (var i=0, l=nodes.length, p=0, n; (i<l) && (n=nodes[i]); i++) {
9668 if (!this.isParsed(n)) { 9938 if (!this.isParsed(n)) {
9669 if (this.hasResource(n)) { 9939 if (this.hasResource(n)) {
(...skipping 11 matching lines...) Expand all
9681 var doc = node.ownerDocument || node; 9951 var doc = node.ownerDocument || node;
9682 return doc === mainDoc ? this.documentSelectors : this.importsSelectors; 9952 return doc === mainDoc ? this.documentSelectors : this.importsSelectors;
9683 }, 9953 },
9684 isParsed: function(node) { 9954 isParsed: function(node) {
9685 return node.__importParsed; 9955 return node.__importParsed;
9686 }, 9956 },
9687 hasResource: function(node) { 9957 hasResource: function(node) {
9688 if (nodeIsImport(node) && !node.import) { 9958 if (nodeIsImport(node) && !node.import) {
9689 return false; 9959 return false;
9690 } 9960 }
9691 if (node.localName === 'script' && node.src && !node.__resource) {
9692 return false;
9693 }
9694 return true; 9961 return true;
9695 } 9962 }
9696 }; 9963 };
9697 9964
9698 function nodeIsImport(elt) { 9965 function nodeIsImport(elt) {
9699 return (elt.localName === 'link') && (elt.rel === IMPORT_LINK_TYPE); 9966 return (elt.localName === 'link') && (elt.rel === IMPORT_LINK_TYPE);
9700 } 9967 }
9701 9968
9969 function generateScriptDataUrl(script) {
9970 var scriptContent = generateScriptContent(script), b64;
9971 try {
9972 b64 = btoa(scriptContent);
9973 } catch(e) {
9974 b64 = btoa(unescape(encodeURIComponent(scriptContent)));
9975 console.warn('Script contained non-latin characters that were forced ' +
9976 'to latin. Some characters may be wrong.', script);
9977 }
9978 return 'data:text/javascript;base64,' + b64;
9979 }
9980
9981 function generateScriptContent(script) {
9982 return script.textContent + generateSourceMapHint(script);
9983 }
9984
9985 // calculate source map hint
9986 function generateSourceMapHint(script) {
9987 var moniker = script.__nodeUrl;
9988 if (!moniker) {
9989 moniker = script.ownerDocument.baseURI;
9990 // there could be more than one script this url
9991 var tag = '[' + Math.floor((Math.random()+1)*1000) + ']';
9992 // TODO(sjmiles): Polymer hack, should be pluggable if we need to allow
9993 // this sort of thing
9994 var matches = script.textContent.match(/Polymer\(['"]([^'"]*)/);
9995 tag = matches && matches[1] || tag;
9996 // tag the moniker
9997 moniker += '/' + tag + '.js';
9998 }
9999 return '\n//# sourceURL=' + moniker + '\n';
10000 }
10001
9702 // style/stylesheet handling 10002 // style/stylesheet handling
9703 10003
9704 // clone style with proper path resolution for main document 10004 // clone style with proper path resolution for main document
9705 // NOTE: styles are the only elements that require direct path fixup. 10005 // NOTE: styles are the only elements that require direct path fixup.
9706 function cloneStyle(style) { 10006 function cloneStyle(style) {
9707 var clone = style.ownerDocument.createElement('style'); 10007 var clone = style.ownerDocument.createElement('style');
9708 clone.textContent = style.textContent; 10008 clone.textContent = style.textContent;
9709 path.resolveUrlsInStyle(clone); 10009 path.resolveUrlsInStyle(clone);
9710 return clone; 10010 return clone;
9711 } 10011 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
9766 // imports 10066 // imports
9767 var xhr = scope.xhr; 10067 var xhr = scope.xhr;
9768 var Loader = scope.Loader; 10068 var Loader = scope.Loader;
9769 var parser = scope.parser; 10069 var parser = scope.parser;
9770 10070
9771 // importer 10071 // importer
9772 // highlander object to manage loading of imports 10072 // highlander object to manage loading of imports
9773 10073
9774 // for any document, importer: 10074 // for any document, importer:
9775 // - loads any linked import documents (with deduping) 10075 // - loads any linked import documents (with deduping)
9776 // for any import document, importer also:
9777 // - loads text of external script tags
9778 10076
9779 var importer = { 10077 var importer = {
9780 documents: {}, 10078 documents: {},
9781 // nodes to load in the mian document 10079 // nodes to load in the mian document
9782 documentPreloadSelectors: 'link[rel=' + IMPORT_LINK_TYPE + ']', 10080 documentPreloadSelectors: 'link[rel=' + IMPORT_LINK_TYPE + ']',
9783 // nodes to load in imports 10081 // nodes to load in imports
9784 importsPreloadSelectors: [ 10082 importsPreloadSelectors: [
9785 'link[rel=' + IMPORT_LINK_TYPE + ']', 10083 'link[rel=' + IMPORT_LINK_TYPE + ']'
9786 'script[src]:not([type])',
9787 'script[src][type="text/javascript"]'
9788 ].join(','), 10084 ].join(','),
9789 loadNode: function(node) { 10085 loadNode: function(node) {
9790 importLoader.addNode(node); 10086 importLoader.addNode(node);
9791 }, 10087 },
9792 // load all loadable elements within the parent element 10088 // load all loadable elements within the parent element
9793 loadSubtree: function(parent) { 10089 loadSubtree: function(parent) {
9794 var nodes = this.marshalNodes(parent); 10090 var nodes = this.marshalNodes(parent);
9795 // add these nodes to loader's queue 10091 // add these nodes to loader's queue
9796 importLoader.addNodes(nodes); 10092 importLoader.addNodes(nodes);
9797 }, 10093 },
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
9864 } 10160 }
9865 // cache the new document's source url 10161 // cache the new document's source url
9866 doc._URL = url; 10162 doc._URL = url;
9867 // establish a relative path via <base> 10163 // establish a relative path via <base>
9868 var base = doc.createElement('base'); 10164 var base = doc.createElement('base');
9869 base.setAttribute('href', url); 10165 base.setAttribute('href', url);
9870 // add baseURI support to browsers (IE) that lack it. 10166 // add baseURI support to browsers (IE) that lack it.
9871 if (!doc.baseURI) { 10167 if (!doc.baseURI) {
9872 doc.baseURI = url; 10168 doc.baseURI = url;
9873 } 10169 }
10170 // ensure UTF-8 charset
10171 var meta = doc.createElement('meta');
10172 meta.setAttribute('charset', 'utf-8');
10173
10174 doc.head.appendChild(meta);
9874 doc.head.appendChild(base); 10175 doc.head.appendChild(base);
9875 // install HTML last as it may trigger CustomElement upgrades 10176 // install HTML last as it may trigger CustomElement upgrades
9876 // TODO(sjmiles): problem wrt to template boostrapping below, 10177 // TODO(sjmiles): problem wrt to template boostrapping below,
9877 // template bootstrapping must (?) come before element upgrade 10178 // template bootstrapping must (?) come before element upgrade
9878 // but we cannot bootstrap templates until they are in a document 10179 // but we cannot bootstrap templates until they are in a document
9879 // which is too late 10180 // which is too late
9880 if (!(resource instanceof Document)) { 10181 if (!(resource instanceof Document)) {
9881 // install html 10182 // install html
9882 doc.body.innerHTML = resource; 10183 doc.body.innerHTML = resource;
9883 } 10184 }
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
10434 } 10735 }
10435 10736
10436 function upgradeDocument(doc) { 10737 function upgradeDocument(doc) {
10437 logFlags.dom && console.group('upgradeDocument: ', (doc.baseURI).split('/').po p()); 10738 logFlags.dom && console.group('upgradeDocument: ', (doc.baseURI).split('/').po p());
10438 addedNode(doc); 10739 addedNode(doc);
10439 logFlags.dom && console.groupEnd(); 10740 logFlags.dom && console.groupEnd();
10440 } 10741 }
10441 10742
10442 function upgradeDocumentTree(doc) { 10743 function upgradeDocumentTree(doc) {
10443 doc = wrapIfNeeded(doc); 10744 doc = wrapIfNeeded(doc);
10444 upgradeDocument(doc);
10445 //console.log('upgradeDocumentTree: ', (doc.baseURI).split('/').pop()); 10745 //console.log('upgradeDocumentTree: ', (doc.baseURI).split('/').pop());
10446 // upgrade contained imported documents 10746 // upgrade contained imported documents
10447 var imports = doc.querySelectorAll('link[rel=' + IMPORT_LINK_TYPE + ']'); 10747 var imports = doc.querySelectorAll('link[rel=' + IMPORT_LINK_TYPE + ']');
10448 for (var i=0, l=imports.length, n; (i<l) && (n=imports[i]); i++) { 10748 for (var i=0, l=imports.length, n; (i<l) && (n=imports[i]); i++) {
10449 if (n.import && n.import.__parsed) { 10749 if (n.import && n.import.__parsed) {
10450 upgradeDocumentTree(n.import); 10750 upgradeDocumentTree(n.import);
10451 } 10751 }
10452 } 10752 }
10753 upgradeDocument(doc);
10453 } 10754 }
10454 10755
10455 // exports 10756 // exports
10456 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE; 10757 scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
10457 scope.watchShadow = watchShadow; 10758 scope.watchShadow = watchShadow;
10458 scope.upgradeDocumentTree = upgradeDocumentTree; 10759 scope.upgradeDocumentTree = upgradeDocumentTree;
10459 scope.upgradeAll = addedNode; 10760 scope.upgradeAll = addedNode;
10460 scope.upgradeSubtree = addedSubtree; 10761 scope.upgradeSubtree = addedSubtree;
10461 scope.insertedNode = insertedNode; 10762 scope.insertedNode = insertedNode;
10462 10763
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
10716 } 11017 }
10717 } 11018 }
10718 11019
10719 function customMixin(inTarget, inSrc, inNative) { 11020 function customMixin(inTarget, inSrc, inNative) {
10720 // TODO(sjmiles): 'used' allows us to only copy the 'youngest' version of 11021 // TODO(sjmiles): 'used' allows us to only copy the 'youngest' version of
10721 // any property. This set should be precalculated. We also need to 11022 // any property. This set should be precalculated. We also need to
10722 // consider this for supporting 'super'. 11023 // consider this for supporting 'super'.
10723 var used = {}; 11024 var used = {};
10724 // start with inSrc 11025 // start with inSrc
10725 var p = inSrc; 11026 var p = inSrc;
10726 // sometimes the default is HTMLUnknownElement.prototype instead of 11027 // The default is HTMLElement.prototype, so we add a test to avoid mixing in
10727 // HTMLElement.prototype, so we add a test 11028 // native prototypes
10728 // the idea is to avoid mixing in native prototypes, so adding 11029 while (p !== inNative && p !== HTMLElement.prototype) {
10729 // the second test is WLOG
10730 while (p !== inNative && p !== HTMLUnknownElement.prototype) {
10731 var keys = Object.getOwnPropertyNames(p); 11030 var keys = Object.getOwnPropertyNames(p);
10732 for (var i=0, k; k=keys[i]; i++) { 11031 for (var i=0, k; k=keys[i]; i++) {
10733 if (!used[k]) { 11032 if (!used[k]) {
10734 Object.defineProperty(inTarget, k, 11033 Object.defineProperty(inTarget, k,
10735 Object.getOwnPropertyDescriptor(p, k)); 11034 Object.getOwnPropertyDescriptor(p, k));
10736 used[k] = 1; 11035 used[k] = 1;
10737 } 11036 }
10738 } 11037 }
10739 p = Object.getPrototypeOf(p); 11038 p = Object.getPrototypeOf(p);
10740 } 11039 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
10792 function registerDefinition(name, definition) { 11091 function registerDefinition(name, definition) {
10793 registry[name] = definition; 11092 registry[name] = definition;
10794 } 11093 }
10795 11094
10796 function generateConstructor(definition) { 11095 function generateConstructor(definition) {
10797 return function() { 11096 return function() {
10798 return instantiate(definition); 11097 return instantiate(definition);
10799 }; 11098 };
10800 } 11099 }
10801 11100
11101 var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
11102 function createElementNS(namespace, tag, typeExtension) {
11103 // NOTE: we do not support non-HTML elements,
11104 // just call createElementNS for non HTML Elements
11105 if (namespace === HTML_NAMESPACE) {
11106 return createElement(tag, typeExtension);
11107 } else {
11108 return domCreateElementNS(namespace, tag);
11109 }
11110 }
11111
10802 function createElement(tag, typeExtension) { 11112 function createElement(tag, typeExtension) {
10803 // TODO(sjmiles): ignore 'tag' when using 'typeExtension', we could 11113 // TODO(sjmiles): ignore 'tag' when using 'typeExtension', we could
10804 // error check it, or perhaps there should only ever be one argument 11114 // error check it, or perhaps there should only ever be one argument
10805 var definition = getRegisteredDefinition(typeExtension || tag); 11115 var definition = getRegisteredDefinition(typeExtension || tag);
10806 if (definition) { 11116 if (definition) {
10807 if (tag == definition.tag && typeExtension == definition.is) { 11117 if (tag == definition.tag && typeExtension == definition.is) {
10808 return new definition.ctor(); 11118 return new definition.ctor();
10809 } 11119 }
10810 // Handle empty string for type extension. 11120 // Handle empty string for type extension.
10811 if (!typeExtension && !definition.is) { 11121 if (!typeExtension && !definition.is) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
10844 // call original clone 11154 // call original clone
10845 var n = domCloneNode.call(this, deep); 11155 var n = domCloneNode.call(this, deep);
10846 // upgrade the element and subtree 11156 // upgrade the element and subtree
10847 scope.upgradeAll(n); 11157 scope.upgradeAll(n);
10848 // return the clone 11158 // return the clone
10849 return n; 11159 return n;
10850 } 11160 }
10851 // capture native createElement before we override it 11161 // capture native createElement before we override it
10852 11162
10853 var domCreateElement = document.createElement.bind(document); 11163 var domCreateElement = document.createElement.bind(document);
11164 var domCreateElementNS = document.createElementNS.bind(document);
10854 11165
10855 // capture native cloneNode before we override it 11166 // capture native cloneNode before we override it
10856 11167
10857 var domCloneNode = Node.prototype.cloneNode; 11168 var domCloneNode = Node.prototype.cloneNode;
10858 11169
10859 // exports 11170 // exports
10860 11171
10861 document.registerElement = register; 11172 document.registerElement = register;
10862 document.createElement = createElement; // override 11173 document.createElement = createElement; // override
11174 document.createElementNS = createElementNS; // override
10863 Node.prototype.cloneNode = cloneNode; // override 11175 Node.prototype.cloneNode = cloneNode; // override
10864 11176
10865 scope.registry = registry; 11177 scope.registry = registry;
10866 11178
10867 /** 11179 /**
10868 * Upgrade an element to a custom element. Upgrading an element 11180 * Upgrade an element to a custom element. Upgrading an element
10869 * causes the custom prototype to be applied, an `is` attribute 11181 * causes the custom prototype to be applied, an `is` attribute
10870 * to be attached (as needed), and invocation of the `readyCallback`. 11182 * to be attached (as needed), and invocation of the `readyCallback`.
10871 * `upgrade` does nothing if the element is already upgraded, or 11183 * `upgrade` does nothing if the element is already upgraded, or
10872 * if it matches no registered custom tag name. 11184 * if it matches no registered custom tag name.
10873 * 11185 *
10874 * @method ugprade 11186 * @method ugprade
10875 * @param {Element} element The element to upgrade. 11187 * @param {Element} element The element to upgrade.
10876 * @return {Element} The upgraded element. 11188 * @return {Element} The upgraded element.
10877 */ 11189 */
10878 scope.upgrade = upgradeElement; 11190 scope.upgrade = upgradeElement;
10879 } 11191 }
10880 11192
11193 // Create a custom 'instanceof'. This is necessary when CustomElements
11194 // are implemented via a mixin strategy, as for example on IE10.
11195 var isInstance;
11196 if (!Object.__proto__ && !useNative) {
11197 isInstance = function(obj, ctor) {
11198 var p = obj;
11199 while (p) {
11200 // NOTE: this is not technically correct since we're not checking if
11201 // an object is an instance of a constructor; however, this should
11202 // be good enough for the mixin strategy.
11203 if (p === ctor.prototype) {
11204 return true;
11205 }
11206 p = p.__proto__;
11207 }
11208 return false;
11209 }
11210 } else {
11211 isInstance = function(obj, base) {
11212 return obj instanceof base;
11213 }
11214 }
11215
11216 // exports
11217 scope.instanceof = isInstance;
11218
10881 // bc 11219 // bc
10882 document.register = document.registerElement; 11220 document.register = document.registerElement;
10883 11221
10884 scope.hasNative = hasNative; 11222 scope.hasNative = hasNative;
10885 scope.useNative = useNative; 11223 scope.useNative = useNative;
10886 11224
10887 })(window.CustomElements); 11225 })(window.CustomElements);
10888 11226
10889 /* 11227 /*
10890 * Copyright 2013 The Polymer Authors. All rights reserved. 11228 * Copyright 2013 The Polymer Authors. All rights reserved.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
11019 11357
11020 })(window.CustomElements); 11358 })(window.CustomElements);
11021 11359
11022 /* 11360 /*
11023 * Copyright 2013 The Polymer Authors. All rights reserved. 11361 * Copyright 2013 The Polymer Authors. All rights reserved.
11024 * Use of this source code is governed by a BSD-style 11362 * Use of this source code is governed by a BSD-style
11025 * license that can be found in the LICENSE file. 11363 * license that can be found in the LICENSE file.
11026 */ 11364 */
11027 (function() { 11365 (function() {
11028 11366
11029 // inject style sheet
11030 var style = document.createElement('style');
11031 style.textContent = 'element {display: none !important;} /* injected by platform .js */';
11032 var head = document.querySelector('head');
11033 head.insertBefore(style, head.firstChild);
11034
11035 if (window.ShadowDOMPolyfill) { 11367 if (window.ShadowDOMPolyfill) {
11036 11368
11037 // ensure wrapped inputs for these functions 11369 // ensure wrapped inputs for these functions
11038 var fns = ['upgradeAll', 'upgradeSubtree', 'observeDocument', 11370 var fns = ['upgradeAll', 'upgradeSubtree', 'observeDocument',
11039 'upgradeDocument']; 11371 'upgradeDocument'];
11040 11372
11041 // cache originals 11373 // cache originals
11042 var original = {}; 11374 var original = {};
11043 fns.forEach(function(fn) { 11375 fns.forEach(function(fn) {
11044 original[fn] = CustomElements[fn]; 11376 original[fn] = CustomElements[fn];
11045 }); 11377 });
11046 11378
11047 // override 11379 // override
11048 fns.forEach(function(fn) { 11380 fns.forEach(function(fn) {
11049 CustomElements[fn] = function(inNode) { 11381 CustomElements[fn] = function(inNode) {
11050 return original[fn](wrap(inNode)); 11382 return original[fn](wrap(inNode));
11051 }; 11383 };
11052 }); 11384 });
11053 11385
11054 } 11386 }
11055 11387
11056 })(); 11388 })();
11057 11389
11058 /* 11390 /*
11059 * Copyright 2014 The Polymer Authors. All rights reserved. 11391 * Copyright 2014 The Polymer Authors. All rights reserved.
11060 * Use of this source code is governed by a BSD-style 11392 * Use of this source code is governed by a BSD-style
11061 * license that can be found in the LICENSE file. 11393 * license that can be found in the LICENSE file.
11062 */ 11394 */
11063 (function(scope) { 11395 (function(scope) {
11396 var endOfMicrotask = scope.endOfMicrotask;
11397
11398 // Generic url loader
11399 function Loader(regex) {
11400 this.regex = regex;
11401 }
11402 Loader.prototype = {
11403 // TODO(dfreedm): there may be a better factoring here
11404 // extract absolute urls from the text (full of relative urls)
11405 extractUrls: function(text, base) {
11406 var matches = [];
11407 var matched, u;
11408 while ((matched = this.regex.exec(text))) {
11409 u = new URL(matched[1], base);
11410 matches.push({matched: matched[0], url: u.href});
11411 }
11412 return matches;
11413 },
11414 // take a text blob, a root url, and a callback and load all the urls found within the text
11415 // returns a map of absolute url to text
11416 process: function(text, root, callback) {
11417 var matches = this.extractUrls(text, root);
11418 this.fetch(matches, {}, callback);
11419 },
11420 // build a mapping of url -> text from matches
11421 fetch: function(matches, map, callback) {
11422 var inflight = matches.length;
11423
11424 // return early if there is no fetching to be done
11425 if (!inflight) {
11426 return callback(map);
11427 }
11428
11429 var done = function() {
11430 if (--inflight === 0) {
11431 callback(map);
11432 }
11433 };
11434
11435 // map url -> responseText
11436 var handleXhr = function(err, request) {
11437 var match = request.match;
11438 var key = match.url;
11439 // handle errors with an empty string
11440 if (err) {
11441 map[key] = '';
11442 return done();
11443 }
11444 var response = request.response || request.responseText;
11445 map[key] = response;
11446 this.fetch(this.extractUrls(response, key), map, done);
11447 };
11448
11449 var m, req, url;
11450 for (var i = 0; i < inflight; i++) {
11451 m = matches[i];
11452 url = m.url;
11453 // if this url has already been requested, skip requesting it again
11454 if (map[url]) {
11455 // Async call to done to simplify the inflight logic
11456 endOfMicrotask(done);
11457 continue;
11458 }
11459 req = this.xhr(url, handleXhr, this);
11460 req.match = m;
11461 // tag the map with an XHR request to deduplicate at the same level
11462 map[url] = req;
11463 }
11464 },
11465 xhr: function(url, callback, scope) {
11466 var request = new XMLHttpRequest();
11467 request.open('GET', url, true);
11468 request.send();
11469 request.onload = function() {
11470 callback.call(scope, null, request);
11471 };
11472 request.onerror = function() {
11473 callback.call(scope, null, request);
11474 };
11475 return request;
11476 }
11477 };
11478
11479 scope.Loader = Loader;
11480 })(window.Platform);
11481
11482 /*
11483 * Copyright 2014 The Polymer Authors. All rights reserved.
11484 * Use of this source code is governed by a BSD-style
11485 * license that can be found in the LICENSE file.
11486 */
11487 (function(scope) {
11064 11488
11065 var STYLE_SELECTOR = 'style'; 11489 var urlResolver = scope.urlResolver;
11490 var Loader = scope.Loader;
11066 11491
11067 var urlResolver = scope.urlResolver; 11492 function StyleResolver() {
11068 11493 this.loader = new Loader(this.regex);
11069 var loader = { 11494 }
11070 cacheStyles: function(styles, callback) { 11495 StyleResolver.prototype = {
11071 var css = []; 11496 regex: /@import\s+(?:url)?["'\(]*([^'"\)]*)['"\)]*;/g,
11072 for (var i=0, l=styles.length, s; (i<l) && (s=styles[i]); i++) { 11497 // Recursively replace @imports with the text at that url
11073 css.push(s.textContent); 11498 resolve: function(text, url, callback) {
11499 var done = function(map) {
11500 callback(this.flatten(text, url, map));
11501 }.bind(this);
11502 this.loader.process(text, url, done);
11503 },
11504 // resolve the textContent of a style node
11505 resolveNode: function(style, callback) {
11506 var text = style.textContent;
11507 var url = style.ownerDocument.baseURI;
11508 var done = function(text) {
11509 style.textContent = text;
11510 callback(style);
11511 };
11512 this.resolve(text, url, done);
11513 },
11514 // flatten all the @imports to text
11515 flatten: function(text, base, map) {
11516 var matches = this.loader.extractUrls(text, base);
11517 var match, url, intermediate;
11518 for (var i = 0; i < matches.length; i++) {
11519 match = matches[i];
11520 url = match.url;
11521 // resolve any css text to be relative to the importer
11522 intermediate = urlResolver.resolveCssText(map[url], url);
11523 // flatten intermediate @imports
11524 intermediate = this.flatten(intermediate, url, map);
11525 text = text.replace(match.matched, intermediate);
11074 } 11526 }
11075 cacheCssText(css.join('\n'), callback); 11527 return text;
11076 }, 11528 },
11077 xhrStyles: function(styles, callback) { 11529 loadStyles: function(styles, callback) {
11078 var loaded=0, l = styles.length; 11530 var loaded=0, l = styles.length;
11079 // called in the context of the style 11531 // called in the context of the style
11080 function loadedStyle(style) { 11532 function loadedStyle(style) {
11081 //console.log(style.textContent);
11082 loaded++; 11533 loaded++;
11083 if (loaded === l && callback) { 11534 if (loaded === l && callback) {
11084 callback(); 11535 callback();
11085 } 11536 }
11086 } 11537 }
11087 for (var i=0, s; (i<l) && (s=styles[i]); i++) { 11538 for (var i=0, s; (i<l) && (s=styles[i]); i++) {
11088 xhrLoadStyle(s, loadedStyle); 11539 this.resolveNode(s, loadedStyle);
11089 } 11540 }
11090 } 11541 }
11091 }; 11542 };
11092 11543
11093 // use the platform to preload styles 11544 var styleResolver = new StyleResolver();
11094 var preloadElement = document.createElement('preloader');
11095 preloadElement.style.display = 'none';
11096 var preloadRoot = preloadElement.createShadowRoot();
11097 document.head.appendChild(preloadElement);
11098
11099 function cacheCssText(cssText, callback) {
11100 var style = createStyleElement(cssText);
11101 if (callback) {
11102 style.addEventListener('load', callback);
11103 style.addEventListener('error', callback);
11104 }
11105 preloadRoot.appendChild(style);
11106 }
11107
11108 function createStyleElement(cssText, scope) {
11109 scope = scope || document;
11110 scope = scope.createElement ? scope : scope.ownerDocument;
11111 var style = scope.createElement('style');
11112 style.textContent = cssText;
11113 return style;
11114 }
11115
11116 // TODO(sorvell): use a common loader shared with HTMLImports polyfill
11117 // currently, this just loads the first @import per style element
11118 // and does not recurse into loaded elements; we'll address this with a
11119 // generalized loader that's built out of the one in the HTMLImports polyfill.
11120 // polyfill the loading of a style element's @import via xhr
11121 function xhrLoadStyle(style, callback) {
11122 HTMLImports.xhr.load(atImportUrlFromStyle(style), function (err, resource,
11123 url) {
11124 replaceAtImportWithCssText(this, url, resource);
11125 this.textContent = urlResolver.resolveCssText(this.textContent, url);
11126 callback && callback(this);
11127 }, style);
11128 }
11129
11130 var atImportRe = /@import\s[(]?['"]?([^\s'";)]*)/;
11131
11132 // get the first @import rule from a style
11133 function atImportUrlFromStyle(style) {
11134 var matches = style.textContent.match(atImportRe);
11135 return matches && matches[1];
11136 }
11137
11138 function replaceAtImportWithCssText(style, url, cssText) {
11139 var re = new RegExp('@import[^;]*' + url + '[^;]*;', 'i');
11140 style.textContent = style.textContent.replace(re, cssText);
11141 }
11142 11545
11143 // exports 11546 // exports
11144 scope.loader = loader; 11547 scope.styleResolver = styleResolver;
11145 11548
11146 })(window.Platform); 11549 })(window.Platform);
11147 11550
11148 /* 11551 /*
11149 * Copyright 2013 The Polymer Authors. All rights reserved. 11552 * Copyright 2013 The Polymer Authors. All rights reserved.
11150 * Use of this source code is governed by a BSD-style 11553 * Use of this source code is governed by a BSD-style
11151 * license that can be found in the LICENSE file. 11554 * license that can be found in the LICENSE file.
11152 */ 11555 */
11153 11556
11154 (function(scope) { 11557 (function(scope) {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
11643 for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) { 12046 for (var i = 0, es; (i < l) && (es = this.eventSourceList[i]); i++) {
11644 // call eventsource register 12047 // call eventsource register
11645 es.unregister.call(es, element); 12048 es.unregister.call(es, element);
11646 } 12049 }
11647 }, 12050 },
11648 contains: scope.external.contains || function(container, contained) { 12051 contains: scope.external.contains || function(container, contained) {
11649 return container.contains(contained); 12052 return container.contains(contained);
11650 }, 12053 },
11651 // EVENTS 12054 // EVENTS
11652 down: function(inEvent) { 12055 down: function(inEvent) {
12056 inEvent.bubbles = true;
11653 this.fireEvent('pointerdown', inEvent); 12057 this.fireEvent('pointerdown', inEvent);
11654 }, 12058 },
11655 move: function(inEvent) { 12059 move: function(inEvent) {
12060 inEvent.bubbles = true;
11656 this.fireEvent('pointermove', inEvent); 12061 this.fireEvent('pointermove', inEvent);
11657 }, 12062 },
11658 up: function(inEvent) { 12063 up: function(inEvent) {
12064 inEvent.bubbles = true;
11659 this.fireEvent('pointerup', inEvent); 12065 this.fireEvent('pointerup', inEvent);
11660 }, 12066 },
11661 enter: function(inEvent) { 12067 enter: function(inEvent) {
11662 inEvent.bubbles = false; 12068 inEvent.bubbles = false;
11663 this.fireEvent('pointerenter', inEvent); 12069 this.fireEvent('pointerenter', inEvent);
11664 }, 12070 },
11665 leave: function(inEvent) { 12071 leave: function(inEvent) {
11666 inEvent.bubbles = false; 12072 inEvent.bubbles = false;
11667 this.fireEvent('pointerleave', inEvent); 12073 this.fireEvent('pointerleave', inEvent);
11668 }, 12074 },
11669 over: function(inEvent) { 12075 over: function(inEvent) {
11670 inEvent.bubbles = true; 12076 inEvent.bubbles = true;
11671 this.fireEvent('pointerover', inEvent); 12077 this.fireEvent('pointerover', inEvent);
11672 }, 12078 },
11673 out: function(inEvent) { 12079 out: function(inEvent) {
11674 inEvent.bubbles = true; 12080 inEvent.bubbles = true;
11675 this.fireEvent('pointerout', inEvent); 12081 this.fireEvent('pointerout', inEvent);
11676 }, 12082 },
11677 cancel: function(inEvent) { 12083 cancel: function(inEvent) {
12084 inEvent.bubbles = true;
11678 this.fireEvent('pointercancel', inEvent); 12085 this.fireEvent('pointercancel', inEvent);
11679 }, 12086 },
11680 leaveOut: function(event) { 12087 leaveOut: function(event) {
11681 this.out(event); 12088 this.out(event);
11682 if (!this.contains(event.target, event.relatedTarget)) { 12089 if (!this.contains(event.target, event.relatedTarget)) {
11683 this.leave(event); 12090 this.leave(event);
11684 } 12091 }
11685 }, 12092 },
11686 enterOver: function(event) { 12093 enterOver: function(event) {
11687 this.over(event); 12094 this.over(event);
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
12991 */ 13398 */
12992 13399
12993 /** 13400 /**
12994 * This event is fired when a pointer is held down for 200ms. 13401 * This event is fired when a pointer is held down for 200ms.
12995 * 13402 *
12996 * @module PointerGestures 13403 * @module PointerGestures
12997 * @submodule Events 13404 * @submodule Events
12998 * @class hold 13405 * @class hold
12999 */ 13406 */
13000 /** 13407 /**
13001 * Milliseconds pointer has been held down. 13408 * Type of pointer that made the holding event.
13409 * @type String
13410 * @property pointerType
13411 */
13412 /**
13413 * Screen X axis position of the held pointer
13002 * @type Number 13414 * @type Number
13003 * @property holdTime 13415 * @property clientX
13416 */
13417 /**
13418 * Screen Y axis position of the held pointer
13419 * @type Number
13420 * @property clientY
13004 */ 13421 */
13005 /** 13422 /**
13006 * Type of pointer that made the holding event. 13423 * Type of pointer that made the holding event.
13007 * @type String 13424 * @type String
13008 * @property pointerType 13425 * @property pointerType
13009 */ 13426 */
13010 /** 13427 /**
13011 * This event is fired every 200ms while a pointer is held down. 13428 * This event is fired every 200ms while a pointer is held down.
13012 * 13429 *
13013 * @class holdpulse 13430 * @class holdpulse
13014 * @extends hold 13431 * @extends hold
13015 */ 13432 */
13016 /** 13433 /**
13434 * Milliseconds pointer has been held down.
13435 * @type Number
13436 * @property holdTime
13437 */
13438 /**
13017 * This event is fired when a held pointer is released or moved. 13439 * This event is fired when a held pointer is released or moved.
13018 * 13440 *
13019 * @class released 13441 * @class released
13020 */ 13442 */
13021 /**
13022 * Type of pointer that made the holding event.
13023 * @type String
13024 * @property pointerType
13025 */
13026 13443
13027 (function(scope) { 13444 (function(scope) {
13028 var dispatcher = scope.dispatcher; 13445 var dispatcher = scope.dispatcher;
13029 var hold = { 13446 var hold = {
13030 // wait at least HOLD_DELAY ms between hold and pulse events 13447 // wait at least HOLD_DELAY ms between hold and pulse events
13031 HOLD_DELAY: 200, 13448 HOLD_DELAY: 200,
13032 // pointer can move WIGGLE_THRESHOLD pixels before not counting as a hold 13449 // pointer can move WIGGLE_THRESHOLD pixels before not counting as a hold
13033 WIGGLE_THRESHOLD: 16, 13450 WIGGLE_THRESHOLD: 16,
13034 events: [ 13451 events: [
13035 'pointerdown', 13452 'pointerdown',
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
13074 if (this.heldPointer && this.heldPointer.pointerId === inEvent.pointerId) { 13491 if (this.heldPointer && this.heldPointer.pointerId === inEvent.pointerId) {
13075 var x = inEvent.clientX - this.heldPointer.clientX; 13492 var x = inEvent.clientX - this.heldPointer.clientX;
13076 var y = inEvent.clientY - this.heldPointer.clientY; 13493 var y = inEvent.clientY - this.heldPointer.clientY;
13077 if ((x * x + y * y) > this.WIGGLE_THRESHOLD) { 13494 if ((x * x + y * y) > this.WIGGLE_THRESHOLD) {
13078 this.cancel(); 13495 this.cancel();
13079 } 13496 }
13080 } 13497 }
13081 }, 13498 },
13082 fireHold: function(inType, inHoldTime) { 13499 fireHold: function(inType, inHoldTime) {
13083 var p = { 13500 var p = {
13084 pointerType: this.heldPointer.pointerType 13501 pointerType: this.heldPointer.pointerType,
13502 clientX: this.heldPointer.clientX,
13503 clientY: this.heldPointer.clientY
13085 }; 13504 };
13086 if (inHoldTime) { 13505 if (inHoldTime) {
13087 p.holdTime = inHoldTime; 13506 p.holdTime = inHoldTime;
13088 } 13507 }
13089 var e = dispatcher.makeEvent(inType, p); 13508 var e = dispatcher.makeEvent(inType, p);
13090 dispatcher.dispatchEvent(e, this.target); 13509 dispatcher.dispatchEvent(e, this.target);
13091 if (e.tapPrevented) { 13510 if (e.tapPrevented) {
13092 dispatcher.preventTap(this.heldPointer.pointerId); 13511 dispatcher.preventTap(this.heldPointer.pointerId);
13093 } 13512 }
13094 } 13513 }
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
13641 pointermove: function(inEvent) { 14060 pointermove: function(inEvent) {
13642 if (inEvent.isPrimary) { 14061 if (inEvent.isPrimary) {
13643 var start = pointermap.get(inEvent.pointerId); 14062 var start = pointermap.get(inEvent.pointerId);
13644 if (start) { 14063 if (start) {
13645 if (inEvent.tapPrevented) { 14064 if (inEvent.tapPrevented) {
13646 pointermap.delete(inEvent.pointerId); 14065 pointermap.delete(inEvent.pointerId);
13647 } 14066 }
13648 } 14067 }
13649 } 14068 }
13650 }, 14069 },
14070 shouldTap: function(e) {
14071 if (!e.tapPrevented) {
14072 // only allow left click to tap for mouse
14073 return e.pointerType === 'mouse' ? e.buttons === 1 : true;
14074 }
14075 },
13651 pointerup: function(inEvent) { 14076 pointerup: function(inEvent) {
13652 var start = pointermap.get(inEvent.pointerId); 14077 var start = pointermap.get(inEvent.pointerId);
13653 if (start && !inEvent.tapPrevented) { 14078 if (start && this.shouldTap(inEvent)) {
13654 var t = scope.findLCA(start.target, inEvent.target); 14079 var t = scope.findLCA(start.target, inEvent.target);
13655 if (t) { 14080 if (t) {
13656 var e = dispatcher.makeEvent('tap', { 14081 var e = dispatcher.makeEvent('tap', {
13657 x: inEvent.clientX, 14082 x: inEvent.clientX,
13658 y: inEvent.clientY, 14083 y: inEvent.clientY,
13659 detail: inEvent.detail, 14084 detail: inEvent.detail,
13660 pointerType: inEvent.pointerType 14085 pointerType: inEvent.pointerType
13661 }); 14086 });
13662 dispatcher.dispatchEvent(e, t); 14087 dispatcher.dispatchEvent(e, t);
13663 } 14088 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
13869 })(); 14294 })();
13870 14295
13871 function getEventForInputType(element) { 14296 function getEventForInputType(element) {
13872 switch (element.type) { 14297 switch (element.type) {
13873 case 'checkbox': 14298 case 'checkbox':
13874 return checkboxEventType; 14299 return checkboxEventType;
13875 case 'radio': 14300 case 'radio':
13876 case 'select-multiple': 14301 case 'select-multiple':
13877 case 'select-one': 14302 case 'select-one':
13878 return 'change'; 14303 return 'change';
14304 case 'range':
14305 if (/Trident|MSIE/.test(navigator.userAgent))
14306 return 'change';
13879 default: 14307 default:
13880 return 'input'; 14308 return 'input';
13881 } 14309 }
13882 } 14310 }
13883 14311
13884 function updateInput(input, property, value, santizeFn) { 14312 function updateInput(input, property, value, santizeFn) {
13885 input[property] = (santizeFn || sanitizeValue)(value); 14313 input[property] = (santizeFn || sanitizeValue)(value);
13886 } 14314 }
13887 14315
13888 function inputBinding(input, property, santizeFn) { 14316 function inputBinding(input, property, santizeFn) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
14221 'TR': true, 14649 'TR': true,
14222 'TD': true, 14650 'TD': true,
14223 'COLGROUP': true, 14651 'COLGROUP': true,
14224 'COL': true, 14652 'COL': true,
14225 'CAPTION': true, 14653 'CAPTION': true,
14226 'OPTION': true, 14654 'OPTION': true,
14227 'OPTGROUP': true 14655 'OPTGROUP': true
14228 }; 14656 };
14229 14657
14230 var hasTemplateElement = typeof HTMLTemplateElement !== 'undefined'; 14658 var hasTemplateElement = typeof HTMLTemplateElement !== 'undefined';
14659 if (hasTemplateElement) {
14660 // TODO(rafaelw): Remove when fix for
14661 // https://codereview.chromium.org/164803002/
14662 // makes it to Chrome release.
14663 (function() {
14664 var t = document.createElement('template');
14665 var d = t.content.ownerDocument;
14666 var html = d.appendChild(d.createElement('html'));
14667 var head = html.appendChild(d.createElement('head'));
14668 var base = d.createElement('base');
14669 base.href = document.baseURI;
14670 head.appendChild(base);
14671 })();
14672 }
14231 14673
14232 var allTemplatesSelectors = 'template, ' + 14674 var allTemplatesSelectors = 'template, ' +
14233 Object.keys(semanticTemplateElements).map(function(tagName) { 14675 Object.keys(semanticTemplateElements).map(function(tagName) {
14234 return tagName.toLowerCase() + '[template]'; 14676 return tagName.toLowerCase() + '[template]';
14235 }).join(', '); 14677 }).join(', ');
14236 14678
14237 function isSVGTemplate(el) { 14679 function isSVGTemplate(el) {
14238 return el.tagName == 'template' && 14680 return el.tagName == 'template' &&
14239 el.namespaceURI == 'http://www.w3.org/2000/svg'; 14681 el.namespaceURI == 'http://www.w3.org/2000/svg';
14240 } 14682 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
14318 doc.templateContentsOwner_ = d; 14760 doc.templateContentsOwner_ = d;
14319 } 14761 }
14320 return d; 14762 return d;
14321 } 14763 }
14322 14764
14323 function getTemplateStagingDocument(template) { 14765 function getTemplateStagingDocument(template) {
14324 if (!template.stagingDocument_) { 14766 if (!template.stagingDocument_) {
14325 var owner = template.ownerDocument; 14767 var owner = template.ownerDocument;
14326 if (!owner.stagingDocument_) { 14768 if (!owner.stagingDocument_) {
14327 owner.stagingDocument_ = owner.implementation.createHTMLDocument(''); 14769 owner.stagingDocument_ = owner.implementation.createHTMLDocument('');
14770
14771 // TODO(rafaelw): Remove when fix for
14772 // https://codereview.chromium.org/164803002/
14773 // makes it to Chrome release.
14774 var base = owner.stagingDocument_.createElement('base');
14775 base.href = document.baseURI;
14776 owner.stagingDocument_.head.appendChild(base);
14777
14328 owner.stagingDocument_.stagingDocument_ = owner.stagingDocument_; 14778 owner.stagingDocument_.stagingDocument_ = owner.stagingDocument_;
14329 } 14779 }
14330 14780
14331 template.stagingDocument_ = owner.stagingDocument_; 14781 template.stagingDocument_ = owner.stagingDocument_;
14332 } 14782 }
14333 14783
14334 return template.stagingDocument_; 14784 return template.stagingDocument_;
14335 } 14785 }
14336 14786
14337 // For non-template browsers, the parser will disallow <template> in certain 14787 // For non-template browsers, the parser will disallow <template> in certain
(...skipping 2688 matching lines...) Expand 10 before | Expand all | Expand 10 after
17026 } 17476 }
17027 } 17477 }
17028 17478
17029 // exports 17479 // exports
17030 scope.flush = flush; 17480 scope.flush = flush;
17031 17481
17032 })(window.Platform); 17482 })(window.Platform);
17033 17483
17034 17484
17035 //# sourceMappingURL=platform.concat.js.map 17485 //# sourceMappingURL=platform.concat.js.map
OLDNEW
« no previous file with comments | « pkg/web_components/lib/platform.js ('k') | pkg/web_components/lib/platform.concat.js.map » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698