OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @param {string} toTest The string to be tested. | 6 * @param {string} toTest The string to be tested. |
7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing | 7 * @return {boolean} True if |toTest| contains only digits. Leading and trailing |
8 * whitespace is allowed. | 8 * whitespace is allowed. |
9 */ | 9 */ |
10 function isInteger(toTest) { | 10 function isInteger(toTest) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 var tempFrom = pageSet[i]; | 180 var tempFrom = pageSet[i]; |
181 while (i + 1 < pageSet.length && pageSet[i + 1] == pageSet[i] + 1) | 181 while (i + 1 < pageSet.length && pageSet[i + 1] == pageSet[i] + 1) |
182 ++i; | 182 ++i; |
183 var tempTo = pageSet[i]; | 183 var tempTo = pageSet[i]; |
184 pageRanges.push({'from': tempFrom, 'to': tempTo}); | 184 pageRanges.push({'from': tempFrom, 'to': tempTo}); |
185 } | 185 } |
186 return pageRanges; | 186 return pageRanges; |
187 } | 187 } |
188 | 188 |
189 /** | 189 /** |
190 * Constructs a url for getting a specific page. | 190 * Shows or hides an element. |
191 * @param {string} id The id of the preview data. | 191 * @param {Element} element Element to show or hide. |
192 * @param {number} pageNumber The number of the desired page. | 192 * @param {boolean} isVisible Whether the element should be visible or not. |
193 * @return {string} The constructed URL. | |
194 */ | 193 */ |
195 function getPageSrcURL(id, pageNumber) { | 194 function setIsVisible(element, isVisible) { |
196 return 'chrome://print/' + id + '/' + pageNumber + '/print.pdf'; | 195 element.style.display = isVisible ? '' : 'none'; |
197 } | 196 } |
198 | 197 |
199 /** | 198 /** |
200 * Returns a random integer within the specified range, |endPointA| and | 199 * @param {Array.<object>} array Array to check for item. |
201 * |endPointB| are included. | 200 * @param {object} item Item to look for in array. |
202 * @param {number} endPointA One end of the desired range. | 201 * @return {boolean} Whether the item is in the array. |
203 * @param {number} endPointB The other end of the desired range. | |
204 * @return {number} The random integer. | |
205 */ | 202 */ |
206 function randomInteger(endPointA, endPointB) { | 203 function arrayContains(array, item) { |
207 var from = Math.min(endPointA, endPointB); | 204 return array.indexOf(item) != -1; |
208 var to = Math.max(endPointA, endPointB); | |
209 return Math.floor(Math.random() * (to - from + 1) + from); | |
210 } | 205 } |
211 | |
212 // Number of points per inch. | |
213 var POINTS_PER_INCH = 72; | |
214 // Number of points per millimeter. | |
215 var POINTS_PER_MILLIMETER = 2.83464567; | |
216 | |
217 /** | |
218 * Converts |value| from inches to points. | |
219 * @param {number} value The number in inches. | |
220 * @return {number} |value| in points. | |
221 */ | |
222 function convertInchesToPoints(value) { | |
223 return value * POINTS_PER_INCH; | |
224 } | |
225 | |
226 /** | |
227 * Converts |value| from points to inches. | |
228 * @param {number} value The number in points. | |
229 * @return {number} |value| in inches. | |
230 */ | |
231 function convertPointsToInches(value) { | |
232 return value / POINTS_PER_INCH; | |
233 } | |
234 | |
235 /** | |
236 * Converts |value| from millimeters to points. | |
237 * @param {number} value The number in millimeters. | |
238 * @return {number} |value| in points. | |
239 */ | |
240 function convertMillimetersToPoints(value) { | |
241 return value * POINTS_PER_MILLIMETER; | |
242 } | |
243 | |
244 /** | |
245 * Converts |value| from points to millimeters. | |
246 * @param {number} value The number in points. | |
247 * @return {number} |value| in millimeters. | |
248 */ | |
249 function convertPointsToMillimeters(value) { | |
250 return value / POINTS_PER_MILLIMETER; | |
251 } | |
252 | |
253 /** | |
254 * Parses |numberFormat| and extracts the symbols used for the thousands point | |
255 * and decimal point. | |
256 * @param {string} numberFormat The formatted version of the number 12345678. | |
257 * @return {!Array.<string>} The extracted symbols in the order | |
258 * [thousandsSymbol, decimalSymbol]]. For example | |
259 * parseNumberFormat("123,456.78") returns [",", "."]. | |
260 */ | |
261 function parseNumberFormat(numberFormat) { | |
262 if (!numberFormat) | |
263 numberFormat = ''; | |
264 var regex = /^(\d+)(\W{0,1})(\d+)(\W{0,1})(\d+)$/; | |
265 var matches = numberFormat.match(regex) || ['', '', ',', '', '.']; | |
266 return [matches[2], matches[4]]; | |
267 } | |
OLD | NEW |