OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 6 /** |
7 * @fileoverview Utilities for rendering most visited thumbnails and titles. | 7 * @fileoverview Utilities for rendering most visited thumbnails and titles. |
8 */ | 8 */ |
9 | 9 |
10 <include src="instant_iframe_validation.js"> | 10 <include src="instant_iframe_validation.js"> |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 }); | 179 }); |
180 | 180 |
181 return link; | 181 return link; |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 /** | 185 /** |
186 * Returns the color to display string with, depending on whether title is | 186 * Returns the color to display string with, depending on whether title is |
187 * displayed, the current theme, and URL parameters. | 187 * displayed, the current theme, and URL parameters. |
188 * @param {Object.<string, string>} params URL parameters specifying style. | 188 * @param {Object<string, string>} params URL parameters specifying style. |
189 * @param {boolean} isTitle if the style is for the Most Visited Title. | 189 * @param {boolean} isTitle if the style is for the Most Visited Title. |
190 * @return {string} The color to use, in "rgba(#,#,#,#)" format. | 190 * @return {string} The color to use, in "rgba(#,#,#,#)" format. |
191 */ | 191 */ |
192 function getTextColor(params, isTitle) { | 192 function getTextColor(params, isTitle) { |
193 // 'RRGGBBAA' color format overrides everything. | 193 // 'RRGGBBAA' color format overrides everything. |
194 if ('c' in params && params.c.match(/^[0-9A-Fa-f]{8}$/)) { | 194 if ('c' in params && params.c.match(/^[0-9A-Fa-f]{8}$/)) { |
195 // Extract the 4 pairs of hex digits, map to number, then form rgba(). | 195 // Extract the 4 pairs of hex digits, map to number, then form rgba(). |
196 var t = params.c.match(/(..)(..)(..)(..)/).slice(1).map(function(s) { | 196 var t = params.c.match(/(..)(..)(..)(..)/).slice(1).map(function(s) { |
197 return parseInt(s, 16); | 197 return parseInt(s, 16); |
198 }); | 198 }); |
(...skipping 15 matching lines...) Expand all Loading... |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 /** | 217 /** |
218 * Decodes most visited styles from URL parameters. | 218 * Decodes most visited styles from URL parameters. |
219 * - c: A hexadecimal number interpreted as a hex color code. | 219 * - c: A hexadecimal number interpreted as a hex color code. |
220 * - f: font-family. | 220 * - f: font-family. |
221 * - fs: font-size as a number in pixels. | 221 * - fs: font-size as a number in pixels. |
222 * - ta: text-align property, as a string. | 222 * - ta: text-align property, as a string. |
223 * - tf: specifying a text fade starting position, in pixels. | 223 * - tf: specifying a text fade starting position, in pixels. |
224 * @param {Object.<string, string>} params URL parameters specifying style. | 224 * @param {Object<string, string>} params URL parameters specifying style. |
225 * @param {boolean} isTitle if the style is for the Most Visited Title. | 225 * @param {boolean} isTitle if the style is for the Most Visited Title. |
226 * @return {Object} Styles suitable for CSS interpolation. | 226 * @return {Object} Styles suitable for CSS interpolation. |
227 */ | 227 */ |
228 function getMostVisitedStyles(params, isTitle) { | 228 function getMostVisitedStyles(params, isTitle) { |
229 var styles = { | 229 var styles = { |
230 color: getTextColor(params, isTitle), // Handles 'c' in params. | 230 color: getTextColor(params, isTitle), // Handles 'c' in params. |
231 fontFamily: '', | 231 fontFamily: '', |
232 fontSize: 11 | 232 fontSize: 11 |
233 }; | 233 }; |
234 if ('f' in params && /^[-0-9a-zA-Z ,]+$/.test(params.f)) | 234 if ('f' in params && /^[-0-9a-zA-Z ,]+$/.test(params.f)) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 if (navigator.sendBeacon) { | 303 if (navigator.sendBeacon) { |
304 navigator.sendBeacon(url); | 304 navigator.sendBeacon(url); |
305 } else { | 305 } else { |
306 // if sendBeacon is not enabled, we fallback for "a ping". | 306 // if sendBeacon is not enabled, we fallback for "a ping". |
307 var a = document.createElement('a'); | 307 var a = document.createElement('a'); |
308 a.href = '#'; | 308 a.href = '#'; |
309 a.ping = url; | 309 a.ping = url; |
310 a.click(); | 310 a.click(); |
311 } | 311 } |
312 } | 312 } |
OLD | NEW |