Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / chrome / browser / resources / pdf / elements / viewer-toolbar / viewer-toolbar.js
blob28f90523e35b0821ab0c727acc76b37f6f5ddfb7
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 Polymer({
6 is: 'viewer-toolbar',
8 properties: {
9 fadingIn: {
10 type: Boolean,
11 value: false,
12 observer: 'fadingInChanged'
16 timerId_: undefined,
18 inInitialFadeIn_: false,
20 ready: function() {
21 this.mousemoveCallback = function(e) {
22 var rect = this.getBoundingClientRect();
23 if (e.clientX >= rect.left && e.clientX <= rect.right &&
24 e.clientY >= rect.top && e.clientY <= rect.bottom) {
25 this.fadingIn = true;
26 // If we hover over the toolbar, cancel the initial fade in.
27 if (this.inInitialFadeIn_)
28 this.inInitialFadeIn_ = false;
29 } else {
30 // Initially we want to keep the toolbar up for a longer period.
31 if (!this.inInitialFadeIn_)
32 this.fadingIn = false;
34 }.bind(this);
37 attached: function() {
38 this.parentNode.addEventListener('mousemove', this.mousemoveCallback);
41 detached: function() {
42 this.parentNode.removeEventListener('mousemove', this.mousemoveCallback);
45 initialFadeIn: function() {
46 this.inInitialFadeIn_ = true;
47 this.fadeIn();
48 this.fadeOutAfterDelay(6000);
51 fadingInChanged: function() {
52 if (this.fadingIn) {
53 this.fadeIn();
54 } else {
55 if (this.timerId_ === undefined)
56 this.fadeOutAfterDelay(3000);
60 fadeIn: function() {
61 this.style.opacity = 1;
62 clearTimeout(this.timerId_);
63 this.timerId_ = undefined;
66 fadeOutAfterDelay: function(delay) {
67 this.timerId_ = setTimeout(
68 function() {
69 this.style.opacity = 0;
70 this.timerId_ = undefined;
71 this.inInitialFadeIn_ = false;
72 }.bind(this), delay);
74 });