| OLD | NEW |
| 1 <polymer-element name="viewer-toolbar" attributes="fadingIn"> | 1 <polymer-element name="viewer-toolbar" attributes="fadingIn"> |
| 2 <template> | 2 <template> |
| 3 <link rel="stylesheet" href="viewer-toolbar.css"> | 3 <link rel="stylesheet" href="viewer-toolbar.css"> |
| 4 <div id="toolbar"> | 4 <div id="toolbar"> |
| 5 <content></content> | 5 <content></content> |
| 6 </div> | 6 </div> |
| 7 </template> | 7 </template> |
| 8 <script> | 8 <script src="viewer-toolbar.js"></script> |
| 9 Polymer('viewer-toolbar', { | |
| 10 fadingIn: false, | |
| 11 timerId_: undefined, | |
| 12 inInitialFadeIn_: false, | |
| 13 ready: function() { | |
| 14 this.mousemoveCallback = function(e) { | |
| 15 var rect = this.getBoundingClientRect(); | |
| 16 if (e.clientX >= rect.left && e.clientX <= rect.right && | |
| 17 e.clientY >= rect.top && e.clientY <= rect.bottom) { | |
| 18 this.fadingIn = true; | |
| 19 // If we hover over the toolbar, cancel the initial fade in. | |
| 20 if (this.inInitialFadeIn_) | |
| 21 this.inInitialFadeIn_ = false; | |
| 22 } else { | |
| 23 // Initially we want to keep the toolbar up for a longer period. | |
| 24 if (!this.inInitialFadeIn_) | |
| 25 this.fadingIn = false; | |
| 26 } | |
| 27 }.bind(this); | |
| 28 }, | |
| 29 attached: function() { | |
| 30 this.parentNode.addEventListener('mousemove', this.mousemoveCallback); | |
| 31 }, | |
| 32 detached: function() { | |
| 33 this.parentNode.removeEventListener('mousemove', this.mousemoveCallback); | |
| 34 }, | |
| 35 initialFadeIn: function() { | |
| 36 this.inInitialFadeIn_ = true; | |
| 37 this.fadeIn(); | |
| 38 this.fadeOutAfterDelay(6000); | |
| 39 }, | |
| 40 fadingInChanged: function() { | |
| 41 if (this.fadingIn) { | |
| 42 this.fadeIn(); | |
| 43 } else { | |
| 44 if (this.timerId_ === undefined) | |
| 45 this.fadeOutAfterDelay(3000); | |
| 46 } | |
| 47 }, | |
| 48 fadeIn: function() { | |
| 49 this.style.opacity = 1; | |
| 50 clearTimeout(this.timerId_); | |
| 51 this.timerId_ = undefined; | |
| 52 }, | |
| 53 fadeOutAfterDelay: function(delay) { | |
| 54 this.timerId_ = setTimeout( | |
| 55 function() { | |
| 56 this.style.opacity = 0; | |
| 57 this.timerId_ = undefined; | |
| 58 this.inInitialFadeIn_ = false; | |
| 59 }.bind(this), delay); | |
| 60 } | |
| 61 }); | |
| 62 </script> | |
| 63 </polymer-element> | 9 </polymer-element> |
| OLD | NEW |