Merge html-office-public repo into src
[chromium-blink-merge.git] / chrome / browser / resources / pdf / elements / viewer-page-indicator / viewer-page-indicator.js
blob8612e170348f1894f46296e0dc5e2be93c984c33
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('viewer-page-indicator', {
6 label: '1',
7 index: 0,
8 timerId: undefined,
9 pageLabels: null,
10 ready: function() {
11 var callback = this.fadeIn.bind(this, 2000);
12 window.addEventListener('scroll', function() {
13 requestAnimationFrame(callback);
14 });
16 initialFadeIn: function() {
17 this.fadeIn(6000);
19 fadeIn: function(displayTime) {
20 var percent = window.scrollY /
21 (document.body.scrollHeight -
22 document.documentElement.clientHeight);
23 this.style.top = percent *
24 (document.documentElement.clientHeight - this.offsetHeight) + 'px';
25 this.style.opacity = 1;
26 clearTimeout(this.timerId);
28 this.timerId = setTimeout(function() {
29 this.style.opacity = 0;
30 this.timerId = undefined;
31 }.bind(this), displayTime);
33 pageLabelsChanged: function() {
34 this.indexChanged();
36 indexChanged: function() {
37 if (this.pageLabels)
38 this.label = this.pageLabels[this.index];
39 else
40 this.label = String(this.index + 1);
42 });