OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var DIGIT_LENGTH = 0.6; | 5 var DIGIT_LENGTH = 0.6; |
6 | 6 |
7 Polymer({ | 7 Polymer({ |
8 is: 'viewer-page-selector', | 8 is: 'viewer-page-selector', |
9 | 9 |
10 properties: { | 10 properties: { |
11 /** | 11 /** |
12 * The index of the current page being viewed (0-based). | |
13 */ | |
14 index: { | |
15 type: Number, | |
16 value: 0, | |
17 observer: 'indexChanged' | |
18 }, | |
19 | |
20 /** | |
21 * The number of pages the document contains. | 12 * The number of pages the document contains. |
22 */ | 13 */ |
23 docLength: { | 14 docLength: { |
24 type: Number, | 15 type: Number, |
25 value: 1, | 16 value: 1, |
26 observer: 'docLengthChanged' | 17 observer: 'docLengthChanged' |
27 }, | 18 }, |
28 | 19 |
29 /** | 20 /** |
30 * The current entry in the input field (1-based). | 21 * The current page being viewed (1-based). |
31 */ | 22 */ |
32 pageNo: { | 23 pageNo: { |
33 type: String, | 24 type: String, |
34 value: '1', | 25 value: '1' |
35 observer: 'pageNoChanged' | |
36 }, | |
37 }, | |
38 | |
39 pageNoChanged: function() { | |
40 var page = parseInt(this.pageNo); | |
41 if (!isNaN(page) && page != this.index + 1) { | |
42 this.fire('change-page', {page: page - 1}); | |
43 } else { | |
44 // Repopulate the input. | |
45 this.indexChanged(); | |
46 } | 26 } |
47 }, | 27 }, |
48 | 28 |
49 indexChanged: function() { | 29 pageNoCommitted: function(e) { |
raymes
2015/06/02 05:45:56
nit: you can remove e
tsergeant
2015/06/03 06:53:11
Done.
| |
50 this.pageNo = String(this.index + 1); | 30 var page = parseInt(this.pageNo); |
31 if (!isNaN(page)) { | |
32 this.fire('change-page', {page: page - 1}); | |
33 } | |
51 }, | 34 }, |
52 | 35 |
53 docLengthChanged: function() { | 36 docLengthChanged: function() { |
54 var numDigits = this.docLength.toString().length; | 37 var numDigits = this.docLength.toString().length; |
55 this.$.pageselector.style.width = (numDigits * DIGIT_LENGTH) + 'em'; | 38 this.$.pageselector.style.width = (numDigits * DIGIT_LENGTH) + 'em'; |
56 }, | 39 }, |
57 | 40 |
58 select: function() { | 41 select: function() { |
59 this.$.input.select(); | 42 this.$.input.select(); |
60 } | 43 } |
61 }); | 44 }); |
OLD | NEW |