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