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 // Single iframe for NTP tiles. | 5 // Single iframe for NTP tiles. |
6 (function() { | 6 (function() { |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 | 9 |
10 /** | 10 /** |
(...skipping 29 matching lines...) Expand all Loading... | |
40 // The visuals of that tile's fallback are handled externally. Unused here. | 40 // The visuals of that tile's fallback are handled externally. Unused here. |
41 NTP_EXTERNAL_TILE_FALLBACK: 8, | 41 NTP_EXTERNAL_TILE_FALLBACK: 8, |
42 // The user moused over an NTP tile. | 42 // The user moused over an NTP tile. |
43 NTP_MOUSEOVER: 9, | 43 NTP_MOUSEOVER: 9, |
44 // A NTP Tile has finished loading (successfully or failing). | 44 // A NTP Tile has finished loading (successfully or failing). |
45 NTP_TILE_LOADED: 10, | 45 NTP_TILE_LOADED: 10, |
46 }; | 46 }; |
47 | 47 |
48 | 48 |
49 /** | 49 /** |
50 * Whether to use icons instead of thumbnails. | |
51 * @const {number} | |
52 */ | |
53 var USE_ICONS = false; | |
54 | |
55 | |
56 /** | |
57 * Total number of tiles to show at any time. If the host page doesn't send | 50 * Total number of tiles to show at any time. If the host page doesn't send |
58 * enough tiles, we fill them blank. | 51 * enough tiles, we fill them blank. |
59 * @const {number} | 52 * @const {number} |
60 */ | 53 */ |
61 var NUMBER_OF_TILES = 8; | 54 var NUMBER_OF_TILES = 8; |
62 | 55 |
63 | 56 |
64 /** | 57 /** |
58 * Whether to use icons instead of thumbnails. | |
59 * @type {boolean} | |
60 */ | |
61 var USE_ICONS = false; | |
62 | |
63 | |
64 /** | |
65 * Number of lines to display in titles. | |
66 * @type {number} | |
67 */ | |
68 var NUM_TITLE_LINES = 1; | |
69 | |
70 | |
71 /** | |
65 * The origin of this request. | 72 * The origin of this request. |
66 * @const {string} | 73 * @const {string} |
67 */ | 74 */ |
68 var DOMAIN_ORIGIN = '{{ORIGIN}}'; | 75 var DOMAIN_ORIGIN = '{{ORIGIN}}'; |
69 | 76 |
70 | 77 |
71 /** | 78 /** |
72 * Counter for DOM elements that we are waiting to finish loading. | 79 * Counter for DOM elements that we are waiting to finish loading. |
73 * @type {number} | 80 * @type {number} |
74 */ | 81 */ |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 } | 345 } |
339 }); | 346 }); |
340 // TODO(fserb): remove this or at least change to mouseenter. | 347 // TODO(fserb): remove this or at least change to mouseenter. |
341 tile.addEventListener('mouseover', function() { | 348 tile.addEventListener('mouseover', function() { |
342 logEvent(LOG_TYPE.NTP_MOUSEOVER); | 349 logEvent(LOG_TYPE.NTP_MOUSEOVER); |
343 }); | 350 }); |
344 | 351 |
345 var title = tile.querySelector('.mv-title'); | 352 var title = tile.querySelector('.mv-title'); |
346 title.innerText = data.title; | 353 title.innerText = data.title; |
347 title.style.direction = data.direction || 'ltr'; | 354 title.style.direction = data.direction || 'ltr'; |
355 if (NUM_TITLE_LINES > 1) { | |
fserb
2015/04/07 17:25:13
How is this supposed to work?
It doesn't matter th
huangs
2015/04/07 17:28:22
It's number of lines per title. Single line title
| |
356 title.classList.add('multiline'); | |
357 } | |
348 | 358 |
349 var hasIcon = USE_ICONS && data.largeIconUrl; | 359 var hasIcon = USE_ICONS && data.largeIconUrl; |
350 var hasThumb = !USE_ICONS && data.thumbnailUrl; | 360 var hasThumb = !USE_ICONS && data.thumbnailUrl; |
351 var thumb = tile.querySelector('.mv-thumb'); | 361 var thumb = tile.querySelector('.mv-thumb'); |
352 if (hasIcon || hasThumb) { | 362 if (hasIcon || hasThumb) { |
353 var img = document.createElement('img'); | 363 var img = document.createElement('img'); |
354 img.title = data.title; | 364 img.title = data.title; |
355 if (hasIcon) { | 365 if (hasIcon) { |
356 img.src = data.largeIconUrl; | 366 img.src = data.largeIconUrl; |
357 img.classList.add('large-icon'); | 367 img.classList.add('large-icon'); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 var query = window.location.search.substring(1).split('&'); | 430 var query = window.location.search.substring(1).split('&'); |
421 queryArgs = {}; | 431 queryArgs = {}; |
422 for (var i = 0; i < query.length; ++i) { | 432 for (var i = 0; i < query.length; ++i) { |
423 var val = query[i].split('='); | 433 var val = query[i].split('='); |
424 if (val[0] == '') continue; | 434 if (val[0] == '') continue; |
425 queryArgs[decodeURIComponent(val[0])] = decodeURIComponent(val[1]); | 435 queryArgs[decodeURIComponent(val[0])] = decodeURIComponent(val[1]); |
426 } | 436 } |
427 | 437 |
428 // Apply class for icon NTP, if specified. | 438 // Apply class for icon NTP, if specified. |
429 USE_ICONS = queryArgs['icons'] == '1'; | 439 USE_ICONS = queryArgs['icons'] == '1'; |
440 if ('ntl' in queryArgs) { | |
441 var ntl = parseInt(queryArgs['ntl'], 10); | |
442 if (isFinite(ntl)) | |
443 NUM_TITLE_LINES = ntl; | |
444 } | |
445 | |
430 // Duplicating NTP_DESIGN.mainClass. | 446 // Duplicating NTP_DESIGN.mainClass. |
431 document.querySelector('#most-visited').classList.add( | 447 document.querySelector('#most-visited').classList.add( |
432 USE_ICONS ? 'icon-ntp' : 'thumb-ntp'); | 448 USE_ICONS ? 'icon-ntp' : 'thumb-ntp'); |
433 | 449 |
434 // Enable RTL. | 450 // Enable RTL. |
435 if (queryArgs['rtl'] == '1') { | 451 if (queryArgs['rtl'] == '1') { |
436 var html = document.querySelector('html'); | 452 var html = document.querySelector('html'); |
437 html.dir = 'rtl'; | 453 html.dir = 'rtl'; |
438 } | 454 } |
439 | 455 |
440 window.addEventListener('message', handlePostMessage); | 456 window.addEventListener('message', handlePostMessage); |
441 }; | 457 }; |
442 | 458 |
443 | 459 |
444 window.addEventListener('DOMContentLoaded', init); | 460 window.addEventListener('DOMContentLoaded', init); |
445 })(); | 461 })(); |
OLD | NEW |