| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 if (typeof Polymer == 'undefined') | 5 if (typeof Polymer == 'undefined') |
| 6 Polymer = {dom: 'shadow'}; | 6 Polymer = {dom: 'shadow'}; |
| 7 else | 7 else |
| 8 console.error('Polymer is already defined.'); | 8 console.error('Polymer is already defined.'); |
| 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 10 // Use of this source code is governed by a BSD-style license that can be | 10 // Use of this source code is governed by a BSD-style license that can be |
| (...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 /** | 1458 /** |
| 1459 * Verify |condition| is truthy and return |condition| if so. | 1459 * Verify |condition| is truthy and return |condition| if so. |
| 1460 * @template T | 1460 * @template T |
| 1461 * @param {T} condition A condition to check for truthiness. Note that this | 1461 * @param {T} condition A condition to check for truthiness. Note that this |
| 1462 * may be used to test whether a value is defined or not, and we don't want | 1462 * may be used to test whether a value is defined or not, and we don't want |
| 1463 * to force a cast to Boolean. | 1463 * to force a cast to Boolean. |
| 1464 * @param {string=} opt_message A message to show on failure. | 1464 * @param {string=} opt_message A message to show on failure. |
| 1465 * @return {T} A non-null |condition|. | 1465 * @return {T} A non-null |condition|. |
| 1466 */ | 1466 */ |
| 1467 function assert(condition, opt_message) { | 1467 function assert(condition, opt_message) { |
| 1468 'use strict'; | |
| 1469 if (!condition) { | 1468 if (!condition) { |
| 1470 var msg = 'Assertion failed'; | 1469 var message = 'Assertion failed'; |
| 1471 if (opt_message) | 1470 if (opt_message) |
| 1472 msg = msg + ': ' + opt_message; | 1471 message = message + ': ' + opt_message; |
| 1473 throw new Error(msg); | 1472 var error = new Error(message); |
| 1473 var global = function() { return this; }(); |
| 1474 if (global.traceAssertionsForTesting) |
| 1475 console.warn(error.stack); |
| 1476 throw error; |
| 1474 } | 1477 } |
| 1475 return condition; | 1478 return condition; |
| 1476 } | 1479 } |
| 1477 | 1480 |
| 1478 /** | 1481 /** |
| 1479 * Call this from places in the code that should never be reached. | 1482 * Call this from places in the code that should never be reached. |
| 1480 * | 1483 * |
| 1481 * For example, handling all the values of enum with a switch() like this: | 1484 * For example, handling all the values of enum with a switch() like this: |
| 1482 * | 1485 * |
| 1483 * function getValueFromEnum(enum) { | 1486 * function getValueFromEnum(enum) { |
| 1484 * switch (enum) { | 1487 * switch (enum) { |
| 1485 * case ENUM_FIRST_OF_TWO: | 1488 * case ENUM_FIRST_OF_TWO: |
| 1486 * return first | 1489 * return first |
| 1487 * case ENUM_LAST_OF_TWO: | 1490 * case ENUM_LAST_OF_TWO: |
| 1488 * return last; | 1491 * return last; |
| 1489 * } | 1492 * } |
| 1490 * assertNotReached(); | 1493 * assertNotReached(); |
| 1491 * return document; | 1494 * return document; |
| 1492 * } | 1495 * } |
| 1493 * | 1496 * |
| 1494 * This code should only be hit in the case of serious programmer error or | 1497 * This code should only be hit in the case of serious programmer error or |
| 1495 * unexpected input. | 1498 * unexpected input. |
| 1496 * | 1499 * |
| 1497 * @param {string=} opt_message A message to show when this is hit. | 1500 * @param {string=} opt_message A message to show when this is hit. |
| 1498 */ | 1501 */ |
| 1499 function assertNotReached(opt_message) { | 1502 function assertNotReached(opt_message) { |
| 1500 throw new Error(opt_message || 'Unreachable code hit'); | 1503 assert(false, opt_message || 'Unreachable code hit'); |
| 1501 } | 1504 } |
| 1502 | 1505 |
| 1503 /** | 1506 /** |
| 1504 * @param {*} value The value to check. | 1507 * @param {*} value The value to check. |
| 1505 * @param {function(new: T, ...)} type A user-defined constructor. | 1508 * @param {function(new: T, ...)} type A user-defined constructor. |
| 1506 * @param {string=} opt_message A message to show when this is hit. | 1509 * @param {string=} opt_message A message to show when this is hit. |
| 1507 * @return {T} | 1510 * @return {T} |
| 1508 * @template T | 1511 * @template T |
| 1509 */ | 1512 */ |
| 1510 function assertInstanceof(value, type, opt_message) { | 1513 function assertInstanceof(value, type, opt_message) { |
| 1511 if (!(value instanceof type)) { | 1514 assert(value instanceof type, |
| 1512 throw new Error(opt_message || | 1515 opt_message || value + ' is not a[n] ' + (type.name || typeof type)); |
| 1513 value + ' is not a[n] ' + (type.name || typeof type)); | |
| 1514 } | |
| 1515 return value; | 1516 return value; |
| 1516 }; | 1517 }; |
| 1517 // Copyright 2015 The Chromium Authors. All rights reserved. | 1518 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 1518 // Use of this source code is governed by a BSD-style license that can be | 1519 // Use of this source code is governed by a BSD-style license that can be |
| 1519 // found in the LICENSE file. | 1520 // found in the LICENSE file. |
| 1520 | 1521 |
| 1521 cr.define('downloads', function() { | 1522 cr.define('downloads', function() { |
| 1522 /** | 1523 /** |
| 1523 * @param {string} chromeSendName | 1524 * @param {string} chromeSendName |
| 1524 * @return {function(string):void} A chrome.send() callback with curried name. | 1525 * @return {function(string):void} A chrome.send() callback with curried name. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1797 if (document.readyState === 'interactive' || document.readyState === 'complete')
{ | 1798 if (document.readyState === 'interactive' || document.readyState === 'complete')
{ |
| 1798 resolve(); | 1799 resolve(); |
| 1799 } else { | 1800 } else { |
| 1800 addEventListener('DOMContentLoaded', resolve); | 1801 addEventListener('DOMContentLoaded', resolve); |
| 1801 } | 1802 } |
| 1802 } | 1803 } |
| 1803 }()); | 1804 }()); |
| 1804 window.Polymer = { | 1805 window.Polymer = { |
| 1805 Settings: function () { | 1806 Settings: function () { |
| 1806 var user = window.Polymer || {}; | 1807 var user = window.Polymer || {}; |
| 1807 location.search.slice(1).split('&').forEach(function (o) { | 1808 var parts = location.search.slice(1).split('&'); |
| 1809 for (var i = 0, o; i < parts.length && (o = parts[i]); i++) { |
| 1808 o = o.split('='); | 1810 o = o.split('='); |
| 1809 o[0] && (user[o[0]] = o[1] || true); | 1811 o[0] && (user[o[0]] = o[1] || true); |
| 1810 }); | 1812 } |
| 1811 var wantShadow = user.dom === 'shadow'; | 1813 var wantShadow = user.dom === 'shadow'; |
| 1812 var hasShadow = Boolean(Element.prototype.createShadowRoot); | 1814 var hasShadow = Boolean(Element.prototype.createShadowRoot); |
| 1813 var nativeShadow = hasShadow && !window.ShadowDOMPolyfill; | 1815 var nativeShadow = hasShadow && !window.ShadowDOMPolyfill; |
| 1814 var useShadow = wantShadow && hasShadow; | 1816 var useShadow = wantShadow && hasShadow; |
| 1815 var hasNativeImports = Boolean('import' in document.createElement('link')); | 1817 var hasNativeImports = Boolean('import' in document.createElement('link')); |
| 1816 var useNativeImports = hasNativeImports; | 1818 var useNativeImports = hasNativeImports; |
| 1817 var useNativeCustomElements = !window.CustomElements || window.CustomElements.us
eNative; | 1819 var useNativeCustomElements = !window.CustomElements || window.CustomElements.us
eNative; |
| 1818 return { | 1820 return { |
| 1819 wantShadow: wantShadow, | 1821 wantShadow: wantShadow, |
| 1820 hasShadow: hasShadow, | 1822 hasShadow: hasShadow, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 _callbacks: [], | 1889 _callbacks: [], |
| 1888 whenReady: function (cb) { | 1890 whenReady: function (cb) { |
| 1889 if (this._ready) { | 1891 if (this._ready) { |
| 1890 cb(); | 1892 cb(); |
| 1891 } else { | 1893 } else { |
| 1892 this._callbacks.push(cb); | 1894 this._callbacks.push(cb); |
| 1893 } | 1895 } |
| 1894 }, | 1896 }, |
| 1895 _makeReady: function () { | 1897 _makeReady: function () { |
| 1896 this._ready = true; | 1898 this._ready = true; |
| 1897 this._callbacks.forEach(function (cb) { | 1899 for (var i = 0; i < this._callbacks.length; i++) { |
| 1898 cb(); | 1900 this._callbacks[i](); |
| 1899 }); | 1901 } |
| 1900 this._callbacks = []; | 1902 this._callbacks = []; |
| 1901 }, | 1903 }, |
| 1902 _catchFirstRender: function () { | 1904 _catchFirstRender: function () { |
| 1903 requestAnimationFrame(function () { | 1905 requestAnimationFrame(function () { |
| 1904 Polymer.RenderStatus._makeReady(); | 1906 Polymer.RenderStatus._makeReady(); |
| 1905 }); | 1907 }); |
| 1908 }, |
| 1909 _afterNextRenderQueue: [], |
| 1910 _waitingNextRender: false, |
| 1911 afterNextRender: function (element, fn, args) { |
| 1912 this._watchNextRender(); |
| 1913 this._afterNextRenderQueue.push([ |
| 1914 element, |
| 1915 fn, |
| 1916 args |
| 1917 ]); |
| 1918 }, |
| 1919 _watchNextRender: function () { |
| 1920 if (!this._waitingNextRender) { |
| 1921 this._waitingNextRender = true; |
| 1922 var fn = function () { |
| 1923 Polymer.RenderStatus._flushNextRender(); |
| 1924 }; |
| 1925 if (!this._ready) { |
| 1926 this.whenReady(fn); |
| 1927 } else { |
| 1928 requestAnimationFrame(fn); |
| 1929 } |
| 1930 } |
| 1931 }, |
| 1932 _flushNextRender: function () { |
| 1933 var self = this; |
| 1934 setTimeout(function () { |
| 1935 self._flushRenderCallbacks(self._afterNextRenderQueue); |
| 1936 self._afterNextRenderQueue = []; |
| 1937 self._waitingNextRender = false; |
| 1938 }); |
| 1939 }, |
| 1940 _flushRenderCallbacks: function (callbacks) { |
| 1941 for (var i = 0, h; i < callbacks.length; i++) { |
| 1942 h = callbacks[i]; |
| 1943 h[1].apply(h[0], h[2] || Polymer.nar); |
| 1944 } |
| 1945 ; |
| 1906 } | 1946 } |
| 1907 }; | 1947 }; |
| 1908 if (window.HTMLImports) { | 1948 if (window.HTMLImports) { |
| 1909 HTMLImports.whenReady(function () { | 1949 HTMLImports.whenReady(function () { |
| 1910 Polymer.RenderStatus._catchFirstRender(); | 1950 Polymer.RenderStatus._catchFirstRender(); |
| 1911 }); | 1951 }); |
| 1912 } else { | 1952 } else { |
| 1913 Polymer.RenderStatus._catchFirstRender(); | 1953 Polymer.RenderStatus._catchFirstRender(); |
| 1914 } | 1954 } |
| 1915 Polymer.ImportStatus = Polymer.RenderStatus; | 1955 Polymer.ImportStatus = Polymer.RenderStatus; |
| 1916 Polymer.ImportStatus.whenLoaded = Polymer.ImportStatus.whenReady; | 1956 Polymer.ImportStatus.whenLoaded = Polymer.ImportStatus.whenReady; |
| 1917 Polymer.Base = { | 1957 Polymer.Base = { |
| 1918 __isPolymerInstance__: true, | 1958 __isPolymerInstance__: true, |
| 1919 _addFeature: function (feature) { | 1959 _addFeature: function (feature) { |
| 1920 this.extend(this, feature); | 1960 this.extend(this, feature); |
| 1921 }, | 1961 }, |
| 1922 registerCallback: function () { | 1962 registerCallback: function () { |
| 1923 this._desugarBehaviors(); | 1963 this._desugarBehaviors(); |
| 1924 this._doBehavior('beforeRegister'); | 1964 this._doBehavior('beforeRegister'); |
| 1925 this._registerFeatures(); | 1965 this._registerFeatures(); |
| 1926 this._doBehavior('registered'); | 1966 this._doBehavior('registered'); |
| 1927 }, | 1967 }, |
| 1928 createdCallback: function () { | 1968 createdCallback: function () { |
| 1929 Polymer.telemetry.instanceCount++; | 1969 Polymer.telemetry.instanceCount++; |
| 1930 this.root = this; | 1970 this.root = this; |
| 1931 this._doBehavior('created'); | 1971 this._doBehavior('created'); |
| 1932 this._initFeatures(); | 1972 this._initFeatures(); |
| 1933 }, | 1973 }, |
| 1934 attachedCallback: function () { | 1974 attachedCallback: function () { |
| 1975 var self = this; |
| 1935 Polymer.RenderStatus.whenReady(function () { | 1976 Polymer.RenderStatus.whenReady(function () { |
| 1936 this.isAttached = true; | 1977 self.isAttached = true; |
| 1937 this._doBehavior('attached'); | 1978 self._doBehavior('attached'); |
| 1938 }.bind(this)); | 1979 }); |
| 1939 }, | 1980 }, |
| 1940 detachedCallback: function () { | 1981 detachedCallback: function () { |
| 1941 this.isAttached = false; | 1982 this.isAttached = false; |
| 1942 this._doBehavior('detached'); | 1983 this._doBehavior('detached'); |
| 1943 }, | 1984 }, |
| 1944 attributeChangedCallback: function (name) { | 1985 attributeChangedCallback: function (name, oldValue, newValue) { |
| 1945 this._attributeChangedImpl(name); | 1986 this._attributeChangedImpl(name); |
| 1946 this._doBehavior('attributeChanged', arguments); | 1987 this._doBehavior('attributeChanged', [ |
| 1988 name, |
| 1989 oldValue, |
| 1990 newValue |
| 1991 ]); |
| 1947 }, | 1992 }, |
| 1948 _attributeChangedImpl: function (name) { | 1993 _attributeChangedImpl: function (name) { |
| 1949 this._setAttributeToProperty(this, name); | 1994 this._setAttributeToProperty(this, name); |
| 1950 }, | 1995 }, |
| 1951 extend: function (prototype, api) { | 1996 extend: function (prototype, api) { |
| 1952 if (prototype && api) { | 1997 if (prototype && api) { |
| 1953 Object.getOwnPropertyNames(api).forEach(function (n) { | 1998 var n$ = Object.getOwnPropertyNames(api); |
| 1999 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { |
| 1954 this.copyOwnProperty(n, api, prototype); | 2000 this.copyOwnProperty(n, api, prototype); |
| 1955 }, this); | 2001 } |
| 1956 } | 2002 } |
| 1957 return prototype || api; | 2003 return prototype || api; |
| 1958 }, | 2004 }, |
| 1959 mixin: function (target, source) { | 2005 mixin: function (target, source) { |
| 1960 for (var i in source) { | 2006 for (var i in source) { |
| 1961 target[i] = source[i]; | 2007 target[i] = source[i]; |
| 1962 } | 2008 } |
| 1963 return target; | 2009 return target; |
| 1964 }, | 2010 }, |
| 1965 copyOwnProperty: function (name, source, target) { | 2011 copyOwnProperty: function (name, source, target) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 if (id) { | 2069 if (id) { |
| 2024 this.id = id; | 2070 this.id = id; |
| 2025 modules[id] = this; | 2071 modules[id] = this; |
| 2026 lcModules[id.toLowerCase()] = this; | 2072 lcModules[id.toLowerCase()] = this; |
| 2027 } | 2073 } |
| 2028 }, | 2074 }, |
| 2029 import: function (id, selector) { | 2075 import: function (id, selector) { |
| 2030 if (id) { | 2076 if (id) { |
| 2031 var m = findModule(id); | 2077 var m = findModule(id); |
| 2032 if (!m) { | 2078 if (!m) { |
| 2033 forceDocumentUpgrade(); | 2079 forceDomModulesUpgrade(); |
| 2034 m = findModule(id); | 2080 m = findModule(id); |
| 2035 } | 2081 } |
| 2036 if (m && selector) { | 2082 if (m && selector) { |
| 2037 m = m.querySelector(selector); | 2083 m = m.querySelector(selector); |
| 2038 } | 2084 } |
| 2039 return m; | 2085 return m; |
| 2040 } | 2086 } |
| 2041 } | 2087 } |
| 2042 }); | 2088 }); |
| 2043 var cePolyfill = window.CustomElements && !CustomElements.useNative; | 2089 var cePolyfill = window.CustomElements && !CustomElements.useNative; |
| 2044 document.registerElement('dom-module', DomModule); | 2090 document.registerElement('dom-module', DomModule); |
| 2045 function forceDocumentUpgrade() { | 2091 function forceDomModulesUpgrade() { |
| 2046 if (cePolyfill) { | 2092 if (cePolyfill) { |
| 2047 var script = document._currentScript || document.currentScript; | 2093 var script = document._currentScript || document.currentScript; |
| 2048 var doc = script && script.ownerDocument; | 2094 var doc = script && script.ownerDocument || document; |
| 2049 if (doc) { | 2095 var modules = doc.querySelectorAll('dom-module'); |
| 2050 CustomElements.upgradeAll(doc); | 2096 for (var i = modules.length - 1, m; i >= 0 && (m = modules[i]); i--) { |
| 2097 if (m.__upgraded__) { |
| 2098 return; |
| 2099 } else { |
| 2100 CustomElements.upgrade(m); |
| 2051 } | 2101 } |
| 2052 } | 2102 } |
| 2053 } | 2103 } |
| 2104 } |
| 2054 }()); | 2105 }()); |
| 2055 Polymer.Base._addFeature({ | 2106 Polymer.Base._addFeature({ |
| 2056 _prepIs: function () { | 2107 _prepIs: function () { |
| 2057 if (!this.is) { | 2108 if (!this.is) { |
| 2058 var module = (document._currentScript || document.currentScript).parentNode; | 2109 var module = (document._currentScript || document.currentScript).parentNode; |
| 2059 if (module.localName === 'dom-module') { | 2110 if (module.localName === 'dom-module') { |
| 2060 var id = module.id || module.getAttribute('name') || module.getAttribute('is'); | 2111 var id = module.id || module.getAttribute('name') || module.getAttribute('is'); |
| 2061 this.is = id; | 2112 this.is = id; |
| 2062 } | 2113 } |
| 2063 } | 2114 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2075 }, | 2126 }, |
| 2076 _desugarSomeBehaviors: function (behaviors) { | 2127 _desugarSomeBehaviors: function (behaviors) { |
| 2077 behaviors = this._flattenBehaviorsList(behaviors); | 2128 behaviors = this._flattenBehaviorsList(behaviors); |
| 2078 for (var i = behaviors.length - 1; i >= 0; i--) { | 2129 for (var i = behaviors.length - 1; i >= 0; i--) { |
| 2079 this._mixinBehavior(behaviors[i]); | 2130 this._mixinBehavior(behaviors[i]); |
| 2080 } | 2131 } |
| 2081 return behaviors; | 2132 return behaviors; |
| 2082 }, | 2133 }, |
| 2083 _flattenBehaviorsList: function (behaviors) { | 2134 _flattenBehaviorsList: function (behaviors) { |
| 2084 var flat = []; | 2135 var flat = []; |
| 2085 behaviors.forEach(function (b) { | 2136 for (var i = 0; i < behaviors.length; i++) { |
| 2137 var b = behaviors[i]; |
| 2086 if (b instanceof Array) { | 2138 if (b instanceof Array) { |
| 2087 flat = flat.concat(this._flattenBehaviorsList(b)); | 2139 flat = flat.concat(this._flattenBehaviorsList(b)); |
| 2088 } else if (b) { | 2140 } else if (b) { |
| 2089 flat.push(b); | 2141 flat.push(b); |
| 2090 } else { | 2142 } else { |
| 2091 this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for miss
ing or 404 import')); | 2143 this._warn(this._logf('_flattenBehaviorsList', 'behavior is null, check for miss
ing or 404 import')); |
| 2092 } | 2144 } |
| 2093 }, this); | 2145 } |
| 2094 return flat; | 2146 return flat; |
| 2095 }, | 2147 }, |
| 2096 _mixinBehavior: function (b) { | 2148 _mixinBehavior: function (b) { |
| 2097 Object.getOwnPropertyNames(b).forEach(function (n) { | 2149 var n$ = Object.getOwnPropertyNames(b); |
| 2098 switch (n) { | 2150 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { |
| 2099 case 'hostAttributes': | 2151 if (!Polymer.Base._behaviorProperties[n] && !this.hasOwnProperty(n)) { |
| 2100 case 'registered': | |
| 2101 case 'properties': | |
| 2102 case 'observers': | |
| 2103 case 'listeners': | |
| 2104 case 'created': | |
| 2105 case 'attached': | |
| 2106 case 'detached': | |
| 2107 case 'attributeChanged': | |
| 2108 case 'configure': | |
| 2109 case 'ready': | |
| 2110 break; | |
| 2111 default: | |
| 2112 if (!this.hasOwnProperty(n)) { | |
| 2113 this.copyOwnProperty(n, b, this); | 2152 this.copyOwnProperty(n, b, this); |
| 2114 } | 2153 } |
| 2115 break; | |
| 2116 } | 2154 } |
| 2117 }, this); | |
| 2118 }, | 2155 }, |
| 2119 _prepBehaviors: function () { | 2156 _prepBehaviors: function () { |
| 2120 this._prepFlattenedBehaviors(this.behaviors); | 2157 this._prepFlattenedBehaviors(this.behaviors); |
| 2121 }, | 2158 }, |
| 2122 _prepFlattenedBehaviors: function (behaviors) { | 2159 _prepFlattenedBehaviors: function (behaviors) { |
| 2123 for (var i = 0, l = behaviors.length; i < l; i++) { | 2160 for (var i = 0, l = behaviors.length; i < l; i++) { |
| 2124 this._prepBehavior(behaviors[i]); | 2161 this._prepBehavior(behaviors[i]); |
| 2125 } | 2162 } |
| 2126 this._prepBehavior(this); | 2163 this._prepBehavior(this); |
| 2127 }, | 2164 }, |
| 2128 _doBehavior: function (name, args) { | 2165 _doBehavior: function (name, args) { |
| 2129 this.behaviors.forEach(function (b) { | 2166 for (var i = 0; i < this.behaviors.length; i++) { |
| 2130 this._invokeBehavior(b, name, args); | 2167 this._invokeBehavior(this.behaviors[i], name, args); |
| 2131 }, this); | 2168 } |
| 2132 this._invokeBehavior(this, name, args); | 2169 this._invokeBehavior(this, name, args); |
| 2133 }, | 2170 }, |
| 2134 _invokeBehavior: function (b, name, args) { | 2171 _invokeBehavior: function (b, name, args) { |
| 2135 var fn = b[name]; | 2172 var fn = b[name]; |
| 2136 if (fn) { | 2173 if (fn) { |
| 2137 fn.apply(this, args || Polymer.nar); | 2174 fn.apply(this, args || Polymer.nar); |
| 2138 } | 2175 } |
| 2139 }, | 2176 }, |
| 2140 _marshalBehaviors: function () { | 2177 _marshalBehaviors: function () { |
| 2141 this.behaviors.forEach(function (b) { | 2178 for (var i = 0; i < this.behaviors.length; i++) { |
| 2142 this._marshalBehavior(b); | 2179 this._marshalBehavior(this.behaviors[i]); |
| 2143 }, this); | 2180 } |
| 2144 this._marshalBehavior(this); | 2181 this._marshalBehavior(this); |
| 2145 } | 2182 } |
| 2146 }); | 2183 }); |
| 2184 Polymer.Base._behaviorProperties = { |
| 2185 hostAttributes: true, |
| 2186 registered: true, |
| 2187 properties: true, |
| 2188 observers: true, |
| 2189 listeners: true, |
| 2190 created: true, |
| 2191 attached: true, |
| 2192 detached: true, |
| 2193 attributeChanged: true, |
| 2194 ready: true |
| 2195 }; |
| 2147 Polymer.Base._addFeature({ | 2196 Polymer.Base._addFeature({ |
| 2148 _getExtendedPrototype: function (tag) { | 2197 _getExtendedPrototype: function (tag) { |
| 2149 return this._getExtendedNativePrototype(tag); | 2198 return this._getExtendedNativePrototype(tag); |
| 2150 }, | 2199 }, |
| 2151 _nativePrototypes: {}, | 2200 _nativePrototypes: {}, |
| 2152 _getExtendedNativePrototype: function (tag) { | 2201 _getExtendedNativePrototype: function (tag) { |
| 2153 var p = this._nativePrototypes[tag]; | 2202 var p = this._nativePrototypes[tag]; |
| 2154 if (!p) { | 2203 if (!p) { |
| 2155 var np = this.getNativePrototype(tag); | 2204 var np = this.getNativePrototype(tag); |
| 2156 p = this.extend(Object.create(np), Polymer.Base); | 2205 p = this.extend(Object.create(np), Polymer.Base); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 } | 2237 } |
| 2189 return elt; | 2238 return elt; |
| 2190 } | 2239 } |
| 2191 }); | 2240 }); |
| 2192 Polymer.nob = Object.create(null); | 2241 Polymer.nob = Object.create(null); |
| 2193 Polymer.Base._addFeature({ | 2242 Polymer.Base._addFeature({ |
| 2194 properties: {}, | 2243 properties: {}, |
| 2195 getPropertyInfo: function (property) { | 2244 getPropertyInfo: function (property) { |
| 2196 var info = this._getPropertyInfo(property, this.properties); | 2245 var info = this._getPropertyInfo(property, this.properties); |
| 2197 if (!info) { | 2246 if (!info) { |
| 2198 this.behaviors.some(function (b) { | 2247 for (var i = 0; i < this.behaviors.length; i++) { |
| 2199 return info = this._getPropertyInfo(property, b.properties); | 2248 info = this._getPropertyInfo(property, this.behaviors[i].properties); |
| 2200 }, this); | 2249 if (info) { |
| 2250 return info; |
| 2251 } |
| 2252 } |
| 2253 ; |
| 2201 } | 2254 } |
| 2202 return info || Polymer.nob; | 2255 return info || Polymer.nob; |
| 2203 }, | 2256 }, |
| 2204 _getPropertyInfo: function (property, properties) { | 2257 _getPropertyInfo: function (property, properties) { |
| 2205 var p = properties && properties[property]; | 2258 var p = properties && properties[property]; |
| 2206 if (typeof p === 'function') { | 2259 if (typeof p === 'function') { |
| 2207 p = properties[property] = { type: p }; | 2260 p = properties[property] = { type: p }; |
| 2208 } | 2261 } |
| 2209 if (p) { | 2262 if (p) { |
| 2210 p.defined = true; | 2263 p.defined = true; |
| 2211 } | 2264 } |
| 2212 return p; | 2265 return p; |
| 2266 }, |
| 2267 _prepPropertyInfo: function () { |
| 2268 this._propertyInfo = {}; |
| 2269 for (var i = 0, p; i < this.behaviors.length; i++) { |
| 2270 this._addPropertyInfo(this._propertyInfo, this.behaviors[i].properties); |
| 2271 } |
| 2272 this._addPropertyInfo(this._propertyInfo, this.properties); |
| 2273 this._addPropertyInfo(this._propertyInfo, this._propertyEffects); |
| 2274 }, |
| 2275 _addPropertyInfo: function (target, source) { |
| 2276 if (source) { |
| 2277 var t, s; |
| 2278 for (var i in source) { |
| 2279 t = target[i]; |
| 2280 s = source[i]; |
| 2281 if (i[0] === '_' && !s.readOnly) { |
| 2282 continue; |
| 2283 } |
| 2284 if (!target[i]) { |
| 2285 target[i] = { |
| 2286 type: typeof s === 'function' ? s : s.type, |
| 2287 readOnly: s.readOnly, |
| 2288 attribute: Polymer.CaseMap.camelToDashCase(i) |
| 2289 }; |
| 2290 } else { |
| 2291 if (!t.type) { |
| 2292 t.type = s.type; |
| 2293 } |
| 2294 if (!t.readOnly) { |
| 2295 t.readOnly = s.readOnly; |
| 2296 } |
| 2297 } |
| 2298 } |
| 2299 } |
| 2213 } | 2300 } |
| 2214 }); | 2301 }); |
| 2215 Polymer.CaseMap = { | 2302 Polymer.CaseMap = { |
| 2216 _caseMap: {}, | 2303 _caseMap: {}, |
| 2217 dashToCamelCase: function (dash) { | 2304 dashToCamelCase: function (dash) { |
| 2218 var mapped = Polymer.CaseMap._caseMap[dash]; | 2305 var mapped = Polymer.CaseMap._caseMap[dash]; |
| 2219 if (mapped) { | 2306 if (mapped) { |
| 2220 return mapped; | 2307 return mapped; |
| 2221 } | 2308 } |
| 2222 if (dash.indexOf('-') < 0) { | 2309 if (dash.indexOf('-') < 0) { |
| 2223 return Polymer.CaseMap._caseMap[dash] = dash; | 2310 return Polymer.CaseMap._caseMap[dash] = dash; |
| 2224 } | 2311 } |
| 2225 return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g, function (m) { | 2312 return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g, function (m) { |
| 2226 return m[1].toUpperCase(); | 2313 return m[1].toUpperCase(); |
| 2227 }); | 2314 }); |
| 2228 }, | 2315 }, |
| 2229 camelToDashCase: function (camel) { | 2316 camelToDashCase: function (camel) { |
| 2230 var mapped = Polymer.CaseMap._caseMap[camel]; | 2317 var mapped = Polymer.CaseMap._caseMap[camel]; |
| 2231 if (mapped) { | 2318 if (mapped) { |
| 2232 return mapped; | 2319 return mapped; |
| 2233 } | 2320 } |
| 2234 return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g, function
(g) { | 2321 return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g, function
(g) { |
| 2235 return g[0] + '-' + g[1].toLowerCase(); | 2322 return g[0] + '-' + g[1].toLowerCase(); |
| 2236 }); | 2323 }); |
| 2237 } | 2324 } |
| 2238 }; | 2325 }; |
| 2239 Polymer.Base._addFeature({ | 2326 Polymer.Base._addFeature({ |
| 2240 _prepAttributes: function () { | 2327 _addHostAttributes: function (attributes) { |
| 2328 if (!this._aggregatedAttributes) { |
| 2241 this._aggregatedAttributes = {}; | 2329 this._aggregatedAttributes = {}; |
| 2242 }, | 2330 } |
| 2243 _addHostAttributes: function (attributes) { | |
| 2244 if (attributes) { | 2331 if (attributes) { |
| 2245 this.mixin(this._aggregatedAttributes, attributes); | 2332 this.mixin(this._aggregatedAttributes, attributes); |
| 2246 } | 2333 } |
| 2247 }, | 2334 }, |
| 2248 _marshalHostAttributes: function () { | 2335 _marshalHostAttributes: function () { |
| 2336 if (this._aggregatedAttributes) { |
| 2249 this._applyAttributes(this, this._aggregatedAttributes); | 2337 this._applyAttributes(this, this._aggregatedAttributes); |
| 2338 } |
| 2250 }, | 2339 }, |
| 2251 _applyAttributes: function (node, attr$) { | 2340 _applyAttributes: function (node, attr$) { |
| 2252 for (var n in attr$) { | 2341 for (var n in attr$) { |
| 2253 if (!this.hasAttribute(n) && n !== 'class') { | 2342 if (!this.hasAttribute(n) && n !== 'class') { |
| 2254 this.serializeValueToAttribute(attr$[n], n, this); | 2343 var v = attr$[n]; |
| 2344 this.serializeValueToAttribute(v, n, this); |
| 2255 } | 2345 } |
| 2256 } | 2346 } |
| 2257 }, | 2347 }, |
| 2258 _marshalAttributes: function () { | 2348 _marshalAttributes: function () { |
| 2259 this._takeAttributesToModel(this); | 2349 this._takeAttributesToModel(this); |
| 2260 }, | 2350 }, |
| 2261 _takeAttributesToModel: function (model) { | 2351 _takeAttributesToModel: function (model) { |
| 2262 for (var i = 0, l = this.attributes.length; i < l; i++) { | 2352 if (this.hasAttributes()) { |
| 2263 this._setAttributeToProperty(model, this.attributes[i].name); | 2353 for (var i in this._propertyInfo) { |
| 2354 var info = this._propertyInfo[i]; |
| 2355 if (this.hasAttribute(info.attribute)) { |
| 2356 this._setAttributeToProperty(model, info.attribute, i, info); |
| 2357 } |
| 2358 } |
| 2264 } | 2359 } |
| 2265 }, | 2360 }, |
| 2266 _setAttributeToProperty: function (model, attrName) { | 2361 _setAttributeToProperty: function (model, attribute, property, info) { |
| 2267 if (!this._serializing) { | 2362 if (!this._serializing) { |
| 2268 var propName = Polymer.CaseMap.dashToCamelCase(attrName); | 2363 var property = property || Polymer.CaseMap.dashToCamelCase(attribute); |
| 2269 var info = this.getPropertyInfo(propName); | 2364 info = info || this._propertyInfo && this._propertyInfo[property]; |
| 2270 if (info.defined || this._propertyEffects && this._propertyEffects[propName]) { | 2365 if (info && !info.readOnly) { |
| 2271 var val = this.getAttribute(attrName); | 2366 var v = this.getAttribute(attribute); |
| 2272 model[propName] = this.deserialize(val, info.type); | 2367 model[property] = this.deserialize(v, info.type); |
| 2273 } | 2368 } |
| 2274 } | 2369 } |
| 2275 }, | 2370 }, |
| 2276 _serializing: false, | 2371 _serializing: false, |
| 2277 reflectPropertyToAttribute: function (name) { | 2372 reflectPropertyToAttribute: function (property, attribute, value) { |
| 2278 this._serializing = true; | 2373 this._serializing = true; |
| 2279 this.serializeValueToAttribute(this[name], Polymer.CaseMap.camelToDashCase(name)
); | 2374 value = value === undefined ? this[property] : value; |
| 2375 this.serializeValueToAttribute(value, attribute || Polymer.CaseMap.camelToDashCa
se(property)); |
| 2280 this._serializing = false; | 2376 this._serializing = false; |
| 2281 }, | 2377 }, |
| 2282 serializeValueToAttribute: function (value, attribute, node) { | 2378 serializeValueToAttribute: function (value, attribute, node) { |
| 2283 var str = this.serialize(value); | 2379 var str = this.serialize(value); |
| 2284 (node || this)[str === undefined ? 'removeAttribute' : 'setAttribute'](attribute
, str); | 2380 node = node || this; |
| 2381 if (str === undefined) { |
| 2382 node.removeAttribute(attribute); |
| 2383 } else { |
| 2384 node.setAttribute(attribute, str); |
| 2385 } |
| 2285 }, | 2386 }, |
| 2286 deserialize: function (value, type) { | 2387 deserialize: function (value, type) { |
| 2287 switch (type) { | 2388 switch (type) { |
| 2288 case Number: | 2389 case Number: |
| 2289 value = Number(value); | 2390 value = Number(value); |
| 2290 break; | 2391 break; |
| 2291 case Boolean: | 2392 case Boolean: |
| 2292 value = value !== null; | 2393 value = value !== null; |
| 2293 break; | 2394 break; |
| 2294 case Object: | 2395 case Object: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2350 debouncer.complete(); | 2451 debouncer.complete(); |
| 2351 } | 2452 } |
| 2352 }, | 2453 }, |
| 2353 cancelDebouncer: function (jobName) { | 2454 cancelDebouncer: function (jobName) { |
| 2354 var debouncer = this._debouncers[jobName]; | 2455 var debouncer = this._debouncers[jobName]; |
| 2355 if (debouncer) { | 2456 if (debouncer) { |
| 2356 debouncer.stop(); | 2457 debouncer.stop(); |
| 2357 } | 2458 } |
| 2358 } | 2459 } |
| 2359 }); | 2460 }); |
| 2360 Polymer.version = '1.1.5'; | 2461 Polymer.version = '1.2.3'; |
| 2361 Polymer.Base._addFeature({ | 2462 Polymer.Base._addFeature({ |
| 2362 _registerFeatures: function () { | 2463 _registerFeatures: function () { |
| 2363 this._prepIs(); | 2464 this._prepIs(); |
| 2364 this._prepAttributes(); | |
| 2365 this._prepBehaviors(); | 2465 this._prepBehaviors(); |
| 2366 this._prepConstructor(); | 2466 this._prepConstructor(); |
| 2467 this._prepPropertyInfo(); |
| 2367 }, | 2468 }, |
| 2368 _prepBehavior: function (b) { | 2469 _prepBehavior: function (b) { |
| 2369 this._addHostAttributes(b.hostAttributes); | 2470 this._addHostAttributes(b.hostAttributes); |
| 2370 }, | 2471 }, |
| 2371 _marshalBehavior: function (b) { | 2472 _marshalBehavior: function (b) { |
| 2372 }, | 2473 }, |
| 2373 _initFeatures: function () { | 2474 _initFeatures: function () { |
| 2374 this._marshalHostAttributes(); | 2475 this._marshalHostAttributes(); |
| 2375 this._setupDebouncers(); | 2476 this._setupDebouncers(); |
| 2376 this._marshalBehaviors(); | 2477 this._marshalBehaviors(); |
| 2377 } | 2478 } |
| 2378 }); | 2479 }); |
| 2379 Polymer.Base._addFeature({ | 2480 Polymer.Base._addFeature({ |
| 2380 _prepTemplate: function () { | 2481 _prepTemplate: function () { |
| 2381 this._template = this._template || Polymer.DomModule.import(this.is, 'template')
; | 2482 if (this._template === undefined) { |
| 2483 this._template = Polymer.DomModule.import(this.is, 'template'); |
| 2484 } |
| 2382 if (this._template && this._template.hasAttribute('is')) { | 2485 if (this._template && this._template.hasAttribute('is')) { |
| 2383 this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not
be a type-extension, found', this._template, 'Move inside simple <template>.'))
; | 2486 this._warn(this._logf('_prepTemplate', 'top-level Polymer template ' + 'must not
be a type-extension, found', this._template, 'Move inside simple <template>.'))
; |
| 2384 } | 2487 } |
| 2385 if (this._template && !this._template.content && HTMLTemplateElement.bootstrap)
{ | 2488 if (this._template && !this._template.content && window.HTMLTemplateElement && H
TMLTemplateElement.decorate) { |
| 2386 HTMLTemplateElement.decorate(this._template); | 2489 HTMLTemplateElement.decorate(this._template); |
| 2387 HTMLTemplateElement.bootstrap(this._template.content); | |
| 2388 } | 2490 } |
| 2389 }, | 2491 }, |
| 2390 _stampTemplate: function () { | 2492 _stampTemplate: function () { |
| 2391 if (this._template) { | 2493 if (this._template) { |
| 2392 this.root = this.instanceTemplate(this._template); | 2494 this.root = this.instanceTemplate(this._template); |
| 2393 } | 2495 } |
| 2394 }, | 2496 }, |
| 2395 instanceTemplate: function (template) { | 2497 instanceTemplate: function (template) { |
| 2396 var dom = document.importNode(template._content || template.content, true); | 2498 var dom = document.importNode(template._content || template.content, true); |
| 2397 return dom; | 2499 return dom; |
| 2398 } | 2500 } |
| 2399 }); | 2501 }); |
| 2400 (function () { | 2502 (function () { |
| 2401 var baseAttachedCallback = Polymer.Base.attachedCallback; | 2503 var baseAttachedCallback = Polymer.Base.attachedCallback; |
| 2402 Polymer.Base._addFeature({ | 2504 Polymer.Base._addFeature({ |
| 2403 _hostStack: [], | 2505 _hostStack: [], |
| 2404 ready: function () { | 2506 ready: function () { |
| 2405 }, | 2507 }, |
| 2406 _pushHost: function (host) { | 2508 _registerHost: function (host) { |
| 2407 this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.l
ength - 1]; | 2509 this.dataHost = host = host || Polymer.Base._hostStack[Polymer.Base._hostStack.l
ength - 1]; |
| 2408 if (host && host._clients) { | 2510 if (host && host._clients) { |
| 2409 host._clients.push(this); | 2511 host._clients.push(this); |
| 2410 } | 2512 } |
| 2411 this._beginHost(); | |
| 2412 }, | 2513 }, |
| 2413 _beginHost: function () { | 2514 _beginHosting: function () { |
| 2414 Polymer.Base._hostStack.push(this); | 2515 Polymer.Base._hostStack.push(this); |
| 2415 if (!this._clients) { | 2516 if (!this._clients) { |
| 2416 this._clients = []; | 2517 this._clients = []; |
| 2417 } | 2518 } |
| 2418 }, | 2519 }, |
| 2419 _popHost: function () { | 2520 _endHosting: function () { |
| 2420 Polymer.Base._hostStack.pop(); | 2521 Polymer.Base._hostStack.pop(); |
| 2421 }, | 2522 }, |
| 2422 _tryReady: function () { | 2523 _tryReady: function () { |
| 2423 if (this._canReady()) { | 2524 if (this._canReady()) { |
| 2424 this._ready(); | 2525 this._ready(); |
| 2425 } | 2526 } |
| 2426 }, | 2527 }, |
| 2427 _canReady: function () { | 2528 _canReady: function () { |
| 2428 return !this.dataHost || this.dataHost._clientsReadied; | 2529 return !this.dataHost || this.dataHost._clientsReadied; |
| 2429 }, | 2530 }, |
| 2430 _ready: function () { | 2531 _ready: function () { |
| 2431 this._beforeClientsReady(); | 2532 this._beforeClientsReady(); |
| 2533 if (this._template) { |
| 2432 this._setupRoot(); | 2534 this._setupRoot(); |
| 2433 this._readyClients(); | 2535 this._readyClients(); |
| 2536 } |
| 2537 this._clientsReadied = true; |
| 2538 this._clients = null; |
| 2434 this._afterClientsReady(); | 2539 this._afterClientsReady(); |
| 2435 this._readySelf(); | 2540 this._readySelf(); |
| 2436 }, | 2541 }, |
| 2437 _readyClients: function () { | 2542 _readyClients: function () { |
| 2438 this._beginDistribute(); | 2543 this._beginDistribute(); |
| 2439 var c$ = this._clients; | 2544 var c$ = this._clients; |
| 2545 if (c$) { |
| 2440 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | 2546 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { |
| 2441 c._ready(); | 2547 c._ready(); |
| 2442 } | 2548 } |
| 2549 } |
| 2443 this._finishDistribute(); | 2550 this._finishDistribute(); |
| 2444 this._clientsReadied = true; | |
| 2445 this._clients = null; | |
| 2446 }, | 2551 }, |
| 2447 _readySelf: function () { | 2552 _readySelf: function () { |
| 2448 this._doBehavior('ready'); | 2553 this._doBehavior('ready'); |
| 2449 this._readied = true; | 2554 this._readied = true; |
| 2450 if (this._attachedPending) { | 2555 if (this._attachedPending) { |
| 2451 this._attachedPending = false; | 2556 this._attachedPending = false; |
| 2452 this.attachedCallback(); | 2557 this.attachedCallback(); |
| 2453 } | 2558 } |
| 2454 }, | 2559 }, |
| 2455 _beforeClientsReady: function () { | 2560 _beforeClientsReady: function () { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2631 }, | 2736 }, |
| 2632 calculateSplices: function (current, previous) { | 2737 calculateSplices: function (current, previous) { |
| 2633 return this.calcSplices(current, 0, current.length, previous, 0, previous.length
); | 2738 return this.calcSplices(current, 0, current.length, previous, 0, previous.length
); |
| 2634 }, | 2739 }, |
| 2635 equals: function (currentValue, previousValue) { | 2740 equals: function (currentValue, previousValue) { |
| 2636 return currentValue === previousValue; | 2741 return currentValue === previousValue; |
| 2637 } | 2742 } |
| 2638 }; | 2743 }; |
| 2639 return new ArraySplice(); | 2744 return new ArraySplice(); |
| 2640 }(); | 2745 }(); |
| 2641 Polymer.EventApi = function () { | |
| 2642 var Settings = Polymer.Settings; | |
| 2643 var EventApi = function (event) { | |
| 2644 this.event = event; | |
| 2645 }; | |
| 2646 if (Settings.useShadow) { | |
| 2647 EventApi.prototype = { | |
| 2648 get rootTarget() { | |
| 2649 return this.event.path[0]; | |
| 2650 }, | |
| 2651 get localTarget() { | |
| 2652 return this.event.target; | |
| 2653 }, | |
| 2654 get path() { | |
| 2655 return this.event.path; | |
| 2656 } | |
| 2657 }; | |
| 2658 } else { | |
| 2659 EventApi.prototype = { | |
| 2660 get rootTarget() { | |
| 2661 return this.event.target; | |
| 2662 }, | |
| 2663 get localTarget() { | |
| 2664 var current = this.event.currentTarget; | |
| 2665 var currentRoot = current && Polymer.dom(current).getOwnerRoot(); | |
| 2666 var p$ = this.path; | |
| 2667 for (var i = 0; i < p$.length; i++) { | |
| 2668 if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) { | |
| 2669 return p$[i]; | |
| 2670 } | |
| 2671 } | |
| 2672 }, | |
| 2673 get path() { | |
| 2674 if (!this.event._path) { | |
| 2675 var path = []; | |
| 2676 var o = this.rootTarget; | |
| 2677 while (o) { | |
| 2678 path.push(o); | |
| 2679 o = Polymer.dom(o).parentNode || o.host; | |
| 2680 } | |
| 2681 path.push(window); | |
| 2682 this.event._path = path; | |
| 2683 } | |
| 2684 return this.event._path; | |
| 2685 } | |
| 2686 }; | |
| 2687 } | |
| 2688 var factory = function (event) { | |
| 2689 if (!event.__eventApi) { | |
| 2690 event.__eventApi = new EventApi(event); | |
| 2691 } | |
| 2692 return event.__eventApi; | |
| 2693 }; | |
| 2694 return { factory: factory }; | |
| 2695 }(); | |
| 2696 Polymer.domInnerHTML = function () { | 2746 Polymer.domInnerHTML = function () { |
| 2697 var escapeAttrRegExp = /[&\u00A0"]/g; | 2747 var escapeAttrRegExp = /[&\u00A0"]/g; |
| 2698 var escapeDataRegExp = /[&\u00A0<>]/g; | 2748 var escapeDataRegExp = /[&\u00A0<>]/g; |
| 2699 function escapeReplace(c) { | 2749 function escapeReplace(c) { |
| 2700 switch (c) { | 2750 switch (c) { |
| 2701 case '&': | 2751 case '&': |
| 2702 return '&'; | 2752 return '&'; |
| 2703 case '<': | 2753 case '<': |
| 2704 return '<'; | 2754 return '<'; |
| 2705 case '>': | 2755 case '>': |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2793 }(); | 2843 }(); |
| 2794 Polymer.DomApi = function () { | 2844 Polymer.DomApi = function () { |
| 2795 'use strict'; | 2845 'use strict'; |
| 2796 var Settings = Polymer.Settings; | 2846 var Settings = Polymer.Settings; |
| 2797 var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; | 2847 var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; |
| 2798 var nativeInsertBefore = Element.prototype.insertBefore; | 2848 var nativeInsertBefore = Element.prototype.insertBefore; |
| 2799 var nativeRemoveChild = Element.prototype.removeChild; | 2849 var nativeRemoveChild = Element.prototype.removeChild; |
| 2800 var nativeAppendChild = Element.prototype.appendChild; | 2850 var nativeAppendChild = Element.prototype.appendChild; |
| 2801 var nativeCloneNode = Element.prototype.cloneNode; | 2851 var nativeCloneNode = Element.prototype.cloneNode; |
| 2802 var nativeImportNode = Document.prototype.importNode; | 2852 var nativeImportNode = Document.prototype.importNode; |
| 2853 var needsToWrap = Settings.hasShadow && !Settings.nativeShadow; |
| 2854 var wrap = window.wrap ? window.wrap : function (node) { |
| 2855 return node; |
| 2856 }; |
| 2803 var DomApi = function (node) { | 2857 var DomApi = function (node) { |
| 2804 this.node = node; | 2858 this.node = needsToWrap ? wrap(node) : node; |
| 2805 if (this.patch) { | 2859 if (this.patch) { |
| 2806 this.patch(); | 2860 this.patch(); |
| 2807 } | 2861 } |
| 2808 }; | 2862 }; |
| 2809 if (window.wrap && Settings.useShadow && !Settings.useNativeShadow) { | |
| 2810 DomApi = function (node) { | |
| 2811 this.node = wrap(node); | |
| 2812 if (this.patch) { | |
| 2813 this.patch(); | |
| 2814 } | |
| 2815 }; | |
| 2816 } | |
| 2817 DomApi.prototype = { | 2863 DomApi.prototype = { |
| 2818 flush: function () { | 2864 flush: function () { |
| 2819 Polymer.dom.flush(); | 2865 Polymer.dom.flush(); |
| 2820 }, | 2866 }, |
| 2867 deepContains: function (node) { |
| 2868 if (this.node.contains(node)) { |
| 2869 return true; |
| 2870 } |
| 2871 var n = node; |
| 2872 var wrappedDocument = wrap(document); |
| 2873 while (n && n !== wrappedDocument && n !== this.node) { |
| 2874 n = Polymer.dom(n).parentNode || n.host; |
| 2875 } |
| 2876 return n === this.node; |
| 2877 }, |
| 2821 _lazyDistribute: function (host) { | 2878 _lazyDistribute: function (host) { |
| 2822 if (host.shadyRoot && host.shadyRoot._distributionClean) { | 2879 if (host.shadyRoot && host.shadyRoot._distributionClean) { |
| 2823 host.shadyRoot._distributionClean = false; | 2880 host.shadyRoot._distributionClean = false; |
| 2824 Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent)); | 2881 Polymer.dom.addDebouncer(host.debounce('_distribute', host._distributeContent)); |
| 2825 } | 2882 } |
| 2826 }, | 2883 }, |
| 2827 appendChild: function (node) { | 2884 appendChild: function (node) { |
| 2828 return this._addNode(node); | 2885 return this._addNode(node); |
| 2829 }, | 2886 }, |
| 2830 insertBefore: function (node, ref_node) { | 2887 insertBefore: function (node, ref_node) { |
| 2831 return this._addNode(node, ref_node); | 2888 return this._addNode(node, ref_node); |
| 2832 }, | 2889 }, |
| 2833 _addNode: function (node, ref_node) { | 2890 _addNode: function (node, ref_node) { |
| 2834 this._removeNodeFromHost(node, true); | 2891 this._removeNodeFromParent(node); |
| 2835 var addedInsertionPoint; | 2892 var addedInsertionPoint; |
| 2836 var root = this.getOwnerRoot(); | 2893 var root = this.getOwnerRoot(); |
| 2837 if (root) { | 2894 if (root) { |
| 2838 addedInsertionPoint = this._maybeAddInsertionPoint(node, this.node); | 2895 addedInsertionPoint = this._maybeAddInsertionPoint(node, this.node); |
| 2839 } | 2896 } |
| 2840 if (this._nodeHasLogicalChildren(this.node)) { | 2897 if (this._nodeHasLogicalChildren(this.node)) { |
| 2841 if (ref_node) { | 2898 if (ref_node) { |
| 2842 var children = this.childNodes; | 2899 var children = this.childNodes; |
| 2843 var index = children.indexOf(ref_node); | 2900 var index = children.indexOf(ref_node); |
| 2844 if (index < 0) { | 2901 if (index < 0) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2856 addToComposedParent(container, node, ref_node); | 2913 addToComposedParent(container, node, ref_node); |
| 2857 if (ref_node) { | 2914 if (ref_node) { |
| 2858 nativeInsertBefore.call(container, node, ref_node); | 2915 nativeInsertBefore.call(container, node, ref_node); |
| 2859 } else { | 2916 } else { |
| 2860 nativeAppendChild.call(container, node); | 2917 nativeAppendChild.call(container, node); |
| 2861 } | 2918 } |
| 2862 } | 2919 } |
| 2863 if (addedInsertionPoint) { | 2920 if (addedInsertionPoint) { |
| 2864 this._updateInsertionPoints(root.host); | 2921 this._updateInsertionPoints(root.host); |
| 2865 } | 2922 } |
| 2923 this.notifyObserver(); |
| 2866 return node; | 2924 return node; |
| 2867 }, | 2925 }, |
| 2868 removeChild: function (node) { | 2926 removeChild: function (node) { |
| 2869 if (factory(node).parentNode !== this.node) { | 2927 if (factory(node).parentNode !== this.node) { |
| 2870 console.warn('The node to be removed is not a child of this node', node); | 2928 console.warn('The node to be removed is not a child of this node', node); |
| 2871 } | 2929 } |
| 2872 this._removeNodeFromHost(node); | 2930 this._removeNodeFromHost(node); |
| 2873 if (!this._maybeDistribute(node, this.node)) { | 2931 if (!this._maybeDistribute(node, this.node)) { |
| 2874 var container = this.node._isShadyRoot ? this.node.host : this.node; | 2932 var container = this.node._isShadyRoot ? this.node.host : this.node; |
| 2875 if (container === node.parentNode) { | 2933 if (container === node.parentNode) { |
| 2876 removeFromComposedParent(container, node); | 2934 removeFromComposedParent(container, node); |
| 2877 nativeRemoveChild.call(container, node); | 2935 nativeRemoveChild.call(container, node); |
| 2878 } | 2936 } |
| 2879 } | 2937 } |
| 2938 this.notifyObserver(); |
| 2880 return node; | 2939 return node; |
| 2881 }, | 2940 }, |
| 2882 replaceChild: function (node, ref_node) { | 2941 replaceChild: function (node, ref_node) { |
| 2883 this.insertBefore(node, ref_node); | 2942 this.insertBefore(node, ref_node); |
| 2884 this.removeChild(ref_node); | 2943 this.removeChild(ref_node); |
| 2885 return node; | 2944 return node; |
| 2886 }, | 2945 }, |
| 2887 _hasCachedOwnerRoot: function (node) { | 2946 _hasCachedOwnerRoot: function (node) { |
| 2888 return Boolean(node._ownerShadyRoot !== undefined); | 2947 return Boolean(node._ownerShadyRoot !== undefined); |
| 2889 }, | 2948 }, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2962 saveLightChildrenIfNeeded(c); | 3021 saveLightChildrenIfNeeded(c); |
| 2963 saveLightChildrenIfNeeded(factory(c).parentNode); | 3022 saveLightChildrenIfNeeded(factory(c).parentNode); |
| 2964 } | 3023 } |
| 2965 }, | 3024 }, |
| 2966 _nodeHasLogicalChildren: function (node) { | 3025 _nodeHasLogicalChildren: function (node) { |
| 2967 return Boolean(node._lightChildren !== undefined); | 3026 return Boolean(node._lightChildren !== undefined); |
| 2968 }, | 3027 }, |
| 2969 _parentNeedsDistribution: function (parent) { | 3028 _parentNeedsDistribution: function (parent) { |
| 2970 return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot); | 3029 return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot); |
| 2971 }, | 3030 }, |
| 3031 _removeNodeFromParent: function (node) { |
| 3032 var parent = node._lightParent || node.parentNode; |
| 3033 if (parent && hasDomApi(parent)) { |
| 3034 factory(parent).notifyObserver(); |
| 3035 } |
| 3036 this._removeNodeFromHost(node, true); |
| 3037 }, |
| 2972 _removeNodeFromHost: function (node, ensureComposedRemoval) { | 3038 _removeNodeFromHost: function (node, ensureComposedRemoval) { |
| 2973 var hostNeedsDist; | 3039 var hostNeedsDist; |
| 2974 var root; | 3040 var root; |
| 2975 var parent = node._lightParent; | 3041 var parent = node._lightParent; |
| 2976 if (parent) { | 3042 if (parent) { |
| 2977 factory(node)._distributeParent(); | 3043 factory(node)._distributeParent(); |
| 2978 root = this._ownerShadyRootForNode(node); | 3044 root = this._ownerShadyRootForNode(node); |
| 2979 if (root) { | 3045 if (root) { |
| 2980 root.host._elementRemove(node); | 3046 root.host._elementRemove(node); |
| 2981 hostNeedsDist = this._removeDistributedChildren(root, node); | 3047 hostNeedsDist = this._removeDistributedChildren(root, node); |
| 2982 } | 3048 } |
| 2983 this._removeLogicalInfo(node, node._lightParent); | 3049 this._removeLogicalInfo(node, parent); |
| 2984 } | 3050 } |
| 2985 this._removeOwnerShadyRoot(node); | 3051 this._removeOwnerShadyRoot(node); |
| 2986 if (root && hostNeedsDist) { | 3052 if (root && hostNeedsDist) { |
| 2987 this._updateInsertionPoints(root.host); | 3053 this._updateInsertionPoints(root.host); |
| 2988 this._lazyDistribute(root.host); | 3054 this._lazyDistribute(root.host); |
| 2989 } else if (ensureComposedRemoval) { | 3055 } else if (ensureComposedRemoval) { |
| 2990 removeFromComposedParent(getComposedParent(node), node); | 3056 removeFromComposedParent(getComposedParent(node), node); |
| 2991 } | 3057 } |
| 2992 }, | 3058 }, |
| 2993 _removeDistributedChildren: function (root, container) { | 3059 _removeDistributedChildren: function (root, container) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3021 _addNodeToHost: function (node) { | 3087 _addNodeToHost: function (node) { |
| 3022 var root = this.getOwnerRoot(); | 3088 var root = this.getOwnerRoot(); |
| 3023 if (root) { | 3089 if (root) { |
| 3024 root.host._elementAdd(node); | 3090 root.host._elementAdd(node); |
| 3025 } | 3091 } |
| 3026 }, | 3092 }, |
| 3027 _addLogicalInfo: function (node, container, index) { | 3093 _addLogicalInfo: function (node, container, index) { |
| 3028 var children = factory(container).childNodes; | 3094 var children = factory(container).childNodes; |
| 3029 index = index === undefined ? children.length : index; | 3095 index = index === undefined ? children.length : index; |
| 3030 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | 3096 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 3031 var c$ = Array.prototype.slice.call(node.childNodes); | 3097 var c$ = arrayCopyChildNodes(node); |
| 3032 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { | 3098 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { |
| 3033 children.splice(index++, 0, n); | 3099 children.splice(index++, 0, n); |
| 3034 n._lightParent = container; | 3100 n._lightParent = container; |
| 3035 } | 3101 } |
| 3036 } else { | 3102 } else { |
| 3037 children.splice(index, 0, node); | 3103 children.splice(index, 0, node); |
| 3038 node._lightParent = container; | 3104 node._lightParent = container; |
| 3039 } | 3105 } |
| 3040 }, | 3106 }, |
| 3041 _removeLogicalInfo: function (node, container) { | 3107 _removeLogicalInfo: function (node, container) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3092 } | 3158 } |
| 3093 this._queryElements(factory(node).childNodes, matcher, list); | 3159 this._queryElements(factory(node).childNodes, matcher, list); |
| 3094 }, | 3160 }, |
| 3095 getDestinationInsertionPoints: function () { | 3161 getDestinationInsertionPoints: function () { |
| 3096 return this.node._destinationInsertionPoints || []; | 3162 return this.node._destinationInsertionPoints || []; |
| 3097 }, | 3163 }, |
| 3098 getDistributedNodes: function () { | 3164 getDistributedNodes: function () { |
| 3099 return this.node._distributedNodes || []; | 3165 return this.node._distributedNodes || []; |
| 3100 }, | 3166 }, |
| 3101 queryDistributedElements: function (selector) { | 3167 queryDistributedElements: function (selector) { |
| 3102 var c$ = this.childNodes; | 3168 var c$ = this.getEffectiveChildNodes(); |
| 3103 var list = []; | 3169 var list = []; |
| 3104 this._distributedFilter(selector, c$, list); | |
| 3105 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | 3170 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { |
| 3106 if (c.localName === CONTENT) { | 3171 if (c.nodeType === Node.ELEMENT_NODE && matchesSelector.call(c, selector)) { |
| 3107 this._distributedFilter(selector, factory(c).getDistributedNodes(), list); | 3172 list.push(c); |
| 3108 } | 3173 } |
| 3109 } | 3174 } |
| 3110 return list; | 3175 return list; |
| 3111 }, | 3176 }, |
| 3112 _distributedFilter: function (selector, list, results) { | 3177 getEffectiveChildNodes: function () { |
| 3113 results = results || []; | 3178 var list = []; |
| 3114 for (var i = 0, l = list.length, d; i < l && (d = list[i]); i++) { | 3179 var c$ = this.childNodes; |
| 3115 if (d.nodeType === Node.ELEMENT_NODE && d.localName !== CONTENT && matchesSelect
or.call(d, selector)) { | 3180 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { |
| 3116 results.push(d); | 3181 if (c.localName === CONTENT) { |
| 3182 var d$ = factory(c).getDistributedNodes(); |
| 3183 for (var j = 0; j < d$.length; j++) { |
| 3184 list.push(d$[j]); |
| 3185 } |
| 3186 } else { |
| 3187 list.push(c); |
| 3117 } | 3188 } |
| 3118 } | 3189 } |
| 3119 return results; | 3190 return list; |
| 3120 }, | 3191 }, |
| 3121 _clear: function () { | 3192 _clear: function () { |
| 3122 while (this.childNodes.length) { | 3193 while (this.childNodes.length) { |
| 3123 this.removeChild(this.childNodes[0]); | 3194 this.removeChild(this.childNodes[0]); |
| 3124 } | 3195 } |
| 3125 }, | 3196 }, |
| 3126 setAttribute: function (name, value) { | 3197 setAttribute: function (name, value) { |
| 3127 this.node.setAttribute(name, value); | 3198 this.node.setAttribute(name, value); |
| 3128 this._distributeParent(); | 3199 this._distributeParent(); |
| 3129 }, | 3200 }, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3153 var n = nativeImportNode.call(doc, externalNode, false); | 3224 var n = nativeImportNode.call(doc, externalNode, false); |
| 3154 if (deep) { | 3225 if (deep) { |
| 3155 var c$ = factory(externalNode).childNodes; | 3226 var c$ = factory(externalNode).childNodes; |
| 3156 var d = factory(n); | 3227 var d = factory(n); |
| 3157 for (var i = 0, nc; i < c$.length; i++) { | 3228 for (var i = 0, nc; i < c$.length; i++) { |
| 3158 nc = factory(doc).importNode(c$[i], true); | 3229 nc = factory(doc).importNode(c$[i], true); |
| 3159 d.appendChild(nc); | 3230 d.appendChild(nc); |
| 3160 } | 3231 } |
| 3161 } | 3232 } |
| 3162 return n; | 3233 return n; |
| 3234 }, |
| 3235 observeNodes: function (callback) { |
| 3236 if (callback) { |
| 3237 if (!this.observer) { |
| 3238 this.observer = this.node.localName === CONTENT ? new DomApi.DistributedNodesObs
erver(this) : new DomApi.EffectiveNodesObserver(this); |
| 3163 } | 3239 } |
| 3164 }; | 3240 return this.observer.addListener(callback); |
| 3165 Object.defineProperty(DomApi.prototype, 'classList', { | |
| 3166 get: function () { | |
| 3167 if (!this._classList) { | |
| 3168 this._classList = new DomApi.ClassList(this); | |
| 3169 } | 3241 } |
| 3170 return this._classList; | |
| 3171 }, | 3242 }, |
| 3172 configurable: true | 3243 unobserveNodes: function (handle) { |
| 3173 }); | 3244 if (this.observer) { |
| 3174 DomApi.ClassList = function (host) { | 3245 this.observer.removeListener(handle); |
| 3175 this.domApi = host; | 3246 } |
| 3176 this.node = host.node; | |
| 3177 }; | |
| 3178 DomApi.ClassList.prototype = { | |
| 3179 add: function () { | |
| 3180 this.node.classList.add.apply(this.node.classList, arguments); | |
| 3181 this.domApi._distributeParent(); | |
| 3182 }, | 3247 }, |
| 3183 remove: function () { | 3248 notifyObserver: function () { |
| 3184 this.node.classList.remove.apply(this.node.classList, arguments); | 3249 if (this.observer) { |
| 3185 this.domApi._distributeParent(); | 3250 this.observer.notify(); |
| 3186 }, | 3251 } |
| 3187 toggle: function () { | |
| 3188 this.node.classList.toggle.apply(this.node.classList, arguments); | |
| 3189 this.domApi._distributeParent(); | |
| 3190 }, | |
| 3191 contains: function () { | |
| 3192 return this.node.classList.contains.apply(this.node.classList, arguments); | |
| 3193 } | 3252 } |
| 3194 }; | 3253 }; |
| 3195 if (!Settings.useShadow) { | 3254 if (!Settings.useShadow) { |
| 3196 Object.defineProperties(DomApi.prototype, { | 3255 Object.defineProperties(DomApi.prototype, { |
| 3197 childNodes: { | 3256 childNodes: { |
| 3198 get: function () { | 3257 get: function () { |
| 3199 var c$ = getLightChildren(this.node); | 3258 var c$ = getLightChildren(this.node); |
| 3200 return Array.isArray(c$) ? c$ : Array.prototype.slice.call(c$); | 3259 return Array.isArray(c$) ? c$ : arrayCopyChildNodes(this.node); |
| 3201 }, | 3260 }, |
| 3202 configurable: true | 3261 configurable: true |
| 3203 }, | 3262 }, |
| 3204 children: { | 3263 children: { |
| 3205 get: function () { | 3264 get: function () { |
| 3206 return Array.prototype.filter.call(this.childNodes, function (n) { | 3265 return Array.prototype.filter.call(this.childNodes, function (n) { |
| 3207 return n.nodeType === Node.ELEMENT_NODE; | 3266 return n.nodeType === Node.ELEMENT_NODE; |
| 3208 }); | 3267 }); |
| 3209 }, | 3268 }, |
| 3210 configurable: true | 3269 configurable: true |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3313 } else { | 3372 } else { |
| 3314 return getInnerHTML(this.node); | 3373 return getInnerHTML(this.node); |
| 3315 } | 3374 } |
| 3316 }, | 3375 }, |
| 3317 set: function (text) { | 3376 set: function (text) { |
| 3318 var nt = this.node.nodeType; | 3377 var nt = this.node.nodeType; |
| 3319 if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) { | 3378 if (nt !== Node.TEXT_NODE || nt !== Node.COMMENT_NODE) { |
| 3320 this._clear(); | 3379 this._clear(); |
| 3321 var d = document.createElement('div'); | 3380 var d = document.createElement('div'); |
| 3322 d.innerHTML = text; | 3381 d.innerHTML = text; |
| 3323 var c$ = Array.prototype.slice.call(d.childNodes); | 3382 var c$ = arrayCopyChildNodes(d); |
| 3324 for (var i = 0; i < c$.length; i++) { | 3383 for (var i = 0; i < c$.length; i++) { |
| 3325 this.appendChild(c$[i]); | 3384 this.appendChild(c$[i]); |
| 3326 } | 3385 } |
| 3327 } | 3386 } |
| 3328 }, | 3387 }, |
| 3329 configurable: true | 3388 configurable: true |
| 3330 } | 3389 } |
| 3331 }); | 3390 }); |
| 3332 DomApi.prototype._getComposedInnerHTML = function () { | 3391 DomApi.prototype._getComposedInnerHTML = function () { |
| 3333 return getInnerHTML(this.node, true); | 3392 return getInnerHTML(this.node, true); |
| 3334 }; | 3393 }; |
| 3335 } else { | 3394 } else { |
| 3336 var forwardMethods = [ | 3395 var forwardMethods = function (m$) { |
| 3396 for (var i = 0; i < m$.length; i++) { |
| 3397 forwardMethod(m$[i]); |
| 3398 } |
| 3399 }; |
| 3400 var forwardMethod = function (method) { |
| 3401 DomApi.prototype[method] = function () { |
| 3402 return this.node[method].apply(this.node, arguments); |
| 3403 }; |
| 3404 }; |
| 3405 forwardMethods([ |
| 3337 'cloneNode', | 3406 'cloneNode', |
| 3338 'appendChild', | 3407 'appendChild', |
| 3339 'insertBefore', | 3408 'insertBefore', |
| 3340 'removeChild', | 3409 'removeChild', |
| 3341 'replaceChild' | 3410 'replaceChild' |
| 3342 ]; | 3411 ]); |
| 3343 forwardMethods.forEach(function (name) { | |
| 3344 DomApi.prototype[name] = function () { | |
| 3345 return this.node[name].apply(this.node, arguments); | |
| 3346 }; | |
| 3347 }); | |
| 3348 DomApi.prototype.querySelectorAll = function (selector) { | 3412 DomApi.prototype.querySelectorAll = function (selector) { |
| 3349 return Array.prototype.slice.call(this.node.querySelectorAll(selector)); | 3413 return arrayCopy(this.node.querySelectorAll(selector)); |
| 3350 }; | 3414 }; |
| 3351 DomApi.prototype.getOwnerRoot = function () { | 3415 DomApi.prototype.getOwnerRoot = function () { |
| 3352 var n = this.node; | 3416 var n = this.node; |
| 3353 while (n) { | 3417 while (n) { |
| 3354 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) { | 3418 if (n.nodeType === Node.DOCUMENT_FRAGMENT_NODE && n.host) { |
| 3355 return n; | 3419 return n; |
| 3356 } | 3420 } |
| 3357 n = n.parentNode; | 3421 n = n.parentNode; |
| 3358 } | 3422 } |
| 3359 }; | 3423 }; |
| 3360 DomApi.prototype.importNode = function (externalNode, deep) { | 3424 DomApi.prototype.importNode = function (externalNode, deep) { |
| 3361 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; | 3425 var doc = this.node instanceof Document ? this.node : this.node.ownerDocument; |
| 3362 return doc.importNode(externalNode, deep); | 3426 return doc.importNode(externalNode, deep); |
| 3363 }; | 3427 }; |
| 3364 DomApi.prototype.getDestinationInsertionPoints = function () { | 3428 DomApi.prototype.getDestinationInsertionPoints = function () { |
| 3365 var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInse
rtionPoints(); | 3429 var n$ = this.node.getDestinationInsertionPoints && this.node.getDestinationInse
rtionPoints(); |
| 3366 return n$ ? Array.prototype.slice.call(n$) : []; | 3430 return n$ ? arrayCopy(n$) : []; |
| 3367 }; | 3431 }; |
| 3368 DomApi.prototype.getDistributedNodes = function () { | 3432 DomApi.prototype.getDistributedNodes = function () { |
| 3369 var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes(); | 3433 var n$ = this.node.getDistributedNodes && this.node.getDistributedNodes(); |
| 3370 return n$ ? Array.prototype.slice.call(n$) : []; | 3434 return n$ ? arrayCopy(n$) : []; |
| 3371 }; | 3435 }; |
| 3372 DomApi.prototype._distributeParent = function () { | 3436 DomApi.prototype._distributeParent = function () { |
| 3373 }; | 3437 }; |
| 3374 Object.defineProperties(DomApi.prototype, { | 3438 Object.defineProperties(DomApi.prototype, { |
| 3375 childNodes: { | 3439 childNodes: { |
| 3376 get: function () { | 3440 get: function () { |
| 3377 return Array.prototype.slice.call(this.node.childNodes); | 3441 return arrayCopyChildNodes(this.node); |
| 3378 }, | 3442 }, |
| 3379 configurable: true | 3443 configurable: true |
| 3380 }, | 3444 }, |
| 3381 children: { | 3445 children: { |
| 3382 get: function () { | 3446 get: function () { |
| 3383 return Array.prototype.slice.call(this.node.children); | 3447 return arrayCopyChildren(this.node); |
| 3384 }, | 3448 }, |
| 3385 configurable: true | 3449 configurable: true |
| 3386 }, | 3450 }, |
| 3387 textContent: { | 3451 textContent: { |
| 3388 get: function () { | 3452 get: function () { |
| 3389 return this.node.textContent; | 3453 return this.node.textContent; |
| 3390 }, | 3454 }, |
| 3391 set: function (value) { | 3455 set: function (value) { |
| 3392 return this.node.textContent = value; | 3456 return this.node.textContent = value; |
| 3393 }, | 3457 }, |
| 3394 configurable: true | 3458 configurable: true |
| 3395 }, | 3459 }, |
| 3396 innerHTML: { | 3460 innerHTML: { |
| 3397 get: function () { | 3461 get: function () { |
| 3398 return this.node.innerHTML; | 3462 return this.node.innerHTML; |
| 3399 }, | 3463 }, |
| 3400 set: function (value) { | 3464 set: function (value) { |
| 3401 return this.node.innerHTML = value; | 3465 return this.node.innerHTML = value; |
| 3402 }, | 3466 }, |
| 3403 configurable: true | 3467 configurable: true |
| 3404 } | 3468 } |
| 3405 }); | 3469 }); |
| 3406 var forwardProperties = [ | 3470 var forwardProperties = function (f$) { |
| 3471 for (var i = 0; i < f$.length; i++) { |
| 3472 forwardProperty(f$[i]); |
| 3473 } |
| 3474 }; |
| 3475 var forwardProperty = function (name) { |
| 3476 Object.defineProperty(DomApi.prototype, name, { |
| 3477 get: function () { |
| 3478 return this.node[name]; |
| 3479 }, |
| 3480 configurable: true |
| 3481 }); |
| 3482 }; |
| 3483 forwardProperties([ |
| 3407 'parentNode', | 3484 'parentNode', |
| 3408 'firstChild', | 3485 'firstChild', |
| 3409 'lastChild', | 3486 'lastChild', |
| 3410 'nextSibling', | 3487 'nextSibling', |
| 3411 'previousSibling', | 3488 'previousSibling', |
| 3412 'firstElementChild', | 3489 'firstElementChild', |
| 3413 'lastElementChild', | 3490 'lastElementChild', |
| 3414 'nextElementSibling', | 3491 'nextElementSibling', |
| 3415 'previousElementSibling' | 3492 'previousElementSibling' |
| 3416 ]; | 3493 ]); |
| 3417 forwardProperties.forEach(function (name) { | |
| 3418 Object.defineProperty(DomApi.prototype, name, { | |
| 3419 get: function () { | |
| 3420 return this.node[name]; | |
| 3421 }, | |
| 3422 configurable: true | |
| 3423 }); | |
| 3424 }); | |
| 3425 } | 3494 } |
| 3426 var CONTENT = 'content'; | 3495 var CONTENT = 'content'; |
| 3427 var factory = function (node, patch) { | 3496 function factory(node, patch) { |
| 3428 node = node || document; | 3497 node = node || document; |
| 3429 if (!node.__domApi) { | 3498 if (!node.__domApi) { |
| 3430 node.__domApi = new DomApi(node, patch); | 3499 node.__domApi = new DomApi(node, patch); |
| 3431 } | 3500 } |
| 3432 return node.__domApi; | 3501 return node.__domApi; |
| 3433 }; | 3502 } |
| 3503 ; |
| 3504 function hasDomApi(node) { |
| 3505 return Boolean(node.__domApi); |
| 3506 } |
| 3507 ; |
| 3434 Polymer.dom = function (obj, patch) { | 3508 Polymer.dom = function (obj, patch) { |
| 3435 if (obj instanceof Event) { | 3509 if (obj instanceof Event) { |
| 3436 return Polymer.EventApi.factory(obj); | 3510 return Polymer.EventApi.factory(obj); |
| 3437 } else { | 3511 } else { |
| 3438 return factory(obj, patch); | 3512 return factory(obj, patch); |
| 3439 } | 3513 } |
| 3440 }; | 3514 }; |
| 3441 Polymer.Base.extend(Polymer.dom, { | |
| 3442 _flushGuard: 0, | |
| 3443 _FLUSH_MAX: 100, | |
| 3444 _needsTakeRecords: !Polymer.Settings.useNativeCustomElements, | |
| 3445 _debouncers: [], | |
| 3446 _finishDebouncer: null, | |
| 3447 flush: function () { | |
| 3448 for (var i = 0; i < this._debouncers.length; i++) { | |
| 3449 this._debouncers[i].complete(); | |
| 3450 } | |
| 3451 if (this._finishDebouncer) { | |
| 3452 this._finishDebouncer.complete(); | |
| 3453 } | |
| 3454 this._flushPolyfills(); | |
| 3455 if (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) { | |
| 3456 this._flushGuard++; | |
| 3457 this.flush(); | |
| 3458 } else { | |
| 3459 if (this._flushGuard >= this._FLUSH_MAX) { | |
| 3460 console.warn('Polymer.dom.flush aborted. Flush may not be complete.'); | |
| 3461 } | |
| 3462 this._flushGuard = 0; | |
| 3463 } | |
| 3464 }, | |
| 3465 _flushPolyfills: function () { | |
| 3466 if (this._needsTakeRecords) { | |
| 3467 CustomElements.takeRecords(); | |
| 3468 } | |
| 3469 }, | |
| 3470 addDebouncer: function (debouncer) { | |
| 3471 this._debouncers.push(debouncer); | |
| 3472 this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlus
h); | |
| 3473 }, | |
| 3474 _finishFlush: function () { | |
| 3475 Polymer.dom._debouncers = []; | |
| 3476 } | |
| 3477 }); | |
| 3478 function getLightChildren(node) { | 3515 function getLightChildren(node) { |
| 3479 var children = node._lightChildren; | 3516 var children = node._lightChildren; |
| 3480 return children ? children : node.childNodes; | 3517 return children ? children : node.childNodes; |
| 3481 } | 3518 } |
| 3482 function getComposedChildren(node) { | 3519 function getComposedChildren(node) { |
| 3483 if (!node._composedChildren) { | 3520 if (!node._composedChildren) { |
| 3484 node._composedChildren = Array.prototype.slice.call(node.childNodes); | 3521 node._composedChildren = arrayCopyChildNodes(node); |
| 3485 } | 3522 } |
| 3486 return node._composedChildren; | 3523 return node._composedChildren; |
| 3487 } | 3524 } |
| 3488 function addToComposedParent(parent, node, ref_node) { | 3525 function addToComposedParent(parent, node, ref_node) { |
| 3489 var children = getComposedChildren(parent); | 3526 var children = getComposedChildren(parent); |
| 3490 var i = ref_node ? children.indexOf(ref_node) : -1; | 3527 var i = ref_node ? children.indexOf(ref_node) : -1; |
| 3491 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | 3528 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 3492 var fragChildren = getComposedChildren(node); | 3529 var fragChildren = getComposedChildren(node); |
| 3493 for (var j = 0; j < fragChildren.length; j++) { | 3530 for (var j = 0; j < fragChildren.length; j++) { |
| 3494 addNodeToComposedChildren(fragChildren[j], parent, children, i + j); | 3531 addNodeToComposedChildren(fragChildren[j], parent, children, i + j); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3510 if (parent) { | 3547 if (parent) { |
| 3511 var children = getComposedChildren(parent); | 3548 var children = getComposedChildren(parent); |
| 3512 var i = children.indexOf(node); | 3549 var i = children.indexOf(node); |
| 3513 if (i >= 0) { | 3550 if (i >= 0) { |
| 3514 children.splice(i, 1); | 3551 children.splice(i, 1); |
| 3515 } | 3552 } |
| 3516 } | 3553 } |
| 3517 } | 3554 } |
| 3518 function saveLightChildrenIfNeeded(node) { | 3555 function saveLightChildrenIfNeeded(node) { |
| 3519 if (!node._lightChildren) { | 3556 if (!node._lightChildren) { |
| 3520 var c$ = Array.prototype.slice.call(node.childNodes); | 3557 var c$ = arrayCopyChildNodes(node); |
| 3521 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { | 3558 for (var i = 0, l = c$.length, child; i < l && (child = c$[i]); i++) { |
| 3522 child._lightParent = child._lightParent || node; | 3559 child._lightParent = child._lightParent || node; |
| 3523 } | 3560 } |
| 3524 node._lightChildren = c$; | 3561 node._lightChildren = c$; |
| 3525 } | 3562 } |
| 3526 } | 3563 } |
| 3564 function arrayCopyChildNodes(parent) { |
| 3565 var copy = [], i = 0; |
| 3566 for (var n = parent.firstChild; n; n = n.nextSibling) { |
| 3567 copy[i++] = n; |
| 3568 } |
| 3569 return copy; |
| 3570 } |
| 3571 function arrayCopyChildren(parent) { |
| 3572 var copy = [], i = 0; |
| 3573 for (var n = parent.firstElementChild; n; n = n.nextElementSibling) { |
| 3574 copy[i++] = n; |
| 3575 } |
| 3576 return copy; |
| 3577 } |
| 3578 function arrayCopy(a$) { |
| 3579 var l = a$.length; |
| 3580 var copy = new Array(l); |
| 3581 for (var i = 0; i < l; i++) { |
| 3582 copy[i] = a$[i]; |
| 3583 } |
| 3584 return copy; |
| 3585 } |
| 3527 function hasInsertionPoint(root) { | 3586 function hasInsertionPoint(root) { |
| 3528 return Boolean(root && root._insertionPoints.length); | 3587 return Boolean(root && root._insertionPoints.length); |
| 3529 } | 3588 } |
| 3530 var p = Element.prototype; | 3589 var p = Element.prototype; |
| 3531 var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector ||
p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; | 3590 var matchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector ||
p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; |
| 3532 return { | 3591 return { |
| 3533 getLightChildren: getLightChildren, | 3592 getLightChildren: getLightChildren, |
| 3534 getComposedParent: getComposedParent, | 3593 getComposedParent: getComposedParent, |
| 3535 getComposedChildren: getComposedChildren, | 3594 getComposedChildren: getComposedChildren, |
| 3536 removeFromComposedParent: removeFromComposedParent, | 3595 removeFromComposedParent: removeFromComposedParent, |
| 3537 saveLightChildrenIfNeeded: saveLightChildrenIfNeeded, | 3596 saveLightChildrenIfNeeded: saveLightChildrenIfNeeded, |
| 3538 matchesSelector: matchesSelector, | 3597 matchesSelector: matchesSelector, |
| 3539 hasInsertionPoint: hasInsertionPoint, | 3598 hasInsertionPoint: hasInsertionPoint, |
| 3540 ctor: DomApi, | 3599 ctor: DomApi, |
| 3541 factory: factory | 3600 factory: factory, |
| 3542 }; | 3601 hasDomApi: hasDomApi, |
| 3602 arrayCopy: arrayCopy, |
| 3603 arrayCopyChildNodes: arrayCopyChildNodes, |
| 3604 arrayCopyChildren: arrayCopyChildren, |
| 3605 wrap: wrap |
| 3606 }; |
| 3607 }(); |
| 3608 Polymer.Base.extend(Polymer.dom, { |
| 3609 _flushGuard: 0, |
| 3610 _FLUSH_MAX: 100, |
| 3611 _needsTakeRecords: !Polymer.Settings.useNativeCustomElements, |
| 3612 _debouncers: [], |
| 3613 _staticFlushList: [], |
| 3614 _finishDebouncer: null, |
| 3615 flush: function () { |
| 3616 this._flushGuard = 0; |
| 3617 this._prepareFlush(); |
| 3618 while (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) { |
| 3619 for (var i = 0; i < this._debouncers.length; i++) { |
| 3620 this._debouncers[i].complete(); |
| 3621 } |
| 3622 if (this._finishDebouncer) { |
| 3623 this._finishDebouncer.complete(); |
| 3624 } |
| 3625 this._prepareFlush(); |
| 3626 this._flushGuard++; |
| 3627 } |
| 3628 if (this._flushGuard >= this._FLUSH_MAX) { |
| 3629 console.warn('Polymer.dom.flush aborted. Flush may not be complete.'); |
| 3630 } |
| 3631 }, |
| 3632 _prepareFlush: function () { |
| 3633 if (this._needsTakeRecords) { |
| 3634 CustomElements.takeRecords(); |
| 3635 } |
| 3636 for (var i = 0; i < this._staticFlushList.length; i++) { |
| 3637 this._staticFlushList[i](); |
| 3638 } |
| 3639 }, |
| 3640 addStaticFlush: function (fn) { |
| 3641 this._staticFlushList.push(fn); |
| 3642 }, |
| 3643 removeStaticFlush: function (fn) { |
| 3644 var i = this._staticFlushList.indexOf(fn); |
| 3645 if (i >= 0) { |
| 3646 this._staticFlushList.splice(i, 1); |
| 3647 } |
| 3648 }, |
| 3649 addDebouncer: function (debouncer) { |
| 3650 this._debouncers.push(debouncer); |
| 3651 this._finishDebouncer = Polymer.Debounce(this._finishDebouncer, this._finishFlus
h); |
| 3652 }, |
| 3653 _finishFlush: function () { |
| 3654 Polymer.dom._debouncers = []; |
| 3655 } |
| 3656 }); |
| 3657 Polymer.EventApi = function () { |
| 3658 'use strict'; |
| 3659 var DomApi = Polymer.DomApi.ctor; |
| 3660 var Settings = Polymer.Settings; |
| 3661 DomApi.Event = function (event) { |
| 3662 this.event = event; |
| 3663 }; |
| 3664 if (Settings.useShadow) { |
| 3665 DomApi.Event.prototype = { |
| 3666 get rootTarget() { |
| 3667 return this.event.path[0]; |
| 3668 }, |
| 3669 get localTarget() { |
| 3670 return this.event.target; |
| 3671 }, |
| 3672 get path() { |
| 3673 return this.event.path; |
| 3674 } |
| 3675 }; |
| 3676 } else { |
| 3677 DomApi.Event.prototype = { |
| 3678 get rootTarget() { |
| 3679 return this.event.target; |
| 3680 }, |
| 3681 get localTarget() { |
| 3682 var current = this.event.currentTarget; |
| 3683 var currentRoot = current && Polymer.dom(current).getOwnerRoot(); |
| 3684 var p$ = this.path; |
| 3685 for (var i = 0; i < p$.length; i++) { |
| 3686 if (Polymer.dom(p$[i]).getOwnerRoot() === currentRoot) { |
| 3687 return p$[i]; |
| 3688 } |
| 3689 } |
| 3690 }, |
| 3691 get path() { |
| 3692 if (!this.event._path) { |
| 3693 var path = []; |
| 3694 var o = this.rootTarget; |
| 3695 while (o) { |
| 3696 path.push(o); |
| 3697 o = Polymer.dom(o).parentNode || o.host; |
| 3698 } |
| 3699 path.push(window); |
| 3700 this.event._path = path; |
| 3701 } |
| 3702 return this.event._path; |
| 3703 } |
| 3704 }; |
| 3705 } |
| 3706 var factory = function (event) { |
| 3707 if (!event.__eventApi) { |
| 3708 event.__eventApi = new DomApi.Event(event); |
| 3709 } |
| 3710 return event.__eventApi; |
| 3711 }; |
| 3712 return { factory: factory }; |
| 3543 }(); | 3713 }(); |
| 3544 (function () { | 3714 (function () { |
| 3715 'use strict'; |
| 3716 var DomApi = Polymer.DomApi.ctor; |
| 3717 Object.defineProperty(DomApi.prototype, 'classList', { |
| 3718 get: function () { |
| 3719 if (!this._classList) { |
| 3720 this._classList = new DomApi.ClassList(this); |
| 3721 } |
| 3722 return this._classList; |
| 3723 }, |
| 3724 configurable: true |
| 3725 }); |
| 3726 DomApi.ClassList = function (host) { |
| 3727 this.domApi = host; |
| 3728 this.node = host.node; |
| 3729 }; |
| 3730 DomApi.ClassList.prototype = { |
| 3731 add: function () { |
| 3732 this.node.classList.add.apply(this.node.classList, arguments); |
| 3733 this.domApi._distributeParent(); |
| 3734 }, |
| 3735 remove: function () { |
| 3736 this.node.classList.remove.apply(this.node.classList, arguments); |
| 3737 this.domApi._distributeParent(); |
| 3738 }, |
| 3739 toggle: function () { |
| 3740 this.node.classList.toggle.apply(this.node.classList, arguments); |
| 3741 this.domApi._distributeParent(); |
| 3742 }, |
| 3743 contains: function () { |
| 3744 return this.node.classList.contains.apply(this.node.classList, arguments); |
| 3745 } |
| 3746 }; |
| 3747 }()); |
| 3748 (function () { |
| 3749 'use strict'; |
| 3750 var DomApi = Polymer.DomApi.ctor; |
| 3751 var Settings = Polymer.Settings; |
| 3752 var hasDomApi = Polymer.DomApi.hasDomApi; |
| 3753 DomApi.EffectiveNodesObserver = function (domApi) { |
| 3754 this.domApi = domApi; |
| 3755 this.node = this.domApi.node; |
| 3756 this._listeners = []; |
| 3757 }; |
| 3758 DomApi.EffectiveNodesObserver.prototype = { |
| 3759 addListener: function (callback) { |
| 3760 if (!this._isSetup) { |
| 3761 this._setup(); |
| 3762 this._isSetup = true; |
| 3763 } |
| 3764 var listener = { |
| 3765 fn: callback, |
| 3766 _nodes: [] |
| 3767 }; |
| 3768 this._listeners.push(listener); |
| 3769 this._scheduleNotify(); |
| 3770 return listener; |
| 3771 }, |
| 3772 removeListener: function (handle) { |
| 3773 var i = this._listeners.indexOf(handle); |
| 3774 if (i >= 0) { |
| 3775 this._listeners.splice(i, 1); |
| 3776 handle._nodes = []; |
| 3777 } |
| 3778 if (!this._hasListeners()) { |
| 3779 this._cleanup(); |
| 3780 this._isSetup = false; |
| 3781 } |
| 3782 }, |
| 3783 _setup: function () { |
| 3784 this._observeContentElements(this.domApi.childNodes); |
| 3785 }, |
| 3786 _cleanup: function () { |
| 3787 this._unobserveContentElements(this.domApi.childNodes); |
| 3788 }, |
| 3789 _hasListeners: function () { |
| 3790 return Boolean(this._listeners.length); |
| 3791 }, |
| 3792 _scheduleNotify: function () { |
| 3793 if (this._debouncer) { |
| 3794 this._debouncer.stop(); |
| 3795 } |
| 3796 this._debouncer = Polymer.Debounce(this._debouncer, this._notify); |
| 3797 this._debouncer.context = this; |
| 3798 Polymer.dom.addDebouncer(this._debouncer); |
| 3799 }, |
| 3800 notify: function () { |
| 3801 if (this._hasListeners()) { |
| 3802 this._scheduleNotify(); |
| 3803 } |
| 3804 }, |
| 3805 _notify: function (mxns) { |
| 3806 this._beforeCallListeners(); |
| 3807 this._callListeners(); |
| 3808 }, |
| 3809 _beforeCallListeners: function () { |
| 3810 this._updateContentElements(); |
| 3811 }, |
| 3812 _updateContentElements: function () { |
| 3813 this._observeContentElements(this.domApi.childNodes); |
| 3814 }, |
| 3815 _observeContentElements: function (elements) { |
| 3816 for (var i = 0, n; i < elements.length && (n = elements[i]); i++) { |
| 3817 if (this._isContent(n)) { |
| 3818 n.__observeNodesMap = n.__observeNodesMap || new WeakMap(); |
| 3819 if (!n.__observeNodesMap.has(this)) { |
| 3820 n.__observeNodesMap.set(this, this._observeContent(n)); |
| 3821 } |
| 3822 } |
| 3823 } |
| 3824 }, |
| 3825 _observeContent: function (content) { |
| 3826 var self = this; |
| 3827 var h = Polymer.dom(content).observeNodes(function () { |
| 3828 self._scheduleNotify(); |
| 3829 }); |
| 3830 h._avoidChangeCalculation = true; |
| 3831 return h; |
| 3832 }, |
| 3833 _unobserveContentElements: function (elements) { |
| 3834 for (var i = 0, n, h; i < elements.length && (n = elements[i]); i++) { |
| 3835 if (this._isContent(n)) { |
| 3836 h = n.__observeNodesMap.get(this); |
| 3837 if (h) { |
| 3838 Polymer.dom(n).unobserveNodes(h); |
| 3839 n.__observeNodesMap.delete(this); |
| 3840 } |
| 3841 } |
| 3842 } |
| 3843 }, |
| 3844 _isContent: function (node) { |
| 3845 return node.localName === 'content'; |
| 3846 }, |
| 3847 _callListeners: function () { |
| 3848 var o$ = this._listeners; |
| 3849 var nodes = this._getEffectiveNodes(); |
| 3850 for (var i = 0, o; i < o$.length && (o = o$[i]); i++) { |
| 3851 var info = this._generateListenerInfo(o, nodes); |
| 3852 if (info || o._alwaysNotify) { |
| 3853 this._callListener(o, info); |
| 3854 } |
| 3855 } |
| 3856 }, |
| 3857 _getEffectiveNodes: function () { |
| 3858 return this.domApi.getEffectiveChildNodes(); |
| 3859 }, |
| 3860 _generateListenerInfo: function (listener, newNodes) { |
| 3861 if (listener._avoidChangeCalculation) { |
| 3862 return true; |
| 3863 } |
| 3864 var oldNodes = listener._nodes; |
| 3865 var info = { |
| 3866 target: this.node, |
| 3867 addedNodes: [], |
| 3868 removedNodes: [] |
| 3869 }; |
| 3870 var splices = Polymer.ArraySplice.calculateSplices(newNodes, oldNodes); |
| 3871 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { |
| 3872 for (var j = 0, n; j < s.removed.length && (n = s.removed[j]); j++) { |
| 3873 info.removedNodes.push(n); |
| 3874 } |
| 3875 } |
| 3876 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { |
| 3877 for (var j = s.index; j < s.index + s.addedCount; j++) { |
| 3878 info.addedNodes.push(newNodes[j]); |
| 3879 } |
| 3880 } |
| 3881 listener._nodes = newNodes; |
| 3882 if (info.addedNodes.length || info.removedNodes.length) { |
| 3883 return info; |
| 3884 } |
| 3885 }, |
| 3886 _callListener: function (listener, info) { |
| 3887 return listener.fn.call(this.node, info); |
| 3888 }, |
| 3889 enableShadowAttributeTracking: function () { |
| 3890 } |
| 3891 }; |
| 3892 if (Settings.useShadow) { |
| 3893 var baseSetup = DomApi.EffectiveNodesObserver.prototype._setup; |
| 3894 var baseCleanup = DomApi.EffectiveNodesObserver.prototype._cleanup; |
| 3895 var beforeCallListeners = DomApi.EffectiveNodesObserver.prototype._beforeCallLis
teners; |
| 3896 Polymer.Base.extend(DomApi.EffectiveNodesObserver.prototype, { |
| 3897 _setup: function () { |
| 3898 if (!this._observer) { |
| 3899 var self = this; |
| 3900 this._mutationHandler = function (mxns) { |
| 3901 if (mxns && mxns.length) { |
| 3902 self._scheduleNotify(); |
| 3903 } |
| 3904 }; |
| 3905 this._observer = new MutationObserver(this._mutationHandler); |
| 3906 this._boundFlush = function () { |
| 3907 self._flush(); |
| 3908 }; |
| 3909 Polymer.dom.addStaticFlush(this._boundFlush); |
| 3910 this._observer.observe(this.node, { childList: true }); |
| 3911 } |
| 3912 baseSetup.call(this); |
| 3913 }, |
| 3914 _cleanup: function () { |
| 3915 this._observer.disconnect(); |
| 3916 this._observer = null; |
| 3917 this._mutationHandler = null; |
| 3918 Polymer.dom.removeStaticFlush(this._boundFlush); |
| 3919 baseCleanup.call(this); |
| 3920 }, |
| 3921 _flush: function () { |
| 3922 if (this._observer) { |
| 3923 this._mutationHandler(this._observer.takeRecords()); |
| 3924 } |
| 3925 }, |
| 3926 enableShadowAttributeTracking: function () { |
| 3927 if (this._observer) { |
| 3928 this._makeContentListenersAlwaysNotify(); |
| 3929 this._observer.disconnect(); |
| 3930 this._observer.observe(this.node, { |
| 3931 childList: true, |
| 3932 attributes: true, |
| 3933 subtree: true |
| 3934 }); |
| 3935 var root = this.domApi.getOwnerRoot(); |
| 3936 var host = root && root.host; |
| 3937 if (host && Polymer.dom(host).observer) { |
| 3938 Polymer.dom(host).observer.enableShadowAttributeTracking(); |
| 3939 } |
| 3940 } |
| 3941 }, |
| 3942 _makeContentListenersAlwaysNotify: function () { |
| 3943 for (var i = 0, h; i < this._listeners.length; i++) { |
| 3944 h = this._listeners[i]; |
| 3945 h._alwaysNotify = h._isContentListener; |
| 3946 } |
| 3947 } |
| 3948 }); |
| 3949 } |
| 3950 }()); |
| 3951 (function () { |
| 3952 'use strict'; |
| 3953 var DomApi = Polymer.DomApi.ctor; |
| 3954 var Settings = Polymer.Settings; |
| 3955 DomApi.DistributedNodesObserver = function (domApi) { |
| 3956 DomApi.EffectiveNodesObserver.call(this, domApi); |
| 3957 }; |
| 3958 DomApi.DistributedNodesObserver.prototype = Object.create(DomApi.EffectiveNodesO
bserver.prototype); |
| 3959 Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { |
| 3960 _setup: function () { |
| 3961 }, |
| 3962 _cleanup: function () { |
| 3963 }, |
| 3964 _beforeCallListeners: function () { |
| 3965 }, |
| 3966 _getEffectiveNodes: function () { |
| 3967 return this.domApi.getDistributedNodes(); |
| 3968 } |
| 3969 }); |
| 3970 if (Settings.useShadow) { |
| 3971 Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { |
| 3972 _setup: function () { |
| 3973 if (!this._observer) { |
| 3974 var root = this.domApi.getOwnerRoot(); |
| 3975 var host = root && root.host; |
| 3976 if (host) { |
| 3977 var self = this; |
| 3978 this._observer = Polymer.dom(host).observeNodes(function () { |
| 3979 self._scheduleNotify(); |
| 3980 }); |
| 3981 this._observer._isContentListener = true; |
| 3982 if (this._hasAttrSelect()) { |
| 3983 Polymer.dom(host).observer.enableShadowAttributeTracking(); |
| 3984 } |
| 3985 } |
| 3986 } |
| 3987 }, |
| 3988 _hasAttrSelect: function () { |
| 3989 var select = this.node.getAttribute('select'); |
| 3990 return select && select.match(/[[.]+/); |
| 3991 }, |
| 3992 _cleanup: function () { |
| 3993 var root = this.domApi.getOwnerRoot(); |
| 3994 var host = root && root.host; |
| 3995 if (host) { |
| 3996 Polymer.dom(host).unobserveNodes(this._observer); |
| 3997 } |
| 3998 this._observer = null; |
| 3999 } |
| 4000 }); |
| 4001 } |
| 4002 }()); |
| 4003 (function () { |
| 4004 var hasDomApi = Polymer.DomApi.hasDomApi; |
| 3545 Polymer.Base._addFeature({ | 4005 Polymer.Base._addFeature({ |
| 3546 _prepShady: function () { | 4006 _prepShady: function () { |
| 3547 this._useContent = this._useContent || Boolean(this._template); | 4007 this._useContent = this._useContent || Boolean(this._template); |
| 3548 }, | 4008 }, |
| 3549 _poolContent: function () { | 4009 _poolContent: function () { |
| 3550 if (this._useContent) { | 4010 if (this._useContent) { |
| 3551 saveLightChildrenIfNeeded(this); | 4011 saveLightChildrenIfNeeded(this); |
| 3552 } | 4012 } |
| 3553 }, | 4013 }, |
| 3554 _setupRoot: function () { | 4014 _setupRoot: function () { |
| 3555 if (this._useContent) { | 4015 if (this._useContent) { |
| 3556 this._createLocalRoot(); | 4016 this._createLocalRoot(); |
| 3557 if (!this.dataHost) { | 4017 if (!this.dataHost) { |
| 3558 upgradeLightChildren(this._lightChildren); | 4018 upgradeLightChildren(this._lightChildren); |
| 3559 } | 4019 } |
| 3560 } | 4020 } |
| 3561 }, | 4021 }, |
| 3562 _createLocalRoot: function () { | 4022 _createLocalRoot: function () { |
| 3563 this.shadyRoot = this.root; | 4023 this.shadyRoot = this.root; |
| 3564 this.shadyRoot._distributionClean = false; | 4024 this.shadyRoot._distributionClean = false; |
| 4025 this.shadyRoot._hasDistributed = false; |
| 3565 this.shadyRoot._isShadyRoot = true; | 4026 this.shadyRoot._isShadyRoot = true; |
| 3566 this.shadyRoot._dirtyRoots = []; | 4027 this.shadyRoot._dirtyRoots = []; |
| 3567 var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasConte
nt ? this.shadyRoot.querySelectorAll('content') : []; | 4028 var i$ = this.shadyRoot._insertionPoints = !this._notes || this._notes._hasConte
nt ? this.shadyRoot.querySelectorAll('content') : []; |
| 3568 saveLightChildrenIfNeeded(this.shadyRoot); | 4029 saveLightChildrenIfNeeded(this.shadyRoot); |
| 3569 for (var i = 0, c; i < i$.length; i++) { | 4030 for (var i = 0, c; i < i$.length; i++) { |
| 3570 c = i$[i]; | 4031 c = i$[i]; |
| 3571 saveLightChildrenIfNeeded(c); | 4032 saveLightChildrenIfNeeded(c); |
| 3572 saveLightChildrenIfNeeded(c.parentNode); | 4033 saveLightChildrenIfNeeded(c.parentNode); |
| 3573 } | 4034 } |
| 3574 this.shadyRoot.host = this; | 4035 this.shadyRoot.host = this; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3605 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { | 4066 for (var i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { |
| 3606 c._distributeContent(); | 4067 c._distributeContent(); |
| 3607 } | 4068 } |
| 3608 this.shadyRoot._dirtyRoots = []; | 4069 this.shadyRoot._dirtyRoots = []; |
| 3609 }, | 4070 }, |
| 3610 _finishDistribute: function () { | 4071 _finishDistribute: function () { |
| 3611 if (this._useContent) { | 4072 if (this._useContent) { |
| 3612 this.shadyRoot._distributionClean = true; | 4073 this.shadyRoot._distributionClean = true; |
| 3613 if (hasInsertionPoint(this.shadyRoot)) { | 4074 if (hasInsertionPoint(this.shadyRoot)) { |
| 3614 this._composeTree(); | 4075 this._composeTree(); |
| 4076 notifyContentObservers(this.shadyRoot); |
| 3615 } else { | 4077 } else { |
| 3616 if (!this.shadyRoot._hasDistributed) { | 4078 if (!this.shadyRoot._hasDistributed) { |
| 3617 this.textContent = ''; | 4079 this.textContent = ''; |
| 3618 this._composedChildren = null; | 4080 this._composedChildren = null; |
| 3619 this.appendChild(this.shadyRoot); | 4081 this.appendChild(this.shadyRoot); |
| 3620 } else { | 4082 } else { |
| 3621 var children = this._composeNode(this); | 4083 var children = this._composeNode(this); |
| 3622 this._updateChildNodes(this, children); | 4084 this._updateChildNodes(this, children); |
| 3623 } | 4085 } |
| 3624 } | 4086 } |
| 4087 if (!this.shadyRoot._hasDistributed) { |
| 4088 notifyInitialDistribution(this); |
| 4089 } |
| 3625 this.shadyRoot._hasDistributed = true; | 4090 this.shadyRoot._hasDistributed = true; |
| 3626 } | 4091 } |
| 3627 }, | 4092 }, |
| 3628 elementMatches: function (selector, node) { | 4093 elementMatches: function (selector, node) { |
| 3629 node = node || this; | 4094 node = node || this; |
| 3630 return matchesSelector.call(node, selector); | 4095 return matchesSelector.call(node, selector); |
| 3631 }, | 4096 }, |
| 3632 _resetDistribution: function () { | 4097 _resetDistribution: function () { |
| 3633 var children = getLightChildren(this); | 4098 var children = getLightChildren(this); |
| 3634 for (var i = 0; i < children.length; i++) { | 4099 for (var i = 0; i < children.length; i++) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3832 } | 4297 } |
| 3833 function hostNeedsRedistribution(host) { | 4298 function hostNeedsRedistribution(host) { |
| 3834 var c$ = Polymer.dom(host).children; | 4299 var c$ = Polymer.dom(host).children; |
| 3835 for (var i = 0, c; i < c$.length; i++) { | 4300 for (var i = 0, c; i < c$.length; i++) { |
| 3836 c = c$[i]; | 4301 c = c$[i]; |
| 3837 if (c.localName === 'content') { | 4302 if (c.localName === 'content') { |
| 3838 return host.domHost; | 4303 return host.domHost; |
| 3839 } | 4304 } |
| 3840 } | 4305 } |
| 3841 } | 4306 } |
| 4307 function notifyContentObservers(root) { |
| 4308 for (var i = 0, c; i < root._insertionPoints.length; i++) { |
| 4309 c = root._insertionPoints[i]; |
| 4310 if (hasDomApi(c)) { |
| 4311 Polymer.dom(c).notifyObserver(); |
| 4312 } |
| 4313 } |
| 4314 } |
| 4315 function notifyInitialDistribution(host) { |
| 4316 if (hasDomApi(host)) { |
| 4317 Polymer.dom(host).notifyObserver(); |
| 4318 } |
| 4319 } |
| 3842 var needsUpgrade = window.CustomElements && !CustomElements.useNative; | 4320 var needsUpgrade = window.CustomElements && !CustomElements.useNative; |
| 3843 function upgradeLightChildren(children) { | 4321 function upgradeLightChildren(children) { |
| 3844 if (needsUpgrade && children) { | 4322 if (needsUpgrade && children) { |
| 3845 for (var i = 0; i < children.length; i++) { | 4323 for (var i = 0; i < children.length; i++) { |
| 3846 CustomElements.upgrade(children[i]); | 4324 CustomElements.upgrade(children[i]); |
| 3847 } | 4325 } |
| 3848 } | 4326 } |
| 3849 } | 4327 } |
| 3850 }()); | 4328 }()); |
| 3851 if (Polymer.Settings.useShadow) { | 4329 if (Polymer.Settings.useShadow) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3864 this.createShadowRoot(); | 4342 this.createShadowRoot(); |
| 3865 this.shadowRoot.appendChild(this.root); | 4343 this.shadowRoot.appendChild(this.root); |
| 3866 this.root = this.shadowRoot; | 4344 this.root = this.shadowRoot; |
| 3867 } | 4345 } |
| 3868 }); | 4346 }); |
| 3869 } | 4347 } |
| 3870 Polymer.DomModule = document.createElement('dom-module'); | 4348 Polymer.DomModule = document.createElement('dom-module'); |
| 3871 Polymer.Base._addFeature({ | 4349 Polymer.Base._addFeature({ |
| 3872 _registerFeatures: function () { | 4350 _registerFeatures: function () { |
| 3873 this._prepIs(); | 4351 this._prepIs(); |
| 3874 this._prepAttributes(); | |
| 3875 this._prepBehaviors(); | 4352 this._prepBehaviors(); |
| 3876 this._prepConstructor(); | 4353 this._prepConstructor(); |
| 3877 this._prepTemplate(); | 4354 this._prepTemplate(); |
| 3878 this._prepShady(); | 4355 this._prepShady(); |
| 4356 this._prepPropertyInfo(); |
| 3879 }, | 4357 }, |
| 3880 _prepBehavior: function (b) { | 4358 _prepBehavior: function (b) { |
| 3881 this._addHostAttributes(b.hostAttributes); | 4359 this._addHostAttributes(b.hostAttributes); |
| 3882 }, | 4360 }, |
| 3883 _initFeatures: function () { | 4361 _initFeatures: function () { |
| 4362 this._registerHost(); |
| 4363 if (this._template) { |
| 3884 this._poolContent(); | 4364 this._poolContent(); |
| 3885 this._pushHost(); | 4365 this._beginHosting(); |
| 3886 this._stampTemplate(); | 4366 this._stampTemplate(); |
| 3887 this._popHost(); | 4367 this._endHosting(); |
| 4368 } |
| 3888 this._marshalHostAttributes(); | 4369 this._marshalHostAttributes(); |
| 3889 this._setupDebouncers(); | 4370 this._setupDebouncers(); |
| 3890 this._marshalBehaviors(); | 4371 this._marshalBehaviors(); |
| 3891 this._tryReady(); | 4372 this._tryReady(); |
| 3892 }, | 4373 }, |
| 3893 _marshalBehavior: function (b) { | 4374 _marshalBehavior: function (b) { |
| 3894 } | 4375 } |
| 3895 }); | 4376 }); |
| 3896 Polymer.nar = []; | 4377 Polymer.nar = []; |
| 3897 Polymer.Annotations = { | 4378 Polymer.Annotations = { |
| 3898 parseAnnotations: function (template) { | 4379 parseAnnotations: function (template) { |
| 3899 var list = []; | 4380 var list = []; |
| 3900 var content = template._content || template.content; | 4381 var content = template._content || template.content; |
| 3901 this._parseNodeAnnotations(content, list); | 4382 this._parseNodeAnnotations(content, list, template.hasAttribute('strip-whitespac
e')); |
| 3902 return list; | 4383 return list; |
| 3903 }, | 4384 }, |
| 3904 _parseNodeAnnotations: function (node, list) { | 4385 _parseNodeAnnotations: function (node, list, stripWhiteSpace) { |
| 3905 return node.nodeType === Node.TEXT_NODE ? this._parseTextNodeAnnotation(node, li
st) : this._parseElementAnnotations(node, list); | 4386 return node.nodeType === Node.TEXT_NODE ? this._parseTextNodeAnnotation(node, li
st) : this._parseElementAnnotations(node, list, stripWhiteSpace); |
| 3906 }, | 4387 }, |
| 3907 _testEscape: function (value) { | 4388 _bindingRegex: /([^{[]*)(\{\{|\[\[)(?!\}\}|\]\])(.+?)(?:\]\]|\}\})/g, |
| 3908 var escape = value.slice(0, 2); | 4389 _parseBindings: function (text) { |
| 3909 if (escape === '{{' || escape === '[[') { | 4390 var re = this._bindingRegex; |
| 3910 return escape; | 4391 var parts = []; |
| 4392 var m, lastIndex; |
| 4393 while ((m = re.exec(text)) !== null) { |
| 4394 if (m[1]) { |
| 4395 parts.push({ literal: m[1] }); |
| 4396 } |
| 4397 var mode = m[2][0]; |
| 4398 var value = m[3].trim(); |
| 4399 var negate = false; |
| 4400 if (value[0] == '!') { |
| 4401 negate = true; |
| 4402 value = value.substring(1).trim(); |
| 4403 } |
| 4404 var customEvent, notifyEvent, colon; |
| 4405 if (mode == '{' && (colon = value.indexOf('::')) > 0) { |
| 4406 notifyEvent = value.substring(colon + 2); |
| 4407 value = value.substring(0, colon); |
| 4408 customEvent = true; |
| 4409 } |
| 4410 parts.push({ |
| 4411 compoundIndex: parts.length, |
| 4412 value: value, |
| 4413 mode: mode, |
| 4414 negate: negate, |
| 4415 event: notifyEvent, |
| 4416 customEvent: customEvent |
| 4417 }); |
| 4418 lastIndex = re.lastIndex; |
| 4419 } |
| 4420 if (lastIndex && lastIndex < text.length) { |
| 4421 var literal = text.substring(lastIndex); |
| 4422 if (literal) { |
| 4423 parts.push({ literal: literal }); |
| 4424 } |
| 4425 } |
| 4426 if (parts.length) { |
| 4427 return parts; |
| 3911 } | 4428 } |
| 3912 }, | 4429 }, |
| 4430 _literalFromParts: function (parts) { |
| 4431 var s = ''; |
| 4432 for (var i = 0; i < parts.length; i++) { |
| 4433 var literal = parts[i].literal; |
| 4434 s += literal || ''; |
| 4435 } |
| 4436 return s; |
| 4437 }, |
| 3913 _parseTextNodeAnnotation: function (node, list) { | 4438 _parseTextNodeAnnotation: function (node, list) { |
| 3914 var v = node.textContent; | 4439 var parts = this._parseBindings(node.textContent); |
| 3915 var escape = this._testEscape(v); | 4440 if (parts) { |
| 3916 if (escape) { | 4441 node.textContent = this._literalFromParts(parts) || ' '; |
| 3917 node.textContent = ' '; | |
| 3918 var annote = { | 4442 var annote = { |
| 3919 bindings: [{ | 4443 bindings: [{ |
| 3920 kind: 'text', | 4444 kind: 'text', |
| 3921 mode: escape[0], | 4445 name: 'textContent', |
| 3922 value: v.slice(2, -2).trim() | 4446 parts: parts, |
| 4447 isCompound: parts.length !== 1 |
| 3923 }] | 4448 }] |
| 3924 }; | 4449 }; |
| 3925 list.push(annote); | 4450 list.push(annote); |
| 3926 return annote; | 4451 return annote; |
| 3927 } | 4452 } |
| 3928 }, | 4453 }, |
| 3929 _parseElementAnnotations: function (element, list) { | 4454 _parseElementAnnotations: function (element, list, stripWhiteSpace) { |
| 3930 var annote = { | 4455 var annote = { |
| 3931 bindings: [], | 4456 bindings: [], |
| 3932 events: [] | 4457 events: [] |
| 3933 }; | 4458 }; |
| 3934 if (element.localName === 'content') { | 4459 if (element.localName === 'content') { |
| 3935 list._hasContent = true; | 4460 list._hasContent = true; |
| 3936 } | 4461 } |
| 3937 this._parseChildNodesAnnotations(element, annote, list); | 4462 this._parseChildNodesAnnotations(element, annote, list, stripWhiteSpace); |
| 3938 if (element.attributes) { | 4463 if (element.attributes) { |
| 3939 this._parseNodeAttributeAnnotations(element, annote, list); | 4464 this._parseNodeAttributeAnnotations(element, annote, list); |
| 3940 if (this.prepElement) { | 4465 if (this.prepElement) { |
| 3941 this.prepElement(element); | 4466 this.prepElement(element); |
| 3942 } | 4467 } |
| 3943 } | 4468 } |
| 3944 if (annote.bindings.length || annote.events.length || annote.id) { | 4469 if (annote.bindings.length || annote.events.length || annote.id) { |
| 3945 list.push(annote); | 4470 list.push(annote); |
| 3946 } | 4471 } |
| 3947 return annote; | 4472 return annote; |
| 3948 }, | 4473 }, |
| 3949 _parseChildNodesAnnotations: function (root, annote, list, callback) { | 4474 _parseChildNodesAnnotations: function (root, annote, list, stripWhiteSpace) { |
| 3950 if (root.firstChild) { | 4475 if (root.firstChild) { |
| 3951 for (var i = 0, node = root.firstChild; node; node = node.nextSibling, i++) { | 4476 var node = root.firstChild; |
| 4477 var i = 0; |
| 4478 while (node) { |
| 4479 var next = node.nextSibling; |
| 3952 if (node.localName === 'template' && !node.hasAttribute('preserve-content')) { | 4480 if (node.localName === 'template' && !node.hasAttribute('preserve-content')) { |
| 3953 this._parseTemplate(node, i, list, annote); | 4481 this._parseTemplate(node, i, list, annote); |
| 3954 } | 4482 } |
| 3955 if (node.nodeType === Node.TEXT_NODE) { | 4483 if (node.nodeType === Node.TEXT_NODE) { |
| 3956 var n = node.nextSibling; | 4484 var n = next; |
| 3957 while (n && n.nodeType === Node.TEXT_NODE) { | 4485 while (n && n.nodeType === Node.TEXT_NODE) { |
| 3958 node.textContent += n.textContent; | 4486 node.textContent += n.textContent; |
| 4487 next = n.nextSibling; |
| 3959 root.removeChild(n); | 4488 root.removeChild(n); |
| 3960 n = n.nextSibling; | 4489 n = next; |
| 4490 } |
| 4491 if (stripWhiteSpace && !node.textContent.trim()) { |
| 4492 root.removeChild(node); |
| 4493 i--; |
| 3961 } | 4494 } |
| 3962 } | 4495 } |
| 3963 var childAnnotation = this._parseNodeAnnotations(node, list, callback); | 4496 if (node.parentNode) { |
| 4497 var childAnnotation = this._parseNodeAnnotations(node, list, stripWhiteSpace); |
| 3964 if (childAnnotation) { | 4498 if (childAnnotation) { |
| 3965 childAnnotation.parent = annote; | 4499 childAnnotation.parent = annote; |
| 3966 childAnnotation.index = i; | 4500 childAnnotation.index = i; |
| 3967 } | 4501 } |
| 3968 } | 4502 } |
| 4503 node = next; |
| 4504 i++; |
| 4505 } |
| 3969 } | 4506 } |
| 3970 }, | 4507 }, |
| 3971 _parseTemplate: function (node, index, list, parent) { | 4508 _parseTemplate: function (node, index, list, parent) { |
| 3972 var content = document.createDocumentFragment(); | 4509 var content = document.createDocumentFragment(); |
| 3973 content._notes = this.parseAnnotations(node); | 4510 content._notes = this.parseAnnotations(node); |
| 3974 content.appendChild(node.content); | 4511 content.appendChild(node.content); |
| 3975 list.push({ | 4512 list.push({ |
| 3976 bindings: Polymer.nar, | 4513 bindings: Polymer.nar, |
| 3977 events: Polymer.nar, | 4514 events: Polymer.nar, |
| 3978 templateContent: content, | 4515 templateContent: content, |
| 3979 parent: parent, | 4516 parent: parent, |
| 3980 index: index | 4517 index: index |
| 3981 }); | 4518 }); |
| 3982 }, | 4519 }, |
| 3983 _parseNodeAttributeAnnotations: function (node, annotation) { | 4520 _parseNodeAttributeAnnotations: function (node, annotation) { |
| 3984 for (var i = node.attributes.length - 1, a; a = node.attributes[i]; i--) { | 4521 var attrs = Array.prototype.slice.call(node.attributes); |
| 3985 var n = a.name, v = a.value; | 4522 for (var i = attrs.length - 1, a; a = attrs[i]; i--) { |
| 3986 if (n === 'id' && !this._testEscape(v)) { | 4523 var n = a.name; |
| 3987 annotation.id = v; | 4524 var v = a.value; |
| 3988 } else if (n.slice(0, 3) === 'on-') { | 4525 var b; |
| 4526 if (n.slice(0, 3) === 'on-') { |
| 3989 node.removeAttribute(n); | 4527 node.removeAttribute(n); |
| 3990 annotation.events.push({ | 4528 annotation.events.push({ |
| 3991 name: n.slice(3), | 4529 name: n.slice(3), |
| 3992 value: v | 4530 value: v |
| 3993 }); | 4531 }); |
| 3994 } else { | 4532 } else if (b = this._parseNodeAttributeAnnotation(node, n, v)) { |
| 3995 var b = this._parseNodeAttributeAnnotation(node, n, v); | |
| 3996 if (b) { | |
| 3997 annotation.bindings.push(b); | 4533 annotation.bindings.push(b); |
| 3998 } | 4534 } else if (n === 'id') { |
| 4535 annotation.id = v; |
| 3999 } | 4536 } |
| 4000 } | 4537 } |
| 4001 }, | 4538 }, |
| 4002 _parseNodeAttributeAnnotation: function (node, n, v) { | 4539 _parseNodeAttributeAnnotation: function (node, name, value) { |
| 4003 var escape = this._testEscape(v); | 4540 var parts = this._parseBindings(value); |
| 4004 if (escape) { | 4541 if (parts) { |
| 4005 var customEvent; | 4542 var origName = name; |
| 4006 var name = n; | |
| 4007 var mode = escape[0]; | |
| 4008 v = v.slice(2, -2).trim(); | |
| 4009 var not = false; | |
| 4010 if (v[0] == '!') { | |
| 4011 v = v.substring(1); | |
| 4012 not = true; | |
| 4013 } | |
| 4014 var kind = 'property'; | 4543 var kind = 'property'; |
| 4015 if (n[n.length - 1] == '$') { | 4544 if (name[name.length - 1] == '$') { |
| 4016 name = n.slice(0, -1); | 4545 name = name.slice(0, -1); |
| 4017 kind = 'attribute'; | 4546 kind = 'attribute'; |
| 4018 } | 4547 } |
| 4019 var notifyEvent, colon; | 4548 var literal = this._literalFromParts(parts); |
| 4020 if (mode == '{' && (colon = v.indexOf('::')) > 0) { | 4549 if (literal && kind == 'attribute') { |
| 4021 notifyEvent = v.substring(colon + 2); | 4550 node.setAttribute(name, literal); |
| 4022 v = v.substring(0, colon); | |
| 4023 customEvent = true; | |
| 4024 } | 4551 } |
| 4025 if (node.localName == 'input' && n == 'value') { | 4552 if (node.localName == 'input' && name == 'value') { |
| 4026 node.setAttribute(n, ''); | 4553 node.setAttribute(origName, ''); |
| 4027 } | 4554 } |
| 4028 node.removeAttribute(n); | 4555 node.removeAttribute(origName); |
| 4029 if (kind === 'property') { | 4556 if (kind === 'property') { |
| 4030 name = Polymer.CaseMap.dashToCamelCase(name); | 4557 name = Polymer.CaseMap.dashToCamelCase(name); |
| 4031 } | 4558 } |
| 4032 return { | 4559 return { |
| 4033 kind: kind, | 4560 kind: kind, |
| 4034 mode: mode, | |
| 4035 name: name, | 4561 name: name, |
| 4036 value: v, | 4562 parts: parts, |
| 4037 negate: not, | 4563 literal: literal, |
| 4038 event: notifyEvent, | 4564 isCompound: parts.length !== 1 |
| 4039 customEvent: customEvent | |
| 4040 }; | 4565 }; |
| 4041 } | 4566 } |
| 4042 }, | 4567 }, |
| 4043 _localSubTree: function (node, host) { | 4568 _localSubTree: function (node, host) { |
| 4044 return node === host ? node.childNodes : node._lightChildren || node.childNodes; | 4569 return node === host ? node.childNodes : node._lightChildren || node.childNodes; |
| 4045 }, | 4570 }, |
| 4046 findAnnotatedNode: function (root, annote) { | 4571 findAnnotatedNode: function (root, annote) { |
| 4047 var parent = annote.parent && Polymer.Annotations.findAnnotatedNode(root, annote
.parent); | 4572 var parent = annote.parent && Polymer.Annotations.findAnnotatedNode(root, annote
.parent); |
| 4048 return !parent ? root : Polymer.Annotations._localSubTree(parent, root)[annote.i
ndex]; | 4573 return !parent ? root : Polymer.Annotations._localSubTree(parent, root)[annote.i
ndex]; |
| 4049 } | 4574 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4105 resolveCss: resolveCss, | 4630 resolveCss: resolveCss, |
| 4106 resolveAttrs: resolveAttrs, | 4631 resolveAttrs: resolveAttrs, |
| 4107 resolveUrl: resolveUrl | 4632 resolveUrl: resolveUrl |
| 4108 }; | 4633 }; |
| 4109 }()); | 4634 }()); |
| 4110 Polymer.Base._addFeature({ | 4635 Polymer.Base._addFeature({ |
| 4111 _prepAnnotations: function () { | 4636 _prepAnnotations: function () { |
| 4112 if (!this._template) { | 4637 if (!this._template) { |
| 4113 this._notes = []; | 4638 this._notes = []; |
| 4114 } else { | 4639 } else { |
| 4115 Polymer.Annotations.prepElement = this._prepElement.bind(this); | 4640 var self = this; |
| 4641 Polymer.Annotations.prepElement = function (element) { |
| 4642 self._prepElement(element); |
| 4643 }; |
| 4116 if (this._template._content && this._template._content._notes) { | 4644 if (this._template._content && this._template._content._notes) { |
| 4117 this._notes = this._template._content._notes; | 4645 this._notes = this._template._content._notes; |
| 4118 } else { | 4646 } else { |
| 4119 this._notes = Polymer.Annotations.parseAnnotations(this._template); | 4647 this._notes = Polymer.Annotations.parseAnnotations(this._template); |
| 4120 } | 4648 } |
| 4121 this._processAnnotations(this._notes); | 4649 this._processAnnotations(this._notes); |
| 4122 Polymer.Annotations.prepElement = null; | 4650 Polymer.Annotations.prepElement = null; |
| 4123 } | 4651 } |
| 4124 }, | 4652 }, |
| 4125 _processAnnotations: function (notes) { | 4653 _processAnnotations: function (notes) { |
| 4126 for (var i = 0; i < notes.length; i++) { | 4654 for (var i = 0; i < notes.length; i++) { |
| 4127 var note = notes[i]; | 4655 var note = notes[i]; |
| 4128 for (var j = 0; j < note.bindings.length; j++) { | 4656 for (var j = 0; j < note.bindings.length; j++) { |
| 4129 var b = note.bindings[j]; | 4657 var b = note.bindings[j]; |
| 4130 b.signature = this._parseMethod(b.value); | 4658 for (var k = 0; k < b.parts.length; k++) { |
| 4131 if (!b.signature) { | 4659 var p = b.parts[k]; |
| 4132 b.model = this._modelForPath(b.value); | 4660 if (!p.literal) { |
| 4661 p.signature = this._parseMethod(p.value); |
| 4662 if (!p.signature) { |
| 4663 p.model = this._modelForPath(p.value); |
| 4664 } |
| 4665 } |
| 4133 } | 4666 } |
| 4134 } | 4667 } |
| 4135 if (note.templateContent) { | 4668 if (note.templateContent) { |
| 4136 this._processAnnotations(note.templateContent._notes); | 4669 this._processAnnotations(note.templateContent._notes); |
| 4137 var pp = note.templateContent._parentProps = this._discoverTemplateParentProps(n
ote.templateContent._notes); | 4670 var pp = note.templateContent._parentProps = this._discoverTemplateParentProps(n
ote.templateContent._notes); |
| 4138 var bindings = []; | 4671 var bindings = []; |
| 4139 for (var prop in pp) { | 4672 for (var prop in pp) { |
| 4140 bindings.push({ | 4673 bindings.push({ |
| 4141 index: note.index, | 4674 index: note.index, |
| 4142 kind: 'property', | 4675 kind: 'property', |
| 4676 name: '_parent_' + prop, |
| 4677 parts: [{ |
| 4143 mode: '{', | 4678 mode: '{', |
| 4144 name: '_parent_' + prop, | |
| 4145 model: prop, | 4679 model: prop, |
| 4146 value: prop | 4680 value: prop |
| 4681 }] |
| 4147 }); | 4682 }); |
| 4148 } | 4683 } |
| 4149 note.bindings = note.bindings.concat(bindings); | 4684 note.bindings = note.bindings.concat(bindings); |
| 4150 } | 4685 } |
| 4151 } | 4686 } |
| 4152 }, | 4687 }, |
| 4153 _discoverTemplateParentProps: function (notes) { | 4688 _discoverTemplateParentProps: function (notes) { |
| 4154 var pp = {}; | 4689 var pp = {}; |
| 4155 notes.forEach(function (n) { | 4690 for (var i = 0, n; i < notes.length && (n = notes[i]); i++) { |
| 4156 n.bindings.forEach(function (b) { | 4691 for (var j = 0, b$ = n.bindings, b; j < b$.length && (b = b$[j]); j++) { |
| 4157 if (b.signature) { | 4692 for (var k = 0, p$ = b.parts, p; k < p$.length && (p = p$[k]); k++) { |
| 4158 var args = b.signature.args; | 4693 if (p.signature) { |
| 4159 for (var k = 0; k < args.length; k++) { | 4694 var args = p.signature.args; |
| 4160 pp[args[k].model] = true; | 4695 for (var kk = 0; kk < args.length; kk++) { |
| 4696 pp[args[kk].model] = true; |
| 4161 } | 4697 } |
| 4162 } else { | 4698 } else { |
| 4163 pp[b.model] = true; | 4699 pp[p.model] = true; |
| 4164 } | 4700 } |
| 4165 }); | 4701 } |
| 4702 } |
| 4166 if (n.templateContent) { | 4703 if (n.templateContent) { |
| 4167 var tpp = n.templateContent._parentProps; | 4704 var tpp = n.templateContent._parentProps; |
| 4168 Polymer.Base.mixin(pp, tpp); | 4705 Polymer.Base.mixin(pp, tpp); |
| 4169 } | 4706 } |
| 4170 }); | 4707 } |
| 4171 return pp; | 4708 return pp; |
| 4172 }, | 4709 }, |
| 4173 _prepElement: function (element) { | 4710 _prepElement: function (element) { |
| 4174 Polymer.ResolveUrl.resolveAttrs(element, this._template.ownerDocument); | 4711 Polymer.ResolveUrl.resolveAttrs(element, this._template.ownerDocument); |
| 4175 }, | 4712 }, |
| 4176 _findAnnotatedNode: Polymer.Annotations.findAnnotatedNode, | 4713 _findAnnotatedNode: Polymer.Annotations.findAnnotatedNode, |
| 4177 _marshalAnnotationReferences: function () { | 4714 _marshalAnnotationReferences: function () { |
| 4178 if (this._template) { | 4715 if (this._template) { |
| 4179 this._marshalIdNodes(); | 4716 this._marshalIdNodes(); |
| 4180 this._marshalAnnotatedNodes(); | 4717 this._marshalAnnotatedNodes(); |
| 4181 this._marshalAnnotatedListeners(); | 4718 this._marshalAnnotatedListeners(); |
| 4182 } | 4719 } |
| 4183 }, | 4720 }, |
| 4184 _configureAnnotationReferences: function () { | 4721 _configureAnnotationReferences: function (config) { |
| 4185 this._configureTemplateContent(); | 4722 var notes = this._notes; |
| 4723 var nodes = this._nodes; |
| 4724 for (var i = 0; i < notes.length; i++) { |
| 4725 var note = notes[i]; |
| 4726 var node = nodes[i]; |
| 4727 this._configureTemplateContent(note, node); |
| 4728 this._configureCompoundBindings(note, node); |
| 4729 } |
| 4186 }, | 4730 }, |
| 4187 _configureTemplateContent: function () { | 4731 _configureTemplateContent: function (note, node) { |
| 4188 this._notes.forEach(function (note, i) { | |
| 4189 if (note.templateContent) { | 4732 if (note.templateContent) { |
| 4190 this._nodes[i]._content = note.templateContent; | 4733 node._content = note.templateContent; |
| 4191 } | 4734 } |
| 4192 }, this); | 4735 }, |
| 4736 _configureCompoundBindings: function (note, node) { |
| 4737 var bindings = note.bindings; |
| 4738 for (var i = 0; i < bindings.length; i++) { |
| 4739 var binding = bindings[i]; |
| 4740 if (binding.isCompound) { |
| 4741 var storage = node.__compoundStorage__ || (node.__compoundStorage__ = {}); |
| 4742 var parts = binding.parts; |
| 4743 var literals = new Array(parts.length); |
| 4744 for (var j = 0; j < parts.length; j++) { |
| 4745 literals[j] = parts[j].literal; |
| 4746 } |
| 4747 var name = binding.name; |
| 4748 storage[name] = literals; |
| 4749 if (binding.literal && binding.kind == 'property') { |
| 4750 if (node._configValue) { |
| 4751 node._configValue(name, binding.literal); |
| 4752 } else { |
| 4753 node[name] = binding.literal; |
| 4754 } |
| 4755 } |
| 4756 } |
| 4757 } |
| 4193 }, | 4758 }, |
| 4194 _marshalIdNodes: function () { | 4759 _marshalIdNodes: function () { |
| 4195 this.$ = {}; | 4760 this.$ = {}; |
| 4196 this._notes.forEach(function (a) { | 4761 for (var i = 0, l = this._notes.length, a; i < l && (a = this._notes[i]); i++) { |
| 4197 if (a.id) { | 4762 if (a.id) { |
| 4198 this.$[a.id] = this._findAnnotatedNode(this.root, a); | 4763 this.$[a.id] = this._findAnnotatedNode(this.root, a); |
| 4199 } | 4764 } |
| 4200 }, this); | 4765 } |
| 4201 }, | 4766 }, |
| 4202 _marshalAnnotatedNodes: function () { | 4767 _marshalAnnotatedNodes: function () { |
| 4203 if (this._nodes) { | 4768 if (this._notes && this._notes.length) { |
| 4204 this._nodes = this._nodes.map(function (a) { | 4769 var r = new Array(this._notes.length); |
| 4205 return this._findAnnotatedNode(this.root, a); | 4770 for (var i = 0; i < this._notes.length; i++) { |
| 4206 }, this); | 4771 r[i] = this._findAnnotatedNode(this.root, this._notes[i]); |
| 4772 } |
| 4773 this._nodes = r; |
| 4207 } | 4774 } |
| 4208 }, | 4775 }, |
| 4209 _marshalAnnotatedListeners: function () { | 4776 _marshalAnnotatedListeners: function () { |
| 4210 this._notes.forEach(function (a) { | 4777 for (var i = 0, l = this._notes.length, a; i < l && (a = this._notes[i]); i++) { |
| 4211 if (a.events && a.events.length) { | 4778 if (a.events && a.events.length) { |
| 4212 var node = this._findAnnotatedNode(this.root, a); | 4779 var node = this._findAnnotatedNode(this.root, a); |
| 4213 a.events.forEach(function (e) { | 4780 for (var j = 0, e$ = a.events, e; j < e$.length && (e = e$[j]); j++) { |
| 4214 this.listen(node, e.name, e.value); | 4781 this.listen(node, e.name, e.value); |
| 4215 }, this); | |
| 4216 } | 4782 } |
| 4217 }, this); | 4783 } |
| 4784 } |
| 4218 } | 4785 } |
| 4219 }); | 4786 }); |
| 4220 Polymer.Base._addFeature({ | 4787 Polymer.Base._addFeature({ |
| 4221 listeners: {}, | 4788 listeners: {}, |
| 4222 _listenListeners: function (listeners) { | 4789 _listenListeners: function (listeners) { |
| 4223 var node, name, key; | 4790 var node, name, eventName; |
| 4224 for (key in listeners) { | 4791 for (eventName in listeners) { |
| 4225 if (key.indexOf('.') < 0) { | 4792 if (eventName.indexOf('.') < 0) { |
| 4226 node = this; | 4793 node = this; |
| 4227 name = key; | 4794 name = eventName; |
| 4228 } else { | 4795 } else { |
| 4229 name = key.split('.'); | 4796 name = eventName.split('.'); |
| 4230 node = this.$[name[0]]; | 4797 node = this.$[name[0]]; |
| 4231 name = name[1]; | 4798 name = name[1]; |
| 4232 } | 4799 } |
| 4233 this.listen(node, name, listeners[key]); | 4800 this.listen(node, name, listeners[eventName]); |
| 4234 } | 4801 } |
| 4235 }, | 4802 }, |
| 4236 listen: function (node, eventName, methodName) { | 4803 listen: function (node, eventName, methodName) { |
| 4237 var handler = this._recallEventHandler(this, eventName, node, methodName); | 4804 var handler = this._recallEventHandler(this, eventName, node, methodName); |
| 4238 if (!handler) { | 4805 if (!handler) { |
| 4239 handler = this._createEventHandler(node, eventName, methodName); | 4806 handler = this._createEventHandler(node, eventName, methodName); |
| 4240 } | 4807 } |
| 4241 if (handler._listening) { | 4808 if (handler._listening) { |
| 4242 return; | 4809 return; |
| 4243 } | 4810 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4294 }, | 4861 }, |
| 4295 _listen: function (node, eventName, handler) { | 4862 _listen: function (node, eventName, handler) { |
| 4296 node.addEventListener(eventName, handler); | 4863 node.addEventListener(eventName, handler); |
| 4297 }, | 4864 }, |
| 4298 _unlisten: function (node, eventName, handler) { | 4865 _unlisten: function (node, eventName, handler) { |
| 4299 node.removeEventListener(eventName, handler); | 4866 node.removeEventListener(eventName, handler); |
| 4300 } | 4867 } |
| 4301 }); | 4868 }); |
| 4302 (function () { | 4869 (function () { |
| 4303 'use strict'; | 4870 'use strict'; |
| 4871 var wrap = Polymer.DomApi.wrap; |
| 4304 var HAS_NATIVE_TA = typeof document.head.style.touchAction === 'string'; | 4872 var HAS_NATIVE_TA = typeof document.head.style.touchAction === 'string'; |
| 4305 var GESTURE_KEY = '__polymerGestures'; | 4873 var GESTURE_KEY = '__polymerGestures'; |
| 4306 var HANDLED_OBJ = '__polymerGesturesHandled'; | 4874 var HANDLED_OBJ = '__polymerGesturesHandled'; |
| 4307 var TOUCH_ACTION = '__polymerGesturesTouchAction'; | 4875 var TOUCH_ACTION = '__polymerGesturesTouchAction'; |
| 4308 var TAP_DISTANCE = 25; | 4876 var TAP_DISTANCE = 25; |
| 4309 var TRACK_DISTANCE = 5; | 4877 var TRACK_DISTANCE = 5; |
| 4310 var TRACK_LENGTH = 2; | 4878 var TRACK_LENGTH = 2; |
| 4311 var MOUSE_TIMEOUT = 2500; | 4879 var MOUSE_TIMEOUT = 2500; |
| 4312 var MOUSE_EVENTS = [ | 4880 var MOUSE_EVENTS = [ |
| 4313 'mousedown', | 4881 'mousedown', |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4444 }, | 5012 }, |
| 4445 findOriginalTarget: function (ev) { | 5013 findOriginalTarget: function (ev) { |
| 4446 if (ev.path) { | 5014 if (ev.path) { |
| 4447 return ev.path[0]; | 5015 return ev.path[0]; |
| 4448 } | 5016 } |
| 4449 return ev.target; | 5017 return ev.target; |
| 4450 }, | 5018 }, |
| 4451 handleNative: function (ev) { | 5019 handleNative: function (ev) { |
| 4452 var handled; | 5020 var handled; |
| 4453 var type = ev.type; | 5021 var type = ev.type; |
| 4454 var node = ev.currentTarget; | 5022 var node = wrap(ev.currentTarget); |
| 4455 var gobj = node[GESTURE_KEY]; | 5023 var gobj = node[GESTURE_KEY]; |
| 5024 if (!gobj) { |
| 5025 return; |
| 5026 } |
| 4456 var gs = gobj[type]; | 5027 var gs = gobj[type]; |
| 4457 if (!gs) { | 5028 if (!gs) { |
| 4458 return; | 5029 return; |
| 4459 } | 5030 } |
| 4460 if (!ev[HANDLED_OBJ]) { | 5031 if (!ev[HANDLED_OBJ]) { |
| 4461 ev[HANDLED_OBJ] = {}; | 5032 ev[HANDLED_OBJ] = {}; |
| 4462 if (type.slice(0, 5) === 'touch') { | 5033 if (type.slice(0, 5) === 'touch') { |
| 4463 var t = ev.changedTouches[0]; | 5034 var t = ev.changedTouches[0]; |
| 4464 if (type === 'touchstart') { | 5035 if (type === 'touchstart') { |
| 4465 if (ev.touches.length === 1) { | 5036 if (ev.touches.length === 1) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4528 prevent = dx > dy; | 5099 prevent = dx > dy; |
| 4529 } | 5100 } |
| 4530 if (prevent) { | 5101 if (prevent) { |
| 4531 ev.preventDefault(); | 5102 ev.preventDefault(); |
| 4532 } else { | 5103 } else { |
| 4533 Gestures.prevent('track'); | 5104 Gestures.prevent('track'); |
| 4534 } | 5105 } |
| 4535 } | 5106 } |
| 4536 }, | 5107 }, |
| 4537 add: function (node, evType, handler) { | 5108 add: function (node, evType, handler) { |
| 5109 node = wrap(node); |
| 4538 var recognizer = this.gestures[evType]; | 5110 var recognizer = this.gestures[evType]; |
| 4539 var deps = recognizer.deps; | 5111 var deps = recognizer.deps; |
| 4540 var name = recognizer.name; | 5112 var name = recognizer.name; |
| 4541 var gobj = node[GESTURE_KEY]; | 5113 var gobj = node[GESTURE_KEY]; |
| 4542 if (!gobj) { | 5114 if (!gobj) { |
| 4543 node[GESTURE_KEY] = gobj = {}; | 5115 node[GESTURE_KEY] = gobj = {}; |
| 4544 } | 5116 } |
| 4545 for (var i = 0, dep, gd; i < deps.length; i++) { | 5117 for (var i = 0, dep, gd; i < deps.length; i++) { |
| 4546 dep = deps[i]; | 5118 dep = deps[i]; |
| 4547 if (IS_TOUCH_ONLY && MOUSE_EVENTS.indexOf(dep) > -1) { | 5119 if (IS_TOUCH_ONLY && MOUSE_EVENTS.indexOf(dep) > -1) { |
| 4548 continue; | 5120 continue; |
| 4549 } | 5121 } |
| 4550 gd = gobj[dep]; | 5122 gd = gobj[dep]; |
| 4551 if (!gd) { | 5123 if (!gd) { |
| 4552 gobj[dep] = gd = { _count: 0 }; | 5124 gobj[dep] = gd = { _count: 0 }; |
| 4553 } | 5125 } |
| 4554 if (gd._count === 0) { | 5126 if (gd._count === 0) { |
| 4555 node.addEventListener(dep, this.handleNative); | 5127 node.addEventListener(dep, this.handleNative); |
| 4556 } | 5128 } |
| 4557 gd[name] = (gd[name] || 0) + 1; | 5129 gd[name] = (gd[name] || 0) + 1; |
| 4558 gd._count = (gd._count || 0) + 1; | 5130 gd._count = (gd._count || 0) + 1; |
| 4559 } | 5131 } |
| 4560 node.addEventListener(evType, handler); | 5132 node.addEventListener(evType, handler); |
| 4561 if (recognizer.touchAction) { | 5133 if (recognizer.touchAction) { |
| 4562 this.setTouchAction(node, recognizer.touchAction); | 5134 this.setTouchAction(node, recognizer.touchAction); |
| 4563 } | 5135 } |
| 4564 }, | 5136 }, |
| 4565 remove: function (node, evType, handler) { | 5137 remove: function (node, evType, handler) { |
| 5138 node = wrap(node); |
| 4566 var recognizer = this.gestures[evType]; | 5139 var recognizer = this.gestures[evType]; |
| 4567 var deps = recognizer.deps; | 5140 var deps = recognizer.deps; |
| 4568 var name = recognizer.name; | 5141 var name = recognizer.name; |
| 4569 var gobj = node[GESTURE_KEY]; | 5142 var gobj = node[GESTURE_KEY]; |
| 4570 if (gobj) { | 5143 if (gobj) { |
| 4571 for (var i = 0, dep, gd; i < deps.length; i++) { | 5144 for (var i = 0, dep, gd; i < deps.length; i++) { |
| 4572 dep = deps[i]; | 5145 dep = deps[i]; |
| 4573 gd = gobj[dep]; | 5146 gd = gobj[dep]; |
| 4574 if (gd && gd[name]) { | 5147 if (gd && gd[name]) { |
| 4575 gd[name] = (gd[name] || 1) - 1; | 5148 gd[name] = (gd[name] || 1) - 1; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4682 }, | 5255 }, |
| 4683 touchend: function (e) { | 5256 touchend: function (e) { |
| 4684 this.fire('up', Gestures.findOriginalTarget(e), e.changedTouches[0]); | 5257 this.fire('up', Gestures.findOriginalTarget(e), e.changedTouches[0]); |
| 4685 }, | 5258 }, |
| 4686 fire: function (type, target, event) { | 5259 fire: function (type, target, event) { |
| 4687 var self = this; | 5260 var self = this; |
| 4688 Gestures.fire(target, type, { | 5261 Gestures.fire(target, type, { |
| 4689 x: event.clientX, | 5262 x: event.clientX, |
| 4690 y: event.clientY, | 5263 y: event.clientY, |
| 4691 sourceEvent: event, | 5264 sourceEvent: event, |
| 4692 prevent: Gestures.prevent.bind(Gestures) | 5265 prevent: function (e) { |
| 5266 return Gestures.prevent(e); |
| 5267 } |
| 4693 }); | 5268 }); |
| 4694 } | 5269 } |
| 4695 }); | 5270 }); |
| 4696 Gestures.register({ | 5271 Gestures.register({ |
| 4697 name: 'track', | 5272 name: 'track', |
| 4698 touchAction: 'none', | 5273 touchAction: 'none', |
| 4699 deps: [ | 5274 deps: [ |
| 4700 'mousedown', | 5275 'mousedown', |
| 4701 'touchstart', | 5276 'touchstart', |
| 4702 'touchmove', | 5277 'touchmove', |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4974 this._lastVal += i; | 5549 this._lastVal += i; |
| 4975 this._twiddle.textContent = this._twiddleContent++; | 5550 this._twiddle.textContent = this._twiddleContent++; |
| 4976 throw e; | 5551 throw e; |
| 4977 } | 5552 } |
| 4978 } | 5553 } |
| 4979 } | 5554 } |
| 4980 this._callbacks.splice(0, len); | 5555 this._callbacks.splice(0, len); |
| 4981 this._lastVal += len; | 5556 this._lastVal += len; |
| 4982 } | 5557 } |
| 4983 }; | 5558 }; |
| 4984 new (window.MutationObserver || JsMutationObserver)(Polymer.Async._atEndOfMicrot
ask.bind(Polymer.Async)).observe(Polymer.Async._twiddle, { characterData: true }
); | 5559 new window.MutationObserver(function () { |
| 5560 Polymer.Async._atEndOfMicrotask(); |
| 5561 }).observe(Polymer.Async._twiddle, { characterData: true }); |
| 4985 Polymer.Debounce = function () { | 5562 Polymer.Debounce = function () { |
| 4986 var Async = Polymer.Async; | 5563 var Async = Polymer.Async; |
| 4987 var Debouncer = function (context) { | 5564 var Debouncer = function (context) { |
| 4988 this.context = context; | 5565 this.context = context; |
| 4989 this.boundComplete = this.complete.bind(this); | 5566 var self = this; |
| 5567 this.boundComplete = function () { |
| 5568 self.complete(); |
| 5569 }; |
| 4990 }; | 5570 }; |
| 4991 Debouncer.prototype = { | 5571 Debouncer.prototype = { |
| 4992 go: function (callback, wait) { | 5572 go: function (callback, wait) { |
| 4993 var h; | 5573 var h; |
| 4994 this.finish = function () { | 5574 this.finish = function () { |
| 4995 Async.cancel(h); | 5575 Async.cancel(h); |
| 4996 }; | 5576 }; |
| 4997 h = Async.run(this.boundComplete, wait); | 5577 h = Async.run(this.boundComplete, wait); |
| 4998 this.callback = callback; | 5578 this.callback = callback; |
| 4999 }, | 5579 }, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5056 } | 5636 } |
| 5057 }, | 5637 }, |
| 5058 attributeFollows: function (name, toElement, fromElement) { | 5638 attributeFollows: function (name, toElement, fromElement) { |
| 5059 if (fromElement) { | 5639 if (fromElement) { |
| 5060 Polymer.dom(fromElement).removeAttribute(name); | 5640 Polymer.dom(fromElement).removeAttribute(name); |
| 5061 } | 5641 } |
| 5062 if (toElement) { | 5642 if (toElement) { |
| 5063 Polymer.dom(toElement).setAttribute(name, ''); | 5643 Polymer.dom(toElement).setAttribute(name, ''); |
| 5064 } | 5644 } |
| 5065 }, | 5645 }, |
| 5646 getEffectiveChildNodes: function () { |
| 5647 return Polymer.dom(this).getEffectiveChildNodes(); |
| 5648 }, |
| 5649 getEffectiveChildren: function () { |
| 5650 var list = Polymer.dom(this).getEffectiveChildNodes(); |
| 5651 return list.filter(function (n) { |
| 5652 return n.nodeType === Node.ELEMENT_NODE; |
| 5653 }); |
| 5654 }, |
| 5655 getEffectiveTextContent: function () { |
| 5656 var cn = this.getEffectiveChildNodes(); |
| 5657 var tc = []; |
| 5658 for (var i = 0, c; c = cn[i]; i++) { |
| 5659 if (c.nodeType !== Node.COMMENT_NODE) { |
| 5660 tc.push(Polymer.dom(c).textContent); |
| 5661 } |
| 5662 } |
| 5663 return tc.join(''); |
| 5664 }, |
| 5665 queryEffectiveChildren: function (slctr) { |
| 5666 var e$ = Polymer.dom(this).queryDistributedElements(slctr); |
| 5667 return e$ && e$[0]; |
| 5668 }, |
| 5669 queryAllEffectiveChildren: function (slctr) { |
| 5670 return Polymer.dom(this).queryDistributedElements(slctr); |
| 5671 }, |
| 5066 getContentChildNodes: function (slctr) { | 5672 getContentChildNodes: function (slctr) { |
| 5067 var content = Polymer.dom(this.root).querySelector(slctr || 'content'); | 5673 var content = Polymer.dom(this.root).querySelector(slctr || 'content'); |
| 5068 return content ? Polymer.dom(content).getDistributedNodes() : []; | 5674 return content ? Polymer.dom(content).getDistributedNodes() : []; |
| 5069 }, | 5675 }, |
| 5070 getContentChildren: function (slctr) { | 5676 getContentChildren: function (slctr) { |
| 5071 return this.getContentChildNodes(slctr).filter(function (n) { | 5677 return this.getContentChildNodes(slctr).filter(function (n) { |
| 5072 return n.nodeType === Node.ELEMENT_NODE; | 5678 return n.nodeType === Node.ELEMENT_NODE; |
| 5073 }); | 5679 }); |
| 5074 }, | 5680 }, |
| 5075 fire: function (type, detail, options) { | 5681 fire: function (type, detail, options) { |
| 5076 options = options || Polymer.nob; | 5682 options = options || Polymer.nob; |
| 5077 var node = options.node || this; | 5683 var node = options.node || this; |
| 5078 var detail = detail === null || detail === undefined ? Polymer.nob : detail; | 5684 var detail = detail === null || detail === undefined ? {} : detail; |
| 5079 var bubbles = options.bubbles === undefined ? true : options.bubbles; | 5685 var bubbles = options.bubbles === undefined ? true : options.bubbles; |
| 5080 var cancelable = Boolean(options.cancelable); | 5686 var cancelable = Boolean(options.cancelable); |
| 5081 var event = new CustomEvent(type, { | 5687 var useCache = options._useCache; |
| 5688 var event = this._getEvent(type, bubbles, cancelable, useCache); |
| 5689 event.detail = detail; |
| 5690 if (useCache) { |
| 5691 this.__eventCache[type] = null; |
| 5692 } |
| 5693 node.dispatchEvent(event); |
| 5694 if (useCache) { |
| 5695 this.__eventCache[type] = event; |
| 5696 } |
| 5697 return event; |
| 5698 }, |
| 5699 __eventCache: {}, |
| 5700 _getEvent: function (type, bubbles, cancelable, useCache) { |
| 5701 var event = useCache && this.__eventCache[type]; |
| 5702 if (!event || (event.bubbles != bubbles || event.cancelable != cancelable)) { |
| 5703 event = new Event(type, { |
| 5082 bubbles: Boolean(bubbles), | 5704 bubbles: Boolean(bubbles), |
| 5083 cancelable: cancelable, | 5705 cancelable: cancelable |
| 5084 detail: detail | |
| 5085 }); | 5706 }); |
| 5086 node.dispatchEvent(event); | 5707 } |
| 5087 return event; | 5708 return event; |
| 5088 }, | 5709 }, |
| 5089 async: function (callback, waitTime) { | 5710 async: function (callback, waitTime) { |
| 5090 return Polymer.Async.run(callback.bind(this), waitTime); | 5711 var self = this; |
| 5712 return Polymer.Async.run(function () { |
| 5713 callback.call(self); |
| 5714 }, waitTime); |
| 5091 }, | 5715 }, |
| 5092 cancelAsync: function (handle) { | 5716 cancelAsync: function (handle) { |
| 5093 Polymer.Async.cancel(handle); | 5717 Polymer.Async.cancel(handle); |
| 5094 }, | 5718 }, |
| 5095 arrayDelete: function (path, item) { | 5719 arrayDelete: function (path, item) { |
| 5096 var index; | 5720 var index; |
| 5097 if (Array.isArray(path)) { | 5721 if (Array.isArray(path)) { |
| 5098 index = path.indexOf(item); | 5722 index = path.indexOf(item); |
| 5099 if (index >= 0) { | 5723 if (index >= 0) { |
| 5100 return path.splice(index, 1); | 5724 return path.splice(index, 1); |
| 5101 } | 5725 } |
| 5102 } else { | 5726 } else { |
| 5103 var arr = this.get(path); | 5727 var arr = this._get(path); |
| 5104 index = arr.indexOf(item); | 5728 index = arr.indexOf(item); |
| 5105 if (index >= 0) { | 5729 if (index >= 0) { |
| 5106 return this.splice(path, index, 1); | 5730 return this.splice(path, index, 1); |
| 5107 } | 5731 } |
| 5108 } | 5732 } |
| 5109 }, | 5733 }, |
| 5110 transform: function (transform, node) { | 5734 transform: function (transform, node) { |
| 5111 node = node || this; | 5735 node = node || this; |
| 5112 node.style.webkitTransform = transform; | 5736 node.style.webkitTransform = transform; |
| 5113 node.style.transform = transform; | 5737 node.style.transform = transform; |
| 5114 }, | 5738 }, |
| 5115 translate3d: function (x, y, z, node) { | 5739 translate3d: function (x, y, z, node) { |
| 5116 node = node || this; | 5740 node = node || this; |
| 5117 this.transform('translate3d(' + x + ',' + y + ',' + z + ')', node); | 5741 this.transform('translate3d(' + x + ',' + y + ',' + z + ')', node); |
| 5118 }, | 5742 }, |
| 5119 importHref: function (href, onload, onerror) { | 5743 importHref: function (href, onload, onerror) { |
| 5120 var l = document.createElement('link'); | 5744 var l = document.createElement('link'); |
| 5121 l.rel = 'import'; | 5745 l.rel = 'import'; |
| 5122 l.href = href; | 5746 l.href = href; |
| 5747 var self = this; |
| 5123 if (onload) { | 5748 if (onload) { |
| 5124 l.onload = onload.bind(this); | 5749 l.onload = function (e) { |
| 5750 return onload.call(self, e); |
| 5751 }; |
| 5125 } | 5752 } |
| 5126 if (onerror) { | 5753 if (onerror) { |
| 5127 l.onerror = onerror.bind(this); | 5754 l.onerror = function (e) { |
| 5755 return onerror.call(self, e); |
| 5756 }; |
| 5128 } | 5757 } |
| 5129 document.head.appendChild(l); | 5758 document.head.appendChild(l); |
| 5130 return l; | 5759 return l; |
| 5131 }, | 5760 }, |
| 5132 create: function (tag, props) { | 5761 create: function (tag, props) { |
| 5133 var elt = document.createElement(tag); | 5762 var elt = document.createElement(tag); |
| 5134 if (props) { | 5763 if (props) { |
| 5135 for (var n in props) { | 5764 for (var n in props) { |
| 5136 elt[n] = props[n]; | 5765 elt[n] = props[n]; |
| 5137 } | 5766 } |
| 5138 } | 5767 } |
| 5139 return elt; | 5768 return elt; |
| 5140 }, | 5769 }, |
| 5141 isLightDescendant: function (node) { | 5770 isLightDescendant: function (node) { |
| 5142 return this.contains(node) && Polymer.dom(this).getOwnerRoot() === Polymer.dom(n
ode).getOwnerRoot(); | 5771 return this !== node && this.contains(node) && Polymer.dom(this).getOwnerRoot()
=== Polymer.dom(node).getOwnerRoot(); |
| 5143 }, | 5772 }, |
| 5144 isLocalDescendant: function (node) { | 5773 isLocalDescendant: function (node) { |
| 5145 return this.root === Polymer.dom(node).getOwnerRoot(); | 5774 return this.root === Polymer.dom(node).getOwnerRoot(); |
| 5146 } | 5775 } |
| 5147 }); | 5776 }); |
| 5148 Polymer.Bind = { | 5777 Polymer.Bind = { |
| 5778 _dataEventCache: {}, |
| 5149 prepareModel: function (model) { | 5779 prepareModel: function (model) { |
| 5150 model._propertyEffects = {}; | |
| 5151 model._bindListeners = []; | |
| 5152 Polymer.Base.mixin(model, this._modelApi); | 5780 Polymer.Base.mixin(model, this._modelApi); |
| 5153 }, | 5781 }, |
| 5154 _modelApi: { | 5782 _modelApi: { |
| 5155 _notifyChange: function (property) { | 5783 _notifyChange: function (source, event, value) { |
| 5156 var eventName = Polymer.CaseMap.camelToDashCase(property) + '-changed'; | 5784 value = value === undefined ? this[source] : value; |
| 5157 Polymer.Base.fire(eventName, { value: this[property] }, { | 5785 event = event || Polymer.CaseMap.camelToDashCase(source) + '-changed'; |
| 5786 this.fire(event, { value: value }, { |
| 5158 bubbles: false, | 5787 bubbles: false, |
| 5159 node: this | 5788 cancelable: false, |
| 5789 _useCache: true |
| 5160 }); | 5790 }); |
| 5161 }, | 5791 }, |
| 5162 _propertySetter: function (property, value, effects, fromAbove) { | 5792 _propertySetter: function (property, value, effects, fromAbove) { |
| 5163 var old = this.__data__[property]; | 5793 var old = this.__data__[property]; |
| 5164 if (old !== value && (old === old || value === value)) { | 5794 if (old !== value && (old === old || value === value)) { |
| 5165 this.__data__[property] = value; | 5795 this.__data__[property] = value; |
| 5166 if (typeof value == 'object') { | 5796 if (typeof value == 'object') { |
| 5167 this._clearPath(property); | 5797 this._clearPath(property); |
| 5168 } | 5798 } |
| 5169 if (this._propertyChanged) { | 5799 if (this._propertyChanged) { |
| 5170 this._propertyChanged(property, value, old); | 5800 this._propertyChanged(property, value, old); |
| 5171 } | 5801 } |
| 5172 if (effects) { | 5802 if (effects) { |
| 5173 this._effectEffects(property, value, effects, old, fromAbove); | 5803 this._effectEffects(property, value, effects, old, fromAbove); |
| 5174 } | 5804 } |
| 5175 } | 5805 } |
| 5176 return old; | 5806 return old; |
| 5177 }, | 5807 }, |
| 5178 __setProperty: function (property, value, quiet, node) { | 5808 __setProperty: function (property, value, quiet, node) { |
| 5179 node = node || this; | 5809 node = node || this; |
| 5180 var effects = node._propertyEffects && node._propertyEffects[property]; | 5810 var effects = node._propertyEffects && node._propertyEffects[property]; |
| 5181 if (effects) { | 5811 if (effects) { |
| 5182 node._propertySetter(property, value, effects, quiet); | 5812 node._propertySetter(property, value, effects, quiet); |
| 5183 } else { | 5813 } else { |
| 5184 node[property] = value; | 5814 node[property] = value; |
| 5185 } | 5815 } |
| 5186 }, | 5816 }, |
| 5187 _effectEffects: function (property, value, effects, old, fromAbove) { | 5817 _effectEffects: function (property, value, effects, old, fromAbove) { |
| 5188 effects.forEach(function (fx) { | 5818 for (var i = 0, l = effects.length, fx; i < l && (fx = effects[i]); i++) { |
| 5189 var fn = Polymer.Bind['_' + fx.kind + 'Effect']; | 5819 fx.fn.call(this, property, value, fx.effect, old, fromAbove); |
| 5190 if (fn) { | |
| 5191 fn.call(this, property, value, fx.effect, old, fromAbove); | |
| 5192 } | 5820 } |
| 5193 }, this); | |
| 5194 }, | 5821 }, |
| 5195 _clearPath: function (path) { | 5822 _clearPath: function (path) { |
| 5196 for (var prop in this.__data__) { | 5823 for (var prop in this.__data__) { |
| 5197 if (prop.indexOf(path + '.') === 0) { | 5824 if (prop.indexOf(path + '.') === 0) { |
| 5198 this.__data__[prop] = undefined; | 5825 this.__data__[prop] = undefined; |
| 5199 } | 5826 } |
| 5200 } | 5827 } |
| 5201 } | 5828 } |
| 5202 }, | 5829 }, |
| 5203 ensurePropertyEffects: function (model, property) { | 5830 ensurePropertyEffects: function (model, property) { |
| 5831 if (!model._propertyEffects) { |
| 5832 model._propertyEffects = {}; |
| 5833 } |
| 5204 var fx = model._propertyEffects[property]; | 5834 var fx = model._propertyEffects[property]; |
| 5205 if (!fx) { | 5835 if (!fx) { |
| 5206 fx = model._propertyEffects[property] = []; | 5836 fx = model._propertyEffects[property] = []; |
| 5207 } | 5837 } |
| 5208 return fx; | 5838 return fx; |
| 5209 }, | 5839 }, |
| 5210 addPropertyEffect: function (model, property, kind, effect) { | 5840 addPropertyEffect: function (model, property, kind, effect) { |
| 5211 var fx = this.ensurePropertyEffects(model, property); | 5841 var fx = this.ensurePropertyEffects(model, property); |
| 5212 fx.push({ | 5842 var propEffect = { |
| 5213 kind: kind, | 5843 kind: kind, |
| 5214 effect: effect | 5844 effect: effect, |
| 5215 }); | 5845 fn: Polymer.Bind['_' + kind + 'Effect'] |
| 5846 }; |
| 5847 fx.push(propEffect); |
| 5848 return propEffect; |
| 5216 }, | 5849 }, |
| 5217 createBindings: function (model) { | 5850 createBindings: function (model) { |
| 5218 var fx$ = model._propertyEffects; | 5851 var fx$ = model._propertyEffects; |
| 5219 if (fx$) { | 5852 if (fx$) { |
| 5220 for (var n in fx$) { | 5853 for (var n in fx$) { |
| 5221 var fx = fx$[n]; | 5854 var fx = fx$[n]; |
| 5222 fx.sort(this._sortPropertyEffects); | 5855 fx.sort(this._sortPropertyEffects); |
| 5223 this._createAccessors(model, n, fx); | 5856 this._createAccessors(model, n, fx); |
| 5224 } | 5857 } |
| 5225 } | 5858 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 5255 } | 5888 } |
| 5256 } else { | 5889 } else { |
| 5257 defun.set = setter; | 5890 defun.set = setter; |
| 5258 } | 5891 } |
| 5259 Object.defineProperty(model, property, defun); | 5892 Object.defineProperty(model, property, defun); |
| 5260 }, | 5893 }, |
| 5261 upper: function (name) { | 5894 upper: function (name) { |
| 5262 return name[0].toUpperCase() + name.substring(1); | 5895 return name[0].toUpperCase() + name.substring(1); |
| 5263 }, | 5896 }, |
| 5264 _addAnnotatedListener: function (model, index, property, path, event) { | 5897 _addAnnotatedListener: function (model, index, property, path, event) { |
| 5265 var fn = this._notedListenerFactory(property, path, this._isStructured(path), th
is._isEventBogus); | 5898 if (!model._bindListeners) { |
| 5899 model._bindListeners = []; |
| 5900 } |
| 5901 var fn = this._notedListenerFactory(property, path, this._isStructured(path)); |
| 5266 var eventName = event || Polymer.CaseMap.camelToDashCase(property) + '-changed'; | 5902 var eventName = event || Polymer.CaseMap.camelToDashCase(property) + '-changed'; |
| 5267 model._bindListeners.push({ | 5903 model._bindListeners.push({ |
| 5268 index: index, | 5904 index: index, |
| 5269 property: property, | 5905 property: property, |
| 5270 path: path, | 5906 path: path, |
| 5271 changedFn: fn, | 5907 changedFn: fn, |
| 5272 event: eventName | 5908 event: eventName |
| 5273 }); | 5909 }); |
| 5274 }, | 5910 }, |
| 5275 _isStructured: function (path) { | 5911 _isStructured: function (path) { |
| 5276 return path.indexOf('.') > 0; | 5912 return path.indexOf('.') > 0; |
| 5277 }, | 5913 }, |
| 5278 _isEventBogus: function (e, target) { | 5914 _isEventBogus: function (e, target) { |
| 5279 return e.path && e.path[0] !== target; | 5915 return e.path && e.path[0] !== target; |
| 5280 }, | 5916 }, |
| 5281 _notedListenerFactory: function (property, path, isStructured, bogusTest) { | 5917 _notedListenerFactory: function (property, path, isStructured) { |
| 5282 return function (e, target) { | 5918 return function (target, value, targetPath) { |
| 5283 if (!bogusTest(e, target)) { | 5919 if (targetPath) { |
| 5284 if (e.detail && e.detail.path) { | 5920 this._notifyPath(this._fixPath(path, property, targetPath), value); |
| 5285 this.notifyPath(this._fixPath(path, property, e.detail.path), e.detail.value); | |
| 5286 } else { | 5921 } else { |
| 5287 var value = target[property]; | 5922 value = target[property]; |
| 5288 if (!isStructured) { | 5923 if (!isStructured) { |
| 5289 this[path] = target[property]; | 5924 this[path] = value; |
| 5290 } else { | 5925 } else { |
| 5291 if (this.__data__[path] != value) { | 5926 if (this.__data__[path] != value) { |
| 5292 this.set(path, value); | 5927 this.set(path, value); |
| 5293 } | 5928 } |
| 5294 } | 5929 } |
| 5295 } | 5930 } |
| 5296 } | |
| 5297 }; | 5931 }; |
| 5298 }, | 5932 }, |
| 5299 prepareInstance: function (inst) { | 5933 prepareInstance: function (inst) { |
| 5300 inst.__data__ = Object.create(null); | 5934 inst.__data__ = Object.create(null); |
| 5301 }, | 5935 }, |
| 5302 setupBindListeners: function (inst) { | 5936 setupBindListeners: function (inst) { |
| 5303 inst._bindListeners.forEach(function (info) { | 5937 var b$ = inst._bindListeners; |
| 5938 for (var i = 0, l = b$.length, info; i < l && (info = b$[i]); i++) { |
| 5304 var node = inst._nodes[info.index]; | 5939 var node = inst._nodes[info.index]; |
| 5305 node.addEventListener(info.event, inst._notifyListener.bind(inst, info.changedFn
)); | 5940 this._addNotifyListener(node, inst, info.event, info.changedFn); |
| 5941 } |
| 5942 ; |
| 5943 }, |
| 5944 _addNotifyListener: function (element, context, event, changedFn) { |
| 5945 element.addEventListener(event, function (e) { |
| 5946 return context._notifyListener(changedFn, e); |
| 5306 }); | 5947 }); |
| 5307 } | 5948 } |
| 5308 }; | 5949 }; |
| 5309 Polymer.Base.extend(Polymer.Bind, { | 5950 Polymer.Base.extend(Polymer.Bind, { |
| 5310 _shouldAddListener: function (effect) { | 5951 _shouldAddListener: function (effect) { |
| 5311 return effect.name && effect.mode === '{' && !effect.negate && effect.kind != 'a
ttribute'; | 5952 return effect.name && effect.kind != 'attribute' && effect.kind != 'text' && !ef
fect.isCompound && effect.parts[0].mode === '{' && !effect.parts[0].negate; |
| 5312 }, | 5953 }, |
| 5313 _annotationEffect: function (source, value, effect) { | 5954 _annotationEffect: function (source, value, effect) { |
| 5314 if (source != effect.value) { | 5955 if (source != effect.value) { |
| 5315 value = this.get(effect.value); | 5956 value = this._get(effect.value); |
| 5316 this.__data__[effect.value] = value; | 5957 this.__data__[effect.value] = value; |
| 5317 } | 5958 } |
| 5318 var calc = effect.negate ? !value : value; | 5959 var calc = effect.negate ? !value : value; |
| 5319 if (!effect.customEvent || this._nodes[effect.index][effect.name] !== calc) { | 5960 if (!effect.customEvent || this._nodes[effect.index][effect.name] !== calc) { |
| 5320 return this._applyEffectValue(calc, effect); | 5961 return this._applyEffectValue(effect, calc); |
| 5321 } | 5962 } |
| 5322 }, | 5963 }, |
| 5323 _reflectEffect: function (source) { | 5964 _reflectEffect: function (source, value, effect) { |
| 5324 this.reflectPropertyToAttribute(source); | 5965 this.reflectPropertyToAttribute(source, effect.attribute, value); |
| 5325 }, | 5966 }, |
| 5326 _notifyEffect: function (source, value, effect, old, fromAbove) { | 5967 _notifyEffect: function (source, value, effect, old, fromAbove) { |
| 5327 if (!fromAbove) { | 5968 if (!fromAbove) { |
| 5328 this._notifyChange(source); | 5969 this._notifyChange(source, effect.event, value); |
| 5329 } | 5970 } |
| 5330 }, | 5971 }, |
| 5331 _functionEffect: function (source, value, fn, old, fromAbove) { | 5972 _functionEffect: function (source, value, fn, old, fromAbove) { |
| 5332 fn.call(this, source, value, old, fromAbove); | 5973 fn.call(this, source, value, old, fromAbove); |
| 5333 }, | 5974 }, |
| 5334 _observerEffect: function (source, value, effect, old) { | 5975 _observerEffect: function (source, value, effect, old) { |
| 5335 var fn = this[effect.method]; | 5976 var fn = this[effect.method]; |
| 5336 if (fn) { | 5977 if (fn) { |
| 5337 fn.call(this, value, old); | 5978 fn.call(this, value, old); |
| 5338 } else { | 5979 } else { |
| 5339 this._warn(this._logf('_observerEffect', 'observer method `' + effect.method + '
` not defined')); | 5980 this._warn(this._logf('_observerEffect', 'observer method `' + effect.method + '
` not defined')); |
| 5340 } | 5981 } |
| 5341 }, | 5982 }, |
| 5342 _complexObserverEffect: function (source, value, effect) { | 5983 _complexObserverEffect: function (source, value, effect) { |
| 5343 var fn = this[effect.method]; | 5984 var fn = this[effect.method]; |
| 5344 if (fn) { | 5985 if (fn) { |
| 5345 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | 5986 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); |
| 5346 if (args) { | 5987 if (args) { |
| 5347 fn.apply(this, args); | 5988 fn.apply(this, args); |
| 5348 } | 5989 } |
| 5349 } else { | 5990 } else { |
| 5350 this._warn(this._logf('_complexObserverEffect', 'observer method `' + effect.met
hod + '` not defined')); | 5991 this._warn(this._logf('_complexObserverEffect', 'observer method `' + effect.met
hod + '` not defined')); |
| 5351 } | 5992 } |
| 5352 }, | 5993 }, |
| 5353 _computeEffect: function (source, value, effect) { | 5994 _computeEffect: function (source, value, effect) { |
| 5354 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | 5995 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); |
| 5355 if (args) { | 5996 if (args) { |
| 5356 var fn = this[effect.method]; | 5997 var fn = this[effect.method]; |
| 5357 if (fn) { | 5998 if (fn) { |
| 5358 this.__setProperty(effect.property, fn.apply(this, args)); | 5999 this.__setProperty(effect.name, fn.apply(this, args)); |
| 5359 } else { | 6000 } else { |
| 5360 this._warn(this._logf('_computeEffect', 'compute method `' + effect.method + '`
not defined')); | 6001 this._warn(this._logf('_computeEffect', 'compute method `' + effect.method + '`
not defined')); |
| 5361 } | 6002 } |
| 5362 } | 6003 } |
| 5363 }, | 6004 }, |
| 5364 _annotatedComputationEffect: function (source, value, effect) { | 6005 _annotatedComputationEffect: function (source, value, effect) { |
| 5365 var computedHost = this._rootDataHost || this; | 6006 var computedHost = this._rootDataHost || this; |
| 5366 var fn = computedHost[effect.method]; | 6007 var fn = computedHost[effect.method]; |
| 5367 if (fn) { | 6008 if (fn) { |
| 5368 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); | 6009 var args = Polymer.Bind._marshalArgs(this.__data__, effect, source, value); |
| 5369 if (args) { | 6010 if (args) { |
| 5370 var computedvalue = fn.apply(computedHost, args); | 6011 var computedvalue = fn.apply(computedHost, args); |
| 5371 if (effect.negate) { | 6012 if (effect.negate) { |
| 5372 computedvalue = !computedvalue; | 6013 computedvalue = !computedvalue; |
| 5373 } | 6014 } |
| 5374 this._applyEffectValue(computedvalue, effect); | 6015 this._applyEffectValue(effect, computedvalue); |
| 5375 } | 6016 } |
| 5376 } else { | 6017 } else { |
| 5377 computedHost._warn(computedHost._logf('_annotatedComputationEffect', 'compute me
thod `' + effect.method + '` not defined')); | 6018 computedHost._warn(computedHost._logf('_annotatedComputationEffect', 'compute me
thod `' + effect.method + '` not defined')); |
| 5378 } | 6019 } |
| 5379 }, | 6020 }, |
| 5380 _marshalArgs: function (model, effect, path, value) { | 6021 _marshalArgs: function (model, effect, path, value) { |
| 5381 var values = []; | 6022 var values = []; |
| 5382 var args = effect.args; | 6023 var args = effect.args; |
| 5383 for (var i = 0, l = args.length; i < l; i++) { | 6024 for (var i = 0, l = args.length; i < l; i++) { |
| 5384 var arg = args[i]; | 6025 var arg = args[i]; |
| 5385 var name = arg.name; | 6026 var name = arg.name; |
| 5386 var v; | 6027 var v; |
| 5387 if (arg.literal) { | 6028 if (arg.literal) { |
| 5388 v = arg.value; | 6029 v = arg.value; |
| 5389 } else if (arg.structured) { | 6030 } else if (arg.structured) { |
| 5390 v = Polymer.Base.get(name, model); | 6031 v = Polymer.Base._get(name, model); |
| 5391 } else { | 6032 } else { |
| 5392 v = model[name]; | 6033 v = model[name]; |
| 5393 } | 6034 } |
| 5394 if (args.length > 1 && v === undefined) { | 6035 if (args.length > 1 && v === undefined) { |
| 5395 return; | 6036 return; |
| 5396 } | 6037 } |
| 5397 if (arg.wildcard) { | 6038 if (arg.wildcard) { |
| 5398 var baseChanged = name.indexOf(path + '.') === 0; | 6039 var baseChanged = name.indexOf(path + '.') === 0; |
| 5399 var matches = effect.trigger.name.indexOf(name) === 0 && !baseChanged; | 6040 var matches = effect.trigger.name.indexOf(name) === 0 && !baseChanged; |
| 5400 values[i] = { | 6041 values[i] = { |
| 5401 path: matches ? path : name, | 6042 path: matches ? path : name, |
| 5402 value: matches ? value : v, | 6043 value: matches ? value : v, |
| 5403 base: v | 6044 base: v |
| 5404 }; | 6045 }; |
| 5405 } else { | 6046 } else { |
| 5406 values[i] = v; | 6047 values[i] = v; |
| 5407 } | 6048 } |
| 5408 } | 6049 } |
| 5409 return values; | 6050 return values; |
| 5410 } | 6051 } |
| 5411 }); | 6052 }); |
| 5412 Polymer.Base._addFeature({ | 6053 Polymer.Base._addFeature({ |
| 5413 _addPropertyEffect: function (property, kind, effect) { | 6054 _addPropertyEffect: function (property, kind, effect) { |
| 5414 Polymer.Bind.addPropertyEffect(this, property, kind, effect); | 6055 var prop = Polymer.Bind.addPropertyEffect(this, property, kind, effect); |
| 6056 prop.pathFn = this['_' + prop.kind + 'PathEffect']; |
| 5415 }, | 6057 }, |
| 5416 _prepEffects: function () { | 6058 _prepEffects: function () { |
| 5417 Polymer.Bind.prepareModel(this); | 6059 Polymer.Bind.prepareModel(this); |
| 5418 this._addAnnotationEffects(this._notes); | 6060 this._addAnnotationEffects(this._notes); |
| 5419 }, | 6061 }, |
| 5420 _prepBindings: function () { | 6062 _prepBindings: function () { |
| 5421 Polymer.Bind.createBindings(this); | 6063 Polymer.Bind.createBindings(this); |
| 5422 }, | 6064 }, |
| 5423 _addPropertyEffects: function (properties) { | 6065 _addPropertyEffects: function (properties) { |
| 5424 if (properties) { | 6066 if (properties) { |
| 5425 for (var p in properties) { | 6067 for (var p in properties) { |
| 5426 var prop = properties[p]; | 6068 var prop = properties[p]; |
| 5427 if (prop.observer) { | 6069 if (prop.observer) { |
| 5428 this._addObserverEffect(p, prop.observer); | 6070 this._addObserverEffect(p, prop.observer); |
| 5429 } | 6071 } |
| 5430 if (prop.computed) { | 6072 if (prop.computed) { |
| 5431 prop.readOnly = true; | 6073 prop.readOnly = true; |
| 5432 this._addComputedEffect(p, prop.computed); | 6074 this._addComputedEffect(p, prop.computed); |
| 5433 } | 6075 } |
| 5434 if (prop.notify) { | 6076 if (prop.notify) { |
| 5435 this._addPropertyEffect(p, 'notify'); | 6077 this._addPropertyEffect(p, 'notify', { event: Polymer.CaseMap.camelToDashCase(p)
+ '-changed' }); |
| 5436 } | 6078 } |
| 5437 if (prop.reflectToAttribute) { | 6079 if (prop.reflectToAttribute) { |
| 5438 this._addPropertyEffect(p, 'reflect'); | 6080 this._addPropertyEffect(p, 'reflect', { attribute: Polymer.CaseMap.camelToDashCa
se(p) }); |
| 5439 } | 6081 } |
| 5440 if (prop.readOnly) { | 6082 if (prop.readOnly) { |
| 5441 Polymer.Bind.ensurePropertyEffects(this, p); | 6083 Polymer.Bind.ensurePropertyEffects(this, p); |
| 5442 } | 6084 } |
| 5443 } | 6085 } |
| 5444 } | 6086 } |
| 5445 }, | 6087 }, |
| 5446 _addComputedEffect: function (name, expression) { | 6088 _addComputedEffect: function (name, expression) { |
| 5447 var sig = this._parseMethod(expression); | 6089 var sig = this._parseMethod(expression); |
| 5448 sig.args.forEach(function (arg) { | 6090 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { |
| 5449 this._addPropertyEffect(arg.model, 'compute', { | 6091 this._addPropertyEffect(arg.model, 'compute', { |
| 5450 method: sig.method, | 6092 method: sig.method, |
| 5451 args: sig.args, | 6093 args: sig.args, |
| 5452 trigger: arg, | 6094 trigger: arg, |
| 5453 property: name | 6095 name: name |
| 5454 }); | 6096 }); |
| 5455 }, this); | 6097 } |
| 5456 }, | 6098 }, |
| 5457 _addObserverEffect: function (property, observer) { | 6099 _addObserverEffect: function (property, observer) { |
| 5458 this._addPropertyEffect(property, 'observer', { | 6100 this._addPropertyEffect(property, 'observer', { |
| 5459 method: observer, | 6101 method: observer, |
| 5460 property: property | 6102 property: property |
| 5461 }); | 6103 }); |
| 5462 }, | 6104 }, |
| 5463 _addComplexObserverEffects: function (observers) { | 6105 _addComplexObserverEffects: function (observers) { |
| 5464 if (observers) { | 6106 if (observers) { |
| 5465 observers.forEach(function (observer) { | 6107 for (var i = 0, o; i < observers.length && (o = observers[i]); i++) { |
| 5466 this._addComplexObserverEffect(observer); | 6108 this._addComplexObserverEffect(o); |
| 5467 }, this); | 6109 } |
| 5468 } | 6110 } |
| 5469 }, | 6111 }, |
| 5470 _addComplexObserverEffect: function (observer) { | 6112 _addComplexObserverEffect: function (observer) { |
| 5471 var sig = this._parseMethod(observer); | 6113 var sig = this._parseMethod(observer); |
| 5472 sig.args.forEach(function (arg) { | 6114 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { |
| 5473 this._addPropertyEffect(arg.model, 'complexObserver', { | 6115 this._addPropertyEffect(arg.model, 'complexObserver', { |
| 5474 method: sig.method, | 6116 method: sig.method, |
| 5475 args: sig.args, | 6117 args: sig.args, |
| 5476 trigger: arg | 6118 trigger: arg |
| 5477 }); | 6119 }); |
| 5478 }, this); | 6120 } |
| 5479 }, | 6121 }, |
| 5480 _addAnnotationEffects: function (notes) { | 6122 _addAnnotationEffects: function (notes) { |
| 5481 this._nodes = []; | 6123 for (var i = 0, note; i < notes.length && (note = notes[i]); i++) { |
| 5482 notes.forEach(function (note) { | 6124 var b$ = note.bindings; |
| 5483 var index = this._nodes.push(note) - 1; | 6125 for (var j = 0, binding; j < b$.length && (binding = b$[j]); j++) { |
| 5484 note.bindings.forEach(function (binding) { | 6126 this._addAnnotationEffect(binding, i); |
| 5485 this._addAnnotationEffect(binding, index); | 6127 } |
| 5486 }, this); | 6128 } |
| 5487 }, this); | |
| 5488 }, | 6129 }, |
| 5489 _addAnnotationEffect: function (note, index) { | 6130 _addAnnotationEffect: function (note, index) { |
| 5490 if (Polymer.Bind._shouldAddListener(note)) { | 6131 if (Polymer.Bind._shouldAddListener(note)) { |
| 5491 Polymer.Bind._addAnnotatedListener(this, index, note.name, note.value, note.even
t); | 6132 Polymer.Bind._addAnnotatedListener(this, index, note.name, note.parts[0].value,
note.parts[0].event); |
| 5492 } | 6133 } |
| 5493 if (note.signature) { | 6134 for (var i = 0; i < note.parts.length; i++) { |
| 5494 this._addAnnotatedComputationEffect(note, index); | 6135 var part = note.parts[i]; |
| 5495 } else { | 6136 if (part.signature) { |
| 5496 note.index = index; | 6137 this._addAnnotatedComputationEffect(note, part, index); |
| 5497 this._addPropertyEffect(note.model, 'annotation', note); | 6138 } else if (!part.literal) { |
| 6139 this._addPropertyEffect(part.model, 'annotation', { |
| 6140 kind: note.kind, |
| 6141 index: index, |
| 6142 name: note.name, |
| 6143 value: part.value, |
| 6144 isCompound: note.isCompound, |
| 6145 compoundIndex: part.compoundIndex, |
| 6146 event: part.event, |
| 6147 customEvent: part.customEvent, |
| 6148 negate: part.negate |
| 6149 }); |
| 6150 } |
| 5498 } | 6151 } |
| 5499 }, | 6152 }, |
| 5500 _addAnnotatedComputationEffect: function (note, index) { | 6153 _addAnnotatedComputationEffect: function (note, part, index) { |
| 5501 var sig = note.signature; | 6154 var sig = part.signature; |
| 5502 if (sig.static) { | 6155 if (sig.static) { |
| 5503 this.__addAnnotatedComputationEffect('__static__', index, note, sig, null); | 6156 this.__addAnnotatedComputationEffect('__static__', index, note, part, null); |
| 5504 } else { | 6157 } else { |
| 5505 sig.args.forEach(function (arg) { | 6158 for (var i = 0, arg; i < sig.args.length && (arg = sig.args[i]); i++) { |
| 5506 if (!arg.literal) { | 6159 if (!arg.literal) { |
| 5507 this.__addAnnotatedComputationEffect(arg.model, index, note, sig, arg); | 6160 this.__addAnnotatedComputationEffect(arg.model, index, note, part, arg); |
| 5508 } | 6161 } |
| 5509 }, this); | 6162 } |
| 5510 } | 6163 } |
| 5511 }, | 6164 }, |
| 5512 __addAnnotatedComputationEffect: function (property, index, note, sig, trigger)
{ | 6165 __addAnnotatedComputationEffect: function (property, index, note, part, trigger)
{ |
| 5513 this._addPropertyEffect(property, 'annotatedComputation', { | 6166 this._addPropertyEffect(property, 'annotatedComputation', { |
| 5514 index: index, | 6167 index: index, |
| 6168 isCompound: note.isCompound, |
| 6169 compoundIndex: part.compoundIndex, |
| 5515 kind: note.kind, | 6170 kind: note.kind, |
| 5516 property: note.name, | 6171 name: note.name, |
| 5517 negate: note.negate, | 6172 negate: part.negate, |
| 5518 method: sig.method, | 6173 method: part.signature.method, |
| 5519 args: sig.args, | 6174 args: part.signature.args, |
| 5520 trigger: trigger | 6175 trigger: trigger |
| 5521 }); | 6176 }); |
| 5522 }, | 6177 }, |
| 5523 _parseMethod: function (expression) { | 6178 _parseMethod: function (expression) { |
| 5524 var m = expression.match(/([^\s]+)\((.*)\)/); | 6179 var m = expression.match(/([^\s]+)\((.*)\)/); |
| 5525 if (m) { | 6180 if (m) { |
| 5526 var sig = { | 6181 var sig = { |
| 5527 method: m[1], | 6182 method: m[1], |
| 5528 static: true | 6183 static: true |
| 5529 }; | 6184 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5576 a.wildcard = arg.slice(-2) == '.*'; | 6231 a.wildcard = arg.slice(-2) == '.*'; |
| 5577 if (a.wildcard) { | 6232 if (a.wildcard) { |
| 5578 a.name = arg.slice(0, -2); | 6233 a.name = arg.slice(0, -2); |
| 5579 } | 6234 } |
| 5580 } | 6235 } |
| 5581 } | 6236 } |
| 5582 return a; | 6237 return a; |
| 5583 }, | 6238 }, |
| 5584 _marshalInstanceEffects: function () { | 6239 _marshalInstanceEffects: function () { |
| 5585 Polymer.Bind.prepareInstance(this); | 6240 Polymer.Bind.prepareInstance(this); |
| 6241 if (this._bindListeners) { |
| 5586 Polymer.Bind.setupBindListeners(this); | 6242 Polymer.Bind.setupBindListeners(this); |
| 6243 } |
| 5587 }, | 6244 }, |
| 5588 _applyEffectValue: function (value, info) { | 6245 _applyEffectValue: function (info, value) { |
| 5589 var node = this._nodes[info.index]; | 6246 var node = this._nodes[info.index]; |
| 5590 var property = info.property || info.name || 'textContent'; | 6247 var property = info.name; |
| 6248 if (info.isCompound) { |
| 6249 var storage = node.__compoundStorage__[property]; |
| 6250 storage[info.compoundIndex] = value; |
| 6251 value = storage.join(''); |
| 6252 } |
| 5591 if (info.kind == 'attribute') { | 6253 if (info.kind == 'attribute') { |
| 5592 this.serializeValueToAttribute(value, property, node); | 6254 this.serializeValueToAttribute(value, property, node); |
| 5593 } else { | 6255 } else { |
| 5594 if (property === 'className') { | 6256 if (property === 'className') { |
| 5595 value = this._scopeElementClass(node, value); | 6257 value = this._scopeElementClass(node, value); |
| 5596 } | 6258 } |
| 5597 if (property === 'textContent' || node.localName == 'input' && property == 'valu
e') { | 6259 if (property === 'textContent' || node.localName == 'input' && property == 'valu
e') { |
| 5598 value = value == undefined ? '' : value; | 6260 value = value == undefined ? '' : value; |
| 5599 } | 6261 } |
| 5600 return node[property] = value; | 6262 var pinfo; |
| 6263 if (!node._propertyInfo || !(pinfo = node._propertyInfo[property]) || !pinfo.rea
dOnly) { |
| 6264 this.__setProperty(property, value, true, node); |
| 6265 } |
| 5601 } | 6266 } |
| 5602 }, | 6267 }, |
| 5603 _executeStaticEffects: function () { | 6268 _executeStaticEffects: function () { |
| 5604 if (this._propertyEffects.__static__) { | 6269 if (this._propertyEffects && this._propertyEffects.__static__) { |
| 5605 this._effectEffects('__static__', null, this._propertyEffects.__static__); | 6270 this._effectEffects('__static__', null, this._propertyEffects.__static__); |
| 5606 } | 6271 } |
| 5607 } | 6272 } |
| 5608 }); | 6273 }); |
| 5609 Polymer.Base._addFeature({ | 6274 Polymer.Base._addFeature({ |
| 5610 _setupConfigure: function (initialConfig) { | 6275 _setupConfigure: function (initialConfig) { |
| 5611 this._config = {}; | 6276 this._config = {}; |
| 6277 this._handlers = []; |
| 6278 if (initialConfig) { |
| 5612 for (var i in initialConfig) { | 6279 for (var i in initialConfig) { |
| 5613 if (initialConfig[i] !== undefined) { | 6280 if (initialConfig[i] !== undefined) { |
| 5614 this._config[i] = initialConfig[i]; | 6281 this._config[i] = initialConfig[i]; |
| 5615 } | 6282 } |
| 5616 } | 6283 } |
| 5617 this._handlers = []; | 6284 } |
| 5618 }, | 6285 }, |
| 5619 _marshalAttributes: function () { | 6286 _marshalAttributes: function () { |
| 5620 this._takeAttributesToModel(this._config); | 6287 this._takeAttributesToModel(this._config); |
| 5621 }, | 6288 }, |
| 5622 _attributeChangedImpl: function (name) { | 6289 _attributeChangedImpl: function (name) { |
| 5623 var model = this._clientsReadied ? this : this._config; | 6290 var model = this._clientsReadied ? this : this._config; |
| 5624 this._setAttributeToProperty(model, name); | 6291 this._setAttributeToProperty(model, name); |
| 5625 }, | 6292 }, |
| 5626 _configValue: function (name, value) { | 6293 _configValue: function (name, value) { |
| 6294 var info = this._propertyInfo[name]; |
| 6295 if (!info || !info.readOnly) { |
| 5627 this._config[name] = value; | 6296 this._config[name] = value; |
| 6297 } |
| 5628 }, | 6298 }, |
| 5629 _beforeClientsReady: function () { | 6299 _beforeClientsReady: function () { |
| 5630 this._configure(); | 6300 this._configure(); |
| 5631 }, | 6301 }, |
| 5632 _configure: function () { | 6302 _configure: function () { |
| 5633 this._configureAnnotationReferences(); | 6303 this._configureAnnotationReferences(); |
| 5634 this._aboveConfig = this.mixin({}, this._config); | 6304 this._aboveConfig = this.mixin({}, this._config); |
| 5635 var config = {}; | 6305 var config = {}; |
| 5636 this.behaviors.forEach(function (b) { | 6306 for (var i = 0; i < this.behaviors.length; i++) { |
| 5637 this._configureProperties(b.properties, config); | 6307 this._configureProperties(this.behaviors[i].properties, config); |
| 5638 }, this); | 6308 } |
| 5639 this._configureProperties(this.properties, config); | 6309 this._configureProperties(this.properties, config); |
| 5640 this._mixinConfigure(config, this._aboveConfig); | 6310 this.mixin(config, this._aboveConfig); |
| 5641 this._config = config; | 6311 this._config = config; |
| 6312 if (this._clients && this._clients.length) { |
| 5642 this._distributeConfig(this._config); | 6313 this._distributeConfig(this._config); |
| 6314 } |
| 5643 }, | 6315 }, |
| 5644 _configureProperties: function (properties, config) { | 6316 _configureProperties: function (properties, config) { |
| 5645 for (var i in properties) { | 6317 for (var i in properties) { |
| 5646 var c = properties[i]; | 6318 var c = properties[i]; |
| 5647 if (c.value !== undefined) { | 6319 if (c.value !== undefined) { |
| 5648 var value = c.value; | 6320 var value = c.value; |
| 5649 if (typeof value == 'function') { | 6321 if (typeof value == 'function') { |
| 5650 value = value.call(this, this._config); | 6322 value = value.call(this, this._config); |
| 5651 } | 6323 } |
| 5652 config[i] = value; | 6324 config[i] = value; |
| 5653 } | 6325 } |
| 5654 } | 6326 } |
| 5655 }, | 6327 }, |
| 5656 _mixinConfigure: function (a, b) { | |
| 5657 for (var prop in b) { | |
| 5658 if (!this.getPropertyInfo(prop).readOnly) { | |
| 5659 a[prop] = b[prop]; | |
| 5660 } | |
| 5661 } | |
| 5662 }, | |
| 5663 _distributeConfig: function (config) { | 6328 _distributeConfig: function (config) { |
| 5664 var fx$ = this._propertyEffects; | 6329 var fx$ = this._propertyEffects; |
| 5665 if (fx$) { | 6330 if (fx$) { |
| 5666 for (var p in config) { | 6331 for (var p in config) { |
| 5667 var fx = fx$[p]; | 6332 var fx = fx$[p]; |
| 5668 if (fx) { | 6333 if (fx) { |
| 5669 for (var i = 0, l = fx.length, x; i < l && (x = fx[i]); i++) { | 6334 for (var i = 0, l = fx.length, x; i < l && (x = fx[i]); i++) { |
| 5670 if (x.kind === 'annotation') { | 6335 if (x.kind === 'annotation' && !x.isCompound) { |
| 5671 var node = this._nodes[x.effect.index]; | 6336 var node = this._nodes[x.effect.index]; |
| 5672 if (node._configValue) { | 6337 if (node._configValue) { |
| 5673 var value = p === x.effect.value ? config[p] : this.get(x.effect.value, config); | 6338 var value = p === x.effect.value ? config[p] : this._get(x.effect.value, config)
; |
| 5674 node._configValue(x.effect.name, value); | 6339 node._configValue(x.effect.name, value); |
| 5675 } | 6340 } |
| 5676 } | 6341 } |
| 5677 } | 6342 } |
| 5678 } | 6343 } |
| 5679 } | 6344 } |
| 5680 } | 6345 } |
| 5681 }, | 6346 }, |
| 5682 _afterClientsReady: function () { | 6347 _afterClientsReady: function () { |
| 5683 this._executeStaticEffects(); | 6348 this._executeStaticEffects(); |
| 5684 this._applyConfig(this._config, this._aboveConfig); | 6349 this._applyConfig(this._config, this._aboveConfig); |
| 5685 this._flushHandlers(); | 6350 this._flushHandlers(); |
| 5686 }, | 6351 }, |
| 5687 _applyConfig: function (config, aboveConfig) { | 6352 _applyConfig: function (config, aboveConfig) { |
| 5688 for (var n in config) { | 6353 for (var n in config) { |
| 5689 if (this[n] === undefined) { | 6354 if (this[n] === undefined) { |
| 5690 this.__setProperty(n, config[n], n in aboveConfig); | 6355 this.__setProperty(n, config[n], n in aboveConfig); |
| 5691 } | 6356 } |
| 5692 } | 6357 } |
| 5693 }, | 6358 }, |
| 5694 _notifyListener: function (fn, e) { | 6359 _notifyListener: function (fn, e) { |
| 6360 if (!Polymer.Bind._isEventBogus(e, e.target)) { |
| 6361 var value, path; |
| 6362 if (e.detail) { |
| 6363 value = e.detail.value; |
| 6364 path = e.detail.path; |
| 6365 } |
| 5695 if (!this._clientsReadied) { | 6366 if (!this._clientsReadied) { |
| 5696 this._queueHandler([ | 6367 this._queueHandler([ |
| 5697 fn, | 6368 fn, |
| 5698 e, | 6369 e.target, |
| 5699 e.target | 6370 value, |
| 6371 path |
| 5700 ]); | 6372 ]); |
| 5701 } else { | 6373 } else { |
| 5702 return fn.call(this, e, e.target); | 6374 return fn.call(this, e.target, value, path); |
| 6375 } |
| 5703 } | 6376 } |
| 5704 }, | 6377 }, |
| 5705 _queueHandler: function (args) { | 6378 _queueHandler: function (args) { |
| 5706 this._handlers.push(args); | 6379 this._handlers.push(args); |
| 5707 }, | 6380 }, |
| 5708 _flushHandlers: function () { | 6381 _flushHandlers: function () { |
| 5709 var h$ = this._handlers; | 6382 var h$ = this._handlers; |
| 5710 for (var i = 0, l = h$.length, h; i < l && (h = h$[i]); i++) { | 6383 for (var i = 0, l = h$.length, h; i < l && (h = h$[i]); i++) { |
| 5711 h[0].call(this, h[1], h[2]); | 6384 h[0].call(this, h[1], h[2], h[3]); |
| 5712 } | 6385 } |
| 5713 this._handlers = []; | 6386 this._handlers = []; |
| 5714 } | 6387 } |
| 5715 }); | 6388 }); |
| 5716 (function () { | 6389 (function () { |
| 5717 'use strict'; | 6390 'use strict'; |
| 5718 Polymer.Base._addFeature({ | 6391 Polymer.Base._addFeature({ |
| 5719 notifyPath: function (path, value, fromAbove) { | 6392 notifyPath: function (path, value, fromAbove) { |
| 6393 var info = {}; |
| 6394 this._get(path, this, info); |
| 6395 this._notifyPath(info.path, value, fromAbove); |
| 6396 }, |
| 6397 _notifyPath: function (path, value, fromAbove) { |
| 5720 var old = this._propertySetter(path, value); | 6398 var old = this._propertySetter(path, value); |
| 5721 if (old !== value && (old === old || value === value)) { | 6399 if (old !== value && (old === old || value === value)) { |
| 5722 this._pathEffector(path, value); | 6400 this._pathEffector(path, value); |
| 5723 if (!fromAbove) { | 6401 if (!fromAbove) { |
| 5724 this._notifyPath(path, value); | 6402 this._notifyPathUp(path, value); |
| 5725 } | 6403 } |
| 5726 return true; | 6404 return true; |
| 5727 } | 6405 } |
| 5728 }, | 6406 }, |
| 5729 _getPathParts: function (path) { | 6407 _getPathParts: function (path) { |
| 5730 if (Array.isArray(path)) { | 6408 if (Array.isArray(path)) { |
| 5731 var parts = []; | 6409 var parts = []; |
| 5732 for (var i = 0; i < path.length; i++) { | 6410 for (var i = 0; i < path.length; i++) { |
| 5733 var args = path[i].toString().split('.'); | 6411 var args = path[i].toString().split('.'); |
| 5734 for (var j = 0; j < args.length; j++) { | 6412 for (var j = 0; j < args.length; j++) { |
| 5735 parts.push(args[j]); | 6413 parts.push(args[j]); |
| 5736 } | 6414 } |
| 5737 } | 6415 } |
| 5738 return parts; | 6416 return parts; |
| 5739 } else { | 6417 } else { |
| 5740 return path.toString().split('.'); | 6418 return path.toString().split('.'); |
| 5741 } | 6419 } |
| 5742 }, | 6420 }, |
| 5743 set: function (path, value, root) { | 6421 set: function (path, value, root) { |
| 5744 var prop = root || this; | 6422 var prop = root || this; |
| 5745 var parts = this._getPathParts(path); | 6423 var parts = this._getPathParts(path); |
| 5746 var array; | 6424 var array; |
| 5747 var last = parts[parts.length - 1]; | 6425 var last = parts[parts.length - 1]; |
| 5748 if (parts.length > 1) { | 6426 if (parts.length > 1) { |
| 5749 for (var i = 0; i < parts.length - 1; i++) { | 6427 for (var i = 0; i < parts.length - 1; i++) { |
| 5750 var part = parts[i]; | 6428 var part = parts[i]; |
| 6429 if (array && part[0] == '#') { |
| 6430 prop = Polymer.Collection.get(array).getItem(part); |
| 6431 } else { |
| 5751 prop = prop[part]; | 6432 prop = prop[part]; |
| 5752 if (array && parseInt(part) == part) { | 6433 if (array && parseInt(part, 10) == part) { |
| 5753 parts[i] = Polymer.Collection.get(array).getKey(prop); | 6434 parts[i] = Polymer.Collection.get(array).getKey(prop); |
| 5754 } | 6435 } |
| 6436 } |
| 5755 if (!prop) { | 6437 if (!prop) { |
| 5756 return; | 6438 return; |
| 5757 } | 6439 } |
| 5758 array = Array.isArray(prop) ? prop : null; | 6440 array = Array.isArray(prop) ? prop : null; |
| 5759 } | 6441 } |
| 5760 if (array && parseInt(last) == last) { | 6442 if (array) { |
| 5761 var coll = Polymer.Collection.get(array); | 6443 var coll = Polymer.Collection.get(array); |
| 6444 if (last[0] == '#') { |
| 6445 var key = last; |
| 6446 var old = coll.getItem(key); |
| 6447 last = array.indexOf(old); |
| 6448 coll.setItem(key, value); |
| 6449 } else if (parseInt(last, 10) == last) { |
| 5762 var old = prop[last]; | 6450 var old = prop[last]; |
| 5763 var key = coll.getKey(old); | 6451 var key = coll.getKey(old); |
| 5764 parts[i] = key; | 6452 parts[i] = key; |
| 5765 coll.setItem(key, value); | 6453 coll.setItem(key, value); |
| 5766 } | 6454 } |
| 6455 } |
| 5767 prop[last] = value; | 6456 prop[last] = value; |
| 5768 if (!root) { | 6457 if (!root) { |
| 5769 this.notifyPath(parts.join('.'), value); | 6458 this._notifyPath(parts.join('.'), value); |
| 5770 } | 6459 } |
| 5771 } else { | 6460 } else { |
| 5772 prop[path] = value; | 6461 prop[path] = value; |
| 5773 } | 6462 } |
| 5774 }, | 6463 }, |
| 5775 get: function (path, root) { | 6464 get: function (path, root) { |
| 6465 return this._get(path, root); |
| 6466 }, |
| 6467 _get: function (path, root, info) { |
| 5776 var prop = root || this; | 6468 var prop = root || this; |
| 5777 var parts = this._getPathParts(path); | 6469 var parts = this._getPathParts(path); |
| 5778 var last = parts.pop(); | 6470 var array; |
| 5779 while (parts.length) { | 6471 for (var i = 0; i < parts.length; i++) { |
| 5780 prop = prop[parts.shift()]; | |
| 5781 if (!prop) { | 6472 if (!prop) { |
| 5782 return; | 6473 return; |
| 5783 } | 6474 } |
| 6475 var part = parts[i]; |
| 6476 if (array && part[0] == '#') { |
| 6477 prop = Polymer.Collection.get(array).getItem(part); |
| 6478 } else { |
| 6479 prop = prop[part]; |
| 6480 if (info && array && parseInt(part, 10) == part) { |
| 6481 parts[i] = Polymer.Collection.get(array).getKey(prop); |
| 5784 } | 6482 } |
| 5785 return prop[last]; | 6483 } |
| 6484 array = Array.isArray(prop) ? prop : null; |
| 6485 } |
| 6486 if (info) { |
| 6487 info.path = parts.join('.'); |
| 6488 } |
| 6489 return prop; |
| 5786 }, | 6490 }, |
| 5787 _pathEffector: function (path, value) { | 6491 _pathEffector: function (path, value) { |
| 5788 var model = this._modelForPath(path); | 6492 var model = this._modelForPath(path); |
| 5789 var fx$ = this._propertyEffects[model]; | 6493 var fx$ = this._propertyEffects && this._propertyEffects[model]; |
| 5790 if (fx$) { | 6494 if (fx$) { |
| 5791 fx$.forEach(function (fx) { | 6495 for (var i = 0, fx; i < fx$.length && (fx = fx$[i]); i++) { |
| 5792 var fxFn = this['_' + fx.kind + 'PathEffect']; | 6496 var fxFn = fx.pathFn; |
| 5793 if (fxFn) { | 6497 if (fxFn) { |
| 5794 fxFn.call(this, path, value, fx.effect); | 6498 fxFn.call(this, path, value, fx.effect); |
| 5795 } | 6499 } |
| 5796 }, this); | 6500 } |
| 5797 } | 6501 } |
| 5798 if (this._boundPaths) { | 6502 if (this._boundPaths) { |
| 5799 this._notifyBoundPaths(path, value); | 6503 this._notifyBoundPaths(path, value); |
| 5800 } | 6504 } |
| 5801 }, | 6505 }, |
| 5802 _annotationPathEffect: function (path, value, effect) { | 6506 _annotationPathEffect: function (path, value, effect) { |
| 5803 if (effect.value === path || effect.value.indexOf(path + '.') === 0) { | 6507 if (effect.value === path || effect.value.indexOf(path + '.') === 0) { |
| 5804 Polymer.Bind._annotationEffect.call(this, path, value, effect); | 6508 Polymer.Bind._annotationEffect.call(this, path, value, effect); |
| 5805 } else if (path.indexOf(effect.value + '.') === 0 && !effect.negate) { | 6509 } else if (path.indexOf(effect.value + '.') === 0 && !effect.negate) { |
| 5806 var node = this._nodes[effect.index]; | 6510 var node = this._nodes[effect.index]; |
| 5807 if (node && node.notifyPath) { | 6511 if (node && node._notifyPath) { |
| 5808 var p = this._fixPath(effect.name, effect.value, path); | 6512 var p = this._fixPath(effect.name, effect.value, path); |
| 5809 node.notifyPath(p, value, true); | 6513 node._notifyPath(p, value, true); |
| 5810 } | 6514 } |
| 5811 } | 6515 } |
| 5812 }, | 6516 }, |
| 5813 _complexObserverPathEffect: function (path, value, effect) { | 6517 _complexObserverPathEffect: function (path, value, effect) { |
| 5814 if (this._pathMatchesEffect(path, effect)) { | 6518 if (this._pathMatchesEffect(path, effect)) { |
| 5815 Polymer.Bind._complexObserverEffect.call(this, path, value, effect); | 6519 Polymer.Bind._complexObserverEffect.call(this, path, value, effect); |
| 5816 } | 6520 } |
| 5817 }, | 6521 }, |
| 5818 _computePathEffect: function (path, value, effect) { | 6522 _computePathEffect: function (path, value, effect) { |
| 5819 if (this._pathMatchesEffect(path, effect)) { | 6523 if (this._pathMatchesEffect(path, effect)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5839 }, | 6543 }, |
| 5840 unlinkPaths: function (path) { | 6544 unlinkPaths: function (path) { |
| 5841 if (this._boundPaths) { | 6545 if (this._boundPaths) { |
| 5842 delete this._boundPaths[path]; | 6546 delete this._boundPaths[path]; |
| 5843 } | 6547 } |
| 5844 }, | 6548 }, |
| 5845 _notifyBoundPaths: function (path, value) { | 6549 _notifyBoundPaths: function (path, value) { |
| 5846 for (var a in this._boundPaths) { | 6550 for (var a in this._boundPaths) { |
| 5847 var b = this._boundPaths[a]; | 6551 var b = this._boundPaths[a]; |
| 5848 if (path.indexOf(a + '.') == 0) { | 6552 if (path.indexOf(a + '.') == 0) { |
| 5849 this.notifyPath(this._fixPath(b, a, path), value); | 6553 this._notifyPath(this._fixPath(b, a, path), value); |
| 5850 } else if (path.indexOf(b + '.') == 0) { | 6554 } else if (path.indexOf(b + '.') == 0) { |
| 5851 this.notifyPath(this._fixPath(a, b, path), value); | 6555 this._notifyPath(this._fixPath(a, b, path), value); |
| 5852 } | 6556 } |
| 5853 } | 6557 } |
| 5854 }, | 6558 }, |
| 5855 _fixPath: function (property, root, path) { | 6559 _fixPath: function (property, root, path) { |
| 5856 return property + path.slice(root.length); | 6560 return property + path.slice(root.length); |
| 5857 }, | 6561 }, |
| 5858 _notifyPath: function (path, value) { | 6562 _notifyPathUp: function (path, value) { |
| 5859 var rootName = this._modelForPath(path); | 6563 var rootName = this._modelForPath(path); |
| 5860 var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName); | 6564 var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName); |
| 5861 var eventName = dashCaseName + this._EVENT_CHANGED; | 6565 var eventName = dashCaseName + this._EVENT_CHANGED; |
| 5862 this.fire(eventName, { | 6566 this.fire(eventName, { |
| 5863 path: path, | 6567 path: path, |
| 5864 value: value | 6568 value: value |
| 5865 }, { bubbles: false }); | 6569 }, { |
| 6570 bubbles: false, |
| 6571 _useCache: true |
| 6572 }); |
| 5866 }, | 6573 }, |
| 5867 _modelForPath: function (path) { | 6574 _modelForPath: function (path) { |
| 5868 var dot = path.indexOf('.'); | 6575 var dot = path.indexOf('.'); |
| 5869 return dot < 0 ? path : path.slice(0, dot); | 6576 return dot < 0 ? path : path.slice(0, dot); |
| 5870 }, | 6577 }, |
| 5871 _EVENT_CHANGED: '-changed', | 6578 _EVENT_CHANGED: '-changed', |
| 6579 notifySplices: function (path, splices) { |
| 6580 var info = {}; |
| 6581 var array = this._get(path, this, info); |
| 6582 this._notifySplices(array, info.path, splices); |
| 6583 }, |
| 6584 _notifySplices: function (array, path, splices) { |
| 6585 var change = { |
| 6586 keySplices: Polymer.Collection.applySplices(array, splices), |
| 6587 indexSplices: splices |
| 6588 }; |
| 6589 if (!array.hasOwnProperty('splices')) { |
| 6590 Object.defineProperty(array, 'splices', { |
| 6591 configurable: true, |
| 6592 writable: true |
| 6593 }); |
| 6594 } |
| 6595 array.splices = change; |
| 6596 this._notifyPath(path + '.splices', change); |
| 6597 this._notifyPath(path + '.length', array.length); |
| 6598 change.keySplices = null; |
| 6599 change.indexSplices = null; |
| 6600 }, |
| 5872 _notifySplice: function (array, path, index, added, removed) { | 6601 _notifySplice: function (array, path, index, added, removed) { |
| 5873 var splices = [{ | 6602 this._notifySplices(array, path, [{ |
| 5874 index: index, | 6603 index: index, |
| 5875 addedCount: added, | 6604 addedCount: added, |
| 5876 removed: removed, | 6605 removed: removed, |
| 5877 object: array, | 6606 object: array, |
| 5878 type: 'splice' | 6607 type: 'splice' |
| 5879 }]; | 6608 }]); |
| 5880 var change = { | |
| 5881 keySplices: Polymer.Collection.applySplices(array, splices), | |
| 5882 indexSplices: splices | |
| 5883 }; | |
| 5884 this.set(path + '.splices', change); | |
| 5885 if (added != removed.length) { | |
| 5886 this.notifyPath(path + '.length', array.length); | |
| 5887 } | |
| 5888 change.keySplices = null; | |
| 5889 change.indexSplices = null; | |
| 5890 }, | 6609 }, |
| 5891 push: function (path) { | 6610 push: function (path) { |
| 5892 var array = this.get(path); | 6611 var info = {}; |
| 6612 var array = this._get(path, this, info); |
| 5893 var args = Array.prototype.slice.call(arguments, 1); | 6613 var args = Array.prototype.slice.call(arguments, 1); |
| 5894 var len = array.length; | 6614 var len = array.length; |
| 5895 var ret = array.push.apply(array, args); | 6615 var ret = array.push.apply(array, args); |
| 5896 if (args.length) { | 6616 if (args.length) { |
| 5897 this._notifySplice(array, path, len, args.length, []); | 6617 this._notifySplice(array, info.path, len, args.length, []); |
| 5898 } | 6618 } |
| 5899 return ret; | 6619 return ret; |
| 5900 }, | 6620 }, |
| 5901 pop: function (path) { | 6621 pop: function (path) { |
| 5902 var array = this.get(path); | 6622 var info = {}; |
| 6623 var array = this._get(path, this, info); |
| 5903 var hadLength = Boolean(array.length); | 6624 var hadLength = Boolean(array.length); |
| 5904 var args = Array.prototype.slice.call(arguments, 1); | 6625 var args = Array.prototype.slice.call(arguments, 1); |
| 5905 var ret = array.pop.apply(array, args); | 6626 var ret = array.pop.apply(array, args); |
| 5906 if (hadLength) { | 6627 if (hadLength) { |
| 5907 this._notifySplice(array, path, array.length, 0, [ret]); | 6628 this._notifySplice(array, info.path, array.length, 0, [ret]); |
| 5908 } | 6629 } |
| 5909 return ret; | 6630 return ret; |
| 5910 }, | 6631 }, |
| 5911 splice: function (path, start, deleteCount) { | 6632 splice: function (path, start, deleteCount) { |
| 5912 var array = this.get(path); | 6633 var info = {}; |
| 6634 var array = this._get(path, this, info); |
| 5913 if (start < 0) { | 6635 if (start < 0) { |
| 5914 start = array.length - Math.floor(-start); | 6636 start = array.length - Math.floor(-start); |
| 5915 } else { | 6637 } else { |
| 5916 start = Math.floor(start); | 6638 start = Math.floor(start); |
| 5917 } | 6639 } |
| 5918 if (!start) { | 6640 if (!start) { |
| 5919 start = 0; | 6641 start = 0; |
| 5920 } | 6642 } |
| 5921 var args = Array.prototype.slice.call(arguments, 1); | 6643 var args = Array.prototype.slice.call(arguments, 1); |
| 5922 var ret = array.splice.apply(array, args); | 6644 var ret = array.splice.apply(array, args); |
| 5923 var addedCount = Math.max(args.length - 2, 0); | 6645 var addedCount = Math.max(args.length - 2, 0); |
| 5924 if (addedCount || ret.length) { | 6646 if (addedCount || ret.length) { |
| 5925 this._notifySplice(array, path, start, addedCount, ret); | 6647 this._notifySplice(array, info.path, start, addedCount, ret); |
| 5926 } | 6648 } |
| 5927 return ret; | 6649 return ret; |
| 5928 }, | 6650 }, |
| 5929 shift: function (path) { | 6651 shift: function (path) { |
| 5930 var array = this.get(path); | 6652 var info = {}; |
| 6653 var array = this._get(path, this, info); |
| 5931 var hadLength = Boolean(array.length); | 6654 var hadLength = Boolean(array.length); |
| 5932 var args = Array.prototype.slice.call(arguments, 1); | 6655 var args = Array.prototype.slice.call(arguments, 1); |
| 5933 var ret = array.shift.apply(array, args); | 6656 var ret = array.shift.apply(array, args); |
| 5934 if (hadLength) { | 6657 if (hadLength) { |
| 5935 this._notifySplice(array, path, 0, 0, [ret]); | 6658 this._notifySplice(array, info.path, 0, 0, [ret]); |
| 5936 } | 6659 } |
| 5937 return ret; | 6660 return ret; |
| 5938 }, | 6661 }, |
| 5939 unshift: function (path) { | 6662 unshift: function (path) { |
| 5940 var array = this.get(path); | 6663 var info = {}; |
| 6664 var array = this._get(path, this, info); |
| 5941 var args = Array.prototype.slice.call(arguments, 1); | 6665 var args = Array.prototype.slice.call(arguments, 1); |
| 5942 var ret = array.unshift.apply(array, args); | 6666 var ret = array.unshift.apply(array, args); |
| 5943 if (args.length) { | 6667 if (args.length) { |
| 5944 this._notifySplice(array, path, 0, args.length, []); | 6668 this._notifySplice(array, info.path, 0, args.length, []); |
| 5945 } | 6669 } |
| 5946 return ret; | 6670 return ret; |
| 5947 }, | 6671 }, |
| 5948 prepareModelNotifyPath: function (model) { | 6672 prepareModelNotifyPath: function (model) { |
| 5949 this.mixin(model, { | 6673 this.mixin(model, { |
| 5950 fire: Polymer.Base.fire, | 6674 fire: Polymer.Base.fire, |
| 6675 _getEvent: Polymer.Base._getEvent, |
| 6676 __eventCache: Polymer.Base.__eventCache, |
| 5951 notifyPath: Polymer.Base.notifyPath, | 6677 notifyPath: Polymer.Base.notifyPath, |
| 6678 _get: Polymer.Base._get, |
| 5952 _EVENT_CHANGED: Polymer.Base._EVENT_CHANGED, | 6679 _EVENT_CHANGED: Polymer.Base._EVENT_CHANGED, |
| 5953 _notifyPath: Polymer.Base._notifyPath, | 6680 _notifyPath: Polymer.Base._notifyPath, |
| 6681 _notifyPathUp: Polymer.Base._notifyPathUp, |
| 5954 _pathEffector: Polymer.Base._pathEffector, | 6682 _pathEffector: Polymer.Base._pathEffector, |
| 5955 _annotationPathEffect: Polymer.Base._annotationPathEffect, | 6683 _annotationPathEffect: Polymer.Base._annotationPathEffect, |
| 5956 _complexObserverPathEffect: Polymer.Base._complexObserverPathEffect, | 6684 _complexObserverPathEffect: Polymer.Base._complexObserverPathEffect, |
| 5957 _annotatedComputationPathEffect: Polymer.Base._annotatedComputationPathEffect, | 6685 _annotatedComputationPathEffect: Polymer.Base._annotatedComputationPathEffect, |
| 5958 _computePathEffect: Polymer.Base._computePathEffect, | 6686 _computePathEffect: Polymer.Base._computePathEffect, |
| 5959 _modelForPath: Polymer.Base._modelForPath, | 6687 _modelForPath: Polymer.Base._modelForPath, |
| 5960 _pathMatchesEffect: Polymer.Base._pathMatchesEffect, | 6688 _pathMatchesEffect: Polymer.Base._pathMatchesEffect, |
| 5961 _notifyBoundPaths: Polymer.Base._notifyBoundPaths | 6689 _notifyBoundPaths: Polymer.Base._notifyBoundPaths, |
| 6690 _getPathParts: Polymer.Base._getPathParts |
| 5962 }); | 6691 }); |
| 5963 } | 6692 } |
| 5964 }); | 6693 }); |
| 5965 }()); | 6694 }()); |
| 5966 Polymer.Base._addFeature({ | 6695 Polymer.Base._addFeature({ |
| 5967 resolveUrl: function (url) { | 6696 resolveUrl: function (url) { |
| 5968 var module = Polymer.DomModule.import(this.is); | 6697 var module = Polymer.DomModule.import(this.is); |
| 5969 var root = ''; | 6698 var root = ''; |
| 5970 if (module) { | 6699 if (module) { |
| 5971 var assetPath = module.getAttribute('assetpath') || ''; | 6700 var assetPath = module.getAttribute('assetpath') || ''; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6011 } | 6740 } |
| 6012 } | 6741 } |
| 6013 return root; | 6742 return root; |
| 6014 }, | 6743 }, |
| 6015 _parseCss: function (node, text) { | 6744 _parseCss: function (node, text) { |
| 6016 var t = text.substring(node.start, node.end - 1); | 6745 var t = text.substring(node.start, node.end - 1); |
| 6017 node.parsedCssText = node.cssText = t.trim(); | 6746 node.parsedCssText = node.cssText = t.trim(); |
| 6018 if (node.parent) { | 6747 if (node.parent) { |
| 6019 var ss = node.previous ? node.previous.end : node.parent.start; | 6748 var ss = node.previous ? node.previous.end : node.parent.start; |
| 6020 t = text.substring(ss, node.start - 1); | 6749 t = text.substring(ss, node.start - 1); |
| 6750 t = this._expandUnicodeEscapes(t); |
| 6751 t = t.replace(this._rx.multipleSpaces, ' '); |
| 6021 t = t.substring(t.lastIndexOf(';') + 1); | 6752 t = t.substring(t.lastIndexOf(';') + 1); |
| 6022 var s = node.parsedSelector = node.selector = t.trim(); | 6753 var s = node.parsedSelector = node.selector = t.trim(); |
| 6023 node.atRule = s.indexOf(this.AT_START) === 0; | 6754 node.atRule = s.indexOf(this.AT_START) === 0; |
| 6024 if (node.atRule) { | 6755 if (node.atRule) { |
| 6025 if (s.indexOf(this.MEDIA_START) === 0) { | 6756 if (s.indexOf(this.MEDIA_START) === 0) { |
| 6026 node.type = this.types.MEDIA_RULE; | 6757 node.type = this.types.MEDIA_RULE; |
| 6027 } else if (s.match(this._rx.keyframesRule)) { | 6758 } else if (s.match(this._rx.keyframesRule)) { |
| 6028 node.type = this.types.KEYFRAMES_RULE; | 6759 node.type = this.types.KEYFRAMES_RULE; |
| 6029 } | 6760 } |
| 6030 } else { | 6761 } else { |
| 6031 if (s.indexOf(this.VAR_START) === 0) { | 6762 if (s.indexOf(this.VAR_START) === 0) { |
| 6032 node.type = this.types.MIXIN_RULE; | 6763 node.type = this.types.MIXIN_RULE; |
| 6033 } else { | 6764 } else { |
| 6034 node.type = this.types.STYLE_RULE; | 6765 node.type = this.types.STYLE_RULE; |
| 6035 } | 6766 } |
| 6036 } | 6767 } |
| 6037 } | 6768 } |
| 6038 var r$ = node.rules; | 6769 var r$ = node.rules; |
| 6039 if (r$) { | 6770 if (r$) { |
| 6040 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { | 6771 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { |
| 6041 this._parseCss(r, text); | 6772 this._parseCss(r, text); |
| 6042 } | 6773 } |
| 6043 } | 6774 } |
| 6044 return node; | 6775 return node; |
| 6045 }, | 6776 }, |
| 6777 _expandUnicodeEscapes: function (s) { |
| 6778 return s.replace(/\\([0-9a-f]{1,6})\s/gi, function () { |
| 6779 var code = arguments[1], repeat = 6 - code.length; |
| 6780 while (repeat--) { |
| 6781 code = '0' + code; |
| 6782 } |
| 6783 return '\\' + code; |
| 6784 }); |
| 6785 }, |
| 6046 stringify: function (node, preserveProperties, text) { | 6786 stringify: function (node, preserveProperties, text) { |
| 6047 text = text || ''; | 6787 text = text || ''; |
| 6048 var cssText = ''; | 6788 var cssText = ''; |
| 6049 if (node.cssText || node.rules) { | 6789 if (node.cssText || node.rules) { |
| 6050 var r$ = node.rules; | 6790 var r$ = node.rules; |
| 6051 if (r$ && (preserveProperties || !this._hasMixinRules(r$))) { | 6791 if (r$ && (preserveProperties || !this._hasMixinRules(r$))) { |
| 6052 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { | 6792 for (var i = 0, l = r$.length, r; i < l && (r = r$[i]); i++) { |
| 6053 cssText = this.stringify(r, preserveProperties, cssText); | 6793 cssText = this.stringify(r, preserveProperties, cssText); |
| 6054 } | 6794 } |
| 6055 } else { | 6795 } else { |
| 6056 cssText = preserveProperties ? node.cssText : this.removeCustomProps(node.cssTex
t); | 6796 cssText = preserveProperties ? node.cssText : this.removeCustomProps(node.cssTex
t); |
| 6057 cssText = cssText.trim(); | 6797 cssText = cssText.trim(); |
| 6058 if (cssText) { | 6798 if (cssText) { |
| 6059 cssText = ' ' + cssText + '\n'; | 6799 cssText = ' ' + cssText + '\n'; |
| 6060 } | 6800 } |
| 6061 } | 6801 } |
| 6062 } | 6802 } |
| 6063 if (cssText) { | 6803 if (cssText) { |
| 6064 if (node.selector) { | 6804 if (node.selector) { |
| 6065 text += node.selector + ' ' + this.OPEN_BRACE + '\n'; | 6805 text += node.selector + ' ' + this.OPEN_BRACE + '\n'; |
| 6066 } | 6806 } |
| 6067 text += cssText; | 6807 text += cssText; |
| 6068 if (node.selector) { | 6808 if (node.selector) { |
| 6069 text += this.CLOSE_BRACE + '\n\n'; | 6809 text += this.CLOSE_BRACE + '\n\n'; |
| 6070 } | 6810 } |
| 6071 } | 6811 } |
| 6072 return text; | 6812 return text; |
| 6073 }, | 6813 }, |
| 6074 _hasMixinRules: function (rules) { | 6814 _hasMixinRules: function (rules) { |
| 6075 return rules[0].selector.indexOf(this.VAR_START) >= 0; | 6815 return rules[0].selector.indexOf(this.VAR_START) === 0; |
| 6076 }, | 6816 }, |
| 6077 removeCustomProps: function (cssText) { | 6817 removeCustomProps: function (cssText) { |
| 6078 return cssText; | 6818 return cssText; |
| 6079 }, | 6819 }, |
| 6080 removeCustomPropAssignment: function (cssText) { | 6820 removeCustomPropAssignment: function (cssText) { |
| 6081 return cssText.replace(this._rx.customProp, '').replace(this._rx.mixinProp, ''); | 6821 return cssText.replace(this._rx.customProp, '').replace(this._rx.mixinProp, ''); |
| 6082 }, | 6822 }, |
| 6083 removeCustomPropApply: function (cssText) { | 6823 removeCustomPropApply: function (cssText) { |
| 6084 return cssText.replace(this._rx.mixinApply, '').replace(this._rx.varApply, ''); | 6824 return cssText.replace(this._rx.mixinApply, '').replace(this._rx.varApply, ''); |
| 6085 }, | 6825 }, |
| 6086 types: { | 6826 types: { |
| 6087 STYLE_RULE: 1, | 6827 STYLE_RULE: 1, |
| 6088 KEYFRAMES_RULE: 7, | 6828 KEYFRAMES_RULE: 7, |
| 6089 MEDIA_RULE: 4, | 6829 MEDIA_RULE: 4, |
| 6090 MIXIN_RULE: 1000 | 6830 MIXIN_RULE: 1000 |
| 6091 }, | 6831 }, |
| 6092 OPEN_BRACE: '{', | 6832 OPEN_BRACE: '{', |
| 6093 CLOSE_BRACE: '}', | 6833 CLOSE_BRACE: '}', |
| 6094 _rx: { | 6834 _rx: { |
| 6095 comments: /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim, | 6835 comments: /\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim, |
| 6096 port: /@import[^;]*;/gim, | 6836 port: /@import[^;]*;/gim, |
| 6097 customProp: /(?:^|[\s;])--[^;{]*?:[^{};]*?(?:[;\n]|$)/gim, | 6837 customProp: /(?:^|[\s;])--[^;{]*?:[^{};]*?(?:[;\n]|$)/gim, |
| 6098 mixinProp: /(?:^|[\s;])--[^;{]*?:[^{;]*?{[^}]*?}(?:[;\n]|$)?/gim, | 6838 mixinProp: /(?:^|[\s;])?--[^;{]*?:[^{;]*?{[^}]*?}(?:[;\n]|$)?/gim, |
| 6099 mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim, | 6839 mixinApply: /@apply[\s]*\([^)]*?\)[\s]*(?:[;\n]|$)?/gim, |
| 6100 varApply: /[^;:]*?:[^;]*var[^;]*(?:[;\n]|$)?/gim, | 6840 varApply: /[^;:]*?:[^;]*?var\([^;]*\)(?:[;\n]|$)?/gim, |
| 6101 keyframesRule: /^@[^\s]*keyframes/ | 6841 keyframesRule: /^@[^\s]*keyframes/, |
| 6842 multipleSpaces: /\s+/g |
| 6102 }, | 6843 }, |
| 6103 VAR_START: '--', | 6844 VAR_START: '--', |
| 6104 MEDIA_START: '@media', | 6845 MEDIA_START: '@media', |
| 6105 AT_START: '@' | 6846 AT_START: '@' |
| 6106 }; | 6847 }; |
| 6107 return api; | 6848 return api; |
| 6108 }(); | 6849 }(); |
| 6109 Polymer.StyleUtil = function () { | 6850 Polymer.StyleUtil = function () { |
| 6110 return { | 6851 return { |
| 6111 MODULE_STYLES_SELECTOR: 'style, link[rel=import][type~=css], template', | 6852 MODULE_STYLES_SELECTOR: 'style, link[rel=import][type~=css], template', |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6171 var modules = moduleIds.trim().split(' '); | 6912 var modules = moduleIds.trim().split(' '); |
| 6172 var cssText = ''; | 6913 var cssText = ''; |
| 6173 for (var i = 0; i < modules.length; i++) { | 6914 for (var i = 0; i < modules.length; i++) { |
| 6174 cssText += this.cssFromModule(modules[i], warnIfNotFound); | 6915 cssText += this.cssFromModule(modules[i], warnIfNotFound); |
| 6175 } | 6916 } |
| 6176 return cssText; | 6917 return cssText; |
| 6177 }, | 6918 }, |
| 6178 cssFromModule: function (moduleId, warnIfNotFound) { | 6919 cssFromModule: function (moduleId, warnIfNotFound) { |
| 6179 var m = Polymer.DomModule.import(moduleId); | 6920 var m = Polymer.DomModule.import(moduleId); |
| 6180 if (m && !m._cssText) { | 6921 if (m && !m._cssText) { |
| 6181 m._cssText = this._cssFromElement(m); | 6922 m._cssText = this.cssFromElement(m); |
| 6182 } | 6923 } |
| 6183 if (!m && warnIfNotFound) { | 6924 if (!m && warnIfNotFound) { |
| 6184 console.warn('Could not find style data in module named', moduleId); | 6925 console.warn('Could not find style data in module named', moduleId); |
| 6185 } | 6926 } |
| 6186 return m && m._cssText || ''; | 6927 return m && m._cssText || ''; |
| 6187 }, | 6928 }, |
| 6188 _cssFromElement: function (element) { | 6929 cssFromElement: function (element) { |
| 6189 var cssText = ''; | 6930 var cssText = ''; |
| 6190 var content = element.content || element; | 6931 var content = element.content || element; |
| 6191 var e$ = Array.prototype.slice.call(content.querySelectorAll(this.MODULE_STYLES_
SELECTOR)); | 6932 var e$ = Polymer.DomApi.arrayCopy(content.querySelectorAll(this.MODULE_STYLES_SE
LECTOR)); |
| 6192 for (var i = 0, e; i < e$.length; i++) { | 6933 for (var i = 0, e; i < e$.length; i++) { |
| 6193 e = e$[i]; | 6934 e = e$[i]; |
| 6194 if (e.localName === 'template') { | 6935 if (e.localName === 'template') { |
| 6195 cssText += this._cssFromElement(e); | 6936 cssText += this.cssFromElement(e); |
| 6196 } else { | 6937 } else { |
| 6197 if (e.localName === 'style') { | 6938 if (e.localName === 'style') { |
| 6198 var include = e.getAttribute(this.INCLUDE_ATTR); | 6939 var include = e.getAttribute(this.INCLUDE_ATTR); |
| 6199 if (include) { | 6940 if (include) { |
| 6200 cssText += this.cssFromModules(include, true); | 6941 cssText += this.cssFromModules(include, true); |
| 6201 } | 6942 } |
| 6202 e = e.__appliedElement || e; | 6943 e = e.__appliedElement || e; |
| 6203 e.parentNode.removeChild(e); | 6944 e.parentNode.removeChild(e); |
| 6204 cssText += this.resolveCss(e.textContent, element.ownerDocument); | 6945 cssText += this.resolveCss(e.textContent, element.ownerDocument); |
| 6205 } else if (e.import && e.import.body) { | 6946 } else if (e.import && e.import.body) { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6434 return map; | 7175 return map; |
| 6435 } | 7176 } |
| 6436 }, | 7177 }, |
| 6437 _findExtendor: function (extend, rule) { | 7178 _findExtendor: function (extend, rule) { |
| 6438 return rule.parent && rule.parent.map && rule.parent.map[extend] || this._findEx
tendor(extend, rule.parent); | 7179 return rule.parent && rule.parent.map && rule.parent.map[extend] || this._findEx
tendor(extend, rule.parent); |
| 6439 }, | 7180 }, |
| 6440 _extendRule: function (target, source) { | 7181 _extendRule: function (target, source) { |
| 6441 if (target.parent !== source.parent) { | 7182 if (target.parent !== source.parent) { |
| 6442 this._cloneAndAddRuleToParent(source, target.parent); | 7183 this._cloneAndAddRuleToParent(source, target.parent); |
| 6443 } | 7184 } |
| 6444 target.extends = target.extends || (target.extends = []); | 7185 target.extends = target.extends || []; |
| 6445 target.extends.push(source); | 7186 target.extends.push(source); |
| 6446 source.selector = source.selector.replace(this.rx.STRIP, ''); | 7187 source.selector = source.selector.replace(this.rx.STRIP, ''); |
| 6447 source.selector = (source.selector && source.selector + ',\n') + target.selector
; | 7188 source.selector = (source.selector && source.selector + ',\n') + target.selector
; |
| 6448 if (source.extends) { | 7189 if (source.extends) { |
| 6449 source.extends.forEach(function (e) { | 7190 source.extends.forEach(function (e) { |
| 6450 this._extendRule(target, e); | 7191 this._extendRule(target, e); |
| 6451 }, this); | 7192 }, this); |
| 6452 } | 7193 } |
| 6453 }, | 7194 }, |
| 6454 _cloneAndAddRuleToParent: function (rule, parent) { | 7195 _cloneAndAddRuleToParent: function (rule, parent) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6475 _prepElement: function (element) { | 7216 _prepElement: function (element) { |
| 6476 if (this._encapsulateStyle) { | 7217 if (this._encapsulateStyle) { |
| 6477 styleTransformer.element(element, this.is, this._scopeCssViaAttr); | 7218 styleTransformer.element(element, this.is, this._scopeCssViaAttr); |
| 6478 } | 7219 } |
| 6479 prepElement.call(this, element); | 7220 prepElement.call(this, element); |
| 6480 }, | 7221 }, |
| 6481 _prepStyles: function () { | 7222 _prepStyles: function () { |
| 6482 if (this._encapsulateStyle === undefined) { | 7223 if (this._encapsulateStyle === undefined) { |
| 6483 this._encapsulateStyle = !nativeShadow && Boolean(this._template); | 7224 this._encapsulateStyle = !nativeShadow && Boolean(this._template); |
| 6484 } | 7225 } |
| 7226 if (this._template) { |
| 6485 this._styles = this._collectStyles(); | 7227 this._styles = this._collectStyles(); |
| 6486 var cssText = styleTransformer.elementStyles(this); | 7228 var cssText = styleTransformer.elementStyles(this); |
| 6487 if (cssText && this._template) { | 7229 if (cssText) { |
| 6488 var style = styleUtil.applyCss(cssText, this.is, nativeShadow ? this._template.c
ontent : null); | 7230 var style = styleUtil.applyCss(cssText, this.is, nativeShadow ? this._template.c
ontent : null); |
| 6489 if (!nativeShadow) { | 7231 if (!nativeShadow) { |
| 6490 this._scopeStyle = style; | 7232 this._scopeStyle = style; |
| 6491 } | 7233 } |
| 6492 } | 7234 } |
| 7235 } else { |
| 7236 this._styles = []; |
| 7237 } |
| 6493 }, | 7238 }, |
| 6494 _collectStyles: function () { | 7239 _collectStyles: function () { |
| 6495 var styles = []; | 7240 var styles = []; |
| 6496 var cssText = '', m$ = this.styleModules; | 7241 var cssText = '', m$ = this.styleModules; |
| 6497 if (m$) { | 7242 if (m$) { |
| 6498 for (var i = 0, l = m$.length, m; i < l && (m = m$[i]); i++) { | 7243 for (var i = 0, l = m$.length, m; i < l && (m = m$[i]); i++) { |
| 6499 cssText += styleUtil.cssFromModule(m); | 7244 cssText += styleUtil.cssFromModule(m); |
| 6500 } | 7245 } |
| 6501 } | 7246 } |
| 6502 cssText += styleUtil.cssFromModule(this.is); | 7247 cssText += styleUtil.cssFromModule(this.is); |
| 7248 var p = this._template && this._template.parentNode; |
| 7249 if (this._template && (!p || p.id.toLowerCase() !== this.is)) { |
| 7250 cssText += styleUtil.cssFromElement(this._template); |
| 7251 } |
| 6503 if (cssText) { | 7252 if (cssText) { |
| 6504 var style = document.createElement('style'); | 7253 var style = document.createElement('style'); |
| 6505 style.textContent = cssText; | 7254 style.textContent = cssText; |
| 6506 if (styleExtends.hasExtends(style.textContent)) { | 7255 if (styleExtends.hasExtends(style.textContent)) { |
| 6507 cssText = styleExtends.transform(style); | 7256 cssText = styleExtends.transform(style); |
| 6508 } | 7257 } |
| 6509 styles.push(style); | 7258 styles.push(style); |
| 6510 } | 7259 } |
| 6511 return styles; | 7260 return styles; |
| 6512 }, | 7261 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6526 }, | 7275 }, |
| 6527 scopeSubtree: function (container, shouldObserve) { | 7276 scopeSubtree: function (container, shouldObserve) { |
| 6528 if (nativeShadow) { | 7277 if (nativeShadow) { |
| 6529 return; | 7278 return; |
| 6530 } | 7279 } |
| 6531 var self = this; | 7280 var self = this; |
| 6532 var scopify = function (node) { | 7281 var scopify = function (node) { |
| 6533 if (node.nodeType === Node.ELEMENT_NODE) { | 7282 if (node.nodeType === Node.ELEMENT_NODE) { |
| 6534 node.className = self._scopeElementClass(node, node.className); | 7283 node.className = self._scopeElementClass(node, node.className); |
| 6535 var n$ = node.querySelectorAll('*'); | 7284 var n$ = node.querySelectorAll('*'); |
| 6536 Array.prototype.forEach.call(n$, function (n) { | 7285 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { |
| 6537 n.className = self._scopeElementClass(n, n.className); | 7286 n.className = self._scopeElementClass(n, n.className); |
| 6538 }); | 7287 } |
| 6539 } | 7288 } |
| 6540 }; | 7289 }; |
| 6541 scopify(container); | 7290 scopify(container); |
| 6542 if (shouldObserve) { | 7291 if (shouldObserve) { |
| 6543 var mo = new MutationObserver(function (mxns) { | 7292 var mo = new MutationObserver(function (mxns) { |
| 6544 mxns.forEach(function (m) { | 7293 for (var i = 0, m; i < mxns.length && (m = mxns[i]); i++) { |
| 6545 if (m.addedNodes) { | 7294 if (m.addedNodes) { |
| 6546 for (var i = 0; i < m.addedNodes.length; i++) { | 7295 for (var j = 0; j < m.addedNodes.length; j++) { |
| 6547 scopify(m.addedNodes[i]); | 7296 scopify(m.addedNodes[j]); |
| 7297 } |
| 6548 } | 7298 } |
| 6549 } | 7299 } |
| 6550 }); | 7300 }); |
| 6551 }); | |
| 6552 mo.observe(container, { | 7301 mo.observe(container, { |
| 6553 childList: true, | 7302 childList: true, |
| 6554 subtree: true | 7303 subtree: true |
| 6555 }); | 7304 }); |
| 6556 return mo; | 7305 return mo; |
| 6557 } | 7306 } |
| 6558 } | 7307 } |
| 6559 }); | 7308 }); |
| 6560 }()); | 7309 }()); |
| 6561 Polymer.StyleProperties = function () { | 7310 Polymer.StyleProperties = function () { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6665 var pp = p.split(':'); | 7414 var pp = p.split(':'); |
| 6666 if (pp[1]) { | 7415 if (pp[1]) { |
| 6667 pp[1] = pp[1].trim(); | 7416 pp[1] = pp[1].trim(); |
| 6668 pp[1] = this.valueForProperty(pp[1], props) || pp[1]; | 7417 pp[1] = this.valueForProperty(pp[1], props) || pp[1]; |
| 6669 } | 7418 } |
| 6670 p = pp.join(':'); | 7419 p = pp.join(':'); |
| 6671 } | 7420 } |
| 6672 parts[i] = p && p.lastIndexOf(';') === p.length - 1 ? p.slice(0, -1) : p || ''; | 7421 parts[i] = p && p.lastIndexOf(';') === p.length - 1 ? p.slice(0, -1) : p || ''; |
| 6673 } | 7422 } |
| 6674 } | 7423 } |
| 6675 return parts.join(';'); | 7424 return parts.filter(function (v) { |
| 7425 return v; |
| 7426 }).join(';'); |
| 6676 }, | 7427 }, |
| 6677 applyProperties: function (rule, props) { | 7428 applyProperties: function (rule, props) { |
| 6678 var output = ''; | 7429 var output = ''; |
| 6679 if (!rule.propertyInfo) { | 7430 if (!rule.propertyInfo) { |
| 6680 this.decorateRule(rule); | 7431 this.decorateRule(rule); |
| 6681 } | 7432 } |
| 6682 if (rule.propertyInfo.cssText) { | 7433 if (rule.propertyInfo.cssText) { |
| 6683 output = this.valueForProperties(rule.propertyInfo.cssText, props); | 7434 output = this.valueForProperties(rule.propertyInfo.cssText, props); |
| 6684 } | 7435 } |
| 6685 rule.cssText = output; | 7436 rule.cssText = output; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6791 mixinCustomStyle: function (props, customStyle) { | 7542 mixinCustomStyle: function (props, customStyle) { |
| 6792 var v; | 7543 var v; |
| 6793 for (var i in customStyle) { | 7544 for (var i in customStyle) { |
| 6794 v = customStyle[i]; | 7545 v = customStyle[i]; |
| 6795 if (v || v === 0) { | 7546 if (v || v === 0) { |
| 6796 props[i] = v; | 7547 props[i] = v; |
| 6797 } | 7548 } |
| 6798 } | 7549 } |
| 6799 }, | 7550 }, |
| 6800 rx: { | 7551 rx: { |
| 6801 VAR_ASSIGN: /(?:^|[;\n]\s*)(--[\w-]*?):\s*(?:([^;{]*)|{([^}]*)})(?:(?=[;\n])|$)/
gi, | 7552 VAR_ASSIGN: /(?:^|[;\s{]\s*)(--[\w-]*?)\s*:\s*(?:([^;{]*)|{([^}]*)})(?:(?=[;\s}]
)|$)/gi, |
| 6802 MIXIN_MATCH: /(?:^|\W+)@apply[\s]*\(([^)]*)\)/i, | 7553 MIXIN_MATCH: /(?:^|\W+)@apply[\s]*\(([^)]*)\)/i, |
| 6803 VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\))
)[\s]*?\)/gi, | 7554 VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\))
)[\s]*?\)/gi, |
| 6804 VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gi, | 7555 VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gi, |
| 6805 IS_VAR: /^--/, | 7556 IS_VAR: /^--/, |
| 6806 BRACKETED: /\{[^}]*\}/g, | 7557 BRACKETED: /\{[^}]*\}/g, |
| 6807 HOST_PREFIX: '(?:^|[^.#[:])', | 7558 HOST_PREFIX: '(?:^|[^.#[:])', |
| 6808 HOST_SUFFIX: '($|[.:[\\s>+~])' | 7559 HOST_SUFFIX: '($|[.:[\\s>+~])' |
| 6809 }, | 7560 }, |
| 6810 HOST_SELECTORS: [':host'], | 7561 HOST_SELECTORS: [':host'], |
| 6811 SCOPE_SELECTORS: [':root'], | 7562 SCOPE_SELECTORS: [':root'], |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6910 (function () { | 7661 (function () { |
| 6911 'use strict'; | 7662 'use strict'; |
| 6912 var serializeValueToAttribute = Polymer.Base.serializeValueToAttribute; | 7663 var serializeValueToAttribute = Polymer.Base.serializeValueToAttribute; |
| 6913 var propertyUtils = Polymer.StyleProperties; | 7664 var propertyUtils = Polymer.StyleProperties; |
| 6914 var styleTransformer = Polymer.StyleTransformer; | 7665 var styleTransformer = Polymer.StyleTransformer; |
| 6915 var styleUtil = Polymer.StyleUtil; | 7666 var styleUtil = Polymer.StyleUtil; |
| 6916 var styleDefaults = Polymer.StyleDefaults; | 7667 var styleDefaults = Polymer.StyleDefaults; |
| 6917 var nativeShadow = Polymer.Settings.useNativeShadow; | 7668 var nativeShadow = Polymer.Settings.useNativeShadow; |
| 6918 Polymer.Base._addFeature({ | 7669 Polymer.Base._addFeature({ |
| 6919 _prepStyleProperties: function () { | 7670 _prepStyleProperties: function () { |
| 6920 this._ownStylePropertyNames = this._styles ? propertyUtils.decorateStyles(this._
styles) : []; | 7671 this._ownStylePropertyNames = this._styles ? propertyUtils.decorateStyles(this._
styles) : null; |
| 6921 }, | 7672 }, |
| 6922 customStyle: {}, | 7673 customStyle: null, |
| 7674 getComputedStyleValue: function (property) { |
| 7675 return this._styleProperties && this._styleProperties[property] || getComputedSt
yle(this).getPropertyValue(property); |
| 7676 }, |
| 6923 _setupStyleProperties: function () { | 7677 _setupStyleProperties: function () { |
| 6924 this.customStyle = {}; | 7678 this.customStyle = {}; |
| 6925 }, | 7679 }, |
| 6926 _needsStyleProperties: function () { | 7680 _needsStyleProperties: function () { |
| 6927 return Boolean(this._ownStylePropertyNames && this._ownStylePropertyNames.length
); | 7681 return Boolean(this._ownStylePropertyNames && this._ownStylePropertyNames.length
); |
| 6928 }, | 7682 }, |
| 6929 _beforeAttached: function () { | 7683 _beforeAttached: function () { |
| 6930 if (!this._scopeSelector && this._needsStyleProperties()) { | 7684 if (!this._scopeSelector && this._needsStyleProperties()) { |
| 6931 this._updateStyleProperties(); | 7685 this._updateStyleProperties(); |
| 6932 } | 7686 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7009 return style; | 7763 return style; |
| 7010 }, | 7764 }, |
| 7011 serializeValueToAttribute: function (value, attribute, node) { | 7765 serializeValueToAttribute: function (value, attribute, node) { |
| 7012 node = node || this; | 7766 node = node || this; |
| 7013 if (attribute === 'class' && !nativeShadow) { | 7767 if (attribute === 'class' && !nativeShadow) { |
| 7014 var host = node === this ? this.domHost || this.dataHost : this; | 7768 var host = node === this ? this.domHost || this.dataHost : this; |
| 7015 if (host) { | 7769 if (host) { |
| 7016 value = host._scopeElementClass(node, value); | 7770 value = host._scopeElementClass(node, value); |
| 7017 } | 7771 } |
| 7018 } | 7772 } |
| 7019 node = Polymer.dom(node); | 7773 node = this.shadyRoot && this.shadyRoot._hasDistributed ? Polymer.dom(node) : no
de; |
| 7020 serializeValueToAttribute.call(this, value, attribute, node); | 7774 serializeValueToAttribute.call(this, value, attribute, node); |
| 7021 }, | 7775 }, |
| 7022 _scopeElementClass: function (element, selector) { | 7776 _scopeElementClass: function (element, selector) { |
| 7023 if (!nativeShadow && !this._scopeCssViaAttr) { | 7777 if (!nativeShadow && !this._scopeCssViaAttr) { |
| 7024 selector += (selector ? ' ' : '') + SCOPE_NAME + ' ' + this.is + (element._scope
Selector ? ' ' + XSCOPE_NAME + ' ' + element._scopeSelector : ''); | 7778 selector += (selector ? ' ' : '') + SCOPE_NAME + ' ' + this.is + (element._scope
Selector ? ' ' + XSCOPE_NAME + ' ' + element._scopeSelector : ''); |
| 7025 } | 7779 } |
| 7026 return selector; | 7780 return selector; |
| 7027 }, | 7781 }, |
| 7028 updateStyles: function (properties) { | 7782 updateStyles: function (properties) { |
| 7029 if (this.isAttached) { | 7783 if (this.isAttached) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 7058 Polymer.Base._updateRootStyles(document); | 7812 Polymer.Base._updateRootStyles(document); |
| 7059 }; | 7813 }; |
| 7060 var styleCache = new Polymer.StyleCache(); | 7814 var styleCache = new Polymer.StyleCache(); |
| 7061 Polymer.customStyleCache = styleCache; | 7815 Polymer.customStyleCache = styleCache; |
| 7062 var SCOPE_NAME = styleTransformer.SCOPE_NAME; | 7816 var SCOPE_NAME = styleTransformer.SCOPE_NAME; |
| 7063 var XSCOPE_NAME = propertyUtils.XSCOPE_NAME; | 7817 var XSCOPE_NAME = propertyUtils.XSCOPE_NAME; |
| 7064 }()); | 7818 }()); |
| 7065 Polymer.Base._addFeature({ | 7819 Polymer.Base._addFeature({ |
| 7066 _registerFeatures: function () { | 7820 _registerFeatures: function () { |
| 7067 this._prepIs(); | 7821 this._prepIs(); |
| 7068 this._prepAttributes(); | |
| 7069 this._prepConstructor(); | 7822 this._prepConstructor(); |
| 7070 this._prepTemplate(); | 7823 this._prepTemplate(); |
| 7071 this._prepStyles(); | 7824 this._prepStyles(); |
| 7072 this._prepStyleProperties(); | 7825 this._prepStyleProperties(); |
| 7073 this._prepAnnotations(); | 7826 this._prepAnnotations(); |
| 7074 this._prepEffects(); | 7827 this._prepEffects(); |
| 7075 this._prepBehaviors(); | 7828 this._prepBehaviors(); |
| 7829 this._prepPropertyInfo(); |
| 7076 this._prepBindings(); | 7830 this._prepBindings(); |
| 7077 this._prepShady(); | 7831 this._prepShady(); |
| 7078 }, | 7832 }, |
| 7079 _prepBehavior: function (b) { | 7833 _prepBehavior: function (b) { |
| 7080 this._addPropertyEffects(b.properties); | 7834 this._addPropertyEffects(b.properties); |
| 7081 this._addComplexObserverEffects(b.observers); | 7835 this._addComplexObserverEffects(b.observers); |
| 7082 this._addHostAttributes(b.hostAttributes); | 7836 this._addHostAttributes(b.hostAttributes); |
| 7083 }, | 7837 }, |
| 7084 _initFeatures: function () { | 7838 _initFeatures: function () { |
| 7085 this._poolContent(); | |
| 7086 this._setupConfigure(); | 7839 this._setupConfigure(); |
| 7087 this._setupStyleProperties(); | 7840 this._setupStyleProperties(); |
| 7088 this._pushHost(); | 7841 this._setupDebouncers(); |
| 7842 this._registerHost(); |
| 7843 if (this._template) { |
| 7844 this._poolContent(); |
| 7845 this._beginHosting(); |
| 7089 this._stampTemplate(); | 7846 this._stampTemplate(); |
| 7090 this._popHost(); | 7847 this._endHosting(); |
| 7091 this._marshalAnnotationReferences(); | 7848 this._marshalAnnotationReferences(); |
| 7092 this._setupDebouncers(); | 7849 } |
| 7093 this._marshalInstanceEffects(); | 7850 this._marshalInstanceEffects(); |
| 7851 this._marshalBehaviors(); |
| 7094 this._marshalHostAttributes(); | 7852 this._marshalHostAttributes(); |
| 7095 this._marshalBehaviors(); | |
| 7096 this._marshalAttributes(); | 7853 this._marshalAttributes(); |
| 7097 this._tryReady(); | 7854 this._tryReady(); |
| 7098 }, | 7855 }, |
| 7099 _marshalBehavior: function (b) { | 7856 _marshalBehavior: function (b) { |
| 7857 if (b.listeners) { |
| 7100 this._listenListeners(b.listeners); | 7858 this._listenListeners(b.listeners); |
| 7101 } | 7859 } |
| 7860 } |
| 7102 }); | 7861 }); |
| 7103 (function () { | 7862 (function () { |
| 7104 var nativeShadow = Polymer.Settings.useNativeShadow; | 7863 var nativeShadow = Polymer.Settings.useNativeShadow; |
| 7105 var propertyUtils = Polymer.StyleProperties; | 7864 var propertyUtils = Polymer.StyleProperties; |
| 7106 var styleUtil = Polymer.StyleUtil; | 7865 var styleUtil = Polymer.StyleUtil; |
| 7107 var cssParse = Polymer.CssParse; | 7866 var cssParse = Polymer.CssParse; |
| 7108 var styleDefaults = Polymer.StyleDefaults; | 7867 var styleDefaults = Polymer.StyleDefaults; |
| 7109 var styleTransformer = Polymer.StyleTransformer; | 7868 var styleTransformer = Polymer.StyleTransformer; |
| 7110 Polymer({ | 7869 Polymer({ |
| 7111 is: 'custom-style', | 7870 is: 'custom-style', |
| 7112 extends: 'style', | 7871 extends: 'style', |
| 7872 _template: null, |
| 7113 properties: { include: String }, | 7873 properties: { include: String }, |
| 7114 ready: function () { | 7874 ready: function () { |
| 7115 this._tryApply(); | 7875 this._tryApply(); |
| 7116 }, | 7876 }, |
| 7117 attached: function () { | 7877 attached: function () { |
| 7118 this._tryApply(); | 7878 this._tryApply(); |
| 7119 }, | 7879 }, |
| 7120 _tryApply: function () { | 7880 _tryApply: function () { |
| 7121 if (!this._appliesToDocument) { | 7881 if (!this._appliesToDocument) { |
| 7122 if (this.parentNode && this.parentNode.localName !== 'dom-module') { | 7882 if (this.parentNode && this.parentNode.localName !== 'dom-module') { |
| 7123 this._appliesToDocument = true; | 7883 this._appliesToDocument = true; |
| 7124 var e = this.__appliedElement || this; | 7884 var e = this.__appliedElement || this; |
| 7125 styleDefaults.addStyle(e); | 7885 styleDefaults.addStyle(e); |
| 7126 if (e.textContent || this.include) { | 7886 if (e.textContent || this.include) { |
| 7127 this._apply(); | 7887 this._apply(true); |
| 7128 } else { | 7888 } else { |
| 7889 var self = this; |
| 7129 var observer = new MutationObserver(function () { | 7890 var observer = new MutationObserver(function () { |
| 7130 observer.disconnect(); | 7891 observer.disconnect(); |
| 7131 this._apply(); | 7892 self._apply(true); |
| 7132 }.bind(this)); | 7893 }); |
| 7133 observer.observe(e, { childList: true }); | 7894 observer.observe(e, { childList: true }); |
| 7134 } | 7895 } |
| 7135 } | 7896 } |
| 7136 } | 7897 } |
| 7137 }, | 7898 }, |
| 7138 _apply: function () { | 7899 _apply: function (deferProperties) { |
| 7139 var e = this.__appliedElement || this; | 7900 var e = this.__appliedElement || this; |
| 7140 if (this.include) { | 7901 if (this.include) { |
| 7141 e.textContent = styleUtil.cssFromModules(this.include, true) + e.textContent; | 7902 e.textContent = styleUtil.cssFromModules(this.include, true) + e.textContent; |
| 7142 } | 7903 } |
| 7143 if (e.textContent) { | 7904 if (e.textContent) { |
| 7144 styleUtil.forEachStyleRule(styleUtil.rulesForStyle(e), function (rule) { | 7905 styleUtil.forEachStyleRule(styleUtil.rulesForStyle(e), function (rule) { |
| 7145 styleTransformer.documentRule(rule); | 7906 styleTransformer.documentRule(rule); |
| 7146 }); | 7907 }); |
| 7147 this._applyCustomProperties(e); | 7908 var self = this; |
| 7909 function fn() { |
| 7910 self._applyCustomProperties(e); |
| 7911 } |
| 7912 if (this._pendingApplyProperties) { |
| 7913 cancelAnimationFrame(this._pendingApplyProperties); |
| 7914 this._pendingApplyProperties = null; |
| 7915 } |
| 7916 if (deferProperties) { |
| 7917 this._pendingApplyProperties = requestAnimationFrame(fn); |
| 7918 } else { |
| 7919 fn(); |
| 7920 } |
| 7148 } | 7921 } |
| 7149 }, | 7922 }, |
| 7150 _applyCustomProperties: function (element) { | 7923 _applyCustomProperties: function (element) { |
| 7151 this._computeStyleProperties(); | 7924 this._computeStyleProperties(); |
| 7152 var props = this._styleProperties; | 7925 var props = this._styleProperties; |
| 7153 var rules = styleUtil.rulesForStyle(element); | 7926 var rules = styleUtil.rulesForStyle(element); |
| 7154 element.textContent = styleUtil.toCssText(rules, function (rule) { | 7927 element.textContent = styleUtil.toCssText(rules, function (rule) { |
| 7155 var css = rule.cssText = rule.parsedCssText; | 7928 var css = rule.cssText = rule.parsedCssText; |
| 7156 if (rule.propertyInfo && rule.propertyInfo.cssText) { | 7929 if (rule.propertyInfo && rule.propertyInfo.cssText) { |
| 7157 css = cssParse.removeCustomPropAssignment(css); | 7930 css = cssParse.removeCustomPropAssignment(css); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 7174 this.ctor = template._content._ctor; | 7947 this.ctor = template._content._ctor; |
| 7175 this._prepParentProperties(this.ctor.prototype, template); | 7948 this._prepParentProperties(this.ctor.prototype, template); |
| 7176 return; | 7949 return; |
| 7177 } | 7950 } |
| 7178 var archetype = Object.create(Polymer.Base); | 7951 var archetype = Object.create(Polymer.Base); |
| 7179 this._customPrepAnnotations(archetype, template); | 7952 this._customPrepAnnotations(archetype, template); |
| 7180 this._prepParentProperties(archetype, template); | 7953 this._prepParentProperties(archetype, template); |
| 7181 archetype._prepEffects(); | 7954 archetype._prepEffects(); |
| 7182 this._customPrepEffects(archetype); | 7955 this._customPrepEffects(archetype); |
| 7183 archetype._prepBehaviors(); | 7956 archetype._prepBehaviors(); |
| 7957 archetype._prepPropertyInfo(); |
| 7184 archetype._prepBindings(); | 7958 archetype._prepBindings(); |
| 7185 archetype._notifyPath = this._notifyPathImpl; | 7959 archetype._notifyPathUp = this._notifyPathUpImpl; |
| 7186 archetype._scopeElementClass = this._scopeElementClassImpl; | 7960 archetype._scopeElementClass = this._scopeElementClassImpl; |
| 7187 archetype.listen = this._listenImpl; | 7961 archetype.listen = this._listenImpl; |
| 7188 archetype._showHideChildren = this._showHideChildrenImpl; | 7962 archetype._showHideChildren = this._showHideChildrenImpl; |
| 7189 var _constructor = this._constructorImpl; | 7963 var _constructor = this._constructorImpl; |
| 7190 var ctor = function TemplateInstance(model, host) { | 7964 var ctor = function TemplateInstance(model, host) { |
| 7191 _constructor.call(this, model, host); | 7965 _constructor.call(this, model, host); |
| 7192 }; | 7966 }; |
| 7193 ctor.prototype = archetype; | 7967 ctor.prototype = archetype; |
| 7194 archetype.constructor = ctor; | 7968 archetype.constructor = ctor; |
| 7195 template._content._ctor = ctor; | 7969 template._content._ctor = ctor; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7236 for (var prop in this._instanceProps) { | 8010 for (var prop in this._instanceProps) { |
| 7237 archetype._addPropertyEffect(prop, 'function', this._createInstancePropEffector(
prop)); | 8011 archetype._addPropertyEffect(prop, 'function', this._createInstancePropEffector(
prop)); |
| 7238 } | 8012 } |
| 7239 }, | 8013 }, |
| 7240 _customPrepAnnotations: function (archetype, template) { | 8014 _customPrepAnnotations: function (archetype, template) { |
| 7241 archetype._template = template; | 8015 archetype._template = template; |
| 7242 var c = template._content; | 8016 var c = template._content; |
| 7243 if (!c._notes) { | 8017 if (!c._notes) { |
| 7244 var rootDataHost = archetype._rootDataHost; | 8018 var rootDataHost = archetype._rootDataHost; |
| 7245 if (rootDataHost) { | 8019 if (rootDataHost) { |
| 7246 Polymer.Annotations.prepElement = rootDataHost._prepElement.bind(rootDataHost); | 8020 Polymer.Annotations.prepElement = function () { |
| 8021 rootDataHost._prepElement(); |
| 8022 }; |
| 7247 } | 8023 } |
| 7248 c._notes = Polymer.Annotations.parseAnnotations(template); | 8024 c._notes = Polymer.Annotations.parseAnnotations(template); |
| 7249 Polymer.Annotations.prepElement = null; | 8025 Polymer.Annotations.prepElement = null; |
| 7250 this._processAnnotations(c._notes); | 8026 this._processAnnotations(c._notes); |
| 7251 } | 8027 } |
| 7252 archetype._notes = c._notes; | 8028 archetype._notes = c._notes; |
| 7253 archetype._parentProps = c._parentProps; | 8029 archetype._parentProps = c._parentProps; |
| 7254 }, | 8030 }, |
| 7255 _prepParentProperties: function (archetype, template) { | 8031 _prepParentProperties: function (archetype, template) { |
| 7256 var parentProps = this._parentProps = archetype._parentProps; | 8032 var parentProps = this._parentProps = archetype._parentProps; |
| 7257 if (this._forwardParentProp && parentProps) { | 8033 if (this._forwardParentProp && parentProps) { |
| 7258 var proto = archetype._parentPropProto; | 8034 var proto = archetype._parentPropProto; |
| 7259 var prop; | 8035 var prop; |
| 7260 if (!proto) { | 8036 if (!proto) { |
| 7261 for (prop in this._instanceProps) { | 8037 for (prop in this._instanceProps) { |
| 7262 delete parentProps[prop]; | 8038 delete parentProps[prop]; |
| 7263 } | 8039 } |
| 7264 proto = archetype._parentPropProto = Object.create(null); | 8040 proto = archetype._parentPropProto = Object.create(null); |
| 7265 if (template != this) { | 8041 if (template != this) { |
| 7266 Polymer.Bind.prepareModel(proto); | 8042 Polymer.Bind.prepareModel(proto); |
| 7267 Polymer.Base.prepareModelNotifyPath(proto); | 8043 Polymer.Base.prepareModelNotifyPath(proto); |
| 7268 } | 8044 } |
| 7269 for (prop in parentProps) { | 8045 for (prop in parentProps) { |
| 7270 var parentProp = this._parentPropPrefix + prop; | 8046 var parentProp = this._parentPropPrefix + prop; |
| 7271 var effects = [ | 8047 var effects = [ |
| 7272 { | 8048 { |
| 7273 kind: 'function', | 8049 kind: 'function', |
| 7274 effect: this._createForwardPropEffector(prop) | 8050 effect: this._createForwardPropEffector(prop), |
| 8051 fn: Polymer.Bind._functionEffect |
| 7275 }, | 8052 }, |
| 7276 { kind: 'notify' } | 8053 { |
| 8054 kind: 'notify', |
| 8055 fn: Polymer.Bind._notifyEffect, |
| 8056 effect: { event: Polymer.CaseMap.camelToDashCase(parentProp) + '-changed' } |
| 8057 } |
| 7277 ]; | 8058 ]; |
| 7278 Polymer.Bind._createAccessors(proto, parentProp, effects); | 8059 Polymer.Bind._createAccessors(proto, parentProp, effects); |
| 7279 } | 8060 } |
| 7280 } | 8061 } |
| 8062 var self = this; |
| 7281 if (template != this) { | 8063 if (template != this) { |
| 7282 Polymer.Bind.prepareInstance(template); | 8064 Polymer.Bind.prepareInstance(template); |
| 7283 template._forwardParentProp = this._forwardParentProp.bind(this); | 8065 template._forwardParentProp = function (source, value) { |
| 8066 self._forwardParentProp(source, value); |
| 8067 }; |
| 7284 } | 8068 } |
| 7285 this._extendTemplate(template, proto); | 8069 this._extendTemplate(template, proto); |
| 7286 template._pathEffector = this._pathEffectorImpl.bind(this); | 8070 template._pathEffector = function (path, value, fromAbove) { |
| 8071 return self._pathEffectorImpl(path, value, fromAbove); |
| 8072 }; |
| 7287 } | 8073 } |
| 7288 }, | 8074 }, |
| 7289 _createForwardPropEffector: function (prop) { | 8075 _createForwardPropEffector: function (prop) { |
| 7290 return function (source, value) { | 8076 return function (source, value) { |
| 7291 this._forwardParentProp(prop, value); | 8077 this._forwardParentProp(prop, value); |
| 7292 }; | 8078 }; |
| 7293 }, | 8079 }, |
| 7294 _createHostPropEffector: function (prop) { | 8080 _createHostPropEffector: function (prop) { |
| 7295 var prefix = this._parentPropPrefix; | 8081 var prefix = this._parentPropPrefix; |
| 7296 return function (source, value) { | 8082 return function (source, value) { |
| 7297 this.dataHost._templatized[prefix + prop] = value; | 8083 this.dataHost._templatized[prefix + prop] = value; |
| 7298 }; | 8084 }; |
| 7299 }, | 8085 }, |
| 7300 _createInstancePropEffector: function (prop) { | 8086 _createInstancePropEffector: function (prop) { |
| 7301 return function (source, value, old, fromAbove) { | 8087 return function (source, value, old, fromAbove) { |
| 7302 if (!fromAbove) { | 8088 if (!fromAbove) { |
| 7303 this.dataHost._forwardInstanceProp(this, prop, value); | 8089 this.dataHost._forwardInstanceProp(this, prop, value); |
| 7304 } | 8090 } |
| 7305 }; | 8091 }; |
| 7306 }, | 8092 }, |
| 7307 _extendTemplate: function (template, proto) { | 8093 _extendTemplate: function (template, proto) { |
| 7308 Object.getOwnPropertyNames(proto).forEach(function (n) { | 8094 var n$ = Object.getOwnPropertyNames(proto); |
| 8095 for (var i = 0, n; i < n$.length && (n = n$[i]); i++) { |
| 7309 var val = template[n]; | 8096 var val = template[n]; |
| 7310 var pd = Object.getOwnPropertyDescriptor(proto, n); | 8097 var pd = Object.getOwnPropertyDescriptor(proto, n); |
| 7311 Object.defineProperty(template, n, pd); | 8098 Object.defineProperty(template, n, pd); |
| 7312 if (val !== undefined) { | 8099 if (val !== undefined) { |
| 7313 template._propertySetter(n, val); | 8100 template._propertySetter(n, val); |
| 7314 } | 8101 } |
| 7315 }); | 8102 } |
| 7316 }, | 8103 }, |
| 7317 _showHideChildren: function (hidden) { | 8104 _showHideChildren: function (hidden) { |
| 7318 }, | 8105 }, |
| 7319 _forwardInstancePath: function (inst, path, value) { | 8106 _forwardInstancePath: function (inst, path, value) { |
| 7320 }, | 8107 }, |
| 7321 _forwardInstanceProp: function (inst, prop, value) { | 8108 _forwardInstanceProp: function (inst, prop, value) { |
| 7322 }, | 8109 }, |
| 7323 _notifyPathImpl: function (path, value) { | 8110 _notifyPathUpImpl: function (path, value) { |
| 7324 var dataHost = this.dataHost; | 8111 var dataHost = this.dataHost; |
| 7325 var dot = path.indexOf('.'); | 8112 var dot = path.indexOf('.'); |
| 7326 var root = dot < 0 ? path : path.slice(0, dot); | 8113 var root = dot < 0 ? path : path.slice(0, dot); |
| 7327 dataHost._forwardInstancePath.call(dataHost, this, path, value); | 8114 dataHost._forwardInstancePath.call(dataHost, this, path, value); |
| 7328 if (root in dataHost._parentProps) { | 8115 if (root in dataHost._parentProps) { |
| 7329 dataHost._templatized.notifyPath(dataHost._parentPropPrefix + path, value); | 8116 dataHost._templatized.notifyPath(dataHost._parentPropPrefix + path, value); |
| 7330 } | 8117 } |
| 7331 }, | 8118 }, |
| 7332 _pathEffectorImpl: function (path, value, fromAbove) { | 8119 _pathEffectorImpl: function (path, value, fromAbove) { |
| 7333 if (this._forwardParentPath) { | 8120 if (this._forwardParentPath) { |
| 7334 if (path.indexOf(this._parentPropPrefix) === 0) { | 8121 if (path.indexOf(this._parentPropPrefix) === 0) { |
| 7335 var subPath = path.substring(this._parentPropPrefix.length); | 8122 var subPath = path.substring(this._parentPropPrefix.length); |
| 8123 var model = this._modelForPath(subPath); |
| 8124 if (model in this._parentProps) { |
| 7336 this._forwardParentPath(subPath, value); | 8125 this._forwardParentPath(subPath, value); |
| 7337 } | 8126 } |
| 7338 } | 8127 } |
| 8128 } |
| 7339 Polymer.Base._pathEffector.call(this._templatized, path, value, fromAbove); | 8129 Polymer.Base._pathEffector.call(this._templatized, path, value, fromAbove); |
| 7340 }, | 8130 }, |
| 7341 _constructorImpl: function (model, host) { | 8131 _constructorImpl: function (model, host) { |
| 7342 this._rootDataHost = host._getRootDataHost(); | 8132 this._rootDataHost = host._getRootDataHost(); |
| 7343 this._setupConfigure(model); | 8133 this._setupConfigure(model); |
| 7344 this._pushHost(host); | 8134 this._registerHost(host); |
| 8135 this._beginHosting(); |
| 7345 this.root = this.instanceTemplate(this._template); | 8136 this.root = this.instanceTemplate(this._template); |
| 7346 this.root.__noContent = !this._notes._hasContent; | 8137 this.root.__noContent = !this._notes._hasContent; |
| 7347 this.root.__styleScoped = true; | 8138 this.root.__styleScoped = true; |
| 7348 this._popHost(); | 8139 this._endHosting(); |
| 7349 this._marshalAnnotatedNodes(); | 8140 this._marshalAnnotatedNodes(); |
| 7350 this._marshalInstanceEffects(); | 8141 this._marshalInstanceEffects(); |
| 7351 this._marshalAnnotatedListeners(); | 8142 this._marshalAnnotatedListeners(); |
| 7352 var children = []; | 8143 var children = []; |
| 7353 for (var n = this.root.firstChild; n; n = n.nextSibling) { | 8144 for (var n = this.root.firstChild; n; n = n.nextSibling) { |
| 7354 children.push(n); | 8145 children.push(n); |
| 7355 n._templateInstance = this; | 8146 n._templateInstance = this; |
| 7356 } | 8147 } |
| 7357 this._children = children; | 8148 this._children = children; |
| 7358 if (host.__hideTemplateChildren__) { | 8149 if (host.__hideTemplateChildren__) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7397 } | 8188 } |
| 7398 } else { | 8189 } else { |
| 7399 el = el.parentNode; | 8190 el = el.parentNode; |
| 7400 } | 8191 } |
| 7401 } | 8192 } |
| 7402 } | 8193 } |
| 7403 }; | 8194 }; |
| 7404 Polymer({ | 8195 Polymer({ |
| 7405 is: 'dom-template', | 8196 is: 'dom-template', |
| 7406 extends: 'template', | 8197 extends: 'template', |
| 8198 _template: null, |
| 7407 behaviors: [Polymer.Templatizer], | 8199 behaviors: [Polymer.Templatizer], |
| 7408 ready: function () { | 8200 ready: function () { |
| 7409 this.templatize(this); | 8201 this.templatize(this); |
| 7410 } | 8202 } |
| 7411 }); | 8203 }); |
| 7412 Polymer._collections = new WeakMap(); | 8204 Polymer._collections = new WeakMap(); |
| 7413 Polymer.Collection = function (userArray) { | 8205 Polymer.Collection = function (userArray) { |
| 7414 Polymer._collections.set(userArray, this); | 8206 Polymer._collections.set(userArray, this); |
| 7415 this.userArray = userArray; | 8207 this.userArray = userArray; |
| 7416 this.store = userArray.slice(); | 8208 this.store = userArray.slice(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7431 } | 8223 } |
| 7432 } | 8224 } |
| 7433 }, | 8225 }, |
| 7434 add: function (item) { | 8226 add: function (item) { |
| 7435 var key = this.store.push(item) - 1; | 8227 var key = this.store.push(item) - 1; |
| 7436 if (item && typeof item == 'object') { | 8228 if (item && typeof item == 'object') { |
| 7437 this.omap.set(item, key); | 8229 this.omap.set(item, key); |
| 7438 } else { | 8230 } else { |
| 7439 this.pmap[item] = key; | 8231 this.pmap[item] = key; |
| 7440 } | 8232 } |
| 7441 return key; | 8233 return '#' + key; |
| 7442 }, | 8234 }, |
| 7443 removeKey: function (key) { | 8235 removeKey: function (key) { |
| 8236 key = this._parseKey(key); |
| 7444 this._removeFromMap(this.store[key]); | 8237 this._removeFromMap(this.store[key]); |
| 7445 delete this.store[key]; | 8238 delete this.store[key]; |
| 7446 }, | 8239 }, |
| 7447 _removeFromMap: function (item) { | 8240 _removeFromMap: function (item) { |
| 7448 if (item && typeof item == 'object') { | 8241 if (item && typeof item == 'object') { |
| 7449 this.omap.delete(item); | 8242 this.omap.delete(item); |
| 7450 } else { | 8243 } else { |
| 7451 delete this.pmap[item]; | 8244 delete this.pmap[item]; |
| 7452 } | 8245 } |
| 7453 }, | 8246 }, |
| 7454 remove: function (item) { | 8247 remove: function (item) { |
| 7455 var key = this.getKey(item); | 8248 var key = this.getKey(item); |
| 7456 this.removeKey(key); | 8249 this.removeKey(key); |
| 7457 return key; | 8250 return key; |
| 7458 }, | 8251 }, |
| 7459 getKey: function (item) { | 8252 getKey: function (item) { |
| 8253 var key; |
| 7460 if (item && typeof item == 'object') { | 8254 if (item && typeof item == 'object') { |
| 7461 return this.omap.get(item); | 8255 key = this.omap.get(item); |
| 7462 } else { | 8256 } else { |
| 7463 return this.pmap[item]; | 8257 key = this.pmap[item]; |
| 8258 } |
| 8259 if (key != undefined) { |
| 8260 return '#' + key; |
| 7464 } | 8261 } |
| 7465 }, | 8262 }, |
| 7466 getKeys: function () { | 8263 getKeys: function () { |
| 7467 return Object.keys(this.store); | 8264 return Object.keys(this.store).map(function (key) { |
| 8265 return '#' + key; |
| 8266 }); |
| 8267 }, |
| 8268 _parseKey: function (key) { |
| 8269 if (key[0] == '#') { |
| 8270 return key.slice(1); |
| 8271 } |
| 8272 throw new Error('unexpected key ' + key); |
| 7468 }, | 8273 }, |
| 7469 setItem: function (key, item) { | 8274 setItem: function (key, item) { |
| 8275 key = this._parseKey(key); |
| 7470 var old = this.store[key]; | 8276 var old = this.store[key]; |
| 7471 if (old) { | 8277 if (old) { |
| 7472 this._removeFromMap(old); | 8278 this._removeFromMap(old); |
| 7473 } | 8279 } |
| 7474 if (item && typeof item == 'object') { | 8280 if (item && typeof item == 'object') { |
| 7475 this.omap.set(item, key); | 8281 this.omap.set(item, key); |
| 7476 } else { | 8282 } else { |
| 7477 this.pmap[item] = key; | 8283 this.pmap[item] = key; |
| 7478 } | 8284 } |
| 7479 this.store[key] = item; | 8285 this.store[key] = item; |
| 7480 }, | 8286 }, |
| 7481 getItem: function (key) { | 8287 getItem: function (key) { |
| 8288 key = this._parseKey(key); |
| 7482 return this.store[key]; | 8289 return this.store[key]; |
| 7483 }, | 8290 }, |
| 7484 getItems: function () { | 8291 getItems: function () { |
| 7485 var items = [], store = this.store; | 8292 var items = [], store = this.store; |
| 7486 for (var key in store) { | 8293 for (var key in store) { |
| 7487 items.push(store[key]); | 8294 items.push(store[key]); |
| 7488 } | 8295 } |
| 7489 return items; | 8296 return items; |
| 7490 }, | 8297 }, |
| 7491 _applySplices: function (splices) { | 8298 _applySplices: function (splices) { |
| 7492 var keyMap = {}, key, i; | 8299 var keyMap = {}, key; |
| 7493 splices.forEach(function (s) { | 8300 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { |
| 7494 s.addedKeys = []; | 8301 s.addedKeys = []; |
| 7495 for (i = 0; i < s.removed.length; i++) { | 8302 for (var j = 0; j < s.removed.length; j++) { |
| 7496 key = this.getKey(s.removed[i]); | 8303 key = this.getKey(s.removed[j]); |
| 7497 keyMap[key] = keyMap[key] ? null : -1; | 8304 keyMap[key] = keyMap[key] ? null : -1; |
| 7498 } | 8305 } |
| 7499 for (i = 0; i < s.addedCount; i++) { | 8306 for (var j = 0; j < s.addedCount; j++) { |
| 7500 var item = this.userArray[s.index + i]; | 8307 var item = this.userArray[s.index + j]; |
| 7501 key = this.getKey(item); | 8308 key = this.getKey(item); |
| 7502 key = key === undefined ? this.add(item) : key; | 8309 key = key === undefined ? this.add(item) : key; |
| 7503 keyMap[key] = keyMap[key] ? null : 1; | 8310 keyMap[key] = keyMap[key] ? null : 1; |
| 7504 s.addedKeys.push(key); | 8311 s.addedKeys.push(key); |
| 7505 } | 8312 } |
| 7506 }, this); | 8313 } |
| 7507 var removed = []; | 8314 var removed = []; |
| 7508 var added = []; | 8315 var added = []; |
| 7509 for (var key in keyMap) { | 8316 for (var key in keyMap) { |
| 7510 if (keyMap[key] < 0) { | 8317 if (keyMap[key] < 0) { |
| 7511 this.removeKey(key); | 8318 this.removeKey(key); |
| 7512 removed.push(key); | 8319 removed.push(key); |
| 7513 } | 8320 } |
| 7514 if (keyMap[key] > 0) { | 8321 if (keyMap[key] > 0) { |
| 7515 added.push(key); | 8322 added.push(key); |
| 7516 } | 8323 } |
| 7517 } | 8324 } |
| 7518 return [{ | 8325 return [{ |
| 7519 removed: removed, | 8326 removed: removed, |
| 7520 added: added | 8327 added: added |
| 7521 }]; | 8328 }]; |
| 7522 } | 8329 } |
| 7523 }; | 8330 }; |
| 7524 Polymer.Collection.get = function (userArray) { | 8331 Polymer.Collection.get = function (userArray) { |
| 7525 return Polymer._collections.get(userArray) || new Polymer.Collection(userArray); | 8332 return Polymer._collections.get(userArray) || new Polymer.Collection(userArray); |
| 7526 }; | 8333 }; |
| 7527 Polymer.Collection.applySplices = function (userArray, splices) { | 8334 Polymer.Collection.applySplices = function (userArray, splices) { |
| 7528 var coll = Polymer._collections.get(userArray); | 8335 var coll = Polymer._collections.get(userArray); |
| 7529 return coll ? coll._applySplices(splices) : null; | 8336 return coll ? coll._applySplices(splices) : null; |
| 7530 }; | 8337 }; |
| 7531 Polymer({ | 8338 Polymer({ |
| 7532 is: 'dom-repeat', | 8339 is: 'dom-repeat', |
| 7533 extends: 'template', | 8340 extends: 'template', |
| 8341 _template: null, |
| 7534 properties: { | 8342 properties: { |
| 7535 items: { type: Array }, | 8343 items: { type: Array }, |
| 7536 as: { | 8344 as: { |
| 7537 type: String, | 8345 type: String, |
| 7538 value: 'item' | 8346 value: 'item' |
| 7539 }, | 8347 }, |
| 7540 indexAs: { | 8348 indexAs: { |
| 7541 type: String, | 8349 type: String, |
| 7542 value: 'index' | 8350 value: 'index' |
| 7543 }, | 8351 }, |
| 7544 sort: { | 8352 sort: { |
| 7545 type: Function, | 8353 type: Function, |
| 7546 observer: '_sortChanged' | 8354 observer: '_sortChanged' |
| 7547 }, | 8355 }, |
| 7548 filter: { | 8356 filter: { |
| 7549 type: Function, | 8357 type: Function, |
| 7550 observer: '_filterChanged' | 8358 observer: '_filterChanged' |
| 7551 }, | 8359 }, |
| 7552 observe: { | 8360 observe: { |
| 7553 type: String, | 8361 type: String, |
| 7554 observer: '_observeChanged' | 8362 observer: '_observeChanged' |
| 7555 }, | 8363 }, |
| 7556 delay: Number | 8364 delay: Number, |
| 8365 initialCount: { |
| 8366 type: Number, |
| 8367 observer: '_initializeChunking' |
| 8368 }, |
| 8369 targetFramerate: { |
| 8370 type: Number, |
| 8371 value: 20 |
| 8372 }, |
| 8373 _targetFrameTime: { computed: '_computeFrameTime(targetFramerate)' } |
| 7557 }, | 8374 }, |
| 7558 behaviors: [Polymer.Templatizer], | 8375 behaviors: [Polymer.Templatizer], |
| 7559 observers: ['_itemsChanged(items.*)'], | 8376 observers: ['_itemsChanged(items.*)'], |
| 7560 created: function () { | 8377 created: function () { |
| 7561 this._instances = []; | 8378 this._instances = []; |
| 8379 this._pool = []; |
| 8380 this._limit = Infinity; |
| 8381 var self = this; |
| 8382 this._boundRenderChunk = function () { |
| 8383 self._renderChunk(); |
| 8384 }; |
| 7562 }, | 8385 }, |
| 7563 detached: function () { | 8386 detached: function () { |
| 7564 for (var i = 0; i < this._instances.length; i++) { | 8387 for (var i = 0; i < this._instances.length; i++) { |
| 7565 this._detachRow(i); | 8388 this._detachInstance(i); |
| 7566 } | 8389 } |
| 7567 }, | 8390 }, |
| 7568 attached: function () { | 8391 attached: function () { |
| 7569 var parentNode = Polymer.dom(this).parentNode; | 8392 var parent = Polymer.dom(Polymer.dom(this).parentNode); |
| 7570 for (var i = 0; i < this._instances.length; i++) { | 8393 for (var i = 0; i < this._instances.length; i++) { |
| 7571 Polymer.dom(parentNode).insertBefore(this._instances[i].root, this); | 8394 this._attachInstance(i, parent); |
| 7572 } | 8395 } |
| 7573 }, | 8396 }, |
| 7574 ready: function () { | 8397 ready: function () { |
| 7575 this._instanceProps = { __key__: true }; | 8398 this._instanceProps = { __key__: true }; |
| 7576 this._instanceProps[this.as] = true; | 8399 this._instanceProps[this.as] = true; |
| 7577 this._instanceProps[this.indexAs] = true; | 8400 this._instanceProps[this.indexAs] = true; |
| 7578 if (!this.ctor) { | 8401 if (!this.ctor) { |
| 7579 this.templatize(this); | 8402 this.templatize(this); |
| 7580 } | 8403 } |
| 7581 }, | 8404 }, |
| 7582 _sortChanged: function () { | 8405 _sortChanged: function (sort) { |
| 7583 var dataHost = this._getRootDataHost(); | 8406 var dataHost = this._getRootDataHost(); |
| 7584 var sort = this.sort; | |
| 7585 this._sortFn = sort && (typeof sort == 'function' ? sort : function () { | 8407 this._sortFn = sort && (typeof sort == 'function' ? sort : function () { |
| 7586 return dataHost[sort].apply(dataHost, arguments); | 8408 return dataHost[sort].apply(dataHost, arguments); |
| 7587 }); | 8409 }); |
| 7588 this._needFullRefresh = true; | 8410 this._needFullRefresh = true; |
| 7589 if (this.items) { | 8411 if (this.items) { |
| 7590 this._debounceTemplate(this._render); | 8412 this._debounceTemplate(this._render); |
| 7591 } | 8413 } |
| 7592 }, | 8414 }, |
| 7593 _filterChanged: function () { | 8415 _filterChanged: function (filter) { |
| 7594 var dataHost = this._getRootDataHost(); | 8416 var dataHost = this._getRootDataHost(); |
| 7595 var filter = this.filter; | |
| 7596 this._filterFn = filter && (typeof filter == 'function' ? filter : function () { | 8417 this._filterFn = filter && (typeof filter == 'function' ? filter : function () { |
| 7597 return dataHost[filter].apply(dataHost, arguments); | 8418 return dataHost[filter].apply(dataHost, arguments); |
| 7598 }); | 8419 }); |
| 7599 this._needFullRefresh = true; | 8420 this._needFullRefresh = true; |
| 7600 if (this.items) { | 8421 if (this.items) { |
| 7601 this._debounceTemplate(this._render); | 8422 this._debounceTemplate(this._render); |
| 7602 } | 8423 } |
| 7603 }, | 8424 }, |
| 8425 _computeFrameTime: function (rate) { |
| 8426 return Math.ceil(1000 / rate); |
| 8427 }, |
| 8428 _initializeChunking: function () { |
| 8429 if (this.initialCount) { |
| 8430 this._limit = this.initialCount; |
| 8431 this._chunkCount = this.initialCount; |
| 8432 this._lastChunkTime = performance.now(); |
| 8433 } |
| 8434 }, |
| 8435 _tryRenderChunk: function () { |
| 8436 if (this.items && this._limit < this.items.length) { |
| 8437 this.debounce('renderChunk', this._requestRenderChunk); |
| 8438 } |
| 8439 }, |
| 8440 _requestRenderChunk: function () { |
| 8441 requestAnimationFrame(this._boundRenderChunk); |
| 8442 }, |
| 8443 _renderChunk: function () { |
| 8444 var currChunkTime = performance.now(); |
| 8445 var ratio = this._targetFrameTime / (currChunkTime - this._lastChunkTime); |
| 8446 this._chunkCount = Math.round(this._chunkCount * ratio) || 1; |
| 8447 this._limit += this._chunkCount; |
| 8448 this._lastChunkTime = currChunkTime; |
| 8449 this._debounceTemplate(this._render); |
| 8450 }, |
| 7604 _observeChanged: function () { | 8451 _observeChanged: function () { |
| 7605 this._observePaths = this.observe && this.observe.replace('.*', '.').split(' '); | 8452 this._observePaths = this.observe && this.observe.replace('.*', '.').split(' '); |
| 7606 }, | 8453 }, |
| 7607 _itemsChanged: function (change) { | 8454 _itemsChanged: function (change) { |
| 7608 if (change.path == 'items') { | 8455 if (change.path == 'items') { |
| 7609 if (Array.isArray(this.items)) { | 8456 if (Array.isArray(this.items)) { |
| 7610 this.collection = Polymer.Collection.get(this.items); | 8457 this.collection = Polymer.Collection.get(this.items); |
| 7611 } else if (!this.items) { | 8458 } else if (!this.items) { |
| 7612 this.collection = null; | 8459 this.collection = null; |
| 7613 } else { | 8460 } else { |
| 7614 this._error(this._logf('dom-repeat', 'expected array for `items`,' + ' found', t
his.items)); | 8461 this._error(this._logf('dom-repeat', 'expected array for `items`,' + ' found', t
his.items)); |
| 7615 } | 8462 } |
| 7616 this._keySplices = []; | 8463 this._keySplices = []; |
| 7617 this._indexSplices = []; | 8464 this._indexSplices = []; |
| 7618 this._needFullRefresh = true; | 8465 this._needFullRefresh = true; |
| 8466 this._initializeChunking(); |
| 7619 this._debounceTemplate(this._render); | 8467 this._debounceTemplate(this._render); |
| 7620 } else if (change.path == 'items.splices') { | 8468 } else if (change.path == 'items.splices') { |
| 7621 this._keySplices = this._keySplices.concat(change.value.keySplices); | 8469 this._keySplices = this._keySplices.concat(change.value.keySplices); |
| 7622 this._indexSplices = this._indexSplices.concat(change.value.indexSplices); | 8470 this._indexSplices = this._indexSplices.concat(change.value.indexSplices); |
| 7623 this._debounceTemplate(this._render); | 8471 this._debounceTemplate(this._render); |
| 7624 } else { | 8472 } else { |
| 7625 var subpath = change.path.slice(6); | 8473 var subpath = change.path.slice(6); |
| 7626 this._forwardItemPath(subpath, change.value); | 8474 this._forwardItemPath(subpath, change.value); |
| 7627 this._checkObservedPaths(subpath); | 8475 this._checkObservedPaths(subpath); |
| 7628 } | 8476 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7647 render: function () { | 8495 render: function () { |
| 7648 this._needFullRefresh = true; | 8496 this._needFullRefresh = true; |
| 7649 this._debounceTemplate(this._render); | 8497 this._debounceTemplate(this._render); |
| 7650 this._flushTemplates(); | 8498 this._flushTemplates(); |
| 7651 }, | 8499 }, |
| 7652 _render: function () { | 8500 _render: function () { |
| 7653 var c = this.collection; | 8501 var c = this.collection; |
| 7654 if (this._needFullRefresh) { | 8502 if (this._needFullRefresh) { |
| 7655 this._applyFullRefresh(); | 8503 this._applyFullRefresh(); |
| 7656 this._needFullRefresh = false; | 8504 this._needFullRefresh = false; |
| 7657 } else { | 8505 } else if (this._keySplices.length) { |
| 7658 if (this._sortFn) { | 8506 if (this._sortFn) { |
| 7659 this._applySplicesUserSort(this._keySplices); | 8507 this._applySplicesUserSort(this._keySplices); |
| 7660 } else { | 8508 } else { |
| 7661 if (this._filterFn) { | 8509 if (this._filterFn) { |
| 7662 this._applyFullRefresh(); | 8510 this._applyFullRefresh(); |
| 7663 } else { | 8511 } else { |
| 7664 this._applySplicesArrayOrder(this._indexSplices); | 8512 this._applySplicesArrayOrder(this._indexSplices); |
| 7665 } | 8513 } |
| 7666 } | 8514 } |
| 8515 } else { |
| 7667 } | 8516 } |
| 7668 this._keySplices = []; | 8517 this._keySplices = []; |
| 7669 this._indexSplices = []; | 8518 this._indexSplices = []; |
| 7670 var keyToIdx = this._keyToInstIdx = {}; | 8519 var keyToIdx = this._keyToInstIdx = {}; |
| 7671 for (var i = 0; i < this._instances.length; i++) { | 8520 for (var i = this._instances.length - 1; i >= 0; i--) { |
| 7672 var inst = this._instances[i]; | 8521 var inst = this._instances[i]; |
| 8522 if (inst.isPlaceholder && i < this._limit) { |
| 8523 inst = this._insertInstance(i, inst.__key__); |
| 8524 } else if (!inst.isPlaceholder && i >= this._limit) { |
| 8525 inst = this._downgradeInstance(i, inst.__key__); |
| 8526 } |
| 7673 keyToIdx[inst.__key__] = i; | 8527 keyToIdx[inst.__key__] = i; |
| 8528 if (!inst.isPlaceholder) { |
| 7674 inst.__setProperty(this.indexAs, i, true); | 8529 inst.__setProperty(this.indexAs, i, true); |
| 7675 } | 8530 } |
| 8531 } |
| 8532 this._pool.length = 0; |
| 7676 this.fire('dom-change'); | 8533 this.fire('dom-change'); |
| 8534 this._tryRenderChunk(); |
| 7677 }, | 8535 }, |
| 7678 _applyFullRefresh: function () { | 8536 _applyFullRefresh: function () { |
| 7679 var c = this.collection; | 8537 var c = this.collection; |
| 7680 var keys; | 8538 var keys; |
| 7681 if (this._sortFn) { | 8539 if (this._sortFn) { |
| 7682 keys = c ? c.getKeys() : []; | 8540 keys = c ? c.getKeys() : []; |
| 7683 } else { | 8541 } else { |
| 7684 keys = []; | 8542 keys = []; |
| 7685 var items = this.items; | 8543 var items = this.items; |
| 7686 if (items) { | 8544 if (items) { |
| 7687 for (var i = 0; i < items.length; i++) { | 8545 for (var i = 0; i < items.length; i++) { |
| 7688 keys.push(c.getKey(items[i])); | 8546 keys.push(c.getKey(items[i])); |
| 7689 } | 8547 } |
| 7690 } | 8548 } |
| 7691 } | 8549 } |
| 8550 var self = this; |
| 7692 if (this._filterFn) { | 8551 if (this._filterFn) { |
| 7693 keys = keys.filter(function (a) { | 8552 keys = keys.filter(function (a) { |
| 7694 return this._filterFn(c.getItem(a)); | 8553 return self._filterFn(c.getItem(a)); |
| 7695 }, this); | 8554 }); |
| 7696 } | 8555 } |
| 7697 if (this._sortFn) { | 8556 if (this._sortFn) { |
| 7698 keys.sort(function (a, b) { | 8557 keys.sort(function (a, b) { |
| 7699 return this._sortFn(c.getItem(a), c.getItem(b)); | 8558 return self._sortFn(c.getItem(a), c.getItem(b)); |
| 7700 }.bind(this)); | 8559 }); |
| 7701 } | 8560 } |
| 7702 for (var i = 0; i < keys.length; i++) { | 8561 for (var i = 0; i < keys.length; i++) { |
| 7703 var key = keys[i]; | 8562 var key = keys[i]; |
| 7704 var inst = this._instances[i]; | 8563 var inst = this._instances[i]; |
| 7705 if (inst) { | 8564 if (inst) { |
| 7706 inst.__setProperty('__key__', key, true); | 8565 inst.__key__ = key; |
| 8566 if (!inst.isPlaceholder && i < this._limit) { |
| 7707 inst.__setProperty(this.as, c.getItem(key), true); | 8567 inst.__setProperty(this.as, c.getItem(key), true); |
| 8568 } |
| 8569 } else if (i < this._limit) { |
| 8570 this._insertInstance(i, key); |
| 7708 } else { | 8571 } else { |
| 7709 this._instances.push(this._insertRow(i, key)); | 8572 this._insertPlaceholder(i, key); |
| 7710 } | 8573 } |
| 7711 } | 8574 } |
| 7712 for (; i < this._instances.length; i++) { | 8575 for (var j = this._instances.length - 1; j >= i; j--) { |
| 7713 this._detachRow(i); | 8576 this._detachAndRemoveInstance(j); |
| 7714 } | 8577 } |
| 7715 this._instances.splice(keys.length, this._instances.length - keys.length); | |
| 7716 }, | |
| 7717 _keySort: function (a, b) { | |
| 7718 return this.collection.getKey(a) - this.collection.getKey(b); | |
| 7719 }, | 8578 }, |
| 7720 _numericSort: function (a, b) { | 8579 _numericSort: function (a, b) { |
| 7721 return a - b; | 8580 return a - b; |
| 7722 }, | 8581 }, |
| 7723 _applySplicesUserSort: function (splices) { | 8582 _applySplicesUserSort: function (splices) { |
| 7724 var c = this.collection; | 8583 var c = this.collection; |
| 7725 var instances = this._instances; | 8584 var instances = this._instances; |
| 7726 var keyMap = {}; | 8585 var keyMap = {}; |
| 7727 var pool = []; | 8586 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { |
| 7728 var sortFn = this._sortFn || this._keySort.bind(this); | 8587 for (var j = 0; j < s.removed.length; j++) { |
| 7729 splices.forEach(function (s) { | 8588 var key = s.removed[j]; |
| 7730 for (var i = 0; i < s.removed.length; i++) { | |
| 7731 var key = s.removed[i]; | |
| 7732 keyMap[key] = keyMap[key] ? null : -1; | 8589 keyMap[key] = keyMap[key] ? null : -1; |
| 7733 } | 8590 } |
| 7734 for (var i = 0; i < s.added.length; i++) { | 8591 for (var j = 0; j < s.added.length; j++) { |
| 7735 var key = s.added[i]; | 8592 var key = s.added[j]; |
| 7736 keyMap[key] = keyMap[key] ? null : 1; | 8593 keyMap[key] = keyMap[key] ? null : 1; |
| 7737 } | 8594 } |
| 7738 }, this); | 8595 } |
| 7739 var removedIdxs = []; | 8596 var removedIdxs = []; |
| 7740 var addedKeys = []; | 8597 var addedKeys = []; |
| 7741 for (var key in keyMap) { | 8598 for (var key in keyMap) { |
| 7742 if (keyMap[key] === -1) { | 8599 if (keyMap[key] === -1) { |
| 7743 removedIdxs.push(this._keyToInstIdx[key]); | 8600 removedIdxs.push(this._keyToInstIdx[key]); |
| 7744 } | 8601 } |
| 7745 if (keyMap[key] === 1) { | 8602 if (keyMap[key] === 1) { |
| 7746 addedKeys.push(key); | 8603 addedKeys.push(key); |
| 7747 } | 8604 } |
| 7748 } | 8605 } |
| 7749 if (removedIdxs.length) { | 8606 if (removedIdxs.length) { |
| 7750 removedIdxs.sort(this._numericSort); | 8607 removedIdxs.sort(this._numericSort); |
| 7751 for (var i = removedIdxs.length - 1; i >= 0; i--) { | 8608 for (var i = removedIdxs.length - 1; i >= 0; i--) { |
| 7752 var idx = removedIdxs[i]; | 8609 var idx = removedIdxs[i]; |
| 7753 if (idx !== undefined) { | 8610 if (idx !== undefined) { |
| 7754 pool.push(this._detachRow(idx)); | 8611 this._detachAndRemoveInstance(idx); |
| 7755 instances.splice(idx, 1); | |
| 7756 } | 8612 } |
| 7757 } | 8613 } |
| 7758 } | 8614 } |
| 8615 var self = this; |
| 7759 if (addedKeys.length) { | 8616 if (addedKeys.length) { |
| 7760 if (this._filterFn) { | 8617 if (this._filterFn) { |
| 7761 addedKeys = addedKeys.filter(function (a) { | 8618 addedKeys = addedKeys.filter(function (a) { |
| 7762 return this._filterFn(c.getItem(a)); | 8619 return self._filterFn(c.getItem(a)); |
| 7763 }, this); | 8620 }); |
| 7764 } | 8621 } |
| 7765 addedKeys.sort(function (a, b) { | 8622 addedKeys.sort(function (a, b) { |
| 7766 return this._sortFn(c.getItem(a), c.getItem(b)); | 8623 return self._sortFn(c.getItem(a), c.getItem(b)); |
| 7767 }.bind(this)); | 8624 }); |
| 7768 var start = 0; | 8625 var start = 0; |
| 7769 for (var i = 0; i < addedKeys.length; i++) { | 8626 for (var i = 0; i < addedKeys.length; i++) { |
| 7770 start = this._insertRowUserSort(start, addedKeys[i], pool); | 8627 start = this._insertRowUserSort(start, addedKeys[i]); |
| 7771 } | 8628 } |
| 7772 } | 8629 } |
| 7773 }, | 8630 }, |
| 7774 _insertRowUserSort: function (start, key, pool) { | 8631 _insertRowUserSort: function (start, key) { |
| 7775 var c = this.collection; | 8632 var c = this.collection; |
| 7776 var item = c.getItem(key); | 8633 var item = c.getItem(key); |
| 7777 var end = this._instances.length - 1; | 8634 var end = this._instances.length - 1; |
| 7778 var idx = -1; | 8635 var idx = -1; |
| 7779 var sortFn = this._sortFn || this._keySort.bind(this); | |
| 7780 while (start <= end) { | 8636 while (start <= end) { |
| 7781 var mid = start + end >> 1; | 8637 var mid = start + end >> 1; |
| 7782 var midKey = this._instances[mid].__key__; | 8638 var midKey = this._instances[mid].__key__; |
| 7783 var cmp = sortFn(c.getItem(midKey), item); | 8639 var cmp = this._sortFn(c.getItem(midKey), item); |
| 7784 if (cmp < 0) { | 8640 if (cmp < 0) { |
| 7785 start = mid + 1; | 8641 start = mid + 1; |
| 7786 } else if (cmp > 0) { | 8642 } else if (cmp > 0) { |
| 7787 end = mid - 1; | 8643 end = mid - 1; |
| 7788 } else { | 8644 } else { |
| 7789 idx = mid; | 8645 idx = mid; |
| 7790 break; | 8646 break; |
| 7791 } | 8647 } |
| 7792 } | 8648 } |
| 7793 if (idx < 0) { | 8649 if (idx < 0) { |
| 7794 idx = end + 1; | 8650 idx = end + 1; |
| 7795 } | 8651 } |
| 7796 this._instances.splice(idx, 0, this._insertRow(idx, key, pool)); | 8652 this._insertPlaceholder(idx, key); |
| 7797 return idx; | 8653 return idx; |
| 7798 }, | 8654 }, |
| 7799 _applySplicesArrayOrder: function (splices) { | 8655 _applySplicesArrayOrder: function (splices) { |
| 7800 var pool = []; | |
| 7801 var c = this.collection; | 8656 var c = this.collection; |
| 7802 splices.forEach(function (s) { | 8657 for (var i = 0, s; i < splices.length && (s = splices[i]); i++) { |
| 7803 for (var i = 0; i < s.removed.length; i++) { | 8658 for (var j = 0; j < s.removed.length; j++) { |
| 7804 var inst = this._detachRow(s.index + i); | 8659 this._detachAndRemoveInstance(s.index); |
| 7805 if (!inst.isPlaceholder) { | |
| 7806 pool.push(inst); | |
| 7807 } | 8660 } |
| 7808 } | 8661 for (var j = 0; j < s.addedKeys.length; j++) { |
| 7809 this._instances.splice(s.index, s.removed.length); | 8662 this._insertPlaceholder(s.index + j, s.addedKeys[j]); |
| 7810 for (var i = 0; i < s.addedKeys.length; i++) { | |
| 7811 var inst = { | |
| 7812 isPlaceholder: true, | |
| 7813 key: s.addedKeys[i] | |
| 7814 }; | |
| 7815 this._instances.splice(s.index + i, 0, inst); | |
| 7816 } | |
| 7817 }, this); | |
| 7818 for (var i = this._instances.length - 1; i >= 0; i--) { | |
| 7819 var inst = this._instances[i]; | |
| 7820 if (inst.isPlaceholder) { | |
| 7821 this._instances[i] = this._insertRow(i, inst.key, pool, true); | |
| 7822 } | 8663 } |
| 7823 } | 8664 } |
| 7824 }, | 8665 }, |
| 7825 _detachRow: function (idx) { | 8666 _detachInstance: function (idx) { |
| 7826 var inst = this._instances[idx]; | 8667 var inst = this._instances[idx]; |
| 7827 if (!inst.isPlaceholder) { | 8668 if (!inst.isPlaceholder) { |
| 7828 var parentNode = Polymer.dom(this).parentNode; | |
| 7829 for (var i = 0; i < inst._children.length; i++) { | 8669 for (var i = 0; i < inst._children.length; i++) { |
| 7830 var el = inst._children[i]; | 8670 var el = inst._children[i]; |
| 7831 Polymer.dom(inst.root).appendChild(el); | 8671 Polymer.dom(inst.root).appendChild(el); |
| 7832 } | 8672 } |
| 8673 return inst; |
| 7833 } | 8674 } |
| 7834 return inst; | |
| 7835 }, | 8675 }, |
| 7836 _insertRow: function (idx, key, pool, replace) { | 8676 _attachInstance: function (idx, parent) { |
| 7837 var inst; | 8677 var inst = this._instances[idx]; |
| 7838 if (inst = pool && pool.pop()) { | 8678 if (!inst.isPlaceholder) { |
| 8679 parent.insertBefore(inst.root, this); |
| 8680 } |
| 8681 }, |
| 8682 _detachAndRemoveInstance: function (idx) { |
| 8683 var inst = this._detachInstance(idx); |
| 8684 if (inst) { |
| 8685 this._pool.push(inst); |
| 8686 } |
| 8687 this._instances.splice(idx, 1); |
| 8688 }, |
| 8689 _insertPlaceholder: function (idx, key) { |
| 8690 this._instances.splice(idx, 0, { |
| 8691 isPlaceholder: true, |
| 8692 __key__: key |
| 8693 }); |
| 8694 }, |
| 8695 _stampInstance: function (idx, key) { |
| 8696 var model = { __key__: key }; |
| 8697 model[this.as] = this.collection.getItem(key); |
| 8698 model[this.indexAs] = idx; |
| 8699 return this.stamp(model); |
| 8700 }, |
| 8701 _insertInstance: function (idx, key) { |
| 8702 var inst = this._pool.pop(); |
| 8703 if (inst) { |
| 7839 inst.__setProperty(this.as, this.collection.getItem(key), true); | 8704 inst.__setProperty(this.as, this.collection.getItem(key), true); |
| 7840 inst.__setProperty('__key__', key, true); | 8705 inst.__setProperty('__key__', key, true); |
| 7841 } else { | 8706 } else { |
| 7842 inst = this._generateRow(idx, key); | 8707 inst = this._stampInstance(idx, key); |
| 7843 } | 8708 } |
| 7844 var beforeRow = this._instances[replace ? idx + 1 : idx]; | 8709 var beforeRow = this._instances[idx + 1]; |
| 7845 var beforeNode = beforeRow ? beforeRow._children[0] : this; | 8710 var beforeNode = beforeRow && !beforeRow.isPlaceholder ? beforeRow._children[0]
: this; |
| 7846 var parentNode = Polymer.dom(this).parentNode; | 8711 var parentNode = Polymer.dom(this).parentNode; |
| 7847 Polymer.dom(parentNode).insertBefore(inst.root, beforeNode); | 8712 Polymer.dom(parentNode).insertBefore(inst.root, beforeNode); |
| 8713 this._instances[idx] = inst; |
| 7848 return inst; | 8714 return inst; |
| 7849 }, | 8715 }, |
| 7850 _generateRow: function (idx, key) { | 8716 _downgradeInstance: function (idx, key) { |
| 7851 var model = { __key__: key }; | 8717 var inst = this._detachInstance(idx); |
| 7852 model[this.as] = this.collection.getItem(key); | 8718 if (inst) { |
| 7853 model[this.indexAs] = idx; | 8719 this._pool.push(inst); |
| 7854 var inst = this.stamp(model); | 8720 } |
| 8721 inst = { |
| 8722 isPlaceholder: true, |
| 8723 __key__: key |
| 8724 }; |
| 8725 this._instances[idx] = inst; |
| 7855 return inst; | 8726 return inst; |
| 7856 }, | 8727 }, |
| 7857 _showHideChildren: function (hidden) { | 8728 _showHideChildren: function (hidden) { |
| 7858 for (var i = 0; i < this._instances.length; i++) { | 8729 for (var i = 0; i < this._instances.length; i++) { |
| 7859 this._instances[i]._showHideChildren(hidden); | 8730 this._instances[i]._showHideChildren(hidden); |
| 7860 } | 8731 } |
| 7861 }, | 8732 }, |
| 7862 _forwardInstanceProp: function (inst, prop, value) { | 8733 _forwardInstanceProp: function (inst, prop, value) { |
| 7863 if (prop == this.as) { | 8734 if (prop == this.as) { |
| 7864 var idx; | 8735 var idx; |
| 7865 if (this._sortFn || this._filterFn) { | 8736 if (this._sortFn || this._filterFn) { |
| 7866 idx = this.items.indexOf(this.collection.getItem(inst.__key__)); | 8737 idx = this.items.indexOf(this.collection.getItem(inst.__key__)); |
| 7867 } else { | 8738 } else { |
| 7868 idx = inst[this.indexAs]; | 8739 idx = inst[this.indexAs]; |
| 7869 } | 8740 } |
| 7870 this.set('items.' + idx, value); | 8741 this.set('items.' + idx, value); |
| 7871 } | 8742 } |
| 7872 }, | 8743 }, |
| 7873 _forwardInstancePath: function (inst, path, value) { | 8744 _forwardInstancePath: function (inst, path, value) { |
| 7874 if (path.indexOf(this.as + '.') === 0) { | 8745 if (path.indexOf(this.as + '.') === 0) { |
| 7875 this.notifyPath('items.' + inst.__key__ + '.' + path.slice(this.as.length + 1),
value); | 8746 this._notifyPath('items.' + inst.__key__ + '.' + path.slice(this.as.length + 1),
value); |
| 7876 } | 8747 } |
| 7877 }, | 8748 }, |
| 7878 _forwardParentProp: function (prop, value) { | 8749 _forwardParentProp: function (prop, value) { |
| 7879 this._instances.forEach(function (inst) { | 8750 var i$ = this._instances; |
| 8751 for (var i = 0, inst; i < i$.length && (inst = i$[i]); i++) { |
| 8752 if (!inst.isPlaceholder) { |
| 7880 inst.__setProperty(prop, value, true); | 8753 inst.__setProperty(prop, value, true); |
| 7881 }, this); | 8754 } |
| 8755 } |
| 7882 }, | 8756 }, |
| 7883 _forwardParentPath: function (path, value) { | 8757 _forwardParentPath: function (path, value) { |
| 7884 this._instances.forEach(function (inst) { | 8758 var i$ = this._instances; |
| 7885 inst.notifyPath(path, value, true); | 8759 for (var i = 0, inst; i < i$.length && (inst = i$[i]); i++) { |
| 7886 }, this); | 8760 if (!inst.isPlaceholder) { |
| 8761 inst._notifyPath(path, value, true); |
| 8762 } |
| 8763 } |
| 7887 }, | 8764 }, |
| 7888 _forwardItemPath: function (path, value) { | 8765 _forwardItemPath: function (path, value) { |
| 7889 if (this._keyToInstIdx) { | 8766 if (this._keyToInstIdx) { |
| 7890 var dot = path.indexOf('.'); | 8767 var dot = path.indexOf('.'); |
| 7891 var key = path.substring(0, dot < 0 ? path.length : dot); | 8768 var key = path.substring(0, dot < 0 ? path.length : dot); |
| 7892 var idx = this._keyToInstIdx[key]; | 8769 var idx = this._keyToInstIdx[key]; |
| 7893 var inst = this._instances[idx]; | 8770 var inst = this._instances[idx]; |
| 7894 if (inst) { | 8771 if (inst && !inst.isPlaceholder) { |
| 7895 if (dot >= 0) { | 8772 if (dot >= 0) { |
| 7896 path = this.as + '.' + path.substring(dot + 1); | 8773 path = this.as + '.' + path.substring(dot + 1); |
| 7897 inst.notifyPath(path, value, true); | 8774 inst._notifyPath(path, value, true); |
| 7898 } else { | 8775 } else { |
| 7899 inst.__setProperty(this.as, value, true); | 8776 inst.__setProperty(this.as, value, true); |
| 7900 } | 8777 } |
| 7901 } | 8778 } |
| 7902 } | 8779 } |
| 7903 }, | 8780 }, |
| 7904 itemForElement: function (el) { | 8781 itemForElement: function (el) { |
| 7905 var instance = this.modelForElement(el); | 8782 var instance = this.modelForElement(el); |
| 7906 return instance && instance[this.as]; | 8783 return instance && instance[this.as]; |
| 7907 }, | 8784 }, |
| 7908 keyForElement: function (el) { | 8785 keyForElement: function (el) { |
| 7909 var instance = this.modelForElement(el); | 8786 var instance = this.modelForElement(el); |
| 7910 return instance && instance.__key__; | 8787 return instance && instance.__key__; |
| 7911 }, | 8788 }, |
| 7912 indexForElement: function (el) { | 8789 indexForElement: function (el) { |
| 7913 var instance = this.modelForElement(el); | 8790 var instance = this.modelForElement(el); |
| 7914 return instance && instance[this.indexAs]; | 8791 return instance && instance[this.indexAs]; |
| 7915 } | 8792 } |
| 7916 }); | 8793 }); |
| 7917 Polymer({ | 8794 Polymer({ |
| 7918 is: 'array-selector', | 8795 is: 'array-selector', |
| 8796 _template: null, |
| 7919 properties: { | 8797 properties: { |
| 7920 items: { | 8798 items: { |
| 7921 type: Array, | 8799 type: Array, |
| 7922 observer: 'clearSelection' | 8800 observer: 'clearSelection' |
| 7923 }, | 8801 }, |
| 7924 multi: { | 8802 multi: { |
| 7925 type: Boolean, | 8803 type: Boolean, |
| 7926 value: false, | 8804 value: false, |
| 7927 observer: 'clearSelection' | 8805 observer: 'clearSelection' |
| 7928 }, | 8806 }, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 7939 value: false | 8817 value: false |
| 7940 } | 8818 } |
| 7941 }, | 8819 }, |
| 7942 clearSelection: function () { | 8820 clearSelection: function () { |
| 7943 if (Array.isArray(this.selected)) { | 8821 if (Array.isArray(this.selected)) { |
| 7944 for (var i = 0; i < this.selected.length; i++) { | 8822 for (var i = 0; i < this.selected.length; i++) { |
| 7945 this.unlinkPaths('selected.' + i); | 8823 this.unlinkPaths('selected.' + i); |
| 7946 } | 8824 } |
| 7947 } else { | 8825 } else { |
| 7948 this.unlinkPaths('selected'); | 8826 this.unlinkPaths('selected'); |
| 8827 this.unlinkPaths('selectedItem'); |
| 7949 } | 8828 } |
| 7950 if (this.multi) { | 8829 if (this.multi) { |
| 7951 if (!this.selected || this.selected.length) { | 8830 if (!this.selected || this.selected.length) { |
| 7952 this.selected = []; | 8831 this.selected = []; |
| 7953 this._selectedColl = Polymer.Collection.get(this.selected); | 8832 this._selectedColl = Polymer.Collection.get(this.selected); |
| 7954 } | 8833 } |
| 7955 } else { | 8834 } else { |
| 7956 this.selected = null; | 8835 this.selected = null; |
| 7957 this._selectedColl = null; | 8836 this._selectedColl = null; |
| 7958 } | 8837 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8000 this.selectedItem = item; | 8879 this.selectedItem = item; |
| 8001 this.linkPaths('selected', 'items.' + key); | 8880 this.linkPaths('selected', 'items.' + key); |
| 8002 this.linkPaths('selectedItem', 'items.' + key); | 8881 this.linkPaths('selectedItem', 'items.' + key); |
| 8003 } | 8882 } |
| 8004 } | 8883 } |
| 8005 } | 8884 } |
| 8006 }); | 8885 }); |
| 8007 Polymer({ | 8886 Polymer({ |
| 8008 is: 'dom-if', | 8887 is: 'dom-if', |
| 8009 extends: 'template', | 8888 extends: 'template', |
| 8889 _template: null, |
| 8010 properties: { | 8890 properties: { |
| 8011 'if': { | 8891 'if': { |
| 8012 type: Boolean, | 8892 type: Boolean, |
| 8013 value: false, | 8893 value: false, |
| 8014 observer: '_queueRender' | 8894 observer: '_queueRender' |
| 8015 }, | 8895 }, |
| 8016 restamp: { | 8896 restamp: { |
| 8017 type: Boolean, | 8897 type: Boolean, |
| 8018 value: false, | 8898 value: false, |
| 8019 observer: '_queueRender' | 8899 observer: '_queueRender' |
| (...skipping 27 matching lines...) Expand all Loading... |
| 8047 if (!this.restamp && this._instance) { | 8927 if (!this.restamp && this._instance) { |
| 8048 this._showHideChildren(); | 8928 this._showHideChildren(); |
| 8049 } | 8929 } |
| 8050 if (this.if != this._lastIf) { | 8930 if (this.if != this._lastIf) { |
| 8051 this.fire('dom-change'); | 8931 this.fire('dom-change'); |
| 8052 this._lastIf = this.if; | 8932 this._lastIf = this.if; |
| 8053 } | 8933 } |
| 8054 }, | 8934 }, |
| 8055 _ensureInstance: function () { | 8935 _ensureInstance: function () { |
| 8056 if (!this._instance) { | 8936 if (!this._instance) { |
| 8937 var parentNode = Polymer.dom(this).parentNode; |
| 8938 if (parentNode) { |
| 8939 var parent = Polymer.dom(parentNode); |
| 8057 this._instance = this.stamp(); | 8940 this._instance = this.stamp(); |
| 8058 var root = this._instance.root; | 8941 var root = this._instance.root; |
| 8059 var parent = Polymer.dom(Polymer.dom(this).parentNode); | |
| 8060 parent.insertBefore(root, this); | 8942 parent.insertBefore(root, this); |
| 8061 } | 8943 } |
| 8944 } |
| 8062 }, | 8945 }, |
| 8063 _teardownInstance: function () { | 8946 _teardownInstance: function () { |
| 8064 if (this._instance) { | 8947 if (this._instance) { |
| 8065 var c = this._instance._children; | 8948 var c$ = this._instance._children; |
| 8066 if (c) { | 8949 if (c$) { |
| 8067 var parent = Polymer.dom(Polymer.dom(c[0]).parentNode); | 8950 var parent = Polymer.dom(Polymer.dom(c$[0]).parentNode); |
| 8068 c.forEach(function (n) { | 8951 for (var i = 0, n; i < c$.length && (n = c$[i]); i++) { |
| 8069 parent.removeChild(n); | 8952 parent.removeChild(n); |
| 8070 }); | 8953 } |
| 8071 } | 8954 } |
| 8072 this._instance = null; | 8955 this._instance = null; |
| 8073 } | 8956 } |
| 8074 }, | 8957 }, |
| 8075 _showHideChildren: function () { | 8958 _showHideChildren: function () { |
| 8076 var hidden = this.__hideTemplateChildren__ || !this.if; | 8959 var hidden = this.__hideTemplateChildren__ || !this.if; |
| 8077 if (this._instance) { | 8960 if (this._instance) { |
| 8078 this._instance._showHideChildren(hidden); | 8961 this._instance._showHideChildren(hidden); |
| 8079 } | 8962 } |
| 8080 }, | 8963 }, |
| 8081 _forwardParentProp: function (prop, value) { | 8964 _forwardParentProp: function (prop, value) { |
| 8082 if (this._instance) { | 8965 if (this._instance) { |
| 8083 this._instance[prop] = value; | 8966 this._instance[prop] = value; |
| 8084 } | 8967 } |
| 8085 }, | 8968 }, |
| 8086 _forwardParentPath: function (path, value) { | 8969 _forwardParentPath: function (path, value) { |
| 8087 if (this._instance) { | 8970 if (this._instance) { |
| 8088 this._instance.notifyPath(path, value, true); | 8971 this._instance._notifyPath(path, value, true); |
| 8089 } | 8972 } |
| 8090 } | 8973 } |
| 8091 }); | 8974 }); |
| 8092 Polymer({ | 8975 Polymer({ |
| 8093 is: 'dom-bind', | 8976 is: 'dom-bind', |
| 8094 extends: 'template', | 8977 extends: 'template', |
| 8978 _template: null, |
| 8095 created: function () { | 8979 created: function () { |
| 8096 Polymer.RenderStatus.whenReady(this._markImportsReady.bind(this)); | 8980 var self = this; |
| 8981 Polymer.RenderStatus.whenReady(function () { |
| 8982 self._markImportsReady(); |
| 8983 }); |
| 8097 }, | 8984 }, |
| 8098 _ensureReady: function () { | 8985 _ensureReady: function () { |
| 8099 if (!this._readied) { | 8986 if (!this._readied) { |
| 8100 this._readySelf(); | 8987 this._readySelf(); |
| 8101 } | 8988 } |
| 8102 }, | 8989 }, |
| 8103 _markImportsReady: function () { | 8990 _markImportsReady: function () { |
| 8104 this._importsReady = true; | 8991 this._importsReady = true; |
| 8105 this._ensureReady(); | 8992 this._ensureReady(); |
| 8106 }, | 8993 }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 8125 return this.dataHost._scopeElementClass(element, selector); | 9012 return this.dataHost._scopeElementClass(element, selector); |
| 8126 } else { | 9013 } else { |
| 8127 return selector; | 9014 return selector; |
| 8128 } | 9015 } |
| 8129 }, | 9016 }, |
| 8130 _prepConfigure: function () { | 9017 _prepConfigure: function () { |
| 8131 var config = {}; | 9018 var config = {}; |
| 8132 for (var prop in this._propertyEffects) { | 9019 for (var prop in this._propertyEffects) { |
| 8133 config[prop] = this[prop]; | 9020 config[prop] = this[prop]; |
| 8134 } | 9021 } |
| 8135 this._setupConfigure = this._setupConfigure.bind(this, config); | 9022 var setupConfigure = this._setupConfigure; |
| 9023 this._setupConfigure = function () { |
| 9024 setupConfigure.call(this, config); |
| 9025 }; |
| 8136 }, | 9026 }, |
| 8137 attached: function () { | 9027 attached: function () { |
| 8138 if (this._importsReady) { | 9028 if (this._importsReady) { |
| 8139 this.render(); | 9029 this.render(); |
| 8140 } | 9030 } |
| 8141 }, | 9031 }, |
| 8142 detached: function () { | 9032 detached: function () { |
| 8143 this._removeChildren(); | 9033 this._removeChildren(); |
| 8144 }, | 9034 }, |
| 8145 render: function () { | 9035 render: function () { |
| 8146 this._ensureReady(); | 9036 this._ensureReady(); |
| 8147 if (!this._children) { | 9037 if (!this._children) { |
| 8148 this._template = this; | 9038 this._template = this; |
| 8149 this._prepAnnotations(); | 9039 this._prepAnnotations(); |
| 8150 this._prepEffects(); | 9040 this._prepEffects(); |
| 8151 this._prepBehaviors(); | 9041 this._prepBehaviors(); |
| 8152 this._prepConfigure(); | 9042 this._prepConfigure(); |
| 8153 this._prepBindings(); | 9043 this._prepBindings(); |
| 9044 this._prepPropertyInfo(); |
| 8154 Polymer.Base._initFeatures.call(this); | 9045 Polymer.Base._initFeatures.call(this); |
| 8155 this._children = Array.prototype.slice.call(this.root.childNodes); | 9046 this._children = Polymer.DomApi.arrayCopyChildNodes(this.root); |
| 8156 } | 9047 } |
| 8157 this._insertChildren(); | 9048 this._insertChildren(); |
| 8158 this.fire('dom-change'); | 9049 this.fire('dom-change'); |
| 8159 } | 9050 } |
| 8160 }); | 9051 }); |
| 8161 /** | 9052 /** |
| 8162 * `IronResizableBehavior` is a behavior that can be used in Polymer elements
to | 9053 * `IronResizableBehavior` is a behavior that can be used in Polymer elements
to |
| 8163 * coordinate the flow of resize events between "resizers" (elements that cont
rol the | 9054 * coordinate the flow of resize events between "resizers" (elements that cont
rol the |
| 8164 * size or hidden state of their children) and "resizables" (elements that nee
d to be | 9055 * size or hidden state of their children) and "resizables" (elements that nee
d to be |
| 8165 * notified when they are resized or un-hidden by their parents in order to ta
ke | 9056 * notified when they are resized or un-hidden by their parents in order to ta
ke |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8333 | 9224 |
| 8334 this._notifyingDescendant = true; | 9225 this._notifyingDescendant = true; |
| 8335 descendant.notifyResize(); | 9226 descendant.notifyResize(); |
| 8336 this._notifyingDescendant = false; | 9227 this._notifyingDescendant = false; |
| 8337 } | 9228 } |
| 8338 }; | 9229 }; |
| 8339 (function() { | 9230 (function() { |
| 8340 | 9231 |
| 8341 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); | 9232 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); |
| 8342 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; | 9233 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; |
| 8343 var DEFAULT_PHYSICAL_COUNT = 20; | 9234 var DEFAULT_PHYSICAL_COUNT = 3; |
| 8344 var MAX_PHYSICAL_COUNT = 500; | 9235 var MAX_PHYSICAL_COUNT = 500; |
| 8345 | 9236 |
| 8346 Polymer({ | 9237 Polymer({ |
| 8347 | 9238 |
| 8348 is: 'iron-list', | 9239 is: 'iron-list', |
| 8349 | 9240 |
| 8350 properties: { | 9241 properties: { |
| 8351 | 9242 |
| 8352 /** | 9243 /** |
| 8353 * An array containing items determining how many instances of the templat
e | 9244 * An array containing items determining how many instances of the templat
e |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8516 * The estimated scroll height based on `_physicalAverage` | 9407 * The estimated scroll height based on `_physicalAverage` |
| 8517 */ | 9408 */ |
| 8518 _estScrollHeight: 0, | 9409 _estScrollHeight: 0, |
| 8519 | 9410 |
| 8520 /** | 9411 /** |
| 8521 * The scroll height of the dom node | 9412 * The scroll height of the dom node |
| 8522 */ | 9413 */ |
| 8523 _scrollHeight: 0, | 9414 _scrollHeight: 0, |
| 8524 | 9415 |
| 8525 /** | 9416 /** |
| 8526 * The size of the viewport | 9417 * The height of the list. This is referred as the viewport in the context o
f list. |
| 8527 */ | 9418 */ |
| 8528 _viewportSize: 0, | 9419 _viewportSize: 0, |
| 8529 | 9420 |
| 8530 /** | 9421 /** |
| 8531 * An array of DOM nodes that are currently in the tree | 9422 * An array of DOM nodes that are currently in the tree |
| 8532 * @type {?Array<!TemplatizerNode>} | 9423 * @type {?Array<!TemplatizerNode>} |
| 8533 */ | 9424 */ |
| 8534 _physicalItems: null, | 9425 _physicalItems: null, |
| 8535 | 9426 |
| 8536 /** | 9427 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 8552 */ | 9443 */ |
| 8553 _collection: null, | 9444 _collection: null, |
| 8554 | 9445 |
| 8555 /** | 9446 /** |
| 8556 * True if the current item list was rendered for the first time | 9447 * True if the current item list was rendered for the first time |
| 8557 * after attached. | 9448 * after attached. |
| 8558 */ | 9449 */ |
| 8559 _itemsRendered: false, | 9450 _itemsRendered: false, |
| 8560 | 9451 |
| 8561 /** | 9452 /** |
| 9453 * The page that is currently rendered. |
| 9454 */ |
| 9455 _lastPage: null, |
| 9456 |
| 9457 /** |
| 9458 * The max number of pages to render. One page is equivalent to the height o
f the list. |
| 9459 */ |
| 9460 _maxPages: 3, |
| 9461 |
| 9462 /** |
| 8562 * The bottom of the physical content. | 9463 * The bottom of the physical content. |
| 8563 */ | 9464 */ |
| 8564 get _physicalBottom() { | 9465 get _physicalBottom() { |
| 8565 return this._physicalTop + this._physicalSize; | 9466 return this._physicalTop + this._physicalSize; |
| 8566 }, | 9467 }, |
| 8567 | 9468 |
| 8568 /** | 9469 /** |
| 9470 * The bottom of the scroll. |
| 9471 */ |
| 9472 get _scrollBottom() { |
| 9473 return this._scrollPosition + this._viewportSize; |
| 9474 }, |
| 9475 |
| 9476 /** |
| 8569 * The n-th item rendered in the last physical item. | 9477 * The n-th item rendered in the last physical item. |
| 8570 */ | 9478 */ |
| 8571 get _virtualEnd() { | 9479 get _virtualEnd() { |
| 8572 return this._virtualStartVal + this._physicalCount - 1; | 9480 return this._virtualStartVal + this._physicalCount - 1; |
| 8573 }, | 9481 }, |
| 8574 | 9482 |
| 8575 /** | 9483 /** |
| 8576 * The lowest n-th value for an item such that it can be rendered in `_physi
calStart`. | 9484 * The lowest n-th value for an item such that it can be rendered in `_physi
calStart`. |
| 8577 */ | 9485 */ |
| 8578 _minVirtualStart: 0, | 9486 _minVirtualStart: 0, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8616 }, | 9524 }, |
| 8617 | 9525 |
| 8618 /** | 9526 /** |
| 8619 * An optimal physical size such that we will have enough physical items | 9527 * An optimal physical size such that we will have enough physical items |
| 8620 * to fill up the viewport and recycle when the user scrolls. | 9528 * to fill up the viewport and recycle when the user scrolls. |
| 8621 * | 9529 * |
| 8622 * This default value assumes that we will at least have the equivalent | 9530 * This default value assumes that we will at least have the equivalent |
| 8623 * to a viewport of physical items above and below the user's viewport. | 9531 * to a viewport of physical items above and below the user's viewport. |
| 8624 */ | 9532 */ |
| 8625 get _optPhysicalSize() { | 9533 get _optPhysicalSize() { |
| 8626 return this._viewportSize * 3; | 9534 return this._viewportSize * this._maxPages; |
| 8627 }, | 9535 }, |
| 8628 | 9536 |
| 8629 /** | 9537 /** |
| 8630 * True if the current list is visible. | 9538 * True if the current list is visible. |
| 8631 */ | 9539 */ |
| 8632 get _isVisible() { | 9540 get _isVisible() { |
| 8633 return this._scroller && Boolean(this._scroller.offsetWidth || this._scrol
ler.offsetHeight); | 9541 return this._scroller && Boolean(this._scroller.offsetWidth || this._scrol
ler.offsetHeight); |
| 8634 }, | 9542 }, |
| 8635 | 9543 |
| 8636 /** | 9544 /** |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8713 var scrollerStyle = window.getComputedStyle(this._scroller); | 9621 var scrollerStyle = window.getComputedStyle(this._scroller); |
| 8714 this._scrollerPaddingTop = parseInt(scrollerStyle['padding-top'], 10); | 9622 this._scrollerPaddingTop = parseInt(scrollerStyle['padding-top'], 10); |
| 8715 this._viewportSize = this._scroller.offsetHeight; | 9623 this._viewportSize = this._scroller.offsetHeight; |
| 8716 }, | 9624 }, |
| 8717 | 9625 |
| 8718 /** | 9626 /** |
| 8719 * Update the models, the position of the | 9627 * Update the models, the position of the |
| 8720 * items in the viewport and recycle tiles as needed. | 9628 * items in the viewport and recycle tiles as needed. |
| 8721 */ | 9629 */ |
| 8722 _refresh: function() { | 9630 _refresh: function() { |
| 8723 var SCROLL_DIRECTION_UP = -1; | |
| 8724 var SCROLL_DIRECTION_DOWN = 1; | |
| 8725 var SCROLL_DIRECTION_NONE = 0; | |
| 8726 | |
| 8727 // clamp the `scrollTop` value | 9631 // clamp the `scrollTop` value |
| 8728 // IE 10|11 scrollTop may go above `_maxScrollTop` | 9632 // IE 10|11 scrollTop may go above `_maxScrollTop` |
| 8729 // iOS `scrollTop` may go below 0 and above `_maxScrollTop` | 9633 // iOS `scrollTop` may go below 0 and above `_maxScrollTop` |
| 8730 var scrollTop = Math.max(0, Math.min(this._maxScrollTop, this._scroller.sc
rollTop)); | 9634 var scrollTop = Math.max(0, Math.min(this._maxScrollTop, this._scroller.sc
rollTop)); |
| 8731 | 9635 var tileHeight, tileTop, kth, recycledTileSet, scrollBottom, physicalBotto
m; |
| 8732 var tileHeight, kth, recycledTileSet; | |
| 8733 var ratio = this._ratio; | 9636 var ratio = this._ratio; |
| 8734 var delta = scrollTop - this._scrollPosition; | 9637 var delta = scrollTop - this._scrollPosition; |
| 8735 var direction = SCROLL_DIRECTION_NONE; | |
| 8736 var recycledTiles = 0; | 9638 var recycledTiles = 0; |
| 8737 var hiddenContentSize = this._hiddenContentSize; | 9639 var hiddenContentSize = this._hiddenContentSize; |
| 8738 var currentRatio = ratio; | 9640 var currentRatio = ratio; |
| 8739 var movingUp = []; | 9641 var movingUp = []; |
| 8740 | 9642 |
| 8741 // track the last `scrollTop` | 9643 // track the last `scrollTop` |
| 8742 this._scrollPosition = scrollTop; | 9644 this._scrollPosition = scrollTop; |
| 8743 | 9645 |
| 8744 // clear cached visible index | 9646 // clear cached visible index |
| 8745 this._firstVisibleIndexVal = null; | 9647 this._firstVisibleIndexVal = null; |
| 8746 | 9648 |
| 9649 scrollBottom = this._scrollBottom; |
| 9650 physicalBottom = this._physicalBottom; |
| 9651 |
| 8747 // random access | 9652 // random access |
| 8748 if (Math.abs(delta) > this._physicalSize) { | 9653 if (Math.abs(delta) > this._physicalSize) { |
| 8749 this._physicalTop += delta; | 9654 this._physicalTop += delta; |
| 8750 direction = SCROLL_DIRECTION_NONE; | |
| 8751 recycledTiles = Math.round(delta / this._physicalAverage); | 9655 recycledTiles = Math.round(delta / this._physicalAverage); |
| 8752 } | 9656 } |
| 8753 // scroll up | 9657 // scroll up |
| 8754 else if (delta < 0) { | 9658 else if (delta < 0) { |
| 8755 var topSpace = scrollTop - this._physicalTop; | 9659 var topSpace = scrollTop - this._physicalTop; |
| 8756 var virtualStart = this._virtualStart; | 9660 var virtualStart = this._virtualStart; |
| 8757 | 9661 |
| 8758 direction = SCROLL_DIRECTION_UP; | |
| 8759 recycledTileSet = []; | 9662 recycledTileSet = []; |
| 8760 | 9663 |
| 8761 kth = this._physicalEnd; | 9664 kth = this._physicalEnd; |
| 8762 currentRatio = topSpace / hiddenContentSize; | 9665 currentRatio = topSpace / hiddenContentSize; |
| 8763 | 9666 |
| 8764 // move tiles from bottom to top | 9667 // move tiles from bottom to top |
| 8765 while ( | 9668 while ( |
| 8766 // approximate `currentRatio` to `ratio` | 9669 // approximate `currentRatio` to `ratio` |
| 8767 currentRatio < ratio && | 9670 currentRatio < ratio && |
| 8768 // recycle less physical items than the total | 9671 // recycle less physical items than the total |
| 8769 recycledTiles < this._physicalCount && | 9672 recycledTiles < this._physicalCount && |
| 8770 // ensure that these recycled tiles are needed | 9673 // ensure that these recycled tiles are needed |
| 8771 virtualStart - recycledTiles > 0 | 9674 virtualStart - recycledTiles > 0 && |
| 9675 // ensure that the tile is not visible |
| 9676 physicalBottom - this._physicalSizes[kth] > scrollBottom |
| 8772 ) { | 9677 ) { |
| 8773 | 9678 |
| 8774 tileHeight = this._physicalSizes[kth] || this._physicalAverage; | 9679 tileHeight = this._physicalSizes[kth]; |
| 8775 currentRatio += tileHeight / hiddenContentSize; | 9680 currentRatio += tileHeight / hiddenContentSize; |
| 8776 | 9681 physicalBottom -= tileHeight; |
| 8777 recycledTileSet.push(kth); | 9682 recycledTileSet.push(kth); |
| 8778 recycledTiles++; | 9683 recycledTiles++; |
| 8779 kth = (kth === 0) ? this._physicalCount - 1 : kth - 1; | 9684 kth = (kth === 0) ? this._physicalCount - 1 : kth - 1; |
| 8780 } | 9685 } |
| 8781 | 9686 |
| 8782 movingUp = recycledTileSet; | 9687 movingUp = recycledTileSet; |
| 8783 recycledTiles = -recycledTiles; | 9688 recycledTiles = -recycledTiles; |
| 8784 | |
| 8785 } | 9689 } |
| 8786 // scroll down | 9690 // scroll down |
| 8787 else if (delta > 0) { | 9691 else if (delta > 0) { |
| 8788 var bottomSpace = this._physicalBottom - (scrollTop + this._viewportSize
); | 9692 var bottomSpace = physicalBottom - scrollBottom; |
| 8789 var virtualEnd = this._virtualEnd; | 9693 var virtualEnd = this._virtualEnd; |
| 8790 var lastVirtualItemIndex = this._virtualCount-1; | 9694 var lastVirtualItemIndex = this._virtualCount-1; |
| 8791 | 9695 |
| 8792 direction = SCROLL_DIRECTION_DOWN; | |
| 8793 recycledTileSet = []; | 9696 recycledTileSet = []; |
| 8794 | 9697 |
| 8795 kth = this._physicalStart; | 9698 kth = this._physicalStart; |
| 8796 currentRatio = bottomSpace / hiddenContentSize; | 9699 currentRatio = bottomSpace / hiddenContentSize; |
| 8797 | 9700 |
| 8798 // move tiles from top to bottom | 9701 // move tiles from top to bottom |
| 8799 while ( | 9702 while ( |
| 8800 // approximate `currentRatio` to `ratio` | 9703 // approximate `currentRatio` to `ratio` |
| 8801 currentRatio < ratio && | 9704 currentRatio < ratio && |
| 8802 // recycle less physical items than the total | 9705 // recycle less physical items than the total |
| 8803 recycledTiles < this._physicalCount && | 9706 recycledTiles < this._physicalCount && |
| 8804 // ensure that these recycled tiles are needed | 9707 // ensure that these recycled tiles are needed |
| 8805 virtualEnd + recycledTiles < lastVirtualItemIndex | 9708 virtualEnd + recycledTiles < lastVirtualItemIndex && |
| 9709 // ensure that the tile is not visible |
| 9710 this._physicalTop + this._physicalSizes[kth] < scrollTop |
| 8806 ) { | 9711 ) { |
| 8807 | 9712 |
| 8808 tileHeight = this._physicalSizes[kth] || this._physicalAverage; | 9713 tileHeight = this._physicalSizes[kth]; |
| 8809 currentRatio += tileHeight / hiddenContentSize; | 9714 currentRatio += tileHeight / hiddenContentSize; |
| 8810 | 9715 |
| 8811 this._physicalTop += tileHeight; | 9716 this._physicalTop += tileHeight; |
| 8812 recycledTileSet.push(kth); | 9717 recycledTileSet.push(kth); |
| 8813 recycledTiles++; | 9718 recycledTiles++; |
| 8814 kth = (kth + 1) % this._physicalCount; | 9719 kth = (kth + 1) % this._physicalCount; |
| 8815 } | 9720 } |
| 8816 } | 9721 } |
| 8817 | 9722 |
| 8818 if (recycledTiles !== 0) { | 9723 if (recycledTiles === 0) { |
| 9724 // If the list ever reach this case, the physical average is not signifi
cant enough |
| 9725 // to create all the items needed to cover the entire viewport. |
| 9726 // e.g. A few items have a height that differs from the average by serve
ral order of magnitude. |
| 9727 if (physicalBottom < scrollBottom || this._physicalTop > scrollTop) { |
| 9728 this.async(this._increasePool.bind(this, 1)); |
| 9729 } |
| 9730 } else { |
| 8819 this._virtualStart = this._virtualStart + recycledTiles; | 9731 this._virtualStart = this._virtualStart + recycledTiles; |
| 8820 this._update(recycledTileSet, movingUp); | 9732 this._update(recycledTileSet, movingUp); |
| 8821 } | 9733 } |
| 8822 }, | 9734 }, |
| 8823 | 9735 |
| 8824 /** | 9736 /** |
| 8825 * Update the list of items, starting from the `_virtualStartVal` item. | 9737 * Update the list of items, starting from the `_virtualStartVal` item. |
| 8826 * @param {!Array<number>=} itemSet | 9738 * @param {!Array<number>=} itemSet |
| 8827 * @param {!Array<number>=} movingUp | 9739 * @param {!Array<number>=} movingUp |
| 8828 */ | 9740 */ |
| 8829 _update: function(itemSet, movingUp) { | 9741 _update: function(itemSet, movingUp) { |
| 8830 // update models | 9742 // update models |
| 8831 this._assignModels(itemSet); | 9743 this._assignModels(itemSet); |
| 8832 | 9744 |
| 8833 // measure heights | 9745 // measure heights |
| 8834 this._updateMetrics(itemSet); | 9746 this._updateMetrics(itemSet); |
| 8835 | 9747 |
| 8836 // adjust offset after measuring | 9748 // adjust offset after measuring |
| 8837 if (movingUp) { | 9749 if (movingUp) { |
| 8838 while (movingUp.length) { | 9750 while (movingUp.length) { |
| 8839 this._physicalTop -= this._physicalSizes[movingUp.pop()]; | 9751 this._physicalTop -= this._physicalSizes[movingUp.pop()]; |
| 8840 } | 9752 } |
| 8841 } | 9753 } |
| 8842 // update the position of the items | 9754 // update the position of the items |
| 8843 this._positionItems(); | 9755 this._positionItems(); |
| 8844 | 9756 |
| 8845 // set the scroller size | 9757 // set the scroller size |
| 8846 this._updateScrollerSize(); | 9758 this._updateScrollerSize(); |
| 8847 | 9759 |
| 8848 // increase the pool of physical items if needed | 9760 // increase the pool of physical items |
| 8849 if (this._increasePoolIfNeeded()) { | 9761 this._increasePoolIfNeeded(); |
| 8850 // set models to the new items | |
| 8851 this.async(this._update); | |
| 8852 } | |
| 8853 }, | 9762 }, |
| 8854 | 9763 |
| 8855 /** | 9764 /** |
| 8856 * Creates a pool of DOM elements and attaches them to the local dom. | 9765 * Creates a pool of DOM elements and attaches them to the local dom. |
| 8857 */ | 9766 */ |
| 8858 _createPool: function(size) { | 9767 _createPool: function(size) { |
| 8859 var physicalItems = new Array(size); | 9768 var physicalItems = new Array(size); |
| 8860 | 9769 |
| 8861 this._ensureTemplatized(); | 9770 this._ensureTemplatized(); |
| 8862 | 9771 |
| 8863 for (var i = 0; i < size; i++) { | 9772 for (var i = 0; i < size; i++) { |
| 8864 var inst = this.stamp(null); | 9773 var inst = this.stamp(null); |
| 8865 | |
| 8866 // First element child is item; Safari doesn't support children[0] | 9774 // First element child is item; Safari doesn't support children[0] |
| 8867 // on a doc fragment | 9775 // on a doc fragment |
| 8868 physicalItems[i] = inst.root.querySelector('*'); | 9776 physicalItems[i] = inst.root.querySelector('*'); |
| 8869 Polymer.dom(this).appendChild(inst.root); | 9777 Polymer.dom(this).appendChild(inst.root); |
| 8870 } | 9778 } |
| 8871 | 9779 |
| 8872 return physicalItems; | 9780 return physicalItems; |
| 8873 }, | 9781 }, |
| 8874 | 9782 |
| 8875 /** | 9783 /** |
| 8876 * Increases the pool size. That is, the physical items in the DOM. | 9784 * Increases the pool of physical items only if needed. |
| 8877 * This function will allocate additional physical items | 9785 * This function will allocate additional physical items |
| 8878 * (limited by `MAX_PHYSICAL_COUNT`) if the content size is shorter than | 9786 * if the physical size is shorter than `_optPhysicalSize` |
| 8879 * `_optPhysicalSize` | |
| 8880 * | |
| 8881 * @return boolean | |
| 8882 */ | 9787 */ |
| 8883 _increasePoolIfNeeded: function() { | 9788 _increasePoolIfNeeded: function() { |
| 8884 if (this._physicalSize >= this._optPhysicalSize || this._physicalAverage =
== 0) { | 9789 if (this._viewportSize !== 0 && this._physicalSize < this._optPhysicalSize
) { |
| 8885 return false; | 9790 // 0 <= `currentPage` <= `_maxPages` |
| 9791 var currentPage = Math.floor(this._physicalSize / this._viewportSize); |
| 9792 |
| 9793 if (currentPage === 0) { |
| 9794 // fill the first page |
| 9795 this.async(this._increasePool.bind(this, Math.round(this._physicalCoun
t * 0.5))); |
| 9796 } else if (this._lastPage !== currentPage) { |
| 9797 // once a page is filled up, paint it and defer the next increase |
| 9798 requestAnimationFrame(this._increasePool.bind(this, 1)); |
| 9799 } else { |
| 9800 // fill the rest of the pages |
| 9801 this.async(this._increasePool.bind(this, 1)); |
| 9802 } |
| 9803 this._lastPage = currentPage; |
| 9804 return true; |
| 8886 } | 9805 } |
| 9806 return false; |
| 9807 }, |
| 8887 | 9808 |
| 8888 // the estimated number of physical items that we will need to reach | 9809 /** |
| 8889 // the cap established by `_optPhysicalSize`. | 9810 * Increases the pool size. |
| 8890 var missingItems = Math.round( | 9811 */ |
| 8891 (this._optPhysicalSize - this._physicalSize) * 1.2 / this._physicalAve
rage | 9812 _increasePool: function(missingItems) { |
| 8892 ); | |
| 8893 | |
| 8894 // limit the size | 9813 // limit the size |
| 8895 var nextPhysicalCount = Math.min( | 9814 var nextPhysicalCount = Math.min( |
| 8896 this._physicalCount + missingItems, | 9815 this._physicalCount + missingItems, |
| 8897 this._virtualCount, | 9816 this._virtualCount, |
| 8898 MAX_PHYSICAL_COUNT | 9817 MAX_PHYSICAL_COUNT |
| 8899 ); | 9818 ); |
| 8900 | |
| 8901 var prevPhysicalCount = this._physicalCount; | 9819 var prevPhysicalCount = this._physicalCount; |
| 8902 var delta = nextPhysicalCount - prevPhysicalCount; | 9820 var delta = nextPhysicalCount - prevPhysicalCount; |
| 8903 | 9821 |
| 8904 if (delta <= 0) { | 9822 if (delta > 0) { |
| 8905 return false; | 9823 [].push.apply(this._physicalItems, this._createPool(delta)); |
| 9824 [].push.apply(this._physicalSizes, new Array(delta)); |
| 9825 |
| 9826 this._physicalCount = prevPhysicalCount + delta; |
| 9827 // tail call |
| 9828 return this._update(); |
| 8906 } | 9829 } |
| 8907 | |
| 8908 var newPhysicalItems = this._createPool(delta); | |
| 8909 var emptyArray = new Array(delta); | |
| 8910 | |
| 8911 [].push.apply(this._physicalItems, newPhysicalItems); | |
| 8912 [].push.apply(this._physicalSizes, emptyArray); | |
| 8913 | |
| 8914 this._physicalCount = prevPhysicalCount + delta; | |
| 8915 | |
| 8916 return true; | |
| 8917 }, | 9830 }, |
| 8918 | 9831 |
| 8919 /** | 9832 /** |
| 8920 * Render a new list of items. This method does exactly the same as `update`
, | 9833 * Render a new list of items. This method does exactly the same as `update`
, |
| 8921 * but it also ensures that only one `update` cycle is created. | 9834 * but it also ensures that only one `update` cycle is created. |
| 8922 */ | 9835 */ |
| 8923 _render: function() { | 9836 _render: function() { |
| 8924 var requiresUpdate = this._virtualCount > 0 || this._physicalCount > 0; | 9837 var requiresUpdate = this._virtualCount > 0 || this._physicalCount > 0; |
| 8925 | 9838 |
| 8926 if (this.isAttached && !this._itemsRendered && this._isVisible && requires
Update) { | 9839 if (this.isAttached && !this._itemsRendered && this._isVisible && requires
Update) { |
| 9840 this._lastPage = 0; |
| 8927 this._update(); | 9841 this._update(); |
| 8928 this._itemsRendered = true; | 9842 this._itemsRendered = true; |
| 8929 } | 9843 } |
| 8930 }, | 9844 }, |
| 8931 | 9845 |
| 8932 /** | 9846 /** |
| 8933 * Templetizes the user template. | 9847 * Templetizes the user template. |
| 8934 */ | 9848 */ |
| 8935 _ensureTemplatized: function() { | 9849 _ensureTemplatized: function() { |
| 8936 if (!this.ctor) { | 9850 if (!this.ctor) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9280 | 10194 |
| 9281 // estimate new physical offset | 10195 // estimate new physical offset |
| 9282 this._physicalTop = this._virtualStart * this._physicalAverage; | 10196 this._physicalTop = this._virtualStart * this._physicalAverage; |
| 9283 | 10197 |
| 9284 var currentTopItem = this._physicalStart; | 10198 var currentTopItem = this._physicalStart; |
| 9285 var currentVirtualItem = this._virtualStart; | 10199 var currentVirtualItem = this._virtualStart; |
| 9286 var targetOffsetTop = 0; | 10200 var targetOffsetTop = 0; |
| 9287 var hiddenContentSize = this._hiddenContentSize; | 10201 var hiddenContentSize = this._hiddenContentSize; |
| 9288 | 10202 |
| 9289 // scroll to the item as much as we can | 10203 // scroll to the item as much as we can |
| 9290 while (currentVirtualItem !== idx && targetOffsetTop < hiddenContentSize)
{ | 10204 while (currentVirtualItem < idx && targetOffsetTop < hiddenContentSize) { |
| 9291 targetOffsetTop = targetOffsetTop + this._physicalSizes[currentTopItem]; | 10205 targetOffsetTop = targetOffsetTop + this._physicalSizes[currentTopItem]; |
| 9292 currentTopItem = (currentTopItem + 1) % this._physicalCount; | 10206 currentTopItem = (currentTopItem + 1) % this._physicalCount; |
| 9293 currentVirtualItem++; | 10207 currentVirtualItem++; |
| 9294 } | 10208 } |
| 9295 | 10209 |
| 9296 // update the scroller size | 10210 // update the scroller size |
| 9297 this._updateScrollerSize(true); | 10211 this._updateScrollerSize(true); |
| 9298 | 10212 |
| 9299 // update the position of the items | 10213 // update the position of the items |
| 9300 this._positionItems(); | 10214 this._positionItems(); |
| 9301 | 10215 |
| 9302 // set the new scroll position | 10216 // set the new scroll position |
| 9303 this._resetScrollPosition(this._physicalTop + targetOffsetTop + 1); | 10217 this._resetScrollPosition(this._physicalTop + targetOffsetTop + 1); |
| 9304 | 10218 |
| 9305 // increase the pool of physical items if needed | 10219 // increase the pool of physical items if needed |
| 9306 if (this._increasePoolIfNeeded()) { | 10220 this._increasePoolIfNeeded(); |
| 9307 // set models to the new items | |
| 9308 this.async(this._update); | |
| 9309 } | |
| 9310 | 10221 |
| 9311 // clear cached visible index | 10222 // clear cached visible index |
| 9312 this._firstVisibleIndexVal = null; | 10223 this._firstVisibleIndexVal = null; |
| 9313 }, | 10224 }, |
| 9314 | 10225 |
| 9315 /** | 10226 /** |
| 9316 * Reset the physical average and the average count. | 10227 * Reset the physical average and the average count. |
| 9317 */ | 10228 */ |
| 9318 _resetAverage: function() { | 10229 _resetAverage: function() { |
| 9319 this._physicalAverage = 0; | 10230 this._physicalAverage = 0; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9481 if (pidx !== undefined) { | 10392 if (pidx !== undefined) { |
| 9482 this._updateMetrics([pidx]); | 10393 this._updateMetrics([pidx]); |
| 9483 this._positionItems(); | 10394 this._positionItems(); |
| 9484 } | 10395 } |
| 9485 } | 10396 } |
| 9486 }); | 10397 }); |
| 9487 | 10398 |
| 9488 })(); | 10399 })(); |
| 9489 (function() { | 10400 (function() { |
| 9490 | 10401 |
| 9491 'use strict'; | |
| 9492 | |
| 9493 var SHADOW_WHEN_SCROLLING = 1; | |
| 9494 var SHADOW_ALWAYS = 2; | |
| 9495 | |
| 9496 | |
| 9497 var MODE_CONFIGS = { | |
| 9498 | |
| 9499 outerScroll: { | |
| 9500 'scroll': true | |
| 9501 }, | |
| 9502 | |
| 9503 shadowMode: { | |
| 9504 'standard': SHADOW_ALWAYS, | |
| 9505 'waterfall': SHADOW_WHEN_SCROLLING, | |
| 9506 'waterfall-tall': SHADOW_WHEN_SCROLLING | |
| 9507 }, | |
| 9508 | |
| 9509 tallMode: { | |
| 9510 'waterfall-tall': true | |
| 9511 } | |
| 9512 }; | |
| 9513 | |
| 9514 Polymer({ | |
| 9515 | |
| 9516 is: 'paper-header-panel', | |
| 9517 | |
| 9518 /** | |
| 9519 * Fired when the content has been scrolled. `event.detail.target` return
s | |
| 9520 * the scrollable element which you can use to access scroll info such as | |
| 9521 * `scrollTop`. | |
| 9522 * | |
| 9523 * <paper-header-panel on-content-scroll="scrollHandler"> | |
| 9524 * ... | |
| 9525 * </paper-header-panel> | |
| 9526 * | |
| 9527 * | |
| 9528 * scrollHandler: function(event) { | |
| 9529 * var scroller = event.detail.target; | |
| 9530 * console.log(scroller.scrollTop); | |
| 9531 * } | |
| 9532 * | |
| 9533 * @event content-scroll | |
| 9534 */ | |
| 9535 | |
| 9536 properties: { | |
| 9537 | |
| 9538 /** | |
| 9539 * Controls header and scrolling behavior. Options are | |
| 9540 * `standard`, `seamed`, `waterfall`, `waterfall-tall`, `scroll` and | |
| 9541 * `cover`. Default is `standard`. | |
| 9542 * | |
| 9543 * `standard`: The header is a step above the panel. The header will con
sume the | |
| 9544 * panel at the point of entry, preventing it from passing through to th
e | |
| 9545 * opposite side. | |
| 9546 * | |
| 9547 * `seamed`: The header is presented as seamed with the panel. | |
| 9548 * | |
| 9549 * `waterfall`: Similar to standard mode, but header is initially presen
ted as | |
| 9550 * seamed with panel, but then separates to form the step. | |
| 9551 * | |
| 9552 * `waterfall-tall`: The header is initially taller (`tall` class is add
ed to | |
| 9553 * the header). As the user scrolls, the header separates (forming an e
dge) | |
| 9554 * while condensing (`tall` class is removed from the header). | |
| 9555 * | |
| 9556 * `scroll`: The header keeps its seam with the panel, and is pushed off
screen. | |
| 9557 * | |
| 9558 * `cover`: The panel covers the whole `paper-header-panel` including th
e | |
| 9559 * header. This allows user to style the panel in such a way that the pa
nel is | |
| 9560 * partially covering the header. | |
| 9561 * | |
| 9562 * <paper-header-panel mode="cover"> | |
| 9563 * <paper-toolbar class="tall"> | |
| 9564 * <core-icon-button icon="menu"></core-icon-button> | |
| 9565 * </paper-toolbar> | |
| 9566 * <div class="content"></div> | |
| 9567 * </paper-header-panel> | |
| 9568 */ | |
| 9569 mode: { | |
| 9570 type: String, | |
| 9571 value: 'standard', | |
| 9572 observer: '_modeChanged', | |
| 9573 reflectToAttribute: true | |
| 9574 }, | |
| 9575 | |
| 9576 /** | |
| 9577 * If true, the drop-shadow is always shown no matter what mode is set t
o. | |
| 9578 */ | |
| 9579 shadow: { | |
| 9580 type: Boolean, | |
| 9581 value: false | |
| 9582 }, | |
| 9583 | |
| 9584 /** | |
| 9585 * The class used in waterfall-tall mode. Change this if the header | |
| 9586 * accepts a different class for toggling height, e.g. "medium-tall" | |
| 9587 */ | |
| 9588 tallClass: { | |
| 9589 type: String, | |
| 9590 value: 'tall' | |
| 9591 }, | |
| 9592 | |
| 9593 /** | |
| 9594 * If true, the scroller is at the top | |
| 9595 */ | |
| 9596 atTop: { | |
| 9597 type: Boolean, | |
| 9598 value: true, | |
| 9599 readOnly: true | |
| 9600 } | |
| 9601 }, | |
| 9602 | |
| 9603 observers: [ | |
| 9604 '_computeDropShadowHidden(atTop, mode, shadow)' | |
| 9605 ], | |
| 9606 | |
| 9607 ready: function() { | |
| 9608 this.scrollHandler = this._scroll.bind(this); | |
| 9609 this._addListener(); | |
| 9610 | |
| 9611 // Run `scroll` logic once to initialze class names, etc. | |
| 9612 this._keepScrollingState(); | |
| 9613 }, | |
| 9614 | |
| 9615 detached: function() { | |
| 9616 this._removeListener(); | |
| 9617 }, | |
| 9618 | |
| 9619 /** | |
| 9620 * Returns the header element | |
| 9621 * | |
| 9622 * @property header | |
| 9623 * @type Object | |
| 9624 */ | |
| 9625 get header() { | |
| 9626 return Polymer.dom(this.$.headerContent).getDistributedNodes()[0]; | |
| 9627 }, | |
| 9628 | |
| 9629 /** | |
| 9630 * Returns the scrollable element. | |
| 9631 * | |
| 9632 * @property scroller | |
| 9633 * @type Object | |
| 9634 */ | |
| 9635 get scroller() { | |
| 9636 return this._getScrollerForMode(this.mode); | |
| 9637 }, | |
| 9638 | |
| 9639 /** | |
| 9640 * Returns true if the scroller has a visible shadow. | |
| 9641 * | |
| 9642 * @property visibleShadow | |
| 9643 * @type Boolean | |
| 9644 */ | |
| 9645 get visibleShadow() { | |
| 9646 return this.$.dropShadow.classList.contains('has-shadow'); | |
| 9647 }, | |
| 9648 | |
| 9649 _computeDropShadowHidden: function(atTop, mode, shadow) { | |
| 9650 | |
| 9651 var shadowMode = MODE_CONFIGS.shadowMode[mode]; | |
| 9652 | |
| 9653 if (this.shadow) { | |
| 9654 this.toggleClass('has-shadow', true, this.$.dropShadow); | |
| 9655 | |
| 9656 } else if (shadowMode === SHADOW_ALWAYS) { | |
| 9657 this.toggleClass('has-shadow', true, this.$.dropShadow); | |
| 9658 | |
| 9659 } else if (shadowMode === SHADOW_WHEN_SCROLLING && !atTop) { | |
| 9660 this.toggleClass('has-shadow', true, this.$.dropShadow); | |
| 9661 | |
| 9662 } else { | |
| 9663 this.toggleClass('has-shadow', false, this.$.dropShadow); | |
| 9664 | |
| 9665 } | |
| 9666 }, | |
| 9667 | |
| 9668 _computeMainContainerClass: function(mode) { | |
| 9669 // TODO: It will be useful to have a utility for classes | |
| 9670 // e.g. Polymer.Utils.classes({ foo: true }); | |
| 9671 | |
| 9672 var classes = {}; | |
| 9673 | |
| 9674 classes['flex'] = mode !== 'cover'; | |
| 9675 | |
| 9676 return Object.keys(classes).filter( | |
| 9677 function(className) { | |
| 9678 return classes[className]; | |
| 9679 }).join(' '); | |
| 9680 }, | |
| 9681 | |
| 9682 _addListener: function() { | |
| 9683 this.scroller.addEventListener('scroll', this.scrollHandler, false); | |
| 9684 }, | |
| 9685 | |
| 9686 _removeListener: function() { | |
| 9687 this.scroller.removeEventListener('scroll', this.scrollHandler); | |
| 9688 }, | |
| 9689 | |
| 9690 _modeChanged: function(newMode, oldMode) { | |
| 9691 var configs = MODE_CONFIGS; | |
| 9692 var header = this.header; | |
| 9693 var animateDuration = 200; | |
| 9694 | |
| 9695 if (header) { | |
| 9696 // in tallMode it may add tallClass to the header; so do the cleanup | |
| 9697 // when mode is changed from tallMode to not tallMode | |
| 9698 if (configs.tallMode[oldMode] && !configs.tallMode[newMode]) { | |
| 9699 header.classList.remove(this.tallClass); | |
| 9700 this.async(function() { | |
| 9701 header.classList.remove('animate'); | |
| 9702 }, animateDuration); | |
| 9703 } else { | |
| 9704 header.classList.toggle('animate', configs.tallMode[newMode]); | |
| 9705 } | |
| 9706 } | |
| 9707 this._keepScrollingState(); | |
| 9708 }, | |
| 9709 | |
| 9710 _keepScrollingState: function() { | |
| 9711 var main = this.scroller; | |
| 9712 var header = this.header; | |
| 9713 | |
| 9714 this._setAtTop(main.scrollTop === 0); | |
| 9715 | |
| 9716 if (header && this.tallClass && MODE_CONFIGS.tallMode[this.mode]) { | |
| 9717 this.toggleClass(this.tallClass, this.atTop || | |
| 9718 header.classList.contains(this.tallClass) && | |
| 9719 main.scrollHeight < this.offsetHeight, header); | |
| 9720 } | |
| 9721 }, | |
| 9722 | |
| 9723 _scroll: function() { | |
| 9724 this._keepScrollingState(); | |
| 9725 this.fire('content-scroll', {target: this.scroller}, {bubbles: false}); | |
| 9726 }, | |
| 9727 | |
| 9728 _getScrollerForMode: function(mode) { | |
| 9729 return MODE_CONFIGS.outerScroll[mode] ? | |
| 9730 this : this.$.mainContainer; | |
| 9731 } | |
| 9732 | |
| 9733 }); | |
| 9734 | |
| 9735 })(); | |
| 9736 (function() { | |
| 9737 | |
| 9738 // monostate data | 10402 // monostate data |
| 9739 var metaDatas = {}; | 10403 var metaDatas = {}; |
| 9740 var metaArrays = {}; | 10404 var metaArrays = {}; |
| 10405 var singleton = null; |
| 9741 | 10406 |
| 9742 Polymer.IronMeta = Polymer({ | 10407 Polymer.IronMeta = Polymer({ |
| 9743 | 10408 |
| 9744 is: 'iron-meta', | 10409 is: 'iron-meta', |
| 9745 | 10410 |
| 9746 properties: { | 10411 properties: { |
| 9747 | 10412 |
| 9748 /** | 10413 /** |
| 9749 * The type of meta-data. All meta-data of the same type is stored | 10414 * The type of meta-data. All meta-data of the same type is stored |
| 9750 * together. | 10415 * together. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9783 /** | 10448 /** |
| 9784 * Array of all meta-data values for the given type. | 10449 * Array of all meta-data values for the given type. |
| 9785 */ | 10450 */ |
| 9786 list: { | 10451 list: { |
| 9787 type: Array, | 10452 type: Array, |
| 9788 notify: true | 10453 notify: true |
| 9789 } | 10454 } |
| 9790 | 10455 |
| 9791 }, | 10456 }, |
| 9792 | 10457 |
| 10458 hostAttributes: { |
| 10459 hidden: true |
| 10460 }, |
| 10461 |
| 9793 /** | 10462 /** |
| 9794 * Only runs if someone invokes the factory/constructor directly | 10463 * Only runs if someone invokes the factory/constructor directly |
| 9795 * e.g. `new Polymer.IronMeta()` | 10464 * e.g. `new Polymer.IronMeta()` |
| 10465 * |
| 10466 * @param {{type: (string|undefined), key: (string|undefined), value}=} co
nfig |
| 9796 */ | 10467 */ |
| 9797 factoryImpl: function(config) { | 10468 factoryImpl: function(config) { |
| 9798 if (config) { | 10469 if (config) { |
| 9799 for (var n in config) { | 10470 for (var n in config) { |
| 9800 switch(n) { | 10471 switch(n) { |
| 9801 case 'type': | 10472 case 'type': |
| 9802 case 'key': | 10473 case 'key': |
| 9803 case 'value': | 10474 case 'value': |
| 9804 this[n] = config[n]; | 10475 this[n] = config[n]; |
| 9805 break; | 10476 break; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9877 if (key in data) { | 10548 if (key in data) { |
| 9878 var value = data[key]; | 10549 var value = data[key]; |
| 9879 delete data[key]; | 10550 delete data[key]; |
| 9880 this.arrayDelete(list, value); | 10551 this.arrayDelete(list, value); |
| 9881 } | 10552 } |
| 9882 } | 10553 } |
| 9883 } | 10554 } |
| 9884 | 10555 |
| 9885 }); | 10556 }); |
| 9886 | 10557 |
| 10558 Polymer.IronMeta.getIronMeta = function getIronMeta() { |
| 10559 if (singleton === null) { |
| 10560 singleton = new Polymer.IronMeta(); |
| 10561 } |
| 10562 return singleton; |
| 10563 }; |
| 10564 |
| 9887 /** | 10565 /** |
| 9888 `iron-meta-query` can be used to access infomation stored in `iron-meta`. | 10566 `iron-meta-query` can be used to access infomation stored in `iron-meta`. |
| 9889 | 10567 |
| 9890 Examples: | 10568 Examples: |
| 9891 | 10569 |
| 9892 If I create an instance like this: | 10570 If I create an instance like this: |
| 9893 | 10571 |
| 9894 <iron-meta key="info" value="foo/bar"></iron-meta> | 10572 <iron-meta key="info" value="foo/bar"></iron-meta> |
| 9895 | 10573 |
| 9896 Note that value="foo/bar" is the metadata I've defined. I could define more | 10574 Note that value="foo/bar" is the metadata I've defined. I could define more |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9943 list: { | 10621 list: { |
| 9944 type: Array, | 10622 type: Array, |
| 9945 notify: true | 10623 notify: true |
| 9946 } | 10624 } |
| 9947 | 10625 |
| 9948 }, | 10626 }, |
| 9949 | 10627 |
| 9950 /** | 10628 /** |
| 9951 * Actually a factory method, not a true constructor. Only runs if | 10629 * Actually a factory method, not a true constructor. Only runs if |
| 9952 * someone invokes it directly (via `new Polymer.IronMeta()`); | 10630 * someone invokes it directly (via `new Polymer.IronMeta()`); |
| 10631 * |
| 10632 * @param {{type: (string|undefined), key: (string|undefined)}=} config |
| 9953 */ | 10633 */ |
| 9954 factoryImpl: function(config) { | 10634 factoryImpl: function(config) { |
| 9955 if (config) { | 10635 if (config) { |
| 9956 for (var n in config) { | 10636 for (var n in config) { |
| 9957 switch(n) { | 10637 switch(n) { |
| 9958 case 'type': | 10638 case 'type': |
| 9959 case 'key': | 10639 case 'key': |
| 9960 this[n] = config[n]; | 10640 this[n] = config[n]; |
| 9961 break; | 10641 break; |
| 9962 } | 10642 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10079 } | 10759 } |
| 10080 } | 10760 } |
| 10081 | 10761 |
| 10082 }); | 10762 }); |
| 10083 /** | 10763 /** |
| 10084 * The `iron-iconset-svg` element allows users to define their own icon sets | 10764 * The `iron-iconset-svg` element allows users to define their own icon sets |
| 10085 * that contain svg icons. The svg icon elements should be children of the | 10765 * that contain svg icons. The svg icon elements should be children of the |
| 10086 * `iron-iconset-svg` element. Multiple icons should be given distinct id's. | 10766 * `iron-iconset-svg` element. Multiple icons should be given distinct id's. |
| 10087 * | 10767 * |
| 10088 * Using svg elements to create icons has a few advantages over traditional | 10768 * Using svg elements to create icons has a few advantages over traditional |
| 10089 * bitmap graphics like jpg or png. Icons that use svg are vector based so the
y | 10769 * bitmap graphics like jpg or png. Icons that use svg are vector based so |
| 10090 * are resolution independent and should look good on any device. They are | 10770 * they are resolution independent and should look good on any device. They |
| 10091 * stylable via css. Icons can be themed, colorized, and even animated. | 10771 * are stylable via css. Icons can be themed, colorized, and even animated. |
| 10092 * | 10772 * |
| 10093 * Example: | 10773 * Example: |
| 10094 * | 10774 * |
| 10095 * <iron-iconset-svg name="my-svg-icons" size="24"> | 10775 * <iron-iconset-svg name="my-svg-icons" size="24"> |
| 10096 * <svg> | 10776 * <svg> |
| 10097 * <defs> | 10777 * <defs> |
| 10098 * <g id="shape"> | 10778 * <g id="shape"> |
| 10099 * <rect x="50" y="50" width="50" height="50" /> | 10779 * <rect x="12" y="0" width="12" height="24" /> |
| 10100 * <circle cx="50" cy="50" r="50" /> | 10780 * <circle cx="12" cy="12" r="12" /> |
| 10101 * </g> | 10781 * </g> |
| 10102 * </defs> | 10782 * </defs> |
| 10103 * </svg> | 10783 * </svg> |
| 10104 * </iron-iconset-svg> | 10784 * </iron-iconset-svg> |
| 10105 * | 10785 * |
| 10106 * This will automatically register the icon set "my-svg-icons" to the iconset | 10786 * This will automatically register the icon set "my-svg-icons" to the iconset |
| 10107 * database. To use these icons from within another element, make a | 10787 * database. To use these icons from within another element, make a |
| 10108 * `iron-iconset` element and call the `byId` method | 10788 * `iron-iconset` element and call the `byId` method |
| 10109 * to retrieve a given iconset. To apply a particular icon inside an | 10789 * to retrieve a given iconset. To apply a particular icon inside an |
| 10110 * element use the `applyIcon` method. For example: | 10790 * element use the `applyIcon` method. For example: |
| 10111 * | 10791 * |
| 10112 * iconset.applyIcon(iconNode, 'car'); | 10792 * iconset.applyIcon(iconNode, 'car'); |
| 10113 * | 10793 * |
| 10114 * @element iron-iconset-svg | 10794 * @element iron-iconset-svg |
| 10115 * @demo demo/index.html | 10795 * @demo demo/index.html |
| 10796 * @implements {Polymer.Iconset} |
| 10116 */ | 10797 */ |
| 10117 Polymer({ | 10798 Polymer({ |
| 10118 | |
| 10119 is: 'iron-iconset-svg', | 10799 is: 'iron-iconset-svg', |
| 10120 | 10800 |
| 10121 properties: { | 10801 properties: { |
| 10122 | 10802 |
| 10123 /** | 10803 /** |
| 10124 * The name of the iconset. | 10804 * The name of the iconset. |
| 10125 * | |
| 10126 * @attribute name | |
| 10127 * @type string | |
| 10128 */ | 10805 */ |
| 10129 name: { | 10806 name: { |
| 10130 type: String, | 10807 type: String, |
| 10131 observer: '_nameChanged' | 10808 observer: '_nameChanged' |
| 10132 }, | 10809 }, |
| 10133 | 10810 |
| 10134 /** | 10811 /** |
| 10135 * The size of an individual icon. Note that icons must be square. | 10812 * The size of an individual icon. Note that icons must be square. |
| 10136 * | |
| 10137 * @attribute iconSize | |
| 10138 * @type number | |
| 10139 * @default 24 | |
| 10140 */ | 10813 */ |
| 10141 size: { | 10814 size: { |
| 10142 type: Number, | 10815 type: Number, |
| 10143 value: 24 | 10816 value: 24 |
| 10144 } | 10817 } |
| 10145 | 10818 |
| 10146 }, | 10819 }, |
| 10147 | 10820 |
| 10821 attached: function() { |
| 10822 this.style.display = 'none'; |
| 10823 }, |
| 10824 |
| 10148 /** | 10825 /** |
| 10149 * Construct an array of all icon names in this iconset. | 10826 * Construct an array of all icon names in this iconset. |
| 10150 * | 10827 * |
| 10151 * @return {!Array} Array of icon names. | 10828 * @return {!Array} Array of icon names. |
| 10152 */ | 10829 */ |
| 10153 getIconNames: function() { | 10830 getIconNames: function() { |
| 10154 this._icons = this._createIconMap(); | 10831 this._icons = this._createIconMap(); |
| 10155 return Object.keys(this._icons).map(function(n) { | 10832 return Object.keys(this._icons).map(function(n) { |
| 10156 return this.name + ':' + n; | 10833 return this.name + ':' + n; |
| 10157 }, this); | 10834 }, this); |
| 10158 }, | 10835 }, |
| 10159 | 10836 |
| 10160 /** | 10837 /** |
| 10161 * Applies an icon to the given element. | 10838 * Applies an icon to the given element. |
| 10162 * | 10839 * |
| 10163 * An svg icon is prepended to the element's shadowRoot if it exists, | 10840 * An svg icon is prepended to the element's shadowRoot if it exists, |
| 10164 * otherwise to the element itself. | 10841 * otherwise to the element itself. |
| 10165 * | 10842 * |
| 10166 * @method applyIcon | 10843 * @method applyIcon |
| 10167 * @param {Element} element Element to which the icon is applied. | 10844 * @param {Element} element Element to which the icon is applied. |
| 10168 * @param {string} iconName Name of the icon to apply. | 10845 * @param {string} iconName Name of the icon to apply. |
| 10169 * @return {Element} The svg element which renders the icon. | 10846 * @return {?Element} The svg element which renders the icon. |
| 10170 */ | 10847 */ |
| 10171 applyIcon: function(element, iconName) { | 10848 applyIcon: function(element, iconName) { |
| 10172 // insert svg element into shadow root, if it exists | 10849 // insert svg element into shadow root, if it exists |
| 10173 element = element.root || element; | 10850 element = element.root || element; |
| 10174 // Remove old svg element | 10851 // Remove old svg element |
| 10175 this.removeIcon(element); | 10852 this.removeIcon(element); |
| 10176 // install new svg element | 10853 // install new svg element |
| 10177 var svg = this._cloneIcon(iconName); | 10854 var svg = this._cloneIcon(iconName); |
| 10178 if (svg) { | 10855 if (svg) { |
| 10179 var pde = Polymer.dom(element); | 10856 var pde = Polymer.dom(element); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10499 /** | 11176 /** |
| 10500 * The HTMLElement that will be firing relevant KeyboardEvents. | 11177 * The HTMLElement that will be firing relevant KeyboardEvents. |
| 10501 */ | 11178 */ |
| 10502 keyEventTarget: { | 11179 keyEventTarget: { |
| 10503 type: Object, | 11180 type: Object, |
| 10504 value: function() { | 11181 value: function() { |
| 10505 return this; | 11182 return this; |
| 10506 } | 11183 } |
| 10507 }, | 11184 }, |
| 10508 | 11185 |
| 11186 /** |
| 11187 * If true, this property will cause the implementing element to |
| 11188 * automatically stop propagation on any handled KeyboardEvents. |
| 11189 */ |
| 11190 stopKeyboardEventPropagation: { |
| 11191 type: Boolean, |
| 11192 value: false |
| 11193 }, |
| 11194 |
| 10509 _boundKeyHandlers: { | 11195 _boundKeyHandlers: { |
| 10510 type: Array, | 11196 type: Array, |
| 10511 value: function() { | 11197 value: function() { |
| 10512 return []; | 11198 return []; |
| 10513 } | 11199 } |
| 10514 }, | 11200 }, |
| 10515 | 11201 |
| 10516 // We use this due to a limitation in IE10 where instances will have | 11202 // We use this due to a limitation in IE10 where instances will have |
| 10517 // own properties of everything on the "prototype". | 11203 // own properties of everything on the "prototype". |
| 10518 _imperativeKeyBindings: { | 11204 _imperativeKeyBindings: { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10642 keyHandlerTuple = this._boundKeyHandlers.pop(); | 11328 keyHandlerTuple = this._boundKeyHandlers.pop(); |
| 10643 keyEventTarget = keyHandlerTuple[0]; | 11329 keyEventTarget = keyHandlerTuple[0]; |
| 10644 eventName = keyHandlerTuple[1]; | 11330 eventName = keyHandlerTuple[1]; |
| 10645 boundKeyHandler = keyHandlerTuple[2]; | 11331 boundKeyHandler = keyHandlerTuple[2]; |
| 10646 | 11332 |
| 10647 keyEventTarget.removeEventListener(eventName, boundKeyHandler); | 11333 keyEventTarget.removeEventListener(eventName, boundKeyHandler); |
| 10648 } | 11334 } |
| 10649 }, | 11335 }, |
| 10650 | 11336 |
| 10651 _onKeyBindingEvent: function(keyBindings, event) { | 11337 _onKeyBindingEvent: function(keyBindings, event) { |
| 11338 if (this.stopKeyboardEventPropagation) { |
| 11339 event.stopPropagation(); |
| 11340 } |
| 11341 |
| 10652 keyBindings.forEach(function(keyBinding) { | 11342 keyBindings.forEach(function(keyBinding) { |
| 10653 var keyCombo = keyBinding[0]; | 11343 var keyCombo = keyBinding[0]; |
| 10654 var handlerName = keyBinding[1]; | 11344 var handlerName = keyBinding[1]; |
| 10655 | 11345 |
| 10656 if (!event.defaultPrevented && keyComboMatchesEvent(keyCombo, event))
{ | 11346 if (!event.defaultPrevented && keyComboMatchesEvent(keyCombo, event))
{ |
| 10657 this._triggerKeyHandler(keyCombo, handlerName, event); | 11347 this._triggerKeyHandler(keyCombo, handlerName, event); |
| 10658 } | 11348 } |
| 10659 }, this); | 11349 }, this); |
| 10660 }, | 11350 }, |
| 10661 | 11351 |
| 10662 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { | 11352 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { |
| 10663 var detail = Object.create(keyCombo); | 11353 var detail = Object.create(keyCombo); |
| 10664 detail.keyboardEvent = keyboardEvent; | 11354 detail.keyboardEvent = keyboardEvent; |
| 10665 | 11355 var event = new CustomEvent(keyCombo.event, { |
| 10666 this[handlerName].call(this, new CustomEvent(keyCombo.event, { | 11356 detail: detail, |
| 10667 detail: detail | 11357 cancelable: true |
| 10668 })); | 11358 }); |
| 11359 this[handlerName].call(this, event); |
| 11360 if (event.defaultPrevented) { |
| 11361 keyboardEvent.preventDefault(); |
| 11362 } |
| 10669 } | 11363 } |
| 10670 }; | 11364 }; |
| 10671 })(); | 11365 })(); |
| 10672 /** | 11366 /** |
| 10673 * @demo demo/index.html | 11367 * @demo demo/index.html |
| 10674 * @polymerBehavior | 11368 * @polymerBehavior |
| 10675 */ | 11369 */ |
| 10676 Polymer.IronControlState = { | 11370 Polymer.IronControlState = { |
| 10677 | 11371 |
| 10678 properties: { | 11372 properties: { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10722 }, | 11416 }, |
| 10723 | 11417 |
| 10724 _focusBlurHandler: function(event) { | 11418 _focusBlurHandler: function(event) { |
| 10725 // NOTE(cdata): if we are in ShadowDOM land, `event.target` will | 11419 // NOTE(cdata): if we are in ShadowDOM land, `event.target` will |
| 10726 // eventually become `this` due to retargeting; if we are not in | 11420 // eventually become `this` due to retargeting; if we are not in |
| 10727 // ShadowDOM land, `event.target` will eventually become `this` due | 11421 // ShadowDOM land, `event.target` will eventually become `this` due |
| 10728 // to the second conditional which fires a synthetic event (that is also | 11422 // to the second conditional which fires a synthetic event (that is also |
| 10729 // handled). In either case, we can disregard `event.path`. | 11423 // handled). In either case, we can disregard `event.path`. |
| 10730 | 11424 |
| 10731 if (event.target === this) { | 11425 if (event.target === this) { |
| 10732 var focused = event.type === 'focus'; | 11426 this._setFocused(event.type === 'focus'); |
| 10733 this._setFocused(focused); | 11427 } else if (!this.shadowRoot && !this.isLightDescendant(event.target)) { |
| 10734 } else if (!this.shadowRoot) { | |
| 10735 this.fire(event.type, {sourceEvent: event}, { | 11428 this.fire(event.type, {sourceEvent: event}, { |
| 10736 node: this, | 11429 node: this, |
| 10737 bubbles: event.bubbles, | 11430 bubbles: event.bubbles, |
| 10738 cancelable: event.cancelable | 11431 cancelable: event.cancelable |
| 10739 }); | 11432 }); |
| 10740 } | 11433 } |
| 10741 }, | 11434 }, |
| 10742 | 11435 |
| 10743 _disabledChanged: function(disabled, old) { | 11436 _disabledChanged: function(disabled, old) { |
| 10744 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | 11437 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10875 this._setPointerDown(true); | 11568 this._setPointerDown(true); |
| 10876 this._setPressed(true); | 11569 this._setPressed(true); |
| 10877 this._setReceivedFocusFromKeyboard(false); | 11570 this._setReceivedFocusFromKeyboard(false); |
| 10878 }, | 11571 }, |
| 10879 | 11572 |
| 10880 _upHandler: function() { | 11573 _upHandler: function() { |
| 10881 this._setPointerDown(false); | 11574 this._setPointerDown(false); |
| 10882 this._setPressed(false); | 11575 this._setPressed(false); |
| 10883 }, | 11576 }, |
| 10884 | 11577 |
| 11578 /** |
| 11579 * @param {!KeyboardEvent} event . |
| 11580 */ |
| 10885 _spaceKeyDownHandler: function(event) { | 11581 _spaceKeyDownHandler: function(event) { |
| 10886 var keyboardEvent = event.detail.keyboardEvent; | 11582 var keyboardEvent = event.detail.keyboardEvent; |
| 11583 var target = Polymer.dom(keyboardEvent).localTarget; |
| 11584 |
| 11585 // Ignore the event if this is coming from a focused light child, since th
at |
| 11586 // element will deal with it. |
| 11587 if (this.isLightDescendant(target)) |
| 11588 return; |
| 11589 |
| 10887 keyboardEvent.preventDefault(); | 11590 keyboardEvent.preventDefault(); |
| 10888 keyboardEvent.stopImmediatePropagation(); | 11591 keyboardEvent.stopImmediatePropagation(); |
| 10889 this._setPressed(true); | 11592 this._setPressed(true); |
| 10890 }, | 11593 }, |
| 10891 | 11594 |
| 10892 _spaceKeyUpHandler: function() { | 11595 /** |
| 11596 * @param {!KeyboardEvent} event . |
| 11597 */ |
| 11598 _spaceKeyUpHandler: function(event) { |
| 11599 var keyboardEvent = event.detail.keyboardEvent; |
| 11600 var target = Polymer.dom(keyboardEvent).localTarget; |
| 11601 |
| 11602 // Ignore the event if this is coming from a focused light child, since th
at |
| 11603 // element will deal with it. |
| 11604 if (this.isLightDescendant(target)) |
| 11605 return; |
| 11606 |
| 10893 if (this.pressed) { | 11607 if (this.pressed) { |
| 10894 this._asyncClick(); | 11608 this._asyncClick(); |
| 10895 } | 11609 } |
| 10896 this._setPressed(false); | 11610 this._setPressed(false); |
| 10897 }, | 11611 }, |
| 10898 | 11612 |
| 10899 // trigger click asynchronously, the asynchrony is useful to allow one | 11613 // trigger click asynchronously, the asynchrony is useful to allow one |
| 10900 // event handler to unwind before triggering another event | 11614 // event handler to unwind before triggering another event |
| 10901 _asyncClick: function() { | 11615 _asyncClick: function() { |
| 10902 this.async(function() { | 11616 this.async(function() { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11343 }, | 12057 }, |
| 11344 | 12058 |
| 11345 _boundAnimate: { | 12059 _boundAnimate: { |
| 11346 type: Function, | 12060 type: Function, |
| 11347 value: function() { | 12061 value: function() { |
| 11348 return this.animate.bind(this); | 12062 return this.animate.bind(this); |
| 11349 } | 12063 } |
| 11350 } | 12064 } |
| 11351 }, | 12065 }, |
| 11352 | 12066 |
| 11353 observers: [ | |
| 11354 '_noinkChanged(noink, isAttached)' | |
| 11355 ], | |
| 11356 | |
| 11357 get target () { | 12067 get target () { |
| 11358 var ownerRoot = Polymer.dom(this).getOwnerRoot(); | 12068 var ownerRoot = Polymer.dom(this).getOwnerRoot(); |
| 11359 var target; | 12069 var target; |
| 11360 | 12070 |
| 11361 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE | 12071 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE |
| 11362 target = ownerRoot.host; | 12072 target = ownerRoot.host; |
| 11363 } else { | 12073 } else { |
| 11364 target = this.parentNode; | 12074 target = this.parentNode; |
| 11365 } | 12075 } |
| 11366 | 12076 |
| 11367 return target; | 12077 return target; |
| 11368 }, | 12078 }, |
| 11369 | 12079 |
| 11370 keyBindings: { | 12080 keyBindings: { |
| 11371 'enter:keydown': '_onEnterKeydown', | 12081 'enter:keydown': '_onEnterKeydown', |
| 11372 'space:keydown': '_onSpaceKeydown', | 12082 'space:keydown': '_onSpaceKeydown', |
| 11373 'space:keyup': '_onSpaceKeyup' | 12083 'space:keyup': '_onSpaceKeyup' |
| 11374 }, | 12084 }, |
| 11375 | 12085 |
| 11376 attached: function() { | 12086 attached: function() { |
| 12087 // Set up a11yKeysBehavior to listen to key events on the target, |
| 12088 // so that space and enter activate the ripple even if the target doesn'
t |
| 12089 // handle key events. The key handlers deal with `noink` themselves. |
| 12090 this.keyEventTarget = this.target; |
| 11377 this.listen(this.target, 'up', 'uiUpAction'); | 12091 this.listen(this.target, 'up', 'uiUpAction'); |
| 11378 this.listen(this.target, 'down', 'uiDownAction'); | 12092 this.listen(this.target, 'down', 'uiDownAction'); |
| 11379 }, | 12093 }, |
| 11380 | 12094 |
| 11381 detached: function() { | 12095 detached: function() { |
| 11382 this.unlisten(this.target, 'up', 'uiUpAction'); | 12096 this.unlisten(this.target, 'up', 'uiUpAction'); |
| 11383 this.unlisten(this.target, 'down', 'uiDownAction'); | 12097 this.unlisten(this.target, 'down', 'uiDownAction'); |
| 11384 }, | 12098 }, |
| 11385 | 12099 |
| 11386 get shouldKeepAnimating () { | 12100 get shouldKeepAnimating () { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11536 // effect. | 12250 // effect. |
| 11537 _holdDownChanged: function(newVal, oldVal) { | 12251 _holdDownChanged: function(newVal, oldVal) { |
| 11538 if (oldVal === undefined) { | 12252 if (oldVal === undefined) { |
| 11539 return; | 12253 return; |
| 11540 } | 12254 } |
| 11541 if (newVal) { | 12255 if (newVal) { |
| 11542 this.downAction(); | 12256 this.downAction(); |
| 11543 } else { | 12257 } else { |
| 11544 this.upAction(); | 12258 this.upAction(); |
| 11545 } | 12259 } |
| 11546 }, | |
| 11547 | |
| 11548 _noinkChanged: function(noink, attached) { | |
| 11549 if (attached) { | |
| 11550 this.keyEventTarget = noink ? this : this.target; | |
| 11551 } | |
| 11552 } | 12260 } |
| 11553 }); | 12261 }); |
| 11554 })(); | 12262 })(); |
| 11555 /** | 12263 /** |
| 11556 * `Polymer.PaperRippleBehavior` dynamically implements a ripple | 12264 * `Polymer.PaperRippleBehavior` dynamically implements a ripple |
| 11557 * when the element has focus via pointer or keyboard. | 12265 * when the element has focus via pointer or keyboard. |
| 11558 * | 12266 * |
| 11559 * NOTE: This behavior is intended to be used in conjunction with and after | 12267 * NOTE: This behavior is intended to be used in conjunction with and after |
| 11560 * `Polymer.IronButtonState` and `Polymer.IronControlState`. | 12268 * `Polymer.IronButtonState` and `Polymer.IronControlState`. |
| 11561 * | 12269 * |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11598 _downHandler: function(event) { | 12306 _downHandler: function(event) { |
| 11599 Polymer.IronButtonStateImpl._downHandler.call(this, event); | 12307 Polymer.IronButtonStateImpl._downHandler.call(this, event); |
| 11600 if (this.pressed) { | 12308 if (this.pressed) { |
| 11601 this.ensureRipple(event); | 12309 this.ensureRipple(event); |
| 11602 } | 12310 } |
| 11603 }, | 12311 }, |
| 11604 | 12312 |
| 11605 /** | 12313 /** |
| 11606 * Ensures this element contains a ripple effect. For startup efficiency | 12314 * Ensures this element contains a ripple effect. For startup efficiency |
| 11607 * the ripple effect is dynamically on demand when needed. | 12315 * the ripple effect is dynamically on demand when needed. |
| 11608 * @param {!Event=} opt_triggeringEvent (optional) event that triggered the | 12316 * @param {!Event=} optTriggeringEvent (optional) event that triggered the |
| 11609 * ripple. | 12317 * ripple. |
| 11610 */ | 12318 */ |
| 11611 ensureRipple: function(opt_triggeringEvent) { | 12319 ensureRipple: function(optTriggeringEvent) { |
| 11612 if (!this.hasRipple()) { | 12320 if (!this.hasRipple()) { |
| 11613 this._ripple = this._createRipple(); | 12321 this._ripple = this._createRipple(); |
| 11614 this._ripple.noink = this.noink; | 12322 this._ripple.noink = this.noink; |
| 11615 var rippleContainer = this._rippleContainer || this.root; | 12323 var rippleContainer = this._rippleContainer || this.root; |
| 11616 if (rippleContainer) { | 12324 if (rippleContainer) { |
| 11617 Polymer.dom(rippleContainer).appendChild(this._ripple); | 12325 Polymer.dom(rippleContainer).appendChild(this._ripple); |
| 11618 } | 12326 } |
| 11619 var domContainer = rippleContainer === this.shadyRoot ? this : | 12327 if (optTriggeringEvent) { |
| 11620 rippleContainer; | 12328 // Check if the event happened inside of the ripple container |
| 11621 if (opt_triggeringEvent) { | 12329 // Fall back to host instead of the root because distributed text |
| 11622 var target = opt_triggeringEvent.target; | 12330 // nodes are not valid event targets |
| 11623 if (domContainer.contains(/** @type {Node} */(target))) { | 12331 var domContainer = Polymer.dom(this._rippleContainer || this); |
| 11624 this._ripple.uiDownAction(opt_triggeringEvent); | 12332 var target = Polymer.dom(optTriggeringEvent).rootTarget; |
| 12333 if (domContainer.deepContains( /** @type {Node} */(target))) { |
| 12334 this._ripple.uiDownAction(optTriggeringEvent); |
| 11625 } | 12335 } |
| 11626 } | 12336 } |
| 11627 } | 12337 } |
| 11628 }, | 12338 }, |
| 11629 | 12339 |
| 11630 /** | 12340 /** |
| 11631 * Returns the `<paper-ripple>` element used by this element to create | 12341 * Returns the `<paper-ripple>` element used by this element to create |
| 11632 * ripple effects. The element's ripple is created on demand, when | 12342 * ripple effects. The element's ripple is created on demand, when |
| 11633 * necessary, and calling this method will force the | 12343 * necessary, and calling this method will force the |
| 11634 * ripple to be created. | 12344 * ripple to be created. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 11659 _noinkChanged: function(noink) { | 12369 _noinkChanged: function(noink) { |
| 11660 if (this.hasRipple()) { | 12370 if (this.hasRipple()) { |
| 11661 this._ripple.noink = noink; | 12371 this._ripple.noink = noink; |
| 11662 } | 12372 } |
| 11663 } | 12373 } |
| 11664 | 12374 |
| 11665 }; | 12375 }; |
| 11666 /** | 12376 /** |
| 11667 * `Polymer.PaperInkyFocusBehavior` implements a ripple when the element has k
eyboard focus. | 12377 * `Polymer.PaperInkyFocusBehavior` implements a ripple when the element has k
eyboard focus. |
| 11668 * | 12378 * |
| 11669 * @polymerBehavior Polymer.PaperInkyFocusBehaviorImpl | 12379 * @polymerBehavior Polymer.PaperInkyFocusBehavior |
| 11670 */ | 12380 */ |
| 11671 Polymer.PaperInkyFocusBehaviorImpl = { | 12381 Polymer.PaperInkyFocusBehaviorImpl = { |
| 11672 | 12382 |
| 11673 observers: [ | 12383 observers: [ |
| 11674 '_focusedChanged(receivedFocusFromKeyboard)' | 12384 '_focusedChanged(receivedFocusFromKeyboard)' |
| 11675 ], | 12385 ], |
| 11676 | 12386 |
| 11677 _focusedChanged: function(receivedFocusFromKeyboard) { | 12387 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 11678 if (receivedFocusFromKeyboard) { | 12388 if (receivedFocusFromKeyboard) { |
| 11679 this.ensureRipple(); | 12389 this.ensureRipple(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 11697 Polymer.PaperInkyFocusBehavior = [ | 12407 Polymer.PaperInkyFocusBehavior = [ |
| 11698 Polymer.IronButtonState, | 12408 Polymer.IronButtonState, |
| 11699 Polymer.IronControlState, | 12409 Polymer.IronControlState, |
| 11700 Polymer.PaperRippleBehavior, | 12410 Polymer.PaperRippleBehavior, |
| 11701 Polymer.PaperInkyFocusBehaviorImpl | 12411 Polymer.PaperInkyFocusBehaviorImpl |
| 11702 ]; | 12412 ]; |
| 11703 Polymer({ | 12413 Polymer({ |
| 11704 is: 'paper-material', | 12414 is: 'paper-material', |
| 11705 | 12415 |
| 11706 properties: { | 12416 properties: { |
| 11707 | |
| 11708 /** | 12417 /** |
| 11709 * The z-depth of this element, from 0-5. Setting to 0 will remove the | 12418 * The z-depth of this element, from 0-5. Setting to 0 will remove the |
| 11710 * shadow, and each increasing number greater than 0 will be "deeper" | 12419 * shadow, and each increasing number greater than 0 will be "deeper" |
| 11711 * than the last. | 12420 * than the last. |
| 11712 * | 12421 * |
| 11713 * @attribute elevation | 12422 * @attribute elevation |
| 11714 * @type number | 12423 * @type number |
| 11715 * @default 1 | 12424 * @default 1 |
| 11716 */ | 12425 */ |
| 11717 elevation: { | 12426 elevation: { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11839 }, | 12548 }, |
| 11840 | 12549 |
| 11841 _calculateElevation: function() { | 12550 _calculateElevation: function() { |
| 11842 if (!this.raised) { | 12551 if (!this.raised) { |
| 11843 this.elevation = 0; | 12552 this.elevation = 0; |
| 11844 } else { | 12553 } else { |
| 11845 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this); | 12554 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this); |
| 11846 } | 12555 } |
| 11847 } | 12556 } |
| 11848 }); | 12557 }); |
| 11849 /** | 12558 /** |
| 11850 * `iron-range-behavior` provides the behavior for something with a minimum to m
aximum range. | 12559 * `iron-range-behavior` provides the behavior for something with a minimum to m
aximum range. |
| 11851 * | 12560 * |
| 11852 * @demo demo/index.html | 12561 * @demo demo/index.html |
| 11853 * @polymerBehavior | 12562 * @polymerBehavior |
| 11854 */ | 12563 */ |
| 11855 Polymer.IronRangeBehavior = { | 12564 Polymer.IronRangeBehavior = { |
| 11856 | 12565 |
| 11857 properties: { | 12566 properties: { |
| 11858 | 12567 |
| 11859 /** | 12568 /** |
| 11860 * The number that represents the current value. | 12569 * The number that represents the current value. |
| 11861 */ | 12570 */ |
| 11862 value: { | 12571 value: { |
| 11863 type: Number, | 12572 type: Number, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11912 return (this._clampValue(value) - this.min) / (this.max - this.min); | 12621 return (this._clampValue(value) - this.min) / (this.max - this.min); |
| 11913 }, | 12622 }, |
| 11914 | 12623 |
| 11915 _clampValue: function(value) { | 12624 _clampValue: function(value) { |
| 11916 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); | 12625 return Math.min(this.max, Math.max(this.min, this._calcStep(value))); |
| 11917 }, | 12626 }, |
| 11918 | 12627 |
| 11919 _calcStep: function(value) { | 12628 _calcStep: function(value) { |
| 11920 /** | 12629 /** |
| 11921 * if we calculate the step using | 12630 * if we calculate the step using |
| 11922 * `Math.round(value / step) * step` we may hit a precision point issue | 12631 * `Math.round(value / step) * step` we may hit a precision point issue |
| 11923 * eg. 0.1 * 0.2 = 0.020000000000000004 | 12632 * eg. 0.1 * 0.2 = 0.020000000000000004 |
| 11924 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html | 12633 * http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html |
| 11925 * | 12634 * |
| 11926 * as a work around we can divide by the reciprocal of `step` | 12635 * as a work around we can divide by the reciprocal of `step` |
| 11927 */ | 12636 */ |
| 11928 // polymer/issues/2493 | 12637 // polymer/issues/2493 |
| 11929 value = parseFloat(value); | 12638 value = parseFloat(value); |
| 11930 return this.step ? (Math.round((value + this.min) / this.step) / (1 / this.s
tep)) - this.min : value; | 12639 return this.step ? (Math.round((value + this.min) / this.step) - |
| 12640 (this.min / this.step)) / (1 / this.step) : value; |
| 11931 }, | 12641 }, |
| 11932 | 12642 |
| 11933 _validateValue: function() { | 12643 _validateValue: function() { |
| 11934 var v = this._clampValue(this.value); | 12644 var v = this._clampValue(this.value); |
| 11935 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; | 12645 this.value = this.oldValue = isNaN(v) ? this.oldValue : v; |
| 11936 return this.value !== v; | 12646 return this.value !== v; |
| 11937 }, | 12647 }, |
| 11938 | 12648 |
| 11939 _update: function() { | 12649 _update: function() { |
| 11940 this._validateValue(); | 12650 this._validateValue(); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12371 onShowTap_: function() { | 13081 onShowTap_: function() { |
| 12372 downloads.ActionService.getInstance().show(this.data.id); | 13082 downloads.ActionService.getInstance().show(this.data.id); |
| 12373 }, | 13083 }, |
| 12374 }); | 13084 }); |
| 12375 | 13085 |
| 12376 return { | 13086 return { |
| 12377 InkyTextButton: InkyTextButton, | 13087 InkyTextButton: InkyTextButton, |
| 12378 Item: Item, | 13088 Item: Item, |
| 12379 }; | 13089 }; |
| 12380 }); | 13090 }); |
| 13091 /** @polymerBehavior Polymer.PaperItemBehavior */ |
| 13092 Polymer.PaperItemBehaviorImpl = { |
| 13093 hostAttributes: { |
| 13094 role: 'option', |
| 13095 tabindex: '0' |
| 13096 } |
| 13097 }; |
| 13098 |
| 13099 /** @polymerBehavior */ |
| 13100 Polymer.PaperItemBehavior = [ |
| 13101 Polymer.IronControlState, |
| 13102 Polymer.IronButtonState, |
| 13103 Polymer.PaperItemBehaviorImpl |
| 13104 ]; |
| 12381 Polymer({ | 13105 Polymer({ |
| 12382 is: 'paper-item', | 13106 is: 'paper-item', |
| 12383 | 13107 |
| 12384 hostAttributes: { | |
| 12385 role: 'listitem', | |
| 12386 tabindex: '0' | |
| 12387 }, | |
| 12388 | |
| 12389 behaviors: [ | 13108 behaviors: [ |
| 12390 Polymer.IronControlState, | 13109 Polymer.PaperItemBehavior |
| 12391 Polymer.IronButtonState | |
| 12392 ] | 13110 ] |
| 12393 }); | 13111 }); |
| 12394 /** | 13112 /** |
| 12395 * @param {!Function} selectCallback | 13113 * @param {!Function} selectCallback |
| 12396 * @constructor | 13114 * @constructor |
| 12397 */ | 13115 */ |
| 12398 Polymer.IronSelection = function(selectCallback) { | 13116 Polymer.IronSelection = function(selectCallback) { |
| 12399 this.selection = []; | 13117 this.selection = []; |
| 12400 this.selectCallback = selectCallback; | 13118 this.selectCallback = selectCallback; |
| 12401 }; | 13119 }; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12535 /** | 13253 /** |
| 12536 * Gets or sets the selected element. The default is to use the index of t
he item. | 13254 * Gets or sets the selected element. The default is to use the index of t
he item. |
| 12537 */ | 13255 */ |
| 12538 selected: { | 13256 selected: { |
| 12539 type: String, | 13257 type: String, |
| 12540 notify: true | 13258 notify: true |
| 12541 }, | 13259 }, |
| 12542 | 13260 |
| 12543 /** | 13261 /** |
| 12544 * Returns the currently selected item. | 13262 * Returns the currently selected item. |
| 13263 * |
| 13264 * @type {?Object} |
| 12545 */ | 13265 */ |
| 12546 selectedItem: { | 13266 selectedItem: { |
| 12547 type: Object, | 13267 type: Object, |
| 12548 readOnly: true, | 13268 readOnly: true, |
| 12549 notify: true | 13269 notify: true |
| 12550 }, | 13270 }, |
| 12551 | 13271 |
| 12552 /** | 13272 /** |
| 12553 * The event that fires from items when they are selected. Selectable | 13273 * The event that fires from items when they are selected. Selectable |
| 12554 * will listen for this event from items and update the selection state. | 13274 * will listen for this event from items and update the selection state. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 12576 | 13296 |
| 12577 /** | 13297 /** |
| 12578 * The attribute to set on elements when selected. | 13298 * The attribute to set on elements when selected. |
| 12579 */ | 13299 */ |
| 12580 selectedAttribute: { | 13300 selectedAttribute: { |
| 12581 type: String, | 13301 type: String, |
| 12582 value: null | 13302 value: null |
| 12583 }, | 13303 }, |
| 12584 | 13304 |
| 12585 /** | 13305 /** |
| 13306 * The list of items from which a selection can be made. |
| 13307 */ |
| 13308 items: { |
| 13309 type: Array, |
| 13310 readOnly: true, |
| 13311 value: function() { |
| 13312 return []; |
| 13313 } |
| 13314 }, |
| 13315 |
| 13316 /** |
| 12586 * The set of excluded elements where the key is the `localName` | 13317 * The set of excluded elements where the key is the `localName` |
| 12587 * of the element that will be ignored from the item list. | 13318 * of the element that will be ignored from the item list. |
| 12588 * | 13319 * |
| 12589 * @type {object} | |
| 12590 * @default {template: 1} | 13320 * @default {template: 1} |
| 12591 */ | 13321 */ |
| 12592 _excludedLocalNames: { | 13322 _excludedLocalNames: { |
| 12593 type: Object, | 13323 type: Object, |
| 12594 value: function() { | 13324 value: function() { |
| 12595 return { | 13325 return { |
| 12596 'template': 1 | 13326 'template': 1 |
| 12597 }; | 13327 }; |
| 12598 } | 13328 } |
| 12599 } | 13329 } |
| 12600 }, | 13330 }, |
| 12601 | 13331 |
| 12602 observers: [ | 13332 observers: [ |
| 12603 '_updateSelected(attrForSelected, selected)' | 13333 '_updateSelected(attrForSelected, selected)' |
| 12604 ], | 13334 ], |
| 12605 | 13335 |
| 12606 created: function() { | 13336 created: function() { |
| 12607 this._bindFilterItem = this._filterItem.bind(this); | 13337 this._bindFilterItem = this._filterItem.bind(this); |
| 12608 this._selection = new Polymer.IronSelection(this._applySelection.bind(this
)); | 13338 this._selection = new Polymer.IronSelection(this._applySelection.bind(this
)); |
| 12609 // TODO(cdata): When polymer/polymer#2535 lands, we do not need to do this | |
| 12610 // book keeping anymore: | |
| 12611 this.__listeningForActivate = false; | |
| 12612 }, | 13339 }, |
| 12613 | 13340 |
| 12614 attached: function() { | 13341 attached: function() { |
| 12615 this._observer = this._observeItems(this); | 13342 this._observer = this._observeItems(this); |
| 12616 this._contentObserver = this._observeContent(this); | 13343 this._updateItems(); |
| 12617 if (!this.selectedItem && this.selected) { | 13344 if (!this._shouldUpdateSelection) { |
| 12618 this._updateSelected(this.attrForSelected,this.selected) | 13345 this._updateSelected(this.attrForSelected,this.selected) |
| 12619 } | 13346 } |
| 12620 this._addListener(this.activateEvent); | 13347 this._addListener(this.activateEvent); |
| 12621 }, | 13348 }, |
| 12622 | 13349 |
| 12623 detached: function() { | 13350 detached: function() { |
| 12624 if (this._observer) { | 13351 if (this._observer) { |
| 12625 this._observer.disconnect(); | 13352 Polymer.dom(this).unobserveNodes(this._observer); |
| 12626 } | |
| 12627 if (this._contentObserver) { | |
| 12628 this._contentObserver.disconnect(); | |
| 12629 } | 13353 } |
| 12630 this._removeListener(this.activateEvent); | 13354 this._removeListener(this.activateEvent); |
| 12631 }, | 13355 }, |
| 12632 | 13356 |
| 12633 /** | 13357 /** |
| 12634 * Returns an array of selectable items. | |
| 12635 * | |
| 12636 * @property items | |
| 12637 * @type Array | |
| 12638 */ | |
| 12639 get items() { | |
| 12640 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable ||
'*'); | |
| 12641 return Array.prototype.filter.call(nodes, this._bindFilterItem); | |
| 12642 }, | |
| 12643 | |
| 12644 /** | |
| 12645 * Returns the index of the given item. | 13358 * Returns the index of the given item. |
| 12646 * | 13359 * |
| 12647 * @method indexOf | 13360 * @method indexOf |
| 12648 * @param {Object} item | 13361 * @param {Object} item |
| 12649 * @returns Returns the index of the item | 13362 * @returns Returns the index of the item |
| 12650 */ | 13363 */ |
| 12651 indexOf: function(item) { | 13364 indexOf: function(item) { |
| 12652 return this.items.indexOf(item); | 13365 return this.items.indexOf(item); |
| 12653 }, | 13366 }, |
| 12654 | 13367 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 12676 /** | 13389 /** |
| 12677 * Selects the next item. | 13390 * Selects the next item. |
| 12678 * | 13391 * |
| 12679 * @method selectNext | 13392 * @method selectNext |
| 12680 */ | 13393 */ |
| 12681 selectNext: function() { | 13394 selectNext: function() { |
| 12682 var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.l
ength; | 13395 var index = (Number(this._valueToIndex(this.selected)) + 1) % this.items.l
ength; |
| 12683 this.selected = this._indexToValue(index); | 13396 this.selected = this._indexToValue(index); |
| 12684 }, | 13397 }, |
| 12685 | 13398 |
| 13399 get _shouldUpdateSelection() { |
| 13400 return this.selected != null; |
| 13401 }, |
| 13402 |
| 12686 _addListener: function(eventName) { | 13403 _addListener: function(eventName) { |
| 12687 if (!this.isAttached || this.__listeningForActivate) { | |
| 12688 return; | |
| 12689 } | |
| 12690 | |
| 12691 this.__listeningForActivate = true; | |
| 12692 this.listen(this, eventName, '_activateHandler'); | 13404 this.listen(this, eventName, '_activateHandler'); |
| 12693 }, | 13405 }, |
| 12694 | 13406 |
| 12695 _removeListener: function(eventName) { | 13407 _removeListener: function(eventName) { |
| 12696 this.unlisten(this, eventName, '_activateHandler'); | 13408 this.unlisten(this, eventName, '_activateHandler'); |
| 12697 this.__listeningForActivate = false; | |
| 12698 }, | 13409 }, |
| 12699 | 13410 |
| 12700 _activateEventChanged: function(eventName, old) { | 13411 _activateEventChanged: function(eventName, old) { |
| 12701 this._removeListener(old); | 13412 this._removeListener(old); |
| 12702 this._addListener(eventName); | 13413 this._addListener(eventName); |
| 12703 }, | 13414 }, |
| 12704 | 13415 |
| 13416 _updateItems: function() { |
| 13417 var nodes = Polymer.dom(this).queryDistributedElements(this.selectable ||
'*'); |
| 13418 nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); |
| 13419 this._setItems(nodes); |
| 13420 }, |
| 13421 |
| 12705 _updateSelected: function() { | 13422 _updateSelected: function() { |
| 12706 this._selectSelected(this.selected); | 13423 this._selectSelected(this.selected); |
| 12707 }, | 13424 }, |
| 12708 | 13425 |
| 12709 _selectSelected: function(selected) { | 13426 _selectSelected: function(selected) { |
| 12710 this._selection.select(this._valueToItem(this.selected)); | 13427 this._selection.select(this._valueToItem(this.selected)); |
| 12711 }, | 13428 }, |
| 12712 | 13429 |
| 12713 _filterItem: function(node) { | 13430 _filterItem: function(node) { |
| 12714 return !this._excludedLocalNames[node.localName]; | 13431 return !this._excludedLocalNames[node.localName]; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12753 this.toggleAttribute(this.selectedAttribute, isSelected, item); | 13470 this.toggleAttribute(this.selectedAttribute, isSelected, item); |
| 12754 } | 13471 } |
| 12755 this._selectionChange(); | 13472 this._selectionChange(); |
| 12756 this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item}); | 13473 this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item}); |
| 12757 }, | 13474 }, |
| 12758 | 13475 |
| 12759 _selectionChange: function() { | 13476 _selectionChange: function() { |
| 12760 this._setSelectedItem(this._selection.get()); | 13477 this._setSelectedItem(this._selection.get()); |
| 12761 }, | 13478 }, |
| 12762 | 13479 |
| 12763 // observe content changes under the given node. | |
| 12764 _observeContent: function(node) { | |
| 12765 var content = node.querySelector('content'); | |
| 12766 if (content && content.parentElement === node) { | |
| 12767 return this._observeItems(node.domHost); | |
| 12768 } | |
| 12769 }, | |
| 12770 | |
| 12771 // observe items change under the given node. | 13480 // observe items change under the given node. |
| 12772 _observeItems: function(node) { | 13481 _observeItems: function(node) { |
| 12773 // TODO(cdata): Update this when we get distributed children changed. | 13482 return Polymer.dom(node).observeNodes(function(mutations) { |
| 12774 var observer = new MutationObserver(function(mutations) { | |
| 12775 // Let other interested parties know about the change so that | 13483 // Let other interested parties know about the change so that |
| 12776 // we don't have to recreate mutation observers everywher. | 13484 // we don't have to recreate mutation observers everywher. |
| 12777 this.fire('iron-items-changed', mutations, { | 13485 this.fire('iron-items-changed', mutations, { |
| 12778 bubbles: false, | 13486 bubbles: false, |
| 12779 cancelable: false | 13487 cancelable: false |
| 12780 }); | 13488 }); |
| 12781 | 13489 |
| 12782 if (this.selected != null) { | 13490 this._updateItems(); |
| 13491 |
| 13492 if (this._shouldUpdateSelection) { |
| 12783 this._updateSelected(); | 13493 this._updateSelected(); |
| 12784 } | 13494 } |
| 12785 }.bind(this)); | |
| 12786 observer.observe(node, { | |
| 12787 childList: true, | |
| 12788 subtree: true | |
| 12789 }); | 13495 }); |
| 12790 return observer; | |
| 12791 }, | 13496 }, |
| 12792 | 13497 |
| 12793 _activateHandler: function(e) { | 13498 _activateHandler: function(e) { |
| 12794 var t = e.target; | 13499 var t = e.target; |
| 12795 var items = this.items; | 13500 var items = this.items; |
| 12796 while (t && t != this) { | 13501 while (t && t != this) { |
| 12797 var i = items.indexOf(t); | 13502 var i = items.indexOf(t); |
| 12798 if (i >= 0) { | 13503 if (i >= 0) { |
| 12799 var value = this._indexToValue(i); | 13504 var value = this._indexToValue(i); |
| 12800 this._itemActivate(value, t); | 13505 this._itemActivate(value, t); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12865 } | 13570 } |
| 12866 } else { | 13571 } else { |
| 12867 this.selected = value; | 13572 this.selected = value; |
| 12868 } | 13573 } |
| 12869 }, | 13574 }, |
| 12870 | 13575 |
| 12871 multiChanged: function(multi) { | 13576 multiChanged: function(multi) { |
| 12872 this._selection.multi = multi; | 13577 this._selection.multi = multi; |
| 12873 }, | 13578 }, |
| 12874 | 13579 |
| 13580 get _shouldUpdateSelection() { |
| 13581 return this.selected != null || |
| 13582 (this.selectedValues != null && this.selectedValues.length); |
| 13583 }, |
| 13584 |
| 12875 _updateSelected: function() { | 13585 _updateSelected: function() { |
| 12876 if (this.multi) { | 13586 if (this.multi) { |
| 12877 this._selectMulti(this.selectedValues); | 13587 this._selectMulti(this.selectedValues); |
| 12878 } else { | 13588 } else { |
| 12879 this._selectSelected(this.selected); | 13589 this._selectSelected(this.selected); |
| 12880 } | 13590 } |
| 12881 }, | 13591 }, |
| 12882 | 13592 |
| 12883 _selectMulti: function(values) { | 13593 _selectMulti: function(values) { |
| 12884 this._selection.clear(); | 13594 this._selection.clear(); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13202 | 13912 |
| 13203 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; | 13913 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; |
| 13204 | 13914 |
| 13205 /** @polymerBehavior Polymer.IronMenuBehavior */ | 13915 /** @polymerBehavior Polymer.IronMenuBehavior */ |
| 13206 Polymer.IronMenuBehavior = [ | 13916 Polymer.IronMenuBehavior = [ |
| 13207 Polymer.IronMultiSelectableBehavior, | 13917 Polymer.IronMultiSelectableBehavior, |
| 13208 Polymer.IronA11yKeysBehavior, | 13918 Polymer.IronA11yKeysBehavior, |
| 13209 Polymer.IronMenuBehaviorImpl | 13919 Polymer.IronMenuBehaviorImpl |
| 13210 ]; | 13920 ]; |
| 13211 (function() { | 13921 (function() { |
| 13922 Polymer({ |
| 13923 is: 'paper-menu', |
| 13212 | 13924 |
| 13213 Polymer({ | 13925 behaviors: [ |
| 13214 | 13926 Polymer.IronMenuBehavior |
| 13215 is: 'paper-menu', | 13927 ] |
| 13216 | 13928 }); |
| 13217 behaviors: [ | 13929 })(); |
| 13218 Polymer.IronMenuBehavior | |
| 13219 ] | |
| 13220 | |
| 13221 }); | |
| 13222 | |
| 13223 })(); | |
| 13224 /** | 13930 /** |
| 13225 Polymer.IronFitBehavior fits an element in another element using `max-height` an
d `max-width`, and | 13931 Polymer.IronFitBehavior fits an element in another element using `max-height` an
d `max-width`, and |
| 13226 optionally centers it in the window or another element. | 13932 optionally centers it in the window or another element. |
| 13227 | 13933 |
| 13228 The element will only be sized and/or positioned if it has not already been size
d and/or positioned | 13934 The element will only be sized and/or positioned if it has not already been size
d and/or positioned |
| 13229 by CSS. | 13935 by CSS. |
| 13230 | 13936 |
| 13231 CSS properties | Action | 13937 CSS properties | Action |
| 13232 -----------------------------|------------------------------------------- | 13938 -----------------------------|------------------------------------------- |
| 13233 `position` set | Element is not centered horizontally or verticall
y | 13939 `position` set | Element is not centered horizontally or verticall
y |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13409 */ | 14115 */ |
| 13410 constrain: function() { | 14116 constrain: function() { |
| 13411 var info = this._fitInfo; | 14117 var info = this._fitInfo; |
| 13412 // position at (0px, 0px) if not already positioned, so we can measure the
natural size. | 14118 // position at (0px, 0px) if not already positioned, so we can measure the
natural size. |
| 13413 if (!this._fitInfo.positionedBy.vertically) { | 14119 if (!this._fitInfo.positionedBy.vertically) { |
| 13414 this.style.top = '0px'; | 14120 this.style.top = '0px'; |
| 13415 } | 14121 } |
| 13416 if (!this._fitInfo.positionedBy.horizontally) { | 14122 if (!this._fitInfo.positionedBy.horizontally) { |
| 13417 this.style.left = '0px'; | 14123 this.style.left = '0px'; |
| 13418 } | 14124 } |
| 14125 if (!this._fitInfo.positionedBy.vertically || !this._fitInfo.positionedBy.
horizontally) { |
| 14126 // need position:fixed to properly size the element |
| 14127 this.style.position = 'fixed'; |
| 14128 } |
| 13419 // need border-box for margin/padding | 14129 // need border-box for margin/padding |
| 13420 this.sizingTarget.style.boxSizing = 'border-box'; | 14130 this.sizingTarget.style.boxSizing = 'border-box'; |
| 13421 // constrain the width and height if not already set | 14131 // constrain the width and height if not already set |
| 13422 var rect = this.getBoundingClientRect(); | 14132 var rect = this.getBoundingClientRect(); |
| 13423 if (!info.sizedBy.height) { | 14133 if (!info.sizedBy.height) { |
| 13424 this._sizeDimension(rect, info.positionedBy.vertically, 'top', 'bottom',
'Height'); | 14134 this._sizeDimension(rect, info.positionedBy.vertically, 'top', 'bottom',
'Height'); |
| 13425 } | 14135 } |
| 13426 if (!info.sizedBy.width) { | 14136 if (!info.sizedBy.width) { |
| 13427 this._sizeDimension(rect, info.positionedBy.horizontally, 'left', 'right
', 'Width'); | 14137 this._sizeDimension(rect, info.positionedBy.horizontally, 'left', 'right
', 'Width'); |
| 13428 } | 14138 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 13454 this.style.top = top + 'px'; | 14164 this.style.top = top + 'px'; |
| 13455 } | 14165 } |
| 13456 if (!this._fitInfo.positionedBy.horizontally) { | 14166 if (!this._fitInfo.positionedBy.horizontally) { |
| 13457 var left = (this._fitWidth - this.offsetWidth) / 2 + this._fitLeft; | 14167 var left = (this._fitWidth - this.offsetWidth) / 2 + this._fitLeft; |
| 13458 left -= this._fitInfo.margin.left; | 14168 left -= this._fitInfo.margin.left; |
| 13459 this.style.left = left + 'px'; | 14169 this.style.left = left + 'px'; |
| 13460 } | 14170 } |
| 13461 } | 14171 } |
| 13462 | 14172 |
| 13463 }; | 14173 }; |
| 13464 Polymer.IronOverlayManager = (function() { | 14174 Polymer.IronOverlayManager = { |
| 13465 | 14175 |
| 13466 var overlays = []; | 14176 _overlays: [], |
| 13467 var DEFAULT_Z = 10; | 14177 |
| 13468 var backdrops = []; | 14178 // iframes have a default z-index of 100, so this default should be at least |
| 14179 // that. |
| 14180 _minimumZ: 101, |
| 14181 |
| 14182 _backdrops: [], |
| 14183 |
| 14184 _applyOverlayZ: function(overlay, aboveZ) { |
| 14185 this._setZ(overlay, aboveZ + 2); |
| 14186 }, |
| 14187 |
| 14188 _setZ: function(element, z) { |
| 14189 element.style.zIndex = z; |
| 14190 }, |
| 13469 | 14191 |
| 13470 // track overlays for z-index and focus managemant | 14192 // track overlays for z-index and focus managemant |
| 13471 function addOverlay(overlay) { | 14193 addOverlay: function(overlay) { |
| 13472 var z0 = currentOverlayZ(); | 14194 var minimumZ = Math.max(this.currentOverlayZ(), this._minimumZ); |
| 13473 overlays.push(overlay); | 14195 this._overlays.push(overlay); |
| 13474 var z1 = currentOverlayZ(); | 14196 var newZ = this.currentOverlayZ(); |
| 13475 if (z1 <= z0) { | 14197 if (newZ <= minimumZ) { |
| 13476 applyOverlayZ(overlay, z0); | 14198 this._applyOverlayZ(overlay, minimumZ); |
| 13477 } | 14199 } |
| 13478 } | 14200 }, |
| 13479 | 14201 |
| 13480 function removeOverlay(overlay) { | 14202 removeOverlay: function(overlay) { |
| 13481 var i = overlays.indexOf(overlay); | 14203 var i = this._overlays.indexOf(overlay); |
| 13482 if (i >= 0) { | 14204 if (i >= 0) { |
| 13483 overlays.splice(i, 1); | 14205 this._overlays.splice(i, 1); |
| 13484 setZ(overlay, ''); | 14206 this._setZ(overlay, ''); |
| 13485 } | 14207 } |
| 13486 } | 14208 }, |
| 13487 | 14209 |
| 13488 function applyOverlayZ(overlay, aboveZ) { | 14210 currentOverlay: function() { |
| 13489 setZ(overlay, aboveZ + 2); | 14211 var i = this._overlays.length - 1; |
| 13490 } | 14212 while (this._overlays[i] && !this._overlays[i].opened) { |
| 13491 | |
| 13492 function setZ(element, z) { | |
| 13493 element.style.zIndex = z; | |
| 13494 } | |
| 13495 | |
| 13496 function currentOverlay() { | |
| 13497 var i = overlays.length - 1; | |
| 13498 while (overlays[i] && !overlays[i].opened) { | |
| 13499 --i; | 14213 --i; |
| 13500 } | 14214 } |
| 13501 return overlays[i]; | 14215 return this._overlays[i]; |
| 13502 } | 14216 }, |
| 13503 | 14217 |
| 13504 function currentOverlayZ() { | 14218 currentOverlayZ: function() { |
| 13505 var z; | 14219 var z = this._minimumZ; |
| 13506 var current = currentOverlay(); | 14220 var current = this.currentOverlay(); |
| 13507 if (current) { | 14221 if (current) { |
| 13508 var z1 = window.getComputedStyle(current).zIndex; | 14222 var z1 = window.getComputedStyle(current).zIndex; |
| 13509 if (!isNaN(z1)) { | 14223 if (!isNaN(z1)) { |
| 13510 z = Number(z1); | 14224 z = Number(z1); |
| 13511 } | 14225 } |
| 13512 } | 14226 } |
| 13513 return z || DEFAULT_Z; | 14227 return z; |
| 13514 } | 14228 }, |
| 13515 | 14229 |
| 13516 function focusOverlay() { | 14230 /** |
| 13517 var current = currentOverlay(); | 14231 * Ensures that the minimum z-index of new overlays is at least `minimumZ`. |
| 14232 * This does not effect the z-index of any existing overlays. |
| 14233 * |
| 14234 * @param {number} minimumZ |
| 14235 */ |
| 14236 ensureMinimumZ: function(minimumZ) { |
| 14237 this._minimumZ = Math.max(this._minimumZ, minimumZ); |
| 14238 }, |
| 14239 |
| 14240 focusOverlay: function() { |
| 14241 var current = this.currentOverlay(); |
| 13518 // We have to be careful to focus the next overlay _after_ any current | 14242 // We have to be careful to focus the next overlay _after_ any current |
| 13519 // transitions are complete (due to the state being toggled prior to the | 14243 // transitions are complete (due to the state being toggled prior to the |
| 13520 // transition). Otherwise, we risk infinite recursion when a transitioning | 14244 // transition). Otherwise, we risk infinite recursion when a transitioning |
| 13521 // (closed) overlay becomes the current overlay. | 14245 // (closed) overlay becomes the current overlay. |
| 13522 // | 14246 // |
| 13523 // NOTE: We make the assumption that any overlay that completes a transiti
on | 14247 // NOTE: We make the assumption that any overlay that completes a transiti
on |
| 13524 // will call into focusOverlay to kick the process back off. Currently: | 14248 // will call into focusOverlay to kick the process back off. Currently: |
| 13525 // transitionend -> _applyFocus -> focusOverlay. | 14249 // transitionend -> _applyFocus -> focusOverlay. |
| 13526 if (current && !current.transitioning) { | 14250 if (current && !current.transitioning) { |
| 13527 current._applyFocus(); | 14251 current._applyFocus(); |
| 13528 } | 14252 } |
| 13529 } | 14253 }, |
| 13530 | 14254 |
| 13531 function trackBackdrop(element) { | 14255 trackBackdrop: function(element) { |
| 13532 // backdrops contains the overlays with a backdrop that are currently | 14256 // backdrops contains the overlays with a backdrop that are currently |
| 13533 // visible | 14257 // visible |
| 13534 if (element.opened) { | 14258 if (element.opened) { |
| 13535 backdrops.push(element); | 14259 this._backdrops.push(element); |
| 13536 } else { | 14260 } else { |
| 13537 var index = backdrops.indexOf(element); | 14261 var index = this._backdrops.indexOf(element); |
| 13538 if (index >= 0) { | 14262 if (index >= 0) { |
| 13539 backdrops.splice(index, 1); | 14263 this._backdrops.splice(index, 1); |
| 13540 } | 14264 } |
| 13541 } | 14265 } |
| 14266 }, |
| 14267 |
| 14268 getBackdrops: function() { |
| 14269 return this._backdrops; |
| 13542 } | 14270 } |
| 13543 | 14271 |
| 13544 function getBackdrops() { | 14272 }; |
| 13545 return backdrops; | |
| 13546 } | |
| 13547 | |
| 13548 return { | |
| 13549 addOverlay: addOverlay, | |
| 13550 removeOverlay: removeOverlay, | |
| 13551 currentOverlay: currentOverlay, | |
| 13552 currentOverlayZ: currentOverlayZ, | |
| 13553 focusOverlay: focusOverlay, | |
| 13554 trackBackdrop: trackBackdrop, | |
| 13555 getBackdrops: getBackdrops | |
| 13556 }; | |
| 13557 | |
| 13558 })(); | |
| 13559 (function() { | 14273 (function() { |
| 13560 | 14274 |
| 13561 Polymer({ | 14275 Polymer({ |
| 13562 | 14276 |
| 13563 is: 'iron-overlay-backdrop', | 14277 is: 'iron-overlay-backdrop', |
| 13564 | 14278 |
| 13565 properties: { | 14279 properties: { |
| 13566 | 14280 |
| 13567 /** | 14281 /** |
| 13568 * Returns true if the backdrop is opened. | 14282 * Returns true if the backdrop is opened. |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14035 this.refit(); | 14749 this.refit(); |
| 14036 } | 14750 } |
| 14037 } | 14751 } |
| 14038 | 14752 |
| 14039 /** | 14753 /** |
| 14040 * Fired after the `iron-overlay` opens. | 14754 * Fired after the `iron-overlay` opens. |
| 14041 * @event iron-overlay-opened | 14755 * @event iron-overlay-opened |
| 14042 */ | 14756 */ |
| 14043 | 14757 |
| 14044 /** | 14758 /** |
| 14759 * Fired when the `iron-overlay` is canceled, but before it is closed. |
| 14760 * Cancel the event to prevent the `iron-overlay` from closing. |
| 14761 * @event iron-overlay-canceled |
| 14762 */ |
| 14763 |
| 14764 /** |
| 14045 * Fired after the `iron-overlay` closes. | 14765 * Fired after the `iron-overlay` closes. |
| 14046 * @event iron-overlay-closed | 14766 * @event iron-overlay-closed |
| 14047 * @param {{canceled: (boolean|undefined)}} set to the `closingReason` attribute | 14767 * @param {{canceled: (boolean|undefined)}} set to the `closingReason` attribute |
| 14048 */ | 14768 */ |
| 14049 }; | 14769 }; |
| 14050 | 14770 |
| 14051 /** @polymerBehavior */ | 14771 /** @polymerBehavior */ |
| 14052 Polymer.IronOverlayBehavior = [Polymer.IronFitBehavior, Polymer.IronResizableB
ehavior, Polymer.IronOverlayBehaviorImpl]; | 14772 Polymer.IronOverlayBehavior = [Polymer.IronFitBehavior, Polymer.IronResizableB
ehavior, Polymer.IronOverlayBehaviorImpl]; |
| 14053 /** | 14773 /** |
| 14054 * Use `Polymer.NeonAnimationBehavior` to implement an animation. | 14774 * Use `Polymer.NeonAnimationBehavior` to implement an animation. |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15400 _altChanged: function(newValue, oldValue) { | 16120 _altChanged: function(newValue, oldValue) { |
| 15401 var label = this.getAttribute('aria-label'); | 16121 var label = this.getAttribute('aria-label'); |
| 15402 | 16122 |
| 15403 // Don't stomp over a user-set aria-label. | 16123 // Don't stomp over a user-set aria-label. |
| 15404 if (!label || oldValue == label) { | 16124 if (!label || oldValue == label) { |
| 15405 this.setAttribute('aria-label', newValue); | 16125 this.setAttribute('aria-label', newValue); |
| 15406 } | 16126 } |
| 15407 } | 16127 } |
| 15408 }); | 16128 }); |
| 15409 /** | 16129 /** |
| 15410 * Use `Polymer.IronValidatableBehavior` to implement an element that validate
s user input. | 16130 * `Use Polymer.IronValidatableBehavior` to implement an element that validate
s user input. |
| 16131 * Use the related `Polymer.IronValidatorBehavior` to add custom validation lo
gic to an iron-input. |
| 16132 * |
| 16133 * By default, an `<iron-form>` element validates its fields when the user pre
sses the submit button. |
| 16134 * To validate a form imperatively, call the form's `validate()` method, which
in turn will |
| 16135 * call `validate()` on all its children. By using `Polymer.IronValidatableBeh
avior`, your |
| 16136 * custom element will get a public `validate()`, which |
| 16137 * will return the validity of the element, and a corresponding `invalid` attr
ibute, |
| 16138 * which can be used for styling. |
| 16139 * |
| 16140 * To implement the custom validation logic of your element, you must override |
| 16141 * the protected `_getValidity()` method of this behaviour, rather than `valid
ate()`. |
| 16142 * See [this](https://github.com/PolymerElements/iron-form/blob/master/demo/si
mple-element.html) |
| 16143 * for an example. |
| 15411 * | 16144 * |
| 15412 * ### Accessibility | 16145 * ### Accessibility |
| 15413 * | 16146 * |
| 15414 * Changing the `invalid` property, either manually or by calling `validate()`
will update the | 16147 * Changing the `invalid` property, either manually or by calling `validate()`
will update the |
| 15415 * `aria-invalid` attribute. | 16148 * `aria-invalid` attribute. |
| 15416 * | 16149 * |
| 15417 * @demo demo/index.html | 16150 * @demo demo/index.html |
| 15418 * @polymerBehavior | 16151 * @polymerBehavior |
| 15419 */ | 16152 */ |
| 15420 Polymer.IronValidatableBehavior = { | 16153 Polymer.IronValidatableBehavior = { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15570 * set, or the `type` attribute (only supported for `type=number`). | 16303 * set, or the `type` attribute (only supported for `type=number`). |
| 15571 */ | 16304 */ |
| 15572 preventInvalidInput: { | 16305 preventInvalidInput: { |
| 15573 type: Boolean | 16306 type: Boolean |
| 15574 }, | 16307 }, |
| 15575 | 16308 |
| 15576 /** | 16309 /** |
| 15577 * Regular expression to match valid input characters. | 16310 * Regular expression to match valid input characters. |
| 15578 */ | 16311 */ |
| 15579 allowedPattern: { | 16312 allowedPattern: { |
| 15580 type: String | 16313 type: String, |
| 16314 observer: "_allowedPatternChanged" |
| 15581 }, | 16315 }, |
| 15582 | 16316 |
| 15583 _previousValidInput: { | 16317 _previousValidInput: { |
| 15584 type: String, | 16318 type: String, |
| 15585 value: '' | 16319 value: '' |
| 15586 }, | 16320 }, |
| 15587 | 16321 |
| 15588 _patternAlreadyChecked: { | 16322 _patternAlreadyChecked: { |
| 15589 type: Boolean, | 16323 type: Boolean, |
| 15590 value: false | 16324 value: false |
| (...skipping 30 matching lines...) Expand all Loading... |
| 15621 * @suppress {checkTypes} | 16355 * @suppress {checkTypes} |
| 15622 */ | 16356 */ |
| 15623 _bindValueChanged: function() { | 16357 _bindValueChanged: function() { |
| 15624 if (this.value !== this.bindValue) { | 16358 if (this.value !== this.bindValue) { |
| 15625 this.value = !(this.bindValue || this.bindValue === 0) ? '' : this.bindV
alue; | 16359 this.value = !(this.bindValue || this.bindValue === 0) ? '' : this.bindV
alue; |
| 15626 } | 16360 } |
| 15627 // manually notify because we don't want to notify until after setting val
ue | 16361 // manually notify because we don't want to notify until after setting val
ue |
| 15628 this.fire('bind-value-changed', {value: this.bindValue}); | 16362 this.fire('bind-value-changed', {value: this.bindValue}); |
| 15629 }, | 16363 }, |
| 15630 | 16364 |
| 16365 _allowedPatternChanged: function() { |
| 16366 // Force to prevent invalid input when an `allowed-pattern` is set |
| 16367 this.preventInvalidInput = this.allowedPattern ? true : false; |
| 16368 }, |
| 16369 |
| 15631 _onInput: function() { | 16370 _onInput: function() { |
| 15632 // Need to validate each of the characters pasted if they haven't | 16371 // Need to validate each of the characters pasted if they haven't |
| 15633 // been validated inside `_onKeypress` already. | 16372 // been validated inside `_onKeypress` already. |
| 15634 if (this.preventInvalidInput && !this._patternAlreadyChecked) { | 16373 if (this.preventInvalidInput && !this._patternAlreadyChecked) { |
| 15635 var valid = this._checkPatternValidity(); | 16374 var valid = this._checkPatternValidity(); |
| 15636 if (!valid) { | 16375 if (!valid) { |
| 15637 this.value = this._previousValidInput; | 16376 this.value = this._previousValidInput; |
| 15638 } | 16377 } |
| 15639 } | 16378 } |
| 15640 | 16379 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15967 } | 16706 } |
| 15968 }, | 16707 }, |
| 15969 | 16708 |
| 15970 _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused,
invalid, _inputHasContent) { | 16709 _computeInputContentClass: function(noLabelFloat, alwaysFloatLabel, focused,
invalid, _inputHasContent) { |
| 15971 var cls = 'input-content'; | 16710 var cls = 'input-content'; |
| 15972 if (!noLabelFloat) { | 16711 if (!noLabelFloat) { |
| 15973 var label = this.querySelector('label'); | 16712 var label = this.querySelector('label'); |
| 15974 | 16713 |
| 15975 if (alwaysFloatLabel || _inputHasContent) { | 16714 if (alwaysFloatLabel || _inputHasContent) { |
| 15976 cls += ' label-is-floating'; | 16715 cls += ' label-is-floating'; |
| 16716 // If the label is floating, ignore any offsets that may have been |
| 16717 // applied from a prefix element. |
| 16718 this.$.labelAndInputContainer.style.position = 'static'; |
| 16719 |
| 15977 if (invalid) { | 16720 if (invalid) { |
| 15978 cls += ' is-invalid'; | 16721 cls += ' is-invalid'; |
| 15979 } else if (focused) { | 16722 } else if (focused) { |
| 15980 cls += " label-is-highlighted"; | 16723 cls += " label-is-highlighted"; |
| 15981 } | 16724 } |
| 15982 // The label might have a horizontal offset if a prefix element exists | |
| 15983 // which needs to be undone when displayed as a floating label. | |
| 15984 if (Polymer.dom(this.$.prefix).getDistributedNodes().length > 0 && | |
| 15985 label && label.offsetParent) { | |
| 15986 label.style.left = -label.offsetParent.offsetLeft + 'px'; | |
| 15987 } | |
| 15988 } else { | 16725 } else { |
| 15989 // When the label is not floating, it should overlap the input element
. | 16726 // When the label is not floating, it should overlap the input element
. |
| 15990 if (label) { | 16727 if (label) { |
| 15991 label.style.left = 0; | 16728 this.$.labelAndInputContainer.style.position = 'relative'; |
| 15992 } | 16729 } |
| 15993 } | 16730 } |
| 15994 } else { | 16731 } else { |
| 15995 if (_inputHasContent) { | 16732 if (_inputHasContent) { |
| 15996 cls += ' label-is-hidden'; | 16733 cls += ' label-is-hidden'; |
| 15997 } | 16734 } |
| 15998 } | 16735 } |
| 15999 return cls; | 16736 return cls; |
| 16000 }, | 16737 }, |
| 16001 | 16738 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16202 hasDownloads_: { | 16939 hasDownloads_: { |
| 16203 type: Boolean, | 16940 type: Boolean, |
| 16204 value: false, | 16941 value: false, |
| 16205 }, | 16942 }, |
| 16206 | 16943 |
| 16207 items_: { | 16944 items_: { |
| 16208 type: Array, | 16945 type: Array, |
| 16209 }, | 16946 }, |
| 16210 }, | 16947 }, |
| 16211 | 16948 |
| 16949 hostAttributes: { |
| 16950 loading: true, |
| 16951 }, |
| 16952 |
| 16212 /** | 16953 /** |
| 16213 * @param {Event} e | 16954 * @param {Event} e |
| 16214 * @private | 16955 * @private |
| 16215 */ | 16956 */ |
| 16216 onCanExecute_: function(e) { | 16957 onCanExecute_: function(e) { |
| 16217 e = /** @type {cr.ui.CanExecuteEvent} */(e); | 16958 e = /** @type {cr.ui.CanExecuteEvent} */(e); |
| 16218 switch (e.command.id) { | 16959 switch (e.command.id) { |
| 16219 case 'undo-command': | 16960 case 'undo-command': |
| 16220 e.canExecute = this.$.toolbar.canUndo(); | 16961 e.canExecute = this.$.toolbar.canUndo(); |
| 16221 break; | 16962 break; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16284 var isSearching = downloads.ActionService.getInstance().isSearching(); | 17025 var isSearching = downloads.ActionService.getInstance().isSearching(); |
| 16285 var messageToShow = isSearching ? 'noSearchResults' : 'noDownloads'; | 17026 var messageToShow = isSearching ? 'noSearchResults' : 'noDownloads'; |
| 16286 this.$['no-downloads'].querySelector('span').textContent = | 17027 this.$['no-downloads'].querySelector('span').textContent = |
| 16287 loadTimeData.getString(messageToShow); | 17028 loadTimeData.getString(messageToShow); |
| 16288 } | 17029 } |
| 16289 this.hasDownloads_ = hasDownloads; | 17030 this.hasDownloads_ = hasDownloads; |
| 16290 | 17031 |
| 16291 if (loadTimeData.getBoolean('allowDeletingHistory')) | 17032 if (loadTimeData.getBoolean('allowDeletingHistory')) |
| 16292 this.$.toolbar.downloadsShowing = this.hasDownloads_; | 17033 this.$.toolbar.downloadsShowing = this.hasDownloads_; |
| 16293 | 17034 |
| 16294 this.$.panel.classList.remove('loading'); | 17035 this.removeAttribute('loading'); |
| 16295 }, | 17036 }, |
| 16296 | 17037 |
| 16297 /** | 17038 /** |
| 16298 * @param {!downloads.Data} data | 17039 * @param {!downloads.Data} data |
| 16299 * @private | 17040 * @private |
| 16300 */ | 17041 */ |
| 16301 updateItem_: function(data) { | 17042 updateItem_: function(data) { |
| 16302 var index = this.idToIndex_[data.id]; | 17043 var index = this.idToIndex_[data.id]; |
| 16303 this.set('items_.' + index, data); | 17044 this.set('items_.' + index, data); |
| 16304 this.$['downloads-list'].updateSizeForItem(index); | 17045 this.$['downloads-list'].updateSizeForItem(index); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 16321 document.querySelector('downloads-manager').onLoad_(); | 17062 document.querySelector('downloads-manager').onLoad_(); |
| 16322 }; | 17063 }; |
| 16323 | 17064 |
| 16324 return {Manager: Manager}; | 17065 return {Manager: Manager}; |
| 16325 }); | 17066 }); |
| 16326 // Copyright 2015 The Chromium Authors. All rights reserved. | 17067 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 16327 // Use of this source code is governed by a BSD-style license that can be | 17068 // Use of this source code is governed by a BSD-style license that can be |
| 16328 // found in the LICENSE file. | 17069 // found in the LICENSE file. |
| 16329 | 17070 |
| 16330 window.addEventListener('load', downloads.Manager.onLoad); | 17071 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |