webcomponentsjs-rails 0.7.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.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/CONTRIBUTORS.txt
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/PATENTS.txt
9
+ */
10
+ // @version 0.7.12
11
+ "undefined"==typeof WeakMap&&!function(){var e=Object.defineProperty,t=Date.now()%1e9,n=function(){this.name="__st"+(1e9*Math.random()>>>0)+(t++ +"__")};n.prototype={set:function(t,n){var o=t[this.name];return o&&o[0]===t?o[1]=n:e(t,this.name,{value:[t,n],writable:!0}),this},get:function(e){var t;return(t=e[this.name])&&t[0]===e?t[1]:void 0},"delete":function(e){var t=e[this.name];return t&&t[0]===e?(t[0]=t[1]=void 0,!0):!1},has:function(e){var t=e[this.name];return t?t[0]===e:!1}},window.WeakMap=n}(),function(e){function t(e){_.push(e),b||(b=!0,w(o))}function n(e){return window.ShadowDOMPolyfill&&window.ShadowDOMPolyfill.wrapIfNeeded(e)||e}function o(){b=!1;var e=_;_=[],e.sort(function(e,t){return e.uid_-t.uid_});var t=!1;e.forEach(function(e){var n=e.takeRecords();r(e),n.length&&(e.callback_(n,e),t=!0)}),t&&o()}function r(e){e.nodes_.forEach(function(t){var n=h.get(t);n&&n.forEach(function(t){t.observer===e&&t.removeTransientObservers()})})}function i(e,t){for(var n=e;n;n=n.parentNode){var o=h.get(n);if(o)for(var r=0;r<o.length;r++){var i=o[r],a=i.options;if(n===e||a.subtree){var d=t(a);d&&i.enqueue(d)}}}}function a(e){this.callback_=e,this.nodes_=[],this.records_=[],this.uid_=++E}function d(e,t){this.type=e,this.target=t,this.addedNodes=[],this.removedNodes=[],this.previousSibling=null,this.nextSibling=null,this.attributeName=null,this.attributeNamespace=null,this.oldValue=null}function s(e){var t=new d(e.type,e.target);return t.addedNodes=e.addedNodes.slice(),t.removedNodes=e.removedNodes.slice(),t.previousSibling=e.previousSibling,t.nextSibling=e.nextSibling,t.attributeName=e.attributeName,t.attributeNamespace=e.attributeNamespace,t.oldValue=e.oldValue,t}function u(e,t){return y=new d(e,t)}function c(e){return N?N:(N=s(y),N.oldValue=e,N)}function f(){y=N=void 0}function l(e){return e===N||e===y}function p(e,t){return e===t?e:N&&l(e)?N:null}function m(e,t,n){this.observer=e,this.target=t,this.options=n,this.transientObservedNodes=[]}var w,h=new WeakMap;if(/Trident|Edge/.test(navigator.userAgent))w=setTimeout;else if(window.setImmediate)w=window.setImmediate;else{var v=[],g=String(Math.random());window.addEventListener("message",function(e){if(e.data===g){var t=v;v=[],t.forEach(function(e){e()})}}),w=function(e){v.push(e),window.postMessage(g,"*")}}var b=!1,_=[],E=0;a.prototype={observe:function(e,t){if(e=n(e),!t.childList&&!t.attributes&&!t.characterData||t.attributeOldValue&&!t.attributes||t.attributeFilter&&t.attributeFilter.length&&!t.attributes||t.characterDataOldValue&&!t.characterData)throw new SyntaxError;var o=h.get(e);o||h.set(e,o=[]);for(var r,i=0;i<o.length;i++)if(o[i].observer===this){r=o[i],r.removeListeners(),r.options=t;break}r||(r=new m(this,e,t),o.push(r),this.nodes_.push(e)),r.addListeners()},disconnect:function(){this.nodes_.forEach(function(e){for(var t=h.get(e),n=0;n<t.length;n++){var o=t[n];if(o.observer===this){o.removeListeners(),t.splice(n,1);break}}},this),this.records_=[]},takeRecords:function(){var e=this.records_;return this.records_=[],e}};var y,N;m.prototype={enqueue:function(e){var n=this.observer.records_,o=n.length;if(n.length>0){var r=n[o-1],i=p(r,e);if(i)return void(n[o-1]=i)}else t(this.observer);n[o]=e},addListeners:function(){this.addListeners_(this.target)},addListeners_:function(e){var t=this.options;t.attributes&&e.addEventListener("DOMAttrModified",this,!0),t.characterData&&e.addEventListener("DOMCharacterDataModified",this,!0),t.childList&&e.addEventListener("DOMNodeInserted",this,!0),(t.childList||t.subtree)&&e.addEventListener("DOMNodeRemoved",this,!0)},removeListeners:function(){this.removeListeners_(this.target)},removeListeners_:function(e){var t=this.options;t.attributes&&e.removeEventListener("DOMAttrModified",this,!0),t.characterData&&e.removeEventListener("DOMCharacterDataModified",this,!0),t.childList&&e.removeEventListener("DOMNodeInserted",this,!0),(t.childList||t.subtree)&&e.removeEventListener("DOMNodeRemoved",this,!0)},addTransientObserver:function(e){if(e!==this.target){this.addListeners_(e),this.transientObservedNodes.push(e);var t=h.get(e);t||h.set(e,t=[]),t.push(this)}},removeTransientObservers:function(){var e=this.transientObservedNodes;this.transientObservedNodes=[],e.forEach(function(e){this.removeListeners_(e);for(var t=h.get(e),n=0;n<t.length;n++)if(t[n]===this){t.splice(n,1);break}},this)},handleEvent:function(e){switch(e.stopImmediatePropagation(),e.type){case"DOMAttrModified":var t=e.attrName,n=e.relatedNode.namespaceURI,o=e.target,r=new u("attributes",o);r.attributeName=t,r.attributeNamespace=n;var a=e.attrChange===MutationEvent.ADDITION?null:e.prevValue;i(o,function(e){return!e.attributes||e.attributeFilter&&e.attributeFilter.length&&-1===e.attributeFilter.indexOf(t)&&-1===e.attributeFilter.indexOf(n)?void 0:e.attributeOldValue?c(a):r});break;case"DOMCharacterDataModified":var o=e.target,r=u("characterData",o),a=e.prevValue;i(o,function(e){return e.characterData?e.characterDataOldValue?c(a):r:void 0});break;case"DOMNodeRemoved":this.addTransientObserver(e.target);case"DOMNodeInserted":var d,s,l=e.target;"DOMNodeInserted"===e.type?(d=[l],s=[]):(d=[],s=[l]);var p=l.previousSibling,m=l.nextSibling,r=u("childList",e.target.parentNode);r.addedNodes=d,r.removedNodes=s,r.previousSibling=p,r.nextSibling=m,i(e.relatedNode,function(e){return e.childList?r:void 0})}f()}},e.JsMutationObserver=a,e.MutationObserver||(e.MutationObserver=a)}(window),window.CustomElements=window.CustomElements||{flags:{}},function(e){var t=e.flags,n=[],o=function(e){n.push(e)},r=function(){n.forEach(function(t){t(e)})};e.addModule=o,e.initializeModules=r,e.hasNative=Boolean(document.registerElement),e.isIE=/Trident/.test(navigator.userAgent),e.useNative=!t.register&&e.hasNative&&!window.ShadowDOMPolyfill&&(!window.HTMLImports||window.HTMLImports.useNative)}(window.CustomElements),window.CustomElements.addModule(function(e){function t(e,t){n(e,function(e){return t(e)?!0:void o(e,t)}),o(e,t)}function n(e,t,o){var r=e.firstElementChild;if(!r)for(r=e.firstChild;r&&r.nodeType!==Node.ELEMENT_NODE;)r=r.nextSibling;for(;r;)t(r,o)!==!0&&n(r,t,o),r=r.nextElementSibling;return null}function o(e,n){for(var o=e.shadowRoot;o;)t(o,n),o=o.olderShadowRoot}function r(e,t){i(e,t,[])}function i(e,t,n){if(e=window.wrap(e),!(n.indexOf(e)>=0)){n.push(e);for(var o,r=e.querySelectorAll("link[rel="+a+"]"),d=0,s=r.length;s>d&&(o=r[d]);d++)o["import"]&&i(o["import"],t,n);t(e)}}var a=window.HTMLImports?window.HTMLImports.IMPORT_LINK_TYPE:"none";e.forDocumentTree=r,e.forSubtree=t}),window.CustomElements.addModule(function(e){function t(e,t){return n(e,t)||o(e,t)}function n(t,n){return e.upgrade(t,n)?!0:void(n&&a(t))}function o(e,t){b(e,function(e){return n(e,t)?!0:void 0})}function r(e){N.push(e),y||(y=!0,setTimeout(i))}function i(){y=!1;for(var e,t=N,n=0,o=t.length;o>n&&(e=t[n]);n++)e();N=[]}function a(e){E?r(function(){d(e)}):d(e)}function d(e){e.__upgraded__&&!e.__attached&&(e.__attached=!0,e.attachedCallback&&e.attachedCallback())}function s(e){u(e),b(e,function(e){u(e)})}function u(e){E?r(function(){c(e)}):c(e)}function c(e){e.__upgraded__&&e.__attached&&(e.__attached=!1,e.detachedCallback&&e.detachedCallback())}function f(e){for(var t=e,n=window.wrap(document);t;){if(t==n)return!0;t=t.parentNode||t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&t.host}}function l(e){if(e.shadowRoot&&!e.shadowRoot.__watched){g.dom&&console.log("watching shadow-root for: ",e.localName);for(var t=e.shadowRoot;t;)w(t),t=t.olderShadowRoot}}function p(e,n){if(g.dom){var o=n[0];if(o&&"childList"===o.type&&o.addedNodes&&o.addedNodes){for(var r=o.addedNodes[0];r&&r!==document&&!r.host;)r=r.parentNode;var i=r&&(r.URL||r._URL||r.host&&r.host.localName)||"";i=i.split("/?").shift().split("/").pop()}console.group("mutations (%d) [%s]",n.length,i||"")}var a=f(e);n.forEach(function(e){"childList"===e.type&&(M(e.addedNodes,function(e){e.localName&&t(e,a)}),M(e.removedNodes,function(e){e.localName&&s(e)}))}),g.dom&&console.groupEnd()}function m(e){for(e=window.wrap(e),e||(e=window.wrap(document));e.parentNode;)e=e.parentNode;var t=e.__observer;t&&(p(e,t.takeRecords()),i())}function w(e){if(!e.__observer){var t=new MutationObserver(p.bind(this,e));t.observe(e,{childList:!0,subtree:!0}),e.__observer=t}}function h(e){e=window.wrap(e),g.dom&&console.group("upgradeDocument: ",e.baseURI.split("/").pop());var n=e===window.wrap(document);t(e,n),w(e),g.dom&&console.groupEnd()}function v(e){_(e,h)}var g=e.flags,b=e.forSubtree,_=e.forDocumentTree,E=!window.MutationObserver||window.MutationObserver===window.JsMutationObserver;e.hasPolyfillMutations=E;var y=!1,N=[],M=Array.prototype.forEach.call.bind(Array.prototype.forEach),O=Element.prototype.createShadowRoot;O&&(Element.prototype.createShadowRoot=function(){var e=O.call(this);return window.CustomElements.watchShadow(this),e}),e.watchShadow=l,e.upgradeDocumentTree=v,e.upgradeDocument=h,e.upgradeSubtree=o,e.upgradeAll=t,e.attached=a,e.takeRecords=m}),window.CustomElements.addModule(function(e){function t(t,o){if(!t.__upgraded__&&t.nodeType===Node.ELEMENT_NODE){var r=t.getAttribute("is"),i=e.getRegisteredDefinition(t.localName)||e.getRegisteredDefinition(r);if(i&&(r&&i.tag==t.localName||!r&&!i["extends"]))return n(t,i,o)}}function n(t,n,r){return a.upgrade&&console.group("upgrade:",t.localName),n.is&&t.setAttribute("is",n.is),o(t,n),t.__upgraded__=!0,i(t),r&&e.attached(t),e.upgradeSubtree(t,r),a.upgrade&&console.groupEnd(),t}function o(e,t){Object.__proto__?e.__proto__=t.prototype:(r(e,t.prototype,t["native"]),e.__proto__=t.prototype)}function r(e,t,n){for(var o={},r=t;r!==n&&r!==HTMLElement.prototype;){for(var i,a=Object.getOwnPropertyNames(r),d=0;i=a[d];d++)o[i]||(Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(r,i)),o[i]=1);r=Object.getPrototypeOf(r)}}function i(e){e.createdCallback&&e.createdCallback()}var a=e.flags;e.upgrade=t,e.upgradeWithDefinition=n,e.implementPrototype=o}),window.CustomElements.addModule(function(e){function t(t,o){var s=o||{};if(!t)throw new Error("document.registerElement: first argument `name` must not be empty");if(t.indexOf("-")<0)throw new Error("document.registerElement: first argument ('name') must contain a dash ('-'). Argument provided was '"+String(t)+"'.");if(r(t))throw new Error("Failed to execute 'registerElement' on 'Document': Registration failed for type '"+String(t)+"'. The type name is invalid.");if(u(t))throw new Error("DuplicateDefinitionError: a type with name '"+String(t)+"' is already registered");return s.prototype||(s.prototype=Object.create(HTMLElement.prototype)),s.__name=t.toLowerCase(),s.lifecycle=s.lifecycle||{},s.ancestry=i(s["extends"]),a(s),d(s),n(s.prototype),c(s.__name,s),s.ctor=f(s),s.ctor.prototype=s.prototype,s.prototype.constructor=s.ctor,e.ready&&v(document),s.ctor}function n(e){if(!e.setAttribute._polyfilled){var t=e.setAttribute;e.setAttribute=function(e,n){o.call(this,e,n,t)};var n=e.removeAttribute;e.removeAttribute=function(e){o.call(this,e,null,n)},e.setAttribute._polyfilled=!0}}function o(e,t,n){e=e.toLowerCase();var o=this.getAttribute(e);n.apply(this,arguments);var r=this.getAttribute(e);this.attributeChangedCallback&&r!==o&&this.attributeChangedCallback(e,o,r)}function r(e){for(var t=0;t<y.length;t++)if(e===y[t])return!0}function i(e){var t=u(e);return t?i(t["extends"]).concat([t]):[]}function a(e){for(var t,n=e["extends"],o=0;t=e.ancestry[o];o++)n=t.is&&t.tag;e.tag=n||e.__name,n&&(e.is=e.__name)}function d(e){if(!Object.__proto__){var t=HTMLElement.prototype;if(e.is){var n=document.createElement(e.tag);t=Object.getPrototypeOf(n)}for(var o,r=e.prototype,i=!1;r;)r==t&&(i=!0),o=Object.getPrototypeOf(r),o&&(r.__proto__=o),r=o;i||console.warn(e.tag+" prototype not found in prototype chain for "+e.is),e["native"]=t}}function s(e){return b(O(e.tag),e)}function u(e){return e?N[e.toLowerCase()]:void 0}function c(e,t){N[e]=t}function f(e){return function(){return s(e)}}function l(e,t,n){return e===M?p(t,n):D(e,t)}function p(e,t){e&&(e=e.toLowerCase()),t&&(t=t.toLowerCase());var n=u(t||e);if(n){if(e==n.tag&&t==n.is)return new n.ctor;if(!t&&!n.is)return new n.ctor}var o;return t?(o=p(e),o.setAttribute("is",t),o):(o=O(e),e.indexOf("-")>=0&&_(o,HTMLElement),o)}function m(e,t){var n=e[t];e[t]=function(){var e=n.apply(this,arguments);return g(e),e}}var w,h=e.isIE,v=e.upgradeDocumentTree,g=e.upgradeAll,b=e.upgradeWithDefinition,_=e.implementPrototype,E=e.useNative,y=["annotation-xml","color-profile","font-face","font-face-src","font-face-uri","font-face-format","font-face-name","missing-glyph"],N={},M="http://www.w3.org/1999/xhtml",O=document.createElement.bind(document),D=document.createElementNS.bind(document);w=Object.__proto__||E?function(e,t){return e instanceof t}:function(e,t){if(e instanceof t)return!0;for(var n=e;n;){if(n===t.prototype)return!0;n=n.__proto__}return!1},m(Node.prototype,"cloneNode"),m(document,"importNode"),h&&!function(){var e=document.importNode;document.importNode=function(){var t=e.apply(document,arguments);if(t.nodeType==t.DOCUMENT_FRAGMENT_NODE){var n=document.createDocumentFragment();return n.appendChild(t),n}return t}}(),document.registerElement=t,document.createElement=p,document.createElementNS=l,e.registry=N,e["instanceof"]=w,e.reservedTagList=y,e.getRegisteredDefinition=u,document.register=document.registerElement}),function(e){function t(){a(window.wrap(document)),window.CustomElements.ready=!0;var e=window.requestAnimationFrame||function(e){setTimeout(e,16)};e(function(){setTimeout(function(){window.CustomElements.readyTime=Date.now(),window.HTMLImports&&(window.CustomElements.elapsed=window.CustomElements.readyTime-window.HTMLImports.readyTime),document.dispatchEvent(new CustomEvent("WebComponentsReady",{bubbles:!0}))})})}var n=e.useNative,o=e.initializeModules,r=e.isIE;if(n){var i=function(){};e.watchShadow=i,e.upgrade=i,e.upgradeAll=i,e.upgradeDocumentTree=i,e.upgradeSubtree=i,e.takeRecords=i,e["instanceof"]=function(e,t){return e instanceof t}}else o();var a=e.upgradeDocumentTree,d=e.upgradeDocument;if(window.wrap||(window.ShadowDOMPolyfill?(window.wrap=window.ShadowDOMPolyfill.wrapIfNeeded,window.unwrap=window.ShadowDOMPolyfill.unwrapIfNeeded):window.wrap=window.unwrap=function(e){return e}),window.HTMLImports&&(window.HTMLImports.__importsParsingHook=function(e){e["import"]&&d(wrap(e["import"]))}),r&&"function"!=typeof window.CustomEvent&&(window.CustomEvent=function(e,t){t=t||{};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,Boolean(t.bubbles),Boolean(t.cancelable),t.detail),n.preventDefault=function(){Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})},n},window.CustomEvent.prototype=window.Event.prototype),"complete"===document.readyState||e.flags.eager)t();else if("interactive"!==document.readyState||window.attachEvent||window.HTMLImports&&!window.HTMLImports.ready){var s=window.HTMLImports&&!window.HTMLImports.ready?"HTMLImportsLoaded":"DOMContentLoaded";window.addEventListener(s,t)}else t()}(window.CustomElements);
@@ -0,0 +1,1090 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.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/CONTRIBUTORS.txt
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/PATENTS.txt
9
+ */
10
+ // @version 0.7.12
11
+ if (typeof WeakMap === "undefined") {
12
+ (function() {
13
+ var defineProperty = Object.defineProperty;
14
+ var counter = Date.now() % 1e9;
15
+ var WeakMap = function() {
16
+ this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
17
+ };
18
+ WeakMap.prototype = {
19
+ set: function(key, value) {
20
+ var entry = key[this.name];
21
+ if (entry && entry[0] === key) entry[1] = value; else defineProperty(key, this.name, {
22
+ value: [ key, value ],
23
+ writable: true
24
+ });
25
+ return this;
26
+ },
27
+ get: function(key) {
28
+ var entry;
29
+ return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined;
30
+ },
31
+ "delete": function(key) {
32
+ var entry = key[this.name];
33
+ if (!entry || entry[0] !== key) return false;
34
+ entry[0] = entry[1] = undefined;
35
+ return true;
36
+ },
37
+ has: function(key) {
38
+ var entry = key[this.name];
39
+ if (!entry) return false;
40
+ return entry[0] === key;
41
+ }
42
+ };
43
+ window.WeakMap = WeakMap;
44
+ })();
45
+ }
46
+
47
+ (function(global) {
48
+ var registrationsTable = new WeakMap();
49
+ var setImmediate;
50
+ if (/Trident|Edge/.test(navigator.userAgent)) {
51
+ setImmediate = setTimeout;
52
+ } else if (window.setImmediate) {
53
+ setImmediate = window.setImmediate;
54
+ } else {
55
+ var setImmediateQueue = [];
56
+ var sentinel = String(Math.random());
57
+ window.addEventListener("message", function(e) {
58
+ if (e.data === sentinel) {
59
+ var queue = setImmediateQueue;
60
+ setImmediateQueue = [];
61
+ queue.forEach(function(func) {
62
+ func();
63
+ });
64
+ }
65
+ });
66
+ setImmediate = function(func) {
67
+ setImmediateQueue.push(func);
68
+ window.postMessage(sentinel, "*");
69
+ };
70
+ }
71
+ var isScheduled = false;
72
+ var scheduledObservers = [];
73
+ function scheduleCallback(observer) {
74
+ scheduledObservers.push(observer);
75
+ if (!isScheduled) {
76
+ isScheduled = true;
77
+ setImmediate(dispatchCallbacks);
78
+ }
79
+ }
80
+ function wrapIfNeeded(node) {
81
+ return window.ShadowDOMPolyfill && window.ShadowDOMPolyfill.wrapIfNeeded(node) || node;
82
+ }
83
+ function dispatchCallbacks() {
84
+ isScheduled = false;
85
+ var observers = scheduledObservers;
86
+ scheduledObservers = [];
87
+ observers.sort(function(o1, o2) {
88
+ return o1.uid_ - o2.uid_;
89
+ });
90
+ var anyNonEmpty = false;
91
+ observers.forEach(function(observer) {
92
+ var queue = observer.takeRecords();
93
+ removeTransientObserversFor(observer);
94
+ if (queue.length) {
95
+ observer.callback_(queue, observer);
96
+ anyNonEmpty = true;
97
+ }
98
+ });
99
+ if (anyNonEmpty) dispatchCallbacks();
100
+ }
101
+ function removeTransientObserversFor(observer) {
102
+ observer.nodes_.forEach(function(node) {
103
+ var registrations = registrationsTable.get(node);
104
+ if (!registrations) return;
105
+ registrations.forEach(function(registration) {
106
+ if (registration.observer === observer) registration.removeTransientObservers();
107
+ });
108
+ });
109
+ }
110
+ function forEachAncestorAndObserverEnqueueRecord(target, callback) {
111
+ for (var node = target; node; node = node.parentNode) {
112
+ var registrations = registrationsTable.get(node);
113
+ if (registrations) {
114
+ for (var j = 0; j < registrations.length; j++) {
115
+ var registration = registrations[j];
116
+ var options = registration.options;
117
+ if (node !== target && !options.subtree) continue;
118
+ var record = callback(options);
119
+ if (record) registration.enqueue(record);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ var uidCounter = 0;
125
+ function JsMutationObserver(callback) {
126
+ this.callback_ = callback;
127
+ this.nodes_ = [];
128
+ this.records_ = [];
129
+ this.uid_ = ++uidCounter;
130
+ }
131
+ JsMutationObserver.prototype = {
132
+ observe: function(target, options) {
133
+ target = wrapIfNeeded(target);
134
+ if (!options.childList && !options.attributes && !options.characterData || options.attributeOldValue && !options.attributes || options.attributeFilter && options.attributeFilter.length && !options.attributes || options.characterDataOldValue && !options.characterData) {
135
+ throw new SyntaxError();
136
+ }
137
+ var registrations = registrationsTable.get(target);
138
+ if (!registrations) registrationsTable.set(target, registrations = []);
139
+ var registration;
140
+ for (var i = 0; i < registrations.length; i++) {
141
+ if (registrations[i].observer === this) {
142
+ registration = registrations[i];
143
+ registration.removeListeners();
144
+ registration.options = options;
145
+ break;
146
+ }
147
+ }
148
+ if (!registration) {
149
+ registration = new Registration(this, target, options);
150
+ registrations.push(registration);
151
+ this.nodes_.push(target);
152
+ }
153
+ registration.addListeners();
154
+ },
155
+ disconnect: function() {
156
+ this.nodes_.forEach(function(node) {
157
+ var registrations = registrationsTable.get(node);
158
+ for (var i = 0; i < registrations.length; i++) {
159
+ var registration = registrations[i];
160
+ if (registration.observer === this) {
161
+ registration.removeListeners();
162
+ registrations.splice(i, 1);
163
+ break;
164
+ }
165
+ }
166
+ }, this);
167
+ this.records_ = [];
168
+ },
169
+ takeRecords: function() {
170
+ var copyOfRecords = this.records_;
171
+ this.records_ = [];
172
+ return copyOfRecords;
173
+ }
174
+ };
175
+ function MutationRecord(type, target) {
176
+ this.type = type;
177
+ this.target = target;
178
+ this.addedNodes = [];
179
+ this.removedNodes = [];
180
+ this.previousSibling = null;
181
+ this.nextSibling = null;
182
+ this.attributeName = null;
183
+ this.attributeNamespace = null;
184
+ this.oldValue = null;
185
+ }
186
+ function copyMutationRecord(original) {
187
+ var record = new MutationRecord(original.type, original.target);
188
+ record.addedNodes = original.addedNodes.slice();
189
+ record.removedNodes = original.removedNodes.slice();
190
+ record.previousSibling = original.previousSibling;
191
+ record.nextSibling = original.nextSibling;
192
+ record.attributeName = original.attributeName;
193
+ record.attributeNamespace = original.attributeNamespace;
194
+ record.oldValue = original.oldValue;
195
+ return record;
196
+ }
197
+ var currentRecord, recordWithOldValue;
198
+ function getRecord(type, target) {
199
+ return currentRecord = new MutationRecord(type, target);
200
+ }
201
+ function getRecordWithOldValue(oldValue) {
202
+ if (recordWithOldValue) return recordWithOldValue;
203
+ recordWithOldValue = copyMutationRecord(currentRecord);
204
+ recordWithOldValue.oldValue = oldValue;
205
+ return recordWithOldValue;
206
+ }
207
+ function clearRecords() {
208
+ currentRecord = recordWithOldValue = undefined;
209
+ }
210
+ function recordRepresentsCurrentMutation(record) {
211
+ return record === recordWithOldValue || record === currentRecord;
212
+ }
213
+ function selectRecord(lastRecord, newRecord) {
214
+ if (lastRecord === newRecord) return lastRecord;
215
+ if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord)) return recordWithOldValue;
216
+ return null;
217
+ }
218
+ function Registration(observer, target, options) {
219
+ this.observer = observer;
220
+ this.target = target;
221
+ this.options = options;
222
+ this.transientObservedNodes = [];
223
+ }
224
+ Registration.prototype = {
225
+ enqueue: function(record) {
226
+ var records = this.observer.records_;
227
+ var length = records.length;
228
+ if (records.length > 0) {
229
+ var lastRecord = records[length - 1];
230
+ var recordToReplaceLast = selectRecord(lastRecord, record);
231
+ if (recordToReplaceLast) {
232
+ records[length - 1] = recordToReplaceLast;
233
+ return;
234
+ }
235
+ } else {
236
+ scheduleCallback(this.observer);
237
+ }
238
+ records[length] = record;
239
+ },
240
+ addListeners: function() {
241
+ this.addListeners_(this.target);
242
+ },
243
+ addListeners_: function(node) {
244
+ var options = this.options;
245
+ if (options.attributes) node.addEventListener("DOMAttrModified", this, true);
246
+ if (options.characterData) node.addEventListener("DOMCharacterDataModified", this, true);
247
+ if (options.childList) node.addEventListener("DOMNodeInserted", this, true);
248
+ if (options.childList || options.subtree) node.addEventListener("DOMNodeRemoved", this, true);
249
+ },
250
+ removeListeners: function() {
251
+ this.removeListeners_(this.target);
252
+ },
253
+ removeListeners_: function(node) {
254
+ var options = this.options;
255
+ if (options.attributes) node.removeEventListener("DOMAttrModified", this, true);
256
+ if (options.characterData) node.removeEventListener("DOMCharacterDataModified", this, true);
257
+ if (options.childList) node.removeEventListener("DOMNodeInserted", this, true);
258
+ if (options.childList || options.subtree) node.removeEventListener("DOMNodeRemoved", this, true);
259
+ },
260
+ addTransientObserver: function(node) {
261
+ if (node === this.target) return;
262
+ this.addListeners_(node);
263
+ this.transientObservedNodes.push(node);
264
+ var registrations = registrationsTable.get(node);
265
+ if (!registrations) registrationsTable.set(node, registrations = []);
266
+ registrations.push(this);
267
+ },
268
+ removeTransientObservers: function() {
269
+ var transientObservedNodes = this.transientObservedNodes;
270
+ this.transientObservedNodes = [];
271
+ transientObservedNodes.forEach(function(node) {
272
+ this.removeListeners_(node);
273
+ var registrations = registrationsTable.get(node);
274
+ for (var i = 0; i < registrations.length; i++) {
275
+ if (registrations[i] === this) {
276
+ registrations.splice(i, 1);
277
+ break;
278
+ }
279
+ }
280
+ }, this);
281
+ },
282
+ handleEvent: function(e) {
283
+ e.stopImmediatePropagation();
284
+ switch (e.type) {
285
+ case "DOMAttrModified":
286
+ var name = e.attrName;
287
+ var namespace = e.relatedNode.namespaceURI;
288
+ var target = e.target;
289
+ var record = new getRecord("attributes", target);
290
+ record.attributeName = name;
291
+ record.attributeNamespace = namespace;
292
+ var oldValue = e.attrChange === MutationEvent.ADDITION ? null : e.prevValue;
293
+ forEachAncestorAndObserverEnqueueRecord(target, function(options) {
294
+ if (!options.attributes) return;
295
+ if (options.attributeFilter && options.attributeFilter.length && options.attributeFilter.indexOf(name) === -1 && options.attributeFilter.indexOf(namespace) === -1) {
296
+ return;
297
+ }
298
+ if (options.attributeOldValue) return getRecordWithOldValue(oldValue);
299
+ return record;
300
+ });
301
+ break;
302
+
303
+ case "DOMCharacterDataModified":
304
+ var target = e.target;
305
+ var record = getRecord("characterData", target);
306
+ var oldValue = e.prevValue;
307
+ forEachAncestorAndObserverEnqueueRecord(target, function(options) {
308
+ if (!options.characterData) return;
309
+ if (options.characterDataOldValue) return getRecordWithOldValue(oldValue);
310
+ return record;
311
+ });
312
+ break;
313
+
314
+ case "DOMNodeRemoved":
315
+ this.addTransientObserver(e.target);
316
+
317
+ case "DOMNodeInserted":
318
+ var changedNode = e.target;
319
+ var addedNodes, removedNodes;
320
+ if (e.type === "DOMNodeInserted") {
321
+ addedNodes = [ changedNode ];
322
+ removedNodes = [];
323
+ } else {
324
+ addedNodes = [];
325
+ removedNodes = [ changedNode ];
326
+ }
327
+ var previousSibling = changedNode.previousSibling;
328
+ var nextSibling = changedNode.nextSibling;
329
+ var record = getRecord("childList", e.target.parentNode);
330
+ record.addedNodes = addedNodes;
331
+ record.removedNodes = removedNodes;
332
+ record.previousSibling = previousSibling;
333
+ record.nextSibling = nextSibling;
334
+ forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) {
335
+ if (!options.childList) return;
336
+ return record;
337
+ });
338
+ }
339
+ clearRecords();
340
+ }
341
+ };
342
+ global.JsMutationObserver = JsMutationObserver;
343
+ if (!global.MutationObserver) global.MutationObserver = JsMutationObserver;
344
+ })(window);
345
+
346
+ window.HTMLImports = window.HTMLImports || {
347
+ flags: {}
348
+ };
349
+
350
+ (function(scope) {
351
+ var IMPORT_LINK_TYPE = "import";
352
+ var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement("link"));
353
+ var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
354
+ var wrap = function(node) {
355
+ return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
356
+ };
357
+ var rootDocument = wrap(document);
358
+ var currentScriptDescriptor = {
359
+ get: function() {
360
+ var script = window.HTMLImports.currentScript || document.currentScript || (document.readyState !== "complete" ? document.scripts[document.scripts.length - 1] : null);
361
+ return wrap(script);
362
+ },
363
+ configurable: true
364
+ };
365
+ Object.defineProperty(document, "_currentScript", currentScriptDescriptor);
366
+ Object.defineProperty(rootDocument, "_currentScript", currentScriptDescriptor);
367
+ var isIE = /Trident/.test(navigator.userAgent);
368
+ function whenReady(callback, doc) {
369
+ doc = doc || rootDocument;
370
+ whenDocumentReady(function() {
371
+ watchImportsLoad(callback, doc);
372
+ }, doc);
373
+ }
374
+ var requiredReadyState = isIE ? "complete" : "interactive";
375
+ var READY_EVENT = "readystatechange";
376
+ function isDocumentReady(doc) {
377
+ return doc.readyState === "complete" || doc.readyState === requiredReadyState;
378
+ }
379
+ function whenDocumentReady(callback, doc) {
380
+ if (!isDocumentReady(doc)) {
381
+ var checkReady = function() {
382
+ if (doc.readyState === "complete" || doc.readyState === requiredReadyState) {
383
+ doc.removeEventListener(READY_EVENT, checkReady);
384
+ whenDocumentReady(callback, doc);
385
+ }
386
+ };
387
+ doc.addEventListener(READY_EVENT, checkReady);
388
+ } else if (callback) {
389
+ callback();
390
+ }
391
+ }
392
+ function markTargetLoaded(event) {
393
+ event.target.__loaded = true;
394
+ }
395
+ function watchImportsLoad(callback, doc) {
396
+ var imports = doc.querySelectorAll("link[rel=import]");
397
+ var parsedCount = 0, importCount = imports.length, newImports = [], errorImports = [];
398
+ function checkDone() {
399
+ if (parsedCount == importCount && callback) {
400
+ callback({
401
+ allImports: imports,
402
+ loadedImports: newImports,
403
+ errorImports: errorImports
404
+ });
405
+ }
406
+ }
407
+ function loadedImport(e) {
408
+ markTargetLoaded(e);
409
+ newImports.push(this);
410
+ parsedCount++;
411
+ checkDone();
412
+ }
413
+ function errorLoadingImport(e) {
414
+ errorImports.push(this);
415
+ parsedCount++;
416
+ checkDone();
417
+ }
418
+ if (importCount) {
419
+ for (var i = 0, imp; i < importCount && (imp = imports[i]); i++) {
420
+ if (isImportLoaded(imp)) {
421
+ parsedCount++;
422
+ checkDone();
423
+ } else {
424
+ imp.addEventListener("load", loadedImport);
425
+ imp.addEventListener("error", errorLoadingImport);
426
+ }
427
+ }
428
+ } else {
429
+ checkDone();
430
+ }
431
+ }
432
+ function isImportLoaded(link) {
433
+ return useNative ? link.__loaded || link.import && link.import.readyState !== "loading" : link.__importParsed;
434
+ }
435
+ if (useNative) {
436
+ new MutationObserver(function(mxns) {
437
+ for (var i = 0, l = mxns.length, m; i < l && (m = mxns[i]); i++) {
438
+ if (m.addedNodes) {
439
+ handleImports(m.addedNodes);
440
+ }
441
+ }
442
+ }).observe(document.head, {
443
+ childList: true
444
+ });
445
+ function handleImports(nodes) {
446
+ for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
447
+ if (isImport(n)) {
448
+ handleImport(n);
449
+ }
450
+ }
451
+ }
452
+ function isImport(element) {
453
+ return element.localName === "link" && element.rel === "import";
454
+ }
455
+ function handleImport(element) {
456
+ var loaded = element.import;
457
+ if (loaded) {
458
+ markTargetLoaded({
459
+ target: element
460
+ });
461
+ } else {
462
+ element.addEventListener("load", markTargetLoaded);
463
+ element.addEventListener("error", markTargetLoaded);
464
+ }
465
+ }
466
+ (function() {
467
+ if (document.readyState === "loading") {
468
+ var imports = document.querySelectorAll("link[rel=import]");
469
+ for (var i = 0, l = imports.length, imp; i < l && (imp = imports[i]); i++) {
470
+ handleImport(imp);
471
+ }
472
+ }
473
+ })();
474
+ }
475
+ whenReady(function(detail) {
476
+ window.HTMLImports.ready = true;
477
+ window.HTMLImports.readyTime = new Date().getTime();
478
+ var evt = rootDocument.createEvent("CustomEvent");
479
+ evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
480
+ rootDocument.dispatchEvent(evt);
481
+ });
482
+ scope.IMPORT_LINK_TYPE = IMPORT_LINK_TYPE;
483
+ scope.useNative = useNative;
484
+ scope.rootDocument = rootDocument;
485
+ scope.whenReady = whenReady;
486
+ scope.isIE = isIE;
487
+ })(window.HTMLImports);
488
+
489
+ (function(scope) {
490
+ var modules = [];
491
+ var addModule = function(module) {
492
+ modules.push(module);
493
+ };
494
+ var initializeModules = function() {
495
+ modules.forEach(function(module) {
496
+ module(scope);
497
+ });
498
+ };
499
+ scope.addModule = addModule;
500
+ scope.initializeModules = initializeModules;
501
+ })(window.HTMLImports);
502
+
503
+ window.HTMLImports.addModule(function(scope) {
504
+ var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
505
+ var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
506
+ var path = {
507
+ resolveUrlsInStyle: function(style, linkUrl) {
508
+ var doc = style.ownerDocument;
509
+ var resolver = doc.createElement("a");
510
+ style.textContent = this.resolveUrlsInCssText(style.textContent, linkUrl, resolver);
511
+ return style;
512
+ },
513
+ resolveUrlsInCssText: function(cssText, linkUrl, urlObj) {
514
+ var r = this.replaceUrls(cssText, urlObj, linkUrl, CSS_URL_REGEXP);
515
+ r = this.replaceUrls(r, urlObj, linkUrl, CSS_IMPORT_REGEXP);
516
+ return r;
517
+ },
518
+ replaceUrls: function(text, urlObj, linkUrl, regexp) {
519
+ return text.replace(regexp, function(m, pre, url, post) {
520
+ var urlPath = url.replace(/["']/g, "");
521
+ if (linkUrl) {
522
+ urlPath = new URL(urlPath, linkUrl).href;
523
+ }
524
+ urlObj.href = urlPath;
525
+ urlPath = urlObj.href;
526
+ return pre + "'" + urlPath + "'" + post;
527
+ });
528
+ }
529
+ };
530
+ scope.path = path;
531
+ });
532
+
533
+ window.HTMLImports.addModule(function(scope) {
534
+ var xhr = {
535
+ async: true,
536
+ ok: function(request) {
537
+ return request.status >= 200 && request.status < 300 || request.status === 304 || request.status === 0;
538
+ },
539
+ load: function(url, next, nextContext) {
540
+ var request = new XMLHttpRequest();
541
+ if (scope.flags.debug || scope.flags.bust) {
542
+ url += "?" + Math.random();
543
+ }
544
+ request.open("GET", url, xhr.async);
545
+ request.addEventListener("readystatechange", function(e) {
546
+ if (request.readyState === 4) {
547
+ var locationHeader = request.getResponseHeader("Location");
548
+ var redirectedUrl = null;
549
+ if (locationHeader) {
550
+ var redirectedUrl = locationHeader.substr(0, 1) === "/" ? location.origin + locationHeader : locationHeader;
551
+ }
552
+ next.call(nextContext, !xhr.ok(request) && request, request.response || request.responseText, redirectedUrl);
553
+ }
554
+ });
555
+ request.send();
556
+ return request;
557
+ },
558
+ loadDocument: function(url, next, nextContext) {
559
+ this.load(url, next, nextContext).responseType = "document";
560
+ }
561
+ };
562
+ scope.xhr = xhr;
563
+ });
564
+
565
+ window.HTMLImports.addModule(function(scope) {
566
+ var xhr = scope.xhr;
567
+ var flags = scope.flags;
568
+ var Loader = function(onLoad, onComplete) {
569
+ this.cache = {};
570
+ this.onload = onLoad;
571
+ this.oncomplete = onComplete;
572
+ this.inflight = 0;
573
+ this.pending = {};
574
+ };
575
+ Loader.prototype = {
576
+ addNodes: function(nodes) {
577
+ this.inflight += nodes.length;
578
+ for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
579
+ this.require(n);
580
+ }
581
+ this.checkDone();
582
+ },
583
+ addNode: function(node) {
584
+ this.inflight++;
585
+ this.require(node);
586
+ this.checkDone();
587
+ },
588
+ require: function(elt) {
589
+ var url = elt.src || elt.href;
590
+ elt.__nodeUrl = url;
591
+ if (!this.dedupe(url, elt)) {
592
+ this.fetch(url, elt);
593
+ }
594
+ },
595
+ dedupe: function(url, elt) {
596
+ if (this.pending[url]) {
597
+ this.pending[url].push(elt);
598
+ return true;
599
+ }
600
+ var resource;
601
+ if (this.cache[url]) {
602
+ this.onload(url, elt, this.cache[url]);
603
+ this.tail();
604
+ return true;
605
+ }
606
+ this.pending[url] = [ elt ];
607
+ return false;
608
+ },
609
+ fetch: function(url, elt) {
610
+ flags.load && console.log("fetch", url, elt);
611
+ if (!url) {
612
+ setTimeout(function() {
613
+ this.receive(url, elt, {
614
+ error: "href must be specified"
615
+ }, null);
616
+ }.bind(this), 0);
617
+ } else if (url.match(/^data:/)) {
618
+ var pieces = url.split(",");
619
+ var header = pieces[0];
620
+ var body = pieces[1];
621
+ if (header.indexOf(";base64") > -1) {
622
+ body = atob(body);
623
+ } else {
624
+ body = decodeURIComponent(body);
625
+ }
626
+ setTimeout(function() {
627
+ this.receive(url, elt, null, body);
628
+ }.bind(this), 0);
629
+ } else {
630
+ var receiveXhr = function(err, resource, redirectedUrl) {
631
+ this.receive(url, elt, err, resource, redirectedUrl);
632
+ }.bind(this);
633
+ xhr.load(url, receiveXhr);
634
+ }
635
+ },
636
+ receive: function(url, elt, err, resource, redirectedUrl) {
637
+ this.cache[url] = resource;
638
+ var $p = this.pending[url];
639
+ for (var i = 0, l = $p.length, p; i < l && (p = $p[i]); i++) {
640
+ this.onload(url, p, resource, err, redirectedUrl);
641
+ this.tail();
642
+ }
643
+ this.pending[url] = null;
644
+ },
645
+ tail: function() {
646
+ --this.inflight;
647
+ this.checkDone();
648
+ },
649
+ checkDone: function() {
650
+ if (!this.inflight) {
651
+ this.oncomplete();
652
+ }
653
+ }
654
+ };
655
+ scope.Loader = Loader;
656
+ });
657
+
658
+ window.HTMLImports.addModule(function(scope) {
659
+ var Observer = function(addCallback) {
660
+ this.addCallback = addCallback;
661
+ this.mo = new MutationObserver(this.handler.bind(this));
662
+ };
663
+ Observer.prototype = {
664
+ handler: function(mutations) {
665
+ for (var i = 0, l = mutations.length, m; i < l && (m = mutations[i]); i++) {
666
+ if (m.type === "childList" && m.addedNodes.length) {
667
+ this.addedNodes(m.addedNodes);
668
+ }
669
+ }
670
+ },
671
+ addedNodes: function(nodes) {
672
+ if (this.addCallback) {
673
+ this.addCallback(nodes);
674
+ }
675
+ for (var i = 0, l = nodes.length, n, loading; i < l && (n = nodes[i]); i++) {
676
+ if (n.children && n.children.length) {
677
+ this.addedNodes(n.children);
678
+ }
679
+ }
680
+ },
681
+ observe: function(root) {
682
+ this.mo.observe(root, {
683
+ childList: true,
684
+ subtree: true
685
+ });
686
+ }
687
+ };
688
+ scope.Observer = Observer;
689
+ });
690
+
691
+ window.HTMLImports.addModule(function(scope) {
692
+ var path = scope.path;
693
+ var rootDocument = scope.rootDocument;
694
+ var flags = scope.flags;
695
+ var isIE = scope.isIE;
696
+ var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
697
+ var IMPORT_SELECTOR = "link[rel=" + IMPORT_LINK_TYPE + "]";
698
+ var importParser = {
699
+ documentSelectors: IMPORT_SELECTOR,
700
+ importsSelectors: [ IMPORT_SELECTOR, "link[rel=stylesheet]:not([type])", "style:not([type])", "script:not([type])", 'script[type="application/javascript"]', 'script[type="text/javascript"]' ].join(","),
701
+ map: {
702
+ link: "parseLink",
703
+ script: "parseScript",
704
+ style: "parseStyle"
705
+ },
706
+ dynamicElements: [],
707
+ parseNext: function() {
708
+ var next = this.nextToParse();
709
+ if (next) {
710
+ this.parse(next);
711
+ }
712
+ },
713
+ parse: function(elt) {
714
+ if (this.isParsed(elt)) {
715
+ flags.parse && console.log("[%s] is already parsed", elt.localName);
716
+ return;
717
+ }
718
+ var fn = this[this.map[elt.localName]];
719
+ if (fn) {
720
+ this.markParsing(elt);
721
+ fn.call(this, elt);
722
+ }
723
+ },
724
+ parseDynamic: function(elt, quiet) {
725
+ this.dynamicElements.push(elt);
726
+ if (!quiet) {
727
+ this.parseNext();
728
+ }
729
+ },
730
+ markParsing: function(elt) {
731
+ flags.parse && console.log("parsing", elt);
732
+ this.parsingElement = elt;
733
+ },
734
+ markParsingComplete: function(elt) {
735
+ elt.__importParsed = true;
736
+ this.markDynamicParsingComplete(elt);
737
+ if (elt.__importElement) {
738
+ elt.__importElement.__importParsed = true;
739
+ this.markDynamicParsingComplete(elt.__importElement);
740
+ }
741
+ this.parsingElement = null;
742
+ flags.parse && console.log("completed", elt);
743
+ },
744
+ markDynamicParsingComplete: function(elt) {
745
+ var i = this.dynamicElements.indexOf(elt);
746
+ if (i >= 0) {
747
+ this.dynamicElements.splice(i, 1);
748
+ }
749
+ },
750
+ parseImport: function(elt) {
751
+ elt.import = elt.__doc;
752
+ if (window.HTMLImports.__importsParsingHook) {
753
+ window.HTMLImports.__importsParsingHook(elt);
754
+ }
755
+ if (elt.import) {
756
+ elt.import.__importParsed = true;
757
+ }
758
+ this.markParsingComplete(elt);
759
+ if (elt.__resource && !elt.__error) {
760
+ elt.dispatchEvent(new CustomEvent("load", {
761
+ bubbles: false
762
+ }));
763
+ } else {
764
+ elt.dispatchEvent(new CustomEvent("error", {
765
+ bubbles: false
766
+ }));
767
+ }
768
+ if (elt.__pending) {
769
+ var fn;
770
+ while (elt.__pending.length) {
771
+ fn = elt.__pending.shift();
772
+ if (fn) {
773
+ fn({
774
+ target: elt
775
+ });
776
+ }
777
+ }
778
+ }
779
+ this.parseNext();
780
+ },
781
+ parseLink: function(linkElt) {
782
+ if (nodeIsImport(linkElt)) {
783
+ this.parseImport(linkElt);
784
+ } else {
785
+ linkElt.href = linkElt.href;
786
+ this.parseGeneric(linkElt);
787
+ }
788
+ },
789
+ parseStyle: function(elt) {
790
+ var src = elt;
791
+ elt = cloneStyle(elt);
792
+ src.__appliedElement = elt;
793
+ elt.__importElement = src;
794
+ this.parseGeneric(elt);
795
+ },
796
+ parseGeneric: function(elt) {
797
+ this.trackElement(elt);
798
+ this.addElementToDocument(elt);
799
+ },
800
+ rootImportForElement: function(elt) {
801
+ var n = elt;
802
+ while (n.ownerDocument.__importLink) {
803
+ n = n.ownerDocument.__importLink;
804
+ }
805
+ return n;
806
+ },
807
+ addElementToDocument: function(elt) {
808
+ var port = this.rootImportForElement(elt.__importElement || elt);
809
+ port.parentNode.insertBefore(elt, port);
810
+ },
811
+ trackElement: function(elt, callback) {
812
+ var self = this;
813
+ var done = function(e) {
814
+ elt.removeEventListener("load", done);
815
+ elt.removeEventListener("error", done);
816
+ if (callback) {
817
+ callback(e);
818
+ }
819
+ self.markParsingComplete(elt);
820
+ self.parseNext();
821
+ };
822
+ elt.addEventListener("load", done);
823
+ elt.addEventListener("error", done);
824
+ if (isIE && elt.localName === "style") {
825
+ var fakeLoad = false;
826
+ if (elt.textContent.indexOf("@import") == -1) {
827
+ fakeLoad = true;
828
+ } else if (elt.sheet) {
829
+ fakeLoad = true;
830
+ var csr = elt.sheet.cssRules;
831
+ var len = csr ? csr.length : 0;
832
+ for (var i = 0, r; i < len && (r = csr[i]); i++) {
833
+ if (r.type === CSSRule.IMPORT_RULE) {
834
+ fakeLoad = fakeLoad && Boolean(r.styleSheet);
835
+ }
836
+ }
837
+ }
838
+ if (fakeLoad) {
839
+ setTimeout(function() {
840
+ elt.dispatchEvent(new CustomEvent("load", {
841
+ bubbles: false
842
+ }));
843
+ });
844
+ }
845
+ }
846
+ },
847
+ parseScript: function(scriptElt) {
848
+ var script = document.createElement("script");
849
+ script.__importElement = scriptElt;
850
+ script.src = scriptElt.src ? scriptElt.src : generateScriptDataUrl(scriptElt);
851
+ scope.currentScript = scriptElt;
852
+ this.trackElement(script, function(e) {
853
+ if (script.parentNode) {
854
+ script.parentNode.removeChild(script);
855
+ }
856
+ scope.currentScript = null;
857
+ });
858
+ this.addElementToDocument(script);
859
+ },
860
+ nextToParse: function() {
861
+ this._mayParse = [];
862
+ return !this.parsingElement && (this.nextToParseInDoc(rootDocument) || this.nextToParseDynamic());
863
+ },
864
+ nextToParseInDoc: function(doc, link) {
865
+ if (doc && this._mayParse.indexOf(doc) < 0) {
866
+ this._mayParse.push(doc);
867
+ var nodes = doc.querySelectorAll(this.parseSelectorsForNode(doc));
868
+ for (var i = 0, l = nodes.length, p = 0, n; i < l && (n = nodes[i]); i++) {
869
+ if (!this.isParsed(n)) {
870
+ if (this.hasResource(n)) {
871
+ return nodeIsImport(n) ? this.nextToParseInDoc(n.__doc, n) : n;
872
+ } else {
873
+ return;
874
+ }
875
+ }
876
+ }
877
+ }
878
+ return link;
879
+ },
880
+ nextToParseDynamic: function() {
881
+ return this.dynamicElements[0];
882
+ },
883
+ parseSelectorsForNode: function(node) {
884
+ var doc = node.ownerDocument || node;
885
+ return doc === rootDocument ? this.documentSelectors : this.importsSelectors;
886
+ },
887
+ isParsed: function(node) {
888
+ return node.__importParsed;
889
+ },
890
+ needsDynamicParsing: function(elt) {
891
+ return this.dynamicElements.indexOf(elt) >= 0;
892
+ },
893
+ hasResource: function(node) {
894
+ if (nodeIsImport(node) && node.__doc === undefined) {
895
+ return false;
896
+ }
897
+ return true;
898
+ }
899
+ };
900
+ function nodeIsImport(elt) {
901
+ return elt.localName === "link" && elt.rel === IMPORT_LINK_TYPE;
902
+ }
903
+ function generateScriptDataUrl(script) {
904
+ var scriptContent = generateScriptContent(script);
905
+ return "data:text/javascript;charset=utf-8," + encodeURIComponent(scriptContent);
906
+ }
907
+ function generateScriptContent(script) {
908
+ return script.textContent + generateSourceMapHint(script);
909
+ }
910
+ function generateSourceMapHint(script) {
911
+ var owner = script.ownerDocument;
912
+ owner.__importedScripts = owner.__importedScripts || 0;
913
+ var moniker = script.ownerDocument.baseURI;
914
+ var num = owner.__importedScripts ? "-" + owner.__importedScripts : "";
915
+ owner.__importedScripts++;
916
+ return "\n//# sourceURL=" + moniker + num + ".js\n";
917
+ }
918
+ function cloneStyle(style) {
919
+ var clone = style.ownerDocument.createElement("style");
920
+ clone.textContent = style.textContent;
921
+ path.resolveUrlsInStyle(clone);
922
+ return clone;
923
+ }
924
+ scope.parser = importParser;
925
+ scope.IMPORT_SELECTOR = IMPORT_SELECTOR;
926
+ });
927
+
928
+ window.HTMLImports.addModule(function(scope) {
929
+ var flags = scope.flags;
930
+ var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE;
931
+ var IMPORT_SELECTOR = scope.IMPORT_SELECTOR;
932
+ var rootDocument = scope.rootDocument;
933
+ var Loader = scope.Loader;
934
+ var Observer = scope.Observer;
935
+ var parser = scope.parser;
936
+ var importer = {
937
+ documents: {},
938
+ documentPreloadSelectors: IMPORT_SELECTOR,
939
+ importsPreloadSelectors: [ IMPORT_SELECTOR ].join(","),
940
+ loadNode: function(node) {
941
+ importLoader.addNode(node);
942
+ },
943
+ loadSubtree: function(parent) {
944
+ var nodes = this.marshalNodes(parent);
945
+ importLoader.addNodes(nodes);
946
+ },
947
+ marshalNodes: function(parent) {
948
+ return parent.querySelectorAll(this.loadSelectorsForNode(parent));
949
+ },
950
+ loadSelectorsForNode: function(node) {
951
+ var doc = node.ownerDocument || node;
952
+ return doc === rootDocument ? this.documentPreloadSelectors : this.importsPreloadSelectors;
953
+ },
954
+ loaded: function(url, elt, resource, err, redirectedUrl) {
955
+ flags.load && console.log("loaded", url, elt);
956
+ elt.__resource = resource;
957
+ elt.__error = err;
958
+ if (isImportLink(elt)) {
959
+ var doc = this.documents[url];
960
+ if (doc === undefined) {
961
+ doc = err ? null : makeDocument(resource, redirectedUrl || url);
962
+ if (doc) {
963
+ doc.__importLink = elt;
964
+ this.bootDocument(doc);
965
+ }
966
+ this.documents[url] = doc;
967
+ }
968
+ elt.__doc = doc;
969
+ }
970
+ parser.parseNext();
971
+ },
972
+ bootDocument: function(doc) {
973
+ this.loadSubtree(doc);
974
+ this.observer.observe(doc);
975
+ parser.parseNext();
976
+ },
977
+ loadedAll: function() {
978
+ parser.parseNext();
979
+ }
980
+ };
981
+ var importLoader = new Loader(importer.loaded.bind(importer), importer.loadedAll.bind(importer));
982
+ importer.observer = new Observer();
983
+ function isImportLink(elt) {
984
+ return isLinkRel(elt, IMPORT_LINK_TYPE);
985
+ }
986
+ function isLinkRel(elt, rel) {
987
+ return elt.localName === "link" && elt.getAttribute("rel") === rel;
988
+ }
989
+ function hasBaseURIAccessor(doc) {
990
+ return !!Object.getOwnPropertyDescriptor(doc, "baseURI");
991
+ }
992
+ function makeDocument(resource, url) {
993
+ var doc = document.implementation.createHTMLDocument(IMPORT_LINK_TYPE);
994
+ doc._URL = url;
995
+ var base = doc.createElement("base");
996
+ base.setAttribute("href", url);
997
+ if (!doc.baseURI && !hasBaseURIAccessor(doc)) {
998
+ Object.defineProperty(doc, "baseURI", {
999
+ value: url
1000
+ });
1001
+ }
1002
+ var meta = doc.createElement("meta");
1003
+ meta.setAttribute("charset", "utf-8");
1004
+ doc.head.appendChild(meta);
1005
+ doc.head.appendChild(base);
1006
+ doc.body.innerHTML = resource;
1007
+ if (window.HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
1008
+ HTMLTemplateElement.bootstrap(doc);
1009
+ }
1010
+ return doc;
1011
+ }
1012
+ if (!document.baseURI) {
1013
+ var baseURIDescriptor = {
1014
+ get: function() {
1015
+ var base = document.querySelector("base");
1016
+ return base ? base.href : window.location.href;
1017
+ },
1018
+ configurable: true
1019
+ };
1020
+ Object.defineProperty(document, "baseURI", baseURIDescriptor);
1021
+ Object.defineProperty(rootDocument, "baseURI", baseURIDescriptor);
1022
+ }
1023
+ scope.importer = importer;
1024
+ scope.importLoader = importLoader;
1025
+ });
1026
+
1027
+ window.HTMLImports.addModule(function(scope) {
1028
+ var parser = scope.parser;
1029
+ var importer = scope.importer;
1030
+ var dynamic = {
1031
+ added: function(nodes) {
1032
+ var owner, parsed, loading;
1033
+ for (var i = 0, l = nodes.length, n; i < l && (n = nodes[i]); i++) {
1034
+ if (!owner) {
1035
+ owner = n.ownerDocument;
1036
+ parsed = parser.isParsed(owner);
1037
+ }
1038
+ loading = this.shouldLoadNode(n);
1039
+ if (loading) {
1040
+ importer.loadNode(n);
1041
+ }
1042
+ if (this.shouldParseNode(n) && parsed) {
1043
+ parser.parseDynamic(n, loading);
1044
+ }
1045
+ }
1046
+ },
1047
+ shouldLoadNode: function(node) {
1048
+ return node.nodeType === 1 && matches.call(node, importer.loadSelectorsForNode(node));
1049
+ },
1050
+ shouldParseNode: function(node) {
1051
+ return node.nodeType === 1 && matches.call(node, parser.parseSelectorsForNode(node));
1052
+ }
1053
+ };
1054
+ importer.observer.addCallback = dynamic.added.bind(dynamic);
1055
+ var matches = HTMLElement.prototype.matches || HTMLElement.prototype.matchesSelector || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector || HTMLElement.prototype.msMatchesSelector;
1056
+ });
1057
+
1058
+ (function(scope) {
1059
+ var initializeModules = scope.initializeModules;
1060
+ var isIE = scope.isIE;
1061
+ if (scope.useNative) {
1062
+ return;
1063
+ }
1064
+ if (isIE && typeof window.CustomEvent !== "function") {
1065
+ window.CustomEvent = function(inType, params) {
1066
+ params = params || {};
1067
+ var e = document.createEvent("CustomEvent");
1068
+ e.initCustomEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable), params.detail);
1069
+ e.preventDefault = function() {
1070
+ Object.defineProperty(this, "defaultPrevented", {
1071
+ get: function() {
1072
+ return true;
1073
+ }
1074
+ });
1075
+ };
1076
+ return e;
1077
+ };
1078
+ window.CustomEvent.prototype = window.Event.prototype;
1079
+ }
1080
+ initializeModules();
1081
+ var rootDocument = scope.rootDocument;
1082
+ function bootstrap() {
1083
+ window.HTMLImports.importer.bootDocument(rootDocument);
1084
+ }
1085
+ if (document.readyState === "complete" || document.readyState === "interactive" && !window.attachEvent) {
1086
+ bootstrap();
1087
+ } else {
1088
+ document.addEventListener("DOMContentLoaded", bootstrap);
1089
+ }
1090
+ })(window.HTMLImports);