| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 6 Code distributed by Google as part of the polymer project is also | |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 8 --> | |
| 9 | |
| 10 <link href="../../polymer/polymer.html" rel="import"> | |
| 11 <link href="../../core-style/core-style.html" rel="import"> | |
| 12 <link href="../../core-transition/core-transition.html" rel="import"> | |
| 13 | |
| 14 <!-- | |
| 15 | |
| 16 `core-transition-pages` represents a page transition, which may include CSS and/
or | |
| 17 script. It will look for a `core-style` element with the same `id` to install in
the | |
| 18 scope of the `core-animated-pages` that's using the transition. | |
| 19 | |
| 20 Example: | |
| 21 | |
| 22 <core-style id="fooTransition"> | |
| 23 // some CSS here | |
| 24 </core-style> | |
| 25 <core-transition-pages id="fooTransition"></core-transition-pages> | |
| 26 | |
| 27 There are three stages to a page transition: | |
| 28 | |
| 29 1. `prepare`: Called to set up the incoming and outgoing pages to the "before" s
tate, | |
| 30 e.g. setting the incoming page to `opacity: 0` for `cross-fade` or find and | |
| 31 measure hero elements for `hero-transition`. | |
| 32 | |
| 33 2. `go`: Called to run the transition. For CSS-based transitions, this generally | |
| 34 applies a CSS `transition` property. | |
| 35 | |
| 36 3. `complete`: Called when the elements are finished transitioning. | |
| 37 | |
| 38 See the individual transition documentation for specific details. | |
| 39 | |
| 40 @element core-transition-pages | |
| 41 @extends core-transition | |
| 42 @status beta | |
| 43 @homepage github.io | |
| 44 --> | |
| 45 <!-- | |
| 46 Fired when the transition completes. | |
| 47 | |
| 48 @event core-transitionend | |
| 49 --> | |
| 50 <polymer-element name="core-transition-pages" extends="core-transition"> | |
| 51 <script> | |
| 52 | |
| 53 (function () { | |
| 54 | |
| 55 // create some basic transition styling data. | |
| 56 var transitions = CoreStyle.g.transitions = CoreStyle.g.transitions || {}; | |
| 57 transitions.duration = '500ms'; | |
| 58 transitions.heroDelay = '50ms'; | |
| 59 transitions.scaleDelay = '500ms'; | |
| 60 transitions.cascadeFadeDuration = '250ms'; | |
| 61 | |
| 62 Polymer({ | |
| 63 | |
| 64 publish: { | |
| 65 /** | |
| 66 * This class will be applied to the scope element in the `prepare` function
. | |
| 67 * It is removed in the `complete` function. Used to activate a set of CSS | |
| 68 * rules that need to apply before the transition runs, e.g. a default opaci
ty | |
| 69 * or transform for the non-active pages. | |
| 70 * | |
| 71 * @attribute scopeClass | |
| 72 * @type string | |
| 73 * @default '' | |
| 74 */ | |
| 75 scopeClass: '', | |
| 76 | |
| 77 /** | |
| 78 * This class will be applied to the scope element in the `go` function. It
is | |
| 79 * remoived in the `complete' function. Generally used to apply a CSS transi
tion | |
| 80 * rule only during the transition. | |
| 81 * | |
| 82 * @attribute activeClass | |
| 83 * @type string | |
| 84 * @default '' | |
| 85 */ | |
| 86 activeClass: '', | |
| 87 | |
| 88 /** | |
| 89 * Specifies which CSS property to look for when it receives a `transitionEn
d` event | |
| 90 * to determine whether the transition is complete. If not specified, the fi
rst | |
| 91 * transitionEnd event received will complete the transition. | |
| 92 * | |
| 93 * @attribute transitionProperty | |
| 94 * @type string | |
| 95 * @default '' | |
| 96 */ | |
| 97 transitionProperty: '' | |
| 98 }, | |
| 99 | |
| 100 /** | |
| 101 * True if this transition is complete. | |
| 102 * | |
| 103 * @attribute completed | |
| 104 * @type boolean | |
| 105 * @default false | |
| 106 */ | |
| 107 completed: false, | |
| 108 | |
| 109 prepare: function(scope, options) { | |
| 110 this.boundCompleteFn = this.complete.bind(this, scope); | |
| 111 if (this.scopeClass) { | |
| 112 scope.classList.add(this.scopeClass); | |
| 113 } | |
| 114 }, | |
| 115 | |
| 116 go: function(scope, options) { | |
| 117 this.completed = false; | |
| 118 if (this.activeClass) { | |
| 119 scope.classList.add(this.activeClass); | |
| 120 } | |
| 121 scope.addEventListener('transitionend', this.boundCompleteFn, false); | |
| 122 }, | |
| 123 | |
| 124 setup: function(scope) { | |
| 125 if (!scope._pageTransitionStyles) { | |
| 126 scope._pageTransitionStyles = {}; | |
| 127 } | |
| 128 | |
| 129 var name = this.calcStyleName(); | |
| 130 | |
| 131 if (!scope._pageTransitionStyles[name]) { | |
| 132 this.installStyleInScope(scope, name); | |
| 133 scope._pageTransitionStyles[name] = true; | |
| 134 } | |
| 135 }, | |
| 136 | |
| 137 calcStyleName: function() { | |
| 138 return this.id || this.localName; | |
| 139 }, | |
| 140 | |
| 141 installStyleInScope: function(scope, id) { | |
| 142 if (!scope.shadowRoot) { | |
| 143 scope.createShadowRoot().innerHTML = '<content></content>'; | |
| 144 } | |
| 145 var root = scope.shadowRoot; | |
| 146 var scopeStyle = document.createElement('core-style'); | |
| 147 root.insertBefore(scopeStyle, root.firstChild); | |
| 148 scopeStyle.applyRef(id); | |
| 149 }, | |
| 150 | |
| 151 complete: function(scope, e) { | |
| 152 // TODO(yvonne): hack, need to manage completion better | |
| 153 if (e.propertyName !== 'box-shadow' && (!this.transitionProperty || e.proper
tyName.indexOf(this.transitionProperty) !== -1)) { | |
| 154 this.completed = true; | |
| 155 this.fire('core-transitionend', this, scope); | |
| 156 } | |
| 157 }, | |
| 158 | |
| 159 // TODO(sorvell): ideally we do this in complete. | |
| 160 ensureComplete: function(scope) { | |
| 161 scope.removeEventListener('transitionend', this.boundCompleteFn, false); | |
| 162 if (this.scopeClass) { | |
| 163 scope.classList.remove(this.scopeClass); | |
| 164 } | |
| 165 if (this.activeClass) { | |
| 166 scope.classList.remove(this.activeClass); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 }); | |
| 171 | |
| 172 })(); | |
| 173 | |
| 174 </script> | |
| 175 </polymer-element> | |
| OLD | NEW |