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). | 12 * The index of the current page being viewed (0-based). |
13 */ | 13 */ |
14 index: { | 14 index: { |
raymes
2015/06/02 01:12:03
As we discussed I wonder if we could potentially r
tsergeant
2015/06/02 05:00:39
Done.
| |
15 type: Number, | 15 type: Number, |
16 value: 0, | 16 value: 0, |
17 observer: 'indexChanged' | 17 observer: 'indexChanged' |
18 }, | 18 }, |
19 | 19 |
20 /** | 20 /** |
21 * The number of pages the document contains. | 21 * The number of pages the document contains. |
22 */ | 22 */ |
23 docLength: { | 23 docLength: { |
24 type: Number, | 24 type: Number, |
25 value: 1, | 25 value: 1, |
26 observer: 'docLengthChanged' | 26 observer: 'docLengthChanged' |
27 }, | 27 }, |
28 | 28 |
29 /** | 29 /** |
30 * The current entry in the input field (1-based). | 30 * The current entry in the input field (1-based). |
31 */ | 31 */ |
32 pageNo: { | 32 pageNo: { |
33 type: String, | 33 type: String, |
34 value: '1', | 34 value: '1' |
35 observer: 'pageNoChanged' | 35 } |
36 }, | |
37 }, | 36 }, |
38 | 37 |
39 pageNoChanged: function() { | 38 ready: function() { |
40 var page = parseInt(this.pageNo); | 39 // Polymer 0.8's iron-input's validation method has a bug which resets the |
40 // cursor position to the end of the input field after every character is | |
41 // typed. This makes editing text in the middle of the input difficult. | |
42 // Since we don't use the input validation, just disable it. | |
43 // TODO(tsergeant): Remove this once we have iron-input >= 0.9.5 available. | |
44 this.$.input._onInput = null; | |
raymes
2015/06/02 01:12:03
Will we be able to remove this before you land thi
tsergeant
2015/06/02 05:00:39
Yes, since I'll be waiting for the Polymer 1.0 pat
| |
45 }, | |
46 | |
47 pageNoCommitted: function(e) { | |
48 var page = parseInt(e.target.value); | |
raymes
2015/06/02 01:12:03
is e.target.value the same as this.pageNo?
tsergeant
2015/06/02 05:00:39
Done.
| |
41 if (!isNaN(page) && page != this.index + 1) { | 49 if (!isNaN(page) && page != this.index + 1) { |
42 this.fire('change-page', {page: page - 1}); | 50 this.fire('change-page', {page: page - 1}); |
43 } else { | 51 } else { |
44 // Repopulate the input. | 52 // Repopulate the input. |
45 this.indexChanged(); | 53 this.indexChanged(); |
46 } | 54 } |
47 }, | 55 }, |
48 | 56 |
49 indexChanged: function() { | 57 indexChanged: function() { |
50 this.pageNo = String(this.index + 1); | 58 this.pageNo = String(this.index + 1); |
51 }, | 59 }, |
52 | 60 |
53 docLengthChanged: function() { | 61 docLengthChanged: function() { |
54 var numDigits = this.docLength.toString().length; | 62 var numDigits = this.docLength.toString().length; |
55 this.$.pageselector.style.width = (numDigits * DIGIT_LENGTH) + 'em'; | 63 this.$.pageselector.style.width = (numDigits * DIGIT_LENGTH) + 'em'; |
56 }, | 64 }, |
57 | 65 |
58 select: function() { | 66 select: function() { |
59 this.$.input.select(); | 67 this.$.input.select(); |
60 } | 68 } |
61 }); | 69 }); |
OLD | NEW |