| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 * Constructs a url for getting a specific page. | 190 * Constructs a url for getting a specific page. |
| 191 * @param {string} id The id of the preview data. | 191 * @param {string} id The id of the preview data. |
| 192 * @param {number} pageNumber The number of the desired page. | 192 * @param {number} pageNumber The number of the desired page. |
| 193 * @return {string} The constructed URL. | 193 * @return {string} The constructed URL. |
| 194 */ | 194 */ |
| 195 function getPageSrcURL(id, pageNumber) { | 195 function getPageSrcURL(id, pageNumber) { |
| 196 return 'chrome://print/' + id + '/' + pageNumber + '/print.pdf'; | 196 return 'chrome://print/' + id + '/' + pageNumber + '/print.pdf'; |
| 197 } | 197 } |
| 198 | 198 |
| 199 /** | 199 /** |
| 200 * Returns a random integer within the specified range, |endPointA| and | 200 * Shows or hides an element. |
| 201 * |endPointB| are included. | 201 * @param {Element} element Element to show or hide. |
| 202 * @param {number} endPointA One end of the desired range. | 202 * @param {boolean} isVisible Whether the element should be visible or not. |
| 203 * @param {number} endPointB The other end of the desired range. | |
| 204 * @return {number} The random integer. | |
| 205 */ | 203 */ |
| 206 function randomInteger(endPointA, endPointB) { | 204 function setIsVisible(element, isVisible) { |
| 207 var from = Math.min(endPointA, endPointB); | 205 element.style.display = isVisible ? '' : 'none'; |
| 208 var to = Math.max(endPointA, endPointB); | |
| 209 return Math.floor(Math.random() * (to - from + 1) + from); | |
| 210 } | |
| 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 } | 206 } |
| 225 | 207 |
| 226 /** | 208 /** |
| 227 * Converts |value| from points to inches. | 209 * @param {Array.<object>} array Array to check for item. |
| 228 * @param {number} value The number in points. | 210 * @param {object} item Item to look for in array. |
| 229 * @return {number} |value| in inches. | 211 * @return {boolean} Whether the item is in the array. |
| 230 */ | 212 */ |
| 231 function convertPointsToInches(value) { | 213 function arrayContains(array, item) { |
| 232 return value / POINTS_PER_INCH; | 214 return array.indexOf(item) != -1; |
| 233 } | 215 } |
| 234 | 216 |
| 235 /** | 217 /** |
| 236 * Converts |value| from millimeters to points. | 218 * Logs an error message without stopping script execution. |
| 237 * @param {number} value The number in millimeters. | 219 * @param {string} message Message to log with the error. |
| 238 * @return {number} |value| in points. | |
| 239 */ | 220 */ |
| 240 function convertMillimetersToPoints(value) { | 221 function logError(message) { |
| 241 return value * POINTS_PER_MILLIMETER; | 222 setTimeout(function() {throw Error(message);}, 0); |
| 242 } | 223 } |
| 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 |