Chromium Code Reviews| 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 The local InstantExtended NTP. | 7 * @fileoverview The local InstantExtended NTP. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * @const | 23 * @const |
| 24 */ | 24 */ |
| 25 var CLASSES = { | 25 var CLASSES = { |
| 26 BLACKLIST: 'mv-blacklist', // triggers tile blacklist animation | 26 BLACKLIST: 'mv-blacklist', // triggers tile blacklist animation |
| 27 BLACKLIST_BUTTON: 'mv-x', | 27 BLACKLIST_BUTTON: 'mv-x', |
| 28 CUSTOM_THEME: 'custom-theme', | 28 CUSTOM_THEME: 'custom-theme', |
| 29 DELAYED_HIDE_NOTIFICATION: 'mv-notice-delayed-hide', | 29 DELAYED_HIDE_NOTIFICATION: 'mv-notice-delayed-hide', |
| 30 FAKEBOX_DISABLE: 'fakebox-disable', // Makes fakebox non-interactive | 30 FAKEBOX_DISABLE: 'fakebox-disable', // Makes fakebox non-interactive |
| 31 FAKEBOX_FOCUS: 'fakebox-focused', // Applies focus styles to the fakebox | 31 FAKEBOX_FOCUS: 'fakebox-focused', // Applies focus styles to the fakebox |
| 32 FAVICON: 'mv-favicon', | 32 FAVICON: 'mv-favicon', |
| 33 HIDE_ATTRIBUTION: 'attribution-hide', | |
| 33 HIDE_BLACKLIST_BUTTON: 'mv-x-hide', // hides blacklist button during animation | 34 HIDE_BLACKLIST_BUTTON: 'mv-x-hide', // hides blacklist button during animation |
| 34 HIDE_FAKEBOX_AND_LOGO: 'hide-fakebox-logo', | 35 HIDE_FAKEBOX_AND_LOGO: 'hide-fakebox-logo', |
| 35 HIDE_NOTIFICATION: 'mv-notice-hide', | 36 HIDE_NOTIFICATION: 'mv-notice-hide', |
| 36 // Vertically centers the most visited section for a non-Google provided page. | 37 // Vertically centers the most visited section for a non-Google provided page. |
| 37 NON_GOOGLE_PAGE: 'non-google-page', | 38 NON_GOOGLE_PAGE: 'non-google-page', |
| 38 PAGE: 'mv-page', // page tiles | 39 PAGE: 'mv-page', // page tiles |
| 39 PAGE_READY: 'mv-page-ready', // page tile when ready | 40 PAGE_READY: 'mv-page-ready', // page tile when ready |
| 40 ROW: 'mv-row', // tile row | 41 ROW: 'mv-row', // tile row |
| 41 RTL: 'rtl', // Right-to-left language text. | 42 RTL: 'rtl', // Right-to-left language text. |
| 42 THUMBNAIL: 'mv-thumb', | 43 THUMBNAIL: 'mv-thumb', |
| 43 THUMBNAIL_MASK: 'mv-mask', | 44 THUMBNAIL_MASK: 'mv-mask', |
| 44 TILE: 'mv-tile', | 45 TILE: 'mv-tile', |
| 45 TITLE: 'mv-title' | 46 TITLE: 'mv-title' |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 | 49 |
| 49 /** | 50 /** |
| 50 * Enum for HTML element ids. | 51 * Enum for HTML element ids. |
| 51 * @enum {string} | 52 * @enum {string} |
| 52 * @const | 53 * @const |
| 53 */ | 54 */ |
| 54 var IDS = { | 55 var IDS = { |
| 55 ATTRIBUTION: 'attribution', | 56 ATTRIBUTION: 'attribution', |
| 57 ATTRIBUTION_TEXT: 'attribution-text', | |
| 56 FAKEBOX: 'fakebox', | 58 FAKEBOX: 'fakebox', |
| 59 FOOTER: 'footer', | |
| 57 LOGO: 'logo', | 60 LOGO: 'logo', |
| 58 NOTIFICATION: 'mv-notice', | 61 NOTIFICATION: 'mv-notice', |
| 59 NOTIFICATION_CLOSE_BUTTON: 'mv-notice-x', | 62 NOTIFICATION_CLOSE_BUTTON: 'mv-notice-x', |
| 60 NOTIFICATION_MESSAGE: 'mv-msg', | 63 NOTIFICATION_MESSAGE: 'mv-msg', |
| 61 NTP_CONTENTS: 'ntp-contents', | 64 NTP_CONTENTS: 'ntp-contents', |
| 65 RECENT_TABS: 'recent-tabs', | |
| 62 RESTORE_ALL_LINK: 'mv-restore', | 66 RESTORE_ALL_LINK: 'mv-restore', |
| 63 TILES: 'mv-tiles', | 67 TILES: 'mv-tiles', |
| 64 UNDO_LINK: 'mv-undo' | 68 UNDO_LINK: 'mv-undo' |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 | 71 |
| 68 /** | 72 /** |
| 69 * Enum for keycodes. | 73 * Enum for keycodes. |
| 70 * @enum {number} | 74 * @enum {number} |
| 71 * @const | 75 * @const |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 82 * @const | 86 * @const |
| 83 */ | 87 */ |
| 84 var NTP_DISPOSE_STATE = { | 88 var NTP_DISPOSE_STATE = { |
| 85 NONE: 0, // Preserve the NTP appearance and functionality | 89 NONE: 0, // Preserve the NTP appearance and functionality |
| 86 DISABLE_FAKEBOX: 1, | 90 DISABLE_FAKEBOX: 1, |
| 87 HIDE_FAKEBOX_AND_LOGO: 2 | 91 HIDE_FAKEBOX_AND_LOGO: 2 |
| 88 }; | 92 }; |
| 89 | 93 |
| 90 | 94 |
| 91 /** | 95 /** |
| 96 * The JavaScript button event value for a middle click. | |
| 97 * @type {number} | |
| 98 * @const | |
| 99 */ | |
| 100 var MIDDLE_MOUSE_BUTTON = 1; | |
| 101 | |
| 102 | |
| 103 /** | |
| 104 * Possible behaviors for navigateContentWindow. | |
| 105 * @enum {number} | |
| 106 */ | |
| 107 var WindowOpenDisposition = { | |
| 108 CURRENT_TAB: 1, | |
| 109 NEW_BACKGROUND_TAB: 2 | |
| 110 }; | |
| 111 | |
| 112 | |
| 113 /** | |
| 92 * The container for the tile elements. | 114 * The container for the tile elements. |
| 93 * @type {Element} | 115 * @type {Element} |
| 94 */ | 116 */ |
| 95 var tilesContainer; | 117 var tilesContainer; |
| 96 | 118 |
| 97 | 119 |
| 98 /** | 120 /** |
| 99 * The notification displayed when a page is blacklisted. | 121 * The notification displayed when a page is blacklisted. |
| 100 * @type {Element} | 122 * @type {Element} |
| 101 */ | 123 */ |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 | 358 |
| 337 | 359 |
| 338 /** | 360 /** |
| 339 * Renders the attribution if the image is present and loadable. Otherwise | 361 * Renders the attribution if the image is present and loadable. Otherwise |
| 340 * hides it. | 362 * hides it. |
| 341 * @param {string} url The URL of the attribution image, if any. | 363 * @param {string} url The URL of the attribution image, if any. |
| 342 * @private | 364 * @private |
| 343 */ | 365 */ |
| 344 function updateAttribution(url) { | 366 function updateAttribution(url) { |
| 345 if (!url) { | 367 if (!url) { |
| 346 attribution.hidden = true; | 368 attribution.classList.add(CLASSES.HIDE_ATTRIBUTION); |
|
Jered
2013/06/24 17:42:26
nit: This change seems unnecessary in the context
jeremycho
2013/06/24 20:12:09
This is for setting display:none when no attributi
| |
| 347 return; | 369 return; |
| 348 } | 370 } |
| 349 var attributionImage = new Image(); | 371 var attributionImage = new Image(); |
| 350 attributionImage.onload = function() { | 372 attributionImage.onload = function() { |
| 351 var oldAttributionImage = attribution.querySelector('img'); | 373 var oldAttributionImage = attribution.querySelector('img'); |
| 352 if (oldAttributionImage) | 374 if (oldAttributionImage) |
| 353 removeNode(oldAttributionImage); | 375 removeNode(oldAttributionImage); |
| 354 attribution.appendChild(attributionImage); | 376 attribution.appendChild(attributionImage); |
| 355 attribution.hidden = false; | 377 attribution.classList.remove(CLASSES.HIDE_ATTRIBUTION); |
| 356 }; | 378 }; |
| 357 attributionImage.onerror = function() { | 379 attributionImage.onerror = function() { |
| 358 attribution.hidden = true; | 380 attribution.classList.add(CLASSES.HIDE_ATTRIBUTION); |
| 359 }; | 381 }; |
| 360 attributionImage.src = url; | 382 attributionImage.src = url; |
| 361 } | 383 } |
| 362 | 384 |
| 363 | 385 |
| 364 /** | 386 /** |
| 365 * Handles a new set of Most Visited page data. | 387 * Handles a new set of Most Visited page data. |
| 366 */ | 388 */ |
| 367 function onMostVisitedChange() { | 389 function onMostVisitedChange() { |
| 368 var pages = ntpApiHandle.mostVisited; | 390 var pages = ntpApiHandle.mostVisited; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 /** | 878 /** |
| 857 * @return {boolean} True if this is a Google page and not some other search | 879 * @return {boolean} True if this is a Google page and not some other search |
| 858 * provider. Used to determine whether to show the logo and fakebox. | 880 * provider. Used to determine whether to show the logo and fakebox. |
| 859 */ | 881 */ |
| 860 function isGooglePage() { | 882 function isGooglePage() { |
| 861 return location.href.indexOf('isGoogle') != -1; | 883 return location.href.indexOf('isGoogle') != -1; |
| 862 } | 884 } |
| 863 | 885 |
| 864 | 886 |
| 865 /** | 887 /** |
| 888 * Extract the desired navigation behavior from a click button. | |
| 889 * @param {number} button The Event#button property of a click event. | |
| 890 * @return {WindowOpenDisposition} The desired behavior for | |
| 891 * navigateContentWindow. | |
| 892 */ | |
| 893 function getDispositionFromClickButton(button) { | |
| 894 if (button == MIDDLE_MOUSE_BUTTON) | |
| 895 return WindowOpenDisposition.NEW_BACKGROUND_TAB; | |
| 896 return WindowOpenDisposition.CURRENT_TAB; | |
| 897 } | |
| 898 | |
| 899 | |
| 900 /** | |
| 866 * Prepares the New Tab Page by adding listeners, rendering the current | 901 * Prepares the New Tab Page by adding listeners, rendering the current |
| 867 * theme, the most visited pages section, and Google-specific elements for a | 902 * theme, the most visited pages section, and Google-specific elements for a |
| 868 * Google-provided page. | 903 * Google-provided page. |
| 869 */ | 904 */ |
| 870 function init() { | 905 function init() { |
| 871 tilesContainer = $(IDS.TILES); | 906 tilesContainer = $(IDS.TILES); |
| 872 notification = $(IDS.NOTIFICATION); | 907 notification = $(IDS.NOTIFICATION); |
| 873 attribution = $(IDS.ATTRIBUTION); | 908 attribution = $(IDS.ATTRIBUTION); |
| 874 ntpContents = $(IDS.NTP_CONTENTS); | 909 ntpContents = $(IDS.NTP_CONTENTS); |
| 875 | 910 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 888 fakebox.innerHTML = | 923 fakebox.innerHTML = |
| 889 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + | 924 '<input autocomplete="off" tabindex="-1" aria-hidden="true">' + |
| 890 '<div id=cursor></div>'; | 925 '<div id=cursor></div>'; |
| 891 | 926 |
| 892 ntpContents.insertBefore(fakebox, ntpContents.firstChild); | 927 ntpContents.insertBefore(fakebox, ntpContents.firstChild); |
| 893 ntpContents.insertBefore(logo, ntpContents.firstChild); | 928 ntpContents.insertBefore(logo, ntpContents.firstChild); |
| 894 } else { | 929 } else { |
| 895 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); | 930 document.body.classList.add(CLASSES.NON_GOOGLE_PAGE); |
| 896 } | 931 } |
| 897 | 932 |
| 933 var recentTabsText = templateData.recentTabs; | |
| 934 if (recentTabsText) { | |
| 935 var recentTabsLink = document.createElement('span'); | |
| 936 recentTabsLink.id = IDS.RECENT_TABS; | |
| 937 recentTabsLink.addEventListener('click', function(event) { | |
| 938 ntpApiHandle.navigateContentWindow( | |
| 939 'chrome://history', getDispositionFromClickButton(event.button)); | |
| 940 }); | |
| 941 recentTabsLink.textContent = recentTabsText; | |
| 942 var footer = $(IDS.FOOTER); | |
| 943 footer.insertBefore(recentTabsLink, footer.firstChild); | |
| 944 } | |
| 898 | 945 |
| 899 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); | 946 var notificationMessage = $(IDS.NOTIFICATION_MESSAGE); |
| 900 notificationMessage.textContent = templateData.thumbnailRemovedNotification; | 947 notificationMessage.textContent = templateData.thumbnailRemovedNotification; |
| 901 var undoLink = $(IDS.UNDO_LINK); | 948 var undoLink = $(IDS.UNDO_LINK); |
| 902 undoLink.addEventListener('click', onUndo); | 949 undoLink.addEventListener('click', onUndo); |
| 903 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); | 950 registerKeyHandler(undoLink, KEYCODE.ENTER, onUndo); |
| 904 undoLink.textContent = templateData.undoThumbnailRemove; | 951 undoLink.textContent = templateData.undoThumbnailRemove; |
| 905 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); | 952 var restoreAllLink = $(IDS.RESTORE_ALL_LINK); |
| 906 restoreAllLink.addEventListener('click', onRestoreAll); | 953 restoreAllLink.addEventListener('click', onRestoreAll); |
| 907 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); | 954 registerKeyHandler(restoreAllLink, KEYCODE.ENTER, onUndo); |
| 908 restoreAllLink.textContent = templateData.restoreThumbnailsShort; | 955 restoreAllLink.textContent = templateData.restoreThumbnailsShort; |
| 909 attribution.textContent = templateData.attributionIntro; | 956 $(IDS.ATTRIBUTION_TEXT).textContent = templateData.attributionIntro; |
| 910 | 957 |
| 911 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); | 958 var notificationCloseButton = $(IDS.NOTIFICATION_CLOSE_BUTTON); |
| 912 notificationCloseButton.addEventListener('click', hideNotification); | 959 notificationCloseButton.addEventListener('click', hideNotification); |
| 913 | 960 |
| 914 userInitiatedMostVisitedChange = false; | 961 userInitiatedMostVisitedChange = false; |
| 915 window.addEventListener('resize', onResize); | 962 window.addEventListener('resize', onResize); |
| 916 onResize(); | 963 onResize(); |
| 917 | 964 |
| 918 var topLevelHandle = getEmbeddedSearchApiHandle(); | 965 var topLevelHandle = getEmbeddedSearchApiHandle(); |
| 919 | 966 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 | 1010 |
| 964 return { | 1011 return { |
| 965 init: init, | 1012 init: init, |
| 966 listen: listen | 1013 listen: listen |
| 967 }; | 1014 }; |
| 968 } | 1015 } |
| 969 | 1016 |
| 970 if (!window.localNTPUnitTest) { | 1017 if (!window.localNTPUnitTest) { |
| 971 LocalNTP(location).listen(); | 1018 LocalNTP(location).listen(); |
| 972 } | 1019 } |
| OLD | NEW |