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

Unified Diff: third_party/polymer/components-chromium/paper-shadow/paper-shadow-extracted.js

Issue 592593002: Inline scripts were extracted from Polymer elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/echo ""/echo/ Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/components-chromium/paper-shadow/paper-shadow-extracted.js
diff --git a/third_party/polymer/components-chromium/paper-shadow/paper-shadow-extracted.js b/third_party/polymer/components-chromium/paper-shadow/paper-shadow-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..6082cde112255ef1a9dcb583922aea97f93a2f05
--- /dev/null
+++ b/third_party/polymer/components-chromium/paper-shadow/paper-shadow-extracted.js
@@ -0,0 +1,149 @@
+
+ Polymer('paper-shadow', {
+
+ publish: {
+ /**
+ * If set, the shadow is applied to this node.
+ *
+ * @attribute target
+ * @type Element
+ * @default null
+ */
+ target: {value: null, reflect: true},
+
+ /**
+ * The z-depth of this shadow, from 0-5.
+ *
+ * @attribute z
+ * @type number
+ * @default 1
+ */
+ z: {value: 1, reflect: true},
+
+ /**
+ * If true, the shadow animates between z-depth changes.
+ *
+ * @attribute animated
+ * @type boolean
+ * @default false
+ */
+ animated: {value: false, reflect: true},
+
+ /**
+ * Workaround: getComputedStyle is wrong sometimes so `paper-shadow`
+ * may overwrite the `position` CSS property. Set this property to
+ * true to prevent this.
+ *
+ * @attribute hasPosition
+ * @type boolean
+ * @default false
+ */
+ hasPosition: {value: false}
+ },
+
+ // NOTE: include template so that styles are loaded, but remove
+ // so that we can decide dynamically what part to include
+ registerCallback: function(polymerElement) {
+ var template = polymerElement.querySelector('template');
+ this._style = template.content.querySelector('style');
+ this._style.removeAttribute('no-shim');
+ },
+
+ fetchTemplate: function() {
+ return null;
+ },
+
+ attached: function() {
+ this.installScopeStyle(this._style);
+
+ // If no target is bound at attach, default the target to the parent
+ // element or shadow host.
+ if (!this.target) {
+ if (!this.parentElement && this.parentNode.host) {
+ this.target = this.parentNode.host;
+ } else if (this.parentElement && (window.ShadowDOMPolyfill ? this.parentElement !== wrap(document.body) : this.parentElement !== document.body)) {
+ this.target = this.parentElement;
+ }
+ }
+ },
+
+ targetChanged: function(old) {
+ if (old) {
+ this.removeShadow(old);
+ }
+ if (this.target) {
+ this.addShadow(this.target);
+ }
+ },
+
+ zChanged: function(old) {
+ if (this.target && this.target._paperShadow) {
+ var shadow = this.target._paperShadow;
+ ['top', 'bottom'].forEach(function(s) {
+ shadow[s].classList.remove('paper-shadow-' + s + '-z-' + old);
+ shadow[s].classList.add('paper-shadow-' + s + '-z-' + this.z);
+ }.bind(this));
+ }
+ },
+
+ animatedChanged: function() {
+ if (this.target && this.target._paperShadow) {
+ var shadow = this.target._paperShadow;
+ ['top', 'bottom'].forEach(function(s) {
+ if (this.animated) {
+ shadow[s].classList.add('paper-shadow-animated');
+ } else {
+ shadow[s].classList.remove('paper-shadow-animated');
+ }
+ }.bind(this));
+ }
+ },
+
+ addShadow: function(node) {
+ if (node._paperShadow) {
+ return;
+ }
+
+ var computed = getComputedStyle(node);
+ if (!this.hasPosition && computed.position === 'static') {
+ node.style.position = 'relative';
+ }
+ node.style.overflow = 'visible';
+
+ // Both the top and bottom shadows are children of the target, so
+ // it does not affect the classes and CSS properties of the target.
+ ['top', 'bottom'].forEach(function(s) {
+ var inner = (node._paperShadow && node._paperShadow[s]) || document.createElement('div');
+ inner.classList.add('paper-shadow');
+ inner.classList.add('paper-shadow-' + s + '-z-' + this.z);
+ if (this.animated) {
+ inner.classList.add('paper-shadow-animated');
+ }
+
+ if (node.shadowRoot) {
+ node.shadowRoot.insertBefore(inner, node.shadowRoot.firstChild);
+ } else {
+ node.insertBefore(inner, node.firstChild);
+ }
+
+ node._paperShadow = node._paperShadow || {};
+ node._paperShadow[s] = inner;
+ }.bind(this));
+
+ },
+
+ removeShadow: function(node) {
+ if (!node._paperShadow) {
+ return;
+ }
+
+ ['top', 'bottom'].forEach(function(s) {
+ node._paperShadow[s].remove();
+ });
+ node._paperShadow = null;
+
+ node.style.position = null;
+ }
+
+ });
+

Powered by Google App Engine
This is Rietveld 408576698