UNPKG

five-bells-visualization

Version:
176 lines (144 loc) 5.19 kB
<!-- Copyright (c) 2014 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> <link href="../../polymer/polymer.html" rel="import"> <link href="../../core-style/core-style.html" rel="import"> <link href="../../core-transition/core-transition.html" rel="import"> <!-- `core-transition-pages` represents a page transition, which may include CSS and/or script. It will look for a `core-style` element with the same `id` to install in the scope of the `core-animated-pages` that's using the transition. Example: <core-style id="fooTransition"> // some CSS here </core-style> <core-transition-pages id="fooTransition"></core-transition-pages> There are three stages to a page transition: 1. `prepare`: Called to set up the incoming and outgoing pages to the "before" state, e.g. setting the incoming page to `opacity: 0` for `cross-fade` or find and measure hero elements for `hero-transition`. 2. `go`: Called to run the transition. For CSS-based transitions, this generally applies a CSS `transition` property. 3. `complete`: Called when the elements are finished transitioning. See the individual transition documentation for specific details. @element core-transition-pages @extends core-transition @status beta @homepage github.io --> <!-- Fired when the transition completes. @event core-transitionend --> <polymer-element name="core-transition-pages" extends="core-transition"> <script> (function () { // create some basic transition styling data. var transitions = CoreStyle.g.transitions = CoreStyle.g.transitions || {}; transitions.duration = '500ms'; transitions.heroDelay = '50ms'; transitions.scaleDelay = '500ms'; transitions.cascadeFadeDuration = '250ms'; Polymer({ publish: { /** * This class will be applied to the scope element in the `prepare` function. * It is removed in the `complete` function. Used to activate a set of CSS * rules that need to apply before the transition runs, e.g. a default opacity * or transform for the non-active pages. * * @attribute scopeClass * @type string * @default '' */ scopeClass: '', /** * This class will be applied to the scope element in the `go` function. It is * remoived in the `complete' function. Generally used to apply a CSS transition * rule only during the transition. * * @attribute activeClass * @type string * @default '' */ activeClass: '', /** * Specifies which CSS property to look for when it receives a `transitionEnd` event * to determine whether the transition is complete. If not specified, the first * transitionEnd event received will complete the transition. * * @attribute transitionProperty * @type string * @default '' */ transitionProperty: '' }, /** * True if this transition is complete. * * @attribute completed * @type boolean * @default false */ completed: false, prepare: function(scope, options) { this.boundCompleteFn = this.complete.bind(this, scope); if (this.scopeClass) { scope.classList.add(this.scopeClass); } }, go: function(scope, options) { this.completed = false; if (this.activeClass) { scope.classList.add(this.activeClass); } scope.addEventListener('transitionend', this.boundCompleteFn, false); }, setup: function(scope) { if (!scope._pageTransitionStyles) { scope._pageTransitionStyles = {}; } var name = this.calcStyleName(); if (!scope._pageTransitionStyles[name]) { this.installStyleInScope(scope, name); scope._pageTransitionStyles[name] = true; } }, calcStyleName: function() { return this.id || this.localName; }, installStyleInScope: function(scope, id) { if (!scope.shadowRoot) { scope.createShadowRoot().innerHTML = '<content></content>'; } var root = scope.shadowRoot; var scopeStyle = document.createElement('core-style'); root.insertBefore(scopeStyle, root.firstChild); scopeStyle.applyRef(id); }, complete: function(scope, e) { // TODO(yvonne): hack, need to manage completion better if (e.propertyName !== 'box-shadow' && (!this.transitionProperty || e.propertyName.indexOf(this.transitionProperty) !== -1)) { this.completed = true; this.fire('core-transitionend', this, scope); } }, // TODO(sorvell): ideally we do this in complete. ensureComplete: function(scope) { scope.removeEventListener('transitionend', this.boundCompleteFn, false); if (this.scopeClass) { scope.classList.remove(this.scopeClass); } if (this.activeClass) { scope.classList.remove(this.activeClass); } } }); })(); </script> </polymer-element>