| OLD | NEW |
| 1 | 1 |
| 2 // Helpers | 2 // Helpers |
| 3 | 3 |
| 4 // TODO(arv): Remove these when classList is available in HTML5. | 4 // TODO(arv): Remove these when classList is available in HTML5. |
| 5 // https://bugs.webkit.org/show_bug.cgi?id=20709 | 5 // https://bugs.webkit.org/show_bug.cgi?id=20709 |
| 6 function hasClass(el, name) { | 6 function hasClass(el, name) { |
| 7 return el.nodeType == 1 && el.className.split(/\s+/).indexOf(name) != -1; | 7 return el.nodeType == 1 && el.className.split(/\s+/).indexOf(name) != -1; |
| 8 } | 8 } |
| 9 | 9 |
| 10 function addClass(el, name) { | 10 function addClass(el, name) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 var tipCache = {}; | 95 var tipCache = {}; |
| 96 | 96 |
| 97 function tips(data) { | 97 function tips(data) { |
| 98 logEvent('received tips'); | 98 logEvent('received tips'); |
| 99 tipCache = data; | 99 tipCache = data; |
| 100 renderTip(); | 100 renderTip(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 function createTip(data) { | 103 function createTip(data) { |
| 104 if (data.length) { | 104 if (data.length) { |
| 105 if (data[0].set_homepage_tip) { | 105 try { |
| 106 var homepageButton = document.createElement('button'); | 106 return parseHtmlSubset(data[0].tip_html_text); |
| 107 homepageButton.className = 'link'; | 107 } catch (parseErr) { |
| 108 homepageButton.textContent = data[0].set_homepage_tip; | 108 console.error('Error parsing tips: ' + parseErr.message); |
| 109 homepageButton.addEventListener('click', setAsHomePageLinkClicked); | |
| 110 return homepageButton; | |
| 111 } else { | |
| 112 try { | |
| 113 return parseHtmlSubset(data[0].tip_html_text); | |
| 114 } catch (parseErr) { | |
| 115 console.error('Error parsing tips: ' + parseErr.message); | |
| 116 } | |
| 117 } | 109 } |
| 118 } | 110 } |
| 119 // Return an empty DF in case of failure. | 111 // Return an empty DF in case of failure. |
| 120 return document.createDocumentFragment(); | 112 return document.createDocumentFragment(); |
| 121 } | 113 } |
| 122 | 114 |
| 123 function clearTipLine() { | 115 function renderTip() { |
| 124 var tipElement = $('tip-line'); | 116 var tipElement = $('tip-line'); |
| 125 // There should always be only one tip. | 117 // There should always be only one tip. |
| 126 tipElement.textContent = ''; | 118 tipElement.textContent = ''; |
| 127 tipElement.removeEventListener('click', setAsHomePageLinkClicked); | |
| 128 } | |
| 129 | |
| 130 function renderTip() { | |
| 131 clearTipLine(); | |
| 132 var tipElement = $('tip-line'); | |
| 133 tipElement.appendChild(createTip(tipCache)); | 119 tipElement.appendChild(createTip(tipCache)); |
| 134 fixLinkUnderlines(tipElement); | 120 fixLinkUnderlines(tipElement); |
| 135 } | 121 } |
| 136 | 122 |
| 137 function recentlyClosedTabs(data) { | 123 function recentlyClosedTabs(data) { |
| 138 logEvent('received recently closed tabs'); | 124 logEvent('received recently closed tabs'); |
| 139 // We need to store the recent items so we can update the layout on a resize. | 125 // We need to store the recent items so we can update the layout on a resize. |
| 140 recentItems = data; | 126 recentItems = data; |
| 141 renderRecentlyClosed(); | 127 renderRecentlyClosed(); |
| 142 } | 128 } |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 bind(logEvent, global, 'Tab.NewTabDOMContentLoaded', true)); | 1250 bind(logEvent, global, 'Tab.NewTabDOMContentLoaded', true)); |
| 1265 | 1251 |
| 1266 // Whether or not we should send the initial 'GetSyncMessage' to the backend | 1252 // Whether or not we should send the initial 'GetSyncMessage' to the backend |
| 1267 // depends on the value of the attribue 'syncispresent' which the backend sets | 1253 // depends on the value of the attribue 'syncispresent' which the backend sets |
| 1268 // to indicate if there is code in the backend which is capable of processing | 1254 // to indicate if there is code in the backend which is capable of processing |
| 1269 // this message. This attribute is loaded by the JSTemplate and therefore we | 1255 // this message. This attribute is loaded by the JSTemplate and therefore we |
| 1270 // must make sure we check the attribute after the DOM is loaded. | 1256 // must make sure we check the attribute after the DOM is loaded. |
| 1271 document.addEventListener('DOMContentLoaded', | 1257 document.addEventListener('DOMContentLoaded', |
| 1272 callGetSyncMessageIfSyncIsPresent); | 1258 callGetSyncMessageIfSyncIsPresent); |
| 1273 | 1259 |
| 1260 // This link allows user to make new tab page as homepage from the new tab |
| 1261 // page itself (without going to Options dialog box). |
| 1262 document.addEventListener('DOMContentLoaded', showSetAsHomePageLink); |
| 1263 |
| 1274 // Set up links and text-decoration for promotional message. | 1264 // Set up links and text-decoration for promotional message. |
| 1275 document.addEventListener('DOMContentLoaded', setUpPromoMessage); | 1265 document.addEventListener('DOMContentLoaded', setUpPromoMessage); |
| 1276 | 1266 |
| 1277 /** | 1267 /** |
| 1278 * The sync code is not yet built by default on all platforms so we have to | 1268 * The sync code is not yet built by default on all platforms so we have to |
| 1279 * make sure we don't send the initial sync message to the backend unless the | 1269 * make sure we don't send the initial sync message to the backend unless the |
| 1280 * backend told us that the sync code is present. | 1270 * backend told us that the sync code is present. |
| 1281 */ | 1271 */ |
| 1282 function callGetSyncMessageIfSyncIsPresent() { | 1272 function callGetSyncMessageIfSyncIsPresent() { |
| 1283 if (document.documentElement.getAttribute('syncispresent') == 'true') { | 1273 if (document.documentElement.getAttribute('syncispresent') == 'true') { |
| 1284 chrome.send('GetSyncMessage'); | 1274 chrome.send('GetSyncMessage'); |
| 1285 } | 1275 } |
| 1286 } | 1276 } |
| 1287 | 1277 |
| 1288 function setAsHomePageLinkClicked(e) { | 1278 function setAsHomePageLinkClicked(e) { |
| 1289 chrome.send('setHomePage'); | 1279 chrome.send('setHomePage'); |
| 1290 e.preventDefault(); | 1280 e.preventDefault(); |
| 1291 } | 1281 } |
| 1292 | 1282 |
| 1283 function showSetAsHomePageLink() { |
| 1284 var setAsHomePageElement = $('set-as-home-page'); |
| 1285 var style = setAsHomePageElement.style; |
| 1286 if (document.documentElement.getAttribute('showsetashomepage') != 'true') { |
| 1287 // Hide the section (if new tab page is already homepage). |
| 1288 return; |
| 1289 } |
| 1290 |
| 1291 style.display = 'block'; |
| 1292 var buttonElement = setAsHomePageElement.firstElementChild; |
| 1293 buttonElement.addEventListener('click', setAsHomePageLinkClicked); |
| 1294 } |
| 1295 |
| 1293 function onHomePageSet(data) { | 1296 function onHomePageSet(data) { |
| 1297 $('set-as-home-page').style.display = 'none'; |
| 1294 showNotification(data[0], data[1]); | 1298 showNotification(data[0], data[1]); |
| 1295 // Removes the "make this my home page" tip. | |
| 1296 clearTipLine(); | |
| 1297 } | 1299 } |
| 1298 | 1300 |
| 1299 function hideAllMenus() { | 1301 function hideAllMenus() { |
| 1300 optionMenu.hide(); | 1302 optionMenu.hide(); |
| 1301 } | 1303 } |
| 1302 | 1304 |
| 1303 window.addEventListener('blur', hideAllMenus); | 1305 window.addEventListener('blur', hideAllMenus); |
| 1304 window.addEventListener('keydown', function(e) { | 1306 window.addEventListener('keydown', function(e) { |
| 1305 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { | 1307 if (e.keyIdentifier == 'Alt' || e.keyIdentifier == 'Meta') { |
| 1306 hideAllMenus(); | 1308 hideAllMenus(); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 syncButton.onclick = syncSectionLinkClicked; | 1636 syncButton.onclick = syncSectionLinkClicked; |
| 1635 fixLinkUnderlines($('promo-message')); | 1637 fixLinkUnderlines($('promo-message')); |
| 1636 } | 1638 } |
| 1637 | 1639 |
| 1638 // A Windows-specific Webkit bug adds padding to buttons and will push the | 1640 // A Windows-specific Webkit bug adds padding to buttons and will push the |
| 1639 // bookmark sync button in the promo message too far to the right unless we | 1641 // bookmark sync button in the promo message too far to the right unless we |
| 1640 // use this fix. See https://bugs.webkit.org/show_bug.cgi?id=31703 | 1642 // use this fix. See https://bugs.webkit.org/show_bug.cgi?id=31703 |
| 1641 if (navigator.platform == 'Win32') { | 1643 if (navigator.platform == 'Win32') { |
| 1642 addClass(document.body, 'win-button-padding-bug'); | 1644 addClass(document.body, 'win-button-padding-bug'); |
| 1643 } | 1645 } |
| OLD | NEW |