Index: third_party/polymer/v0_8/components-chromium/paper-ripple/paper-ripple-extracted.js |
diff --git a/third_party/polymer/v0_8/components-chromium/paper-ripple/paper-ripple-extracted.js b/third_party/polymer/v0_8/components-chromium/paper-ripple/paper-ripple-extracted.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..af02d203f458b3237dd429b2286c56dacb69e2ea |
--- /dev/null |
+++ b/third_party/polymer/v0_8/components-chromium/paper-ripple/paper-ripple-extracted.js |
@@ -0,0 +1,482 @@ |
+ |
+ (function() { |
+ var Utility = { |
+ cssColorWithAlpha: function(cssColor, alpha) { |
+ var parts = cssColor.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); |
+ |
+ if (typeof alpha == 'undefined') { |
+ alpha = 1; |
+ } |
+ |
+ if (!parts) { |
+ return 'rgba(255, 255, 255, ' + alpha + ')'; |
+ } |
+ |
+ return 'rgba(' + parts[1] + ', ' + parts[2] + ', ' + parts[3] + ', ' + alpha + ')'; |
+ }, |
+ |
+ distance: function(x1, y1, x2, y2) { |
+ var xDelta = (x1 - x2); |
+ var yDelta = (y1 - y2); |
+ |
+ return Math.sqrt(xDelta * xDelta + yDelta * yDelta); |
+ }, |
+ |
+ now: (function() { |
+ if (window.performance && window.performance.now) { |
+ return window.performance.now.bind(window.performance); |
+ } |
+ |
+ return Date.now; |
+ })() |
+ }; |
+ |
+ /** |
+ * @param {HTMLElement} element |
+ * @constructor |
+ */ |
+ function ElementMetrics(element) { |
+ this.element = element; |
+ this.width = this.boundingRect.width; |
+ this.height = this.boundingRect.height; |
+ |
+ this.size = Math.max(this.width, this.height); |
+ } |
+ |
+ ElementMetrics.prototype = { |
+ get boundingRect () { |
+ return this.element.getBoundingClientRect(); |
+ }, |
+ |
+ furthestCornerDistanceFrom: function(x, y) { |
+ var topLeft = Utility.distance(x, y, 0, 0); |
+ var topRight = Utility.distance(x, y, this.width, 0); |
+ var bottomLeft = Utility.distance(x, y, 0, this.height); |
+ var bottomRight = Utility.distance(x, y, this.width, this.height); |
+ |
+ return Math.max(topLeft, topRight, bottomLeft, bottomRight); |
+ } |
+ }; |
+ |
+ /** |
+ * @param {HTMLElement} element |
+ * @constructor |
+ */ |
+ function Ripple(element) { |
+ this.element = element; |
+ this.color = window.getComputedStyle(element).color; |
+ |
+ this.wave = document.createElement('div'); |
+ this.waveContainer = document.createElement('div'); |
+ this.wave.style.backgroundColor = this.color; |
+ this.wave.classList.add('wave'); |
+ this.waveContainer.classList.add('wave-container'); |
+ Polymer.dom(this.waveContainer).appendChild(this.wave); |
+ |
+ this.resetInteractionState(); |
+ } |
+ |
+ Ripple.MAX_RADIUS = 300; |
+ |
+ Ripple.prototype = { |
+ get recenters() { |
+ return this.element.recenters; |
+ }, |
+ |
+ get mouseDownElapsed() { |
+ var elapsed; |
+ |
+ if (!this.mouseDownStart) { |
+ return 0; |
+ } |
+ |
+ elapsed = Utility.now() - this.mouseDownStart; |
+ |
+ if (this.mouseUpStart) { |
+ elapsed -= this.mouseUpElapsed; |
+ } |
+ |
+ return elapsed; |
+ }, |
+ |
+ get mouseUpElapsed() { |
+ return this.mouseUpStart ? |
+ Utility.now () - this.mouseUpStart : 0; |
+ }, |
+ |
+ get mouseDownElapsedSeconds() { |
+ return this.mouseDownElapsed / 1000; |
+ }, |
+ |
+ get mouseUpElapsedSeconds() { |
+ return this.mouseUpElapsed / 1000; |
+ }, |
+ |
+ get mouseInteractionSeconds() { |
+ return this.mouseDownElapsedSeconds + this.mouseUpElapsedSeconds; |
+ }, |
+ |
+ get initialOpacity() { |
+ return this.element.initialOpacity; |
+ }, |
+ |
+ get opacityDecayVelocity() { |
+ return this.element.opacityDecayVelocity; |
+ }, |
+ |
+ get radius() { |
+ var width2 = this.containerMetrics.width * this.containerMetrics.width; |
+ var height2 = this.containerMetrics.height * this.containerMetrics.height; |
+ var waveRadius = Math.min( |
+ Math.sqrt(width2 + height2), |
+ Ripple.MAX_RADIUS |
+ ) * 1.1 + 5; |
+ |
+ var duration = 1.1 - 0.2 * (waveRadius / Ripple.MAX_RADIUS); |
+ var timeNow = this.mouseInteractionSeconds / duration; |
+ var size = waveRadius * (1 - Math.pow(80, -timeNow)); |
+ |
+ return Math.abs(size); |
+ }, |
+ |
+ get opacity() { |
+ if (!this.mouseUpStart) { |
+ return this.initialOpacity; |
+ } |
+ |
+ return Math.max( |
+ 0, |
+ this.initialOpacity - this.mouseUpElapsedSeconds * this.opacityDecayVelocity |
+ ); |
+ }, |
+ |
+ get outerOpacity() { |
+ // Linear increase in background opacity, capped at the opacity |
+ // of the wavefront (waveOpacity). |
+ var outerOpacity = this.mouseUpElapsedSeconds * 0.3; |
+ var waveOpacity = this.opacity; |
+ |
+ return Math.max( |
+ 0, |
+ Math.min(outerOpacity, waveOpacity) |
+ ); |
+ }, |
+ |
+ get isOpacityFullyDecayed() { |
+ return this.opacity < 0.01 && |
+ this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS); |
+ }, |
+ |
+ get isRestingAtMaxRadius() { |
+ return this.opacity >= this.initialOpacity && |
+ this.radius >= Math.min(this.maxRadius, Ripple.MAX_RADIUS); |
+ }, |
+ |
+ get isAnimationComplete() { |
+ return this.mouseUpStart ? |
+ this.isOpacityFullyDecayed : this.isRestingAtMaxRadius; |
+ }, |
+ |
+ get translationFraction() { |
+ return Math.min( |
+ 1, |
+ this.radius / this.containerMetrics.size * 2 / Math.sqrt(2) |
+ ); |
+ }, |
+ |
+ get xNow() { |
+ if (this.xEnd) { |
+ return this.xStart + this.translationFraction * (this.xEnd - this.xStart); |
+ } |
+ |
+ return this.xStart; |
+ }, |
+ |
+ get yNow() { |
+ if (this.yEnd) { |
+ return this.yStart + this.translationFraction * (this.yEnd - this.yStart); |
+ } |
+ |
+ return this.yStart; |
+ }, |
+ |
+ get isMouseDown() { |
+ return this.mouseDownStart && !this.mouseUpStart; |
+ }, |
+ |
+ resetInteractionState: function() { |
+ this.maxRadius = 0; |
+ this.mouseDownStart = 0; |
+ this.mouseUpStart = 0; |
+ |
+ this.xStart = 0; |
+ this.yStart = 0; |
+ this.xEnd = 0; |
+ this.yEnd = 0; |
+ this.slideDistance = 0; |
+ |
+ this.containerMetrics = new ElementMetrics(this.element); |
+ }, |
+ |
+ draw: function() { |
+ var scale; |
+ var translateString; |
+ var dx; |
+ var dy; |
+ |
+ this.wave.style.opacity = this.opacity; |
+ |
+ scale = this.radius / (this.containerMetrics.size / 2); |
+ dx = this.xNow - (this.containerMetrics.width / 2); |
+ dy = this.yNow - (this.containerMetrics.height / 2); |
+ |
+ Polymer.Base.translate3d(this.waveContainer, dx + 'px', dy + 'px', 0); |
+ |
+ // 2d transform for safari because of border-radius and overflow:hidden clipping bug. |
+ // https://bugs.webkit.org/show_bug.cgi?id=98538 |
+ this.wave.style.webkitTransform = 'scale(' + scale + ',' + scale + ')'; |
+ this.wave.style.transform = 'scale3d(' + scale + ',' + scale + ',1)'; |
+ }, |
+ |
+ mousedownAction: function(event) { |
+ this.resetInteractionState(); |
+ this.mouseDownStart = Utility.now(); |
+ |
+ this.xStart = event ? |
+ event.x - this.containerMetrics.boundingRect.left : |
+ this.containerMetrics.width / 2; |
+ this.yStart = event ? |
+ event.y - this.containerMetrics.boundingRect.top : |
+ this.containerMetrics.height / 2; |
+ |
+ if (this.recenters) { |
+ this.xEnd = this.containerMetrics.width / 2; |
+ this.yEnd = this.containerMetrics.height / 2; |
+ this.slideDistance = Utility.distance( |
+ this.xStart, this.yStart, this.xEnd, this.yEnd |
+ ); |
+ } |
+ |
+ this.maxRadius = this.containerMetrics.furthestCornerDistanceFrom( |
+ this.xStart, |
+ this.yStart |
+ ); |
+ |
+ this.waveContainer.style.top = |
+ (this.containerMetrics.height - this.containerMetrics.size) / 2 + 'px'; |
+ this.waveContainer.style.left = |
+ (this.containerMetrics.width - this.containerMetrics.size) / 2 + 'px'; |
+ |
+ this.waveContainer.style.width = this.containerMetrics.size + 'px'; |
+ this.waveContainer.style.height = this.containerMetrics.size + 'px'; |
+ }, |
+ |
+ mouseupAction: function(event) { |
+ if (!this.isMouseDown) { |
+ return; |
+ } |
+ |
+ this.mouseUpStart = Utility.now(); |
+ }, |
+ |
+ remove: function() { |
+ Polymer.dom(this.waveContainer.parentNode).removeChild( |
+ this.waveContainer |
+ ); |
+ } |
+ }; |
+ |
+ Polymer({ |
+ is: 'paper-ripple', |
+ |
+ properties: { |
+ /** |
+ * The initial opacity set on the wave. |
+ * |
+ * @attribute initialOpacity |
+ * @type number |
+ * @default 0.25 |
+ */ |
+ initialOpacity: { |
+ type: Number, |
+ value: 0.25 |
+ }, |
+ |
+ /** |
+ * How fast (opacity per second) the wave fades out. |
+ * |
+ * @attribute opacityDecayVelocity |
+ * @type number |
+ * @default 0.8 |
+ */ |
+ opacityDecayVelocity: { |
+ type: Number, |
+ value: 0.8 |
+ }, |
+ |
+ /** |
+ * If true, ripples will exhibit a gravitational pull towards |
+ * the center of their container as they fade away. |
+ * |
+ * @attribute recenters |
+ * @type boolean |
+ * @default false |
+ */ |
+ recenters: { |
+ type: Boolean, |
+ value: false |
+ }, |
+ |
+ /** |
+ * A list of the visual ripples. |
+ * |
+ * @attribute ripples |
+ * @type Array |
+ * @default [] |
+ */ |
+ ripples: { |
+ type: Array, |
+ value: function() { |
+ return []; |
+ } |
+ }, |
+ |
+ _animating: { |
+ type: Boolean |
+ }, |
+ |
+ _boundAnimate: { |
+ type: Function, |
+ value: function() { |
+ return this.animate.bind(this); |
+ } |
+ }, |
+ |
+ _boundMousedownAction: { |
+ type: Function, |
+ value: function() { |
+ return this.mousedownAction.bind(this); |
+ } |
+ }, |
+ |
+ _boundMouseupAction: { |
+ type: Function, |
+ value: function() { |
+ return this.mouseupAction.bind(this); |
+ } |
+ } |
+ }, |
+ |
+ get target () { |
+ return this.host || this.parentNode; |
+ }, |
+ |
+ attached: function() { |
+ this.target.addEventListener('mousedown', this._boundMousedownAction); |
+ this.target.addEventListener('mouseup', this._boundMouseupAction); |
+ }, |
+ |
+ detached: function() { |
+ this.target.removeEventListener('mousedown', this._boundMousedownAction); |
+ this.target.removeEventListener('mouseup', this._boundMouseupAction); |
+ }, |
+ |
+ /* TODO(cdata): Replace the above attached / detached listeners when |
+ PolymerGestures equivalent lands in 0.8. |
+ listeners: { |
+ mousedown: 'mousedownAction', |
+ mouseup: 'mouseupAction' |
+ }, |
+ */ |
+ |
+ get shouldKeepAnimating () { |
+ for (var index = 0; index < this.ripples.length; ++index) { |
+ if (!this.ripples[index].isAnimationComplete) { |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+ }, |
+ |
+ simulatedRipple: function() { |
+ this.mousedownAction(null); |
+ |
+ // Please see polymer/polymer#1305 |
+ this.async(function() { |
+ this.mouseupAction(); |
+ }, 1); |
+ }, |
+ |
+ mousedownAction: function(event) { |
+ var ripple = this.addRipple(); |
+ |
+ ripple.mousedownAction(event); |
+ |
+ if (!this._animating) { |
+ this.animate(); |
+ } |
+ }, |
+ |
+ mouseupAction: function(event) { |
+ this.ripples.forEach(function(ripple) { |
+ ripple.mouseupAction(event); |
+ }); |
+ |
+ this.animate(); |
+ }, |
+ |
+ onAnimationComplete: function() { |
+ this._animating = false; |
+ this.$.background.style.backgroundColor = null; |
+ this.fire('transitionend'); |
+ }, |
+ |
+ addRipple: function() { |
+ var ripple = new Ripple(this); |
+ |
+ Polymer.dom(this.$.waves).appendChild(ripple.waveContainer); |
+ this.$.background.style.backgroundColor = ripple.color; |
+ this.ripples.push(ripple); |
+ |
+ return ripple; |
+ }, |
+ |
+ removeRipple: function(ripple) { |
+ var rippleIndex = this.ripples.indexOf(ripple); |
+ |
+ if (rippleIndex < 0) { |
+ return; |
+ } |
+ |
+ this.ripples.splice(rippleIndex, 1); |
+ |
+ ripple.remove(); |
+ }, |
+ |
+ animate: function() { |
+ var index; |
+ var ripple; |
+ |
+ this._animating = true; |
+ |
+ for (index = 0; index < this.ripples.length; ++index) { |
+ ripple = this.ripples[index]; |
+ |
+ ripple.draw(); |
+ |
+ this.$.background.style.opacity = ripple.outerOpacity; |
+ |
+ if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) { |
+ this.removeRipple(ripple); |
+ } |
+ } |
+ |
+ if (this.shouldKeepAnimating) { |
+ window.requestAnimationFrame(this._boundAnimate); |
+ } else if (this.ripples.length === 0) { |
+ this.onAnimationComplete(); |
+ } |
+ } |
+ }); |
+ })(); |