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; | |
6 | |
7 Polymer({ | 5 Polymer({ |
8 is: 'viewer-page-selector', | 6 is: 'viewer-page-selector', |
9 | 7 |
10 properties: { | 8 properties: { |
11 /** | 9 /** |
12 * The number of pages the document contains. | 10 * The number of pages the document contains. |
13 */ | 11 */ |
14 docLength: { | 12 docLength: { |
15 type: Number, | 13 type: Number, |
16 value: 1, | 14 value: 1, |
(...skipping 12 matching lines...) Expand all Loading... |
29 pageNoCommitted: function() { | 27 pageNoCommitted: function() { |
30 var page = parseInt(this.pageNo); | 28 var page = parseInt(this.pageNo); |
31 if (!isNaN(page)) { | 29 if (!isNaN(page)) { |
32 this.fire('change-page', {page: page - 1}); | 30 this.fire('change-page', {page: page - 1}); |
33 this.$.input.blur(); | 31 this.$.input.blur(); |
34 } | 32 } |
35 }, | 33 }, |
36 | 34 |
37 docLengthChanged: function() { | 35 docLengthChanged: function() { |
38 var numDigits = this.docLength.toString().length; | 36 var numDigits = this.docLength.toString().length; |
39 this.$.pageselector.style.width = (numDigits * DIGIT_LENGTH) + 'em'; | 37 this.$.pageselector.style.width = numDigits + 'ch'; |
| 38 // Set both sides of the slash to the same width, so that the layout is |
| 39 // exactly centered. |
| 40 this.$['pagelength-spacer'].style.width = numDigits + 'ch'; |
40 }, | 41 }, |
41 | 42 |
42 select: function() { | 43 select: function() { |
43 this.$.input.select(); | 44 this.$.input.select(); |
44 }, | 45 }, |
45 | 46 |
46 /** | 47 /** |
47 * @return {boolean} True if the selector input field is currently focused. | 48 * @return {boolean} True if the selector input field is currently focused. |
48 */ | 49 */ |
49 isActive: function() { | 50 isActive: function() { |
50 return this.shadowRoot.activeElement == this.$.input; | 51 return this.shadowRoot.activeElement == this.$.input; |
51 } | 52 } |
52 }); | 53 }); |
OLD | NEW |