| 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) { |
| 11 el.className += ' ' + name; | 11 var names = el.className.split(/\s+/); |
| 12 if (names.indexOf(name) == -1) { |
| 13 el.className += ' ' + name; |
| 14 } |
| 12 } | 15 } |
| 13 | 16 |
| 14 function removeClass(el, name) { | 17 function removeClass(el, name) { |
| 15 var names = el.className.split(/\s+/); | 18 var names = el.className.split(/\s+/); |
| 16 el.className = names.filter(function(n) { | 19 el.className = names.filter(function(n) { |
| 17 return name != n; | 20 return name != n; |
| 18 }).join(' '); | 21 }).join(' '); |
| 19 } | 22 } |
| 20 | 23 |
| 21 function findAncestorByClass(el, className) { | 24 function findAncestorByClass(el, className) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 293 } |
| 291 | 294 |
| 292 function showSection(section) { | 295 function showSection(section) { |
| 293 if (!(section & shownSections)) { | 296 if (!(section & shownSections)) { |
| 294 shownSections |= section; | 297 shownSections |= section; |
| 295 | 298 |
| 296 // THUMBS and LIST are mutually exclusive. | 299 // THUMBS and LIST are mutually exclusive. |
| 297 if (section == Section.THUMB) { | 300 if (section == Section.THUMB) { |
| 298 // hide LIST | 301 // hide LIST |
| 299 shownSections &= ~Section.LIST; | 302 shownSections &= ~Section.LIST; |
| 300 mostVisited.invalidate(); | |
| 301 } else if (section == Section.LIST) { | 303 } else if (section == Section.LIST) { |
| 302 // hide THUMB | 304 // hide THUMB |
| 303 shownSections &= ~Section.THUMB; | 305 shownSections &= ~Section.THUMB; |
| 304 mostVisited.invalidate(); | |
| 305 } else { | |
| 306 renderRecentlyClosed(); | |
| 307 } | 306 } |
| 308 | 307 switch (section) { |
| 309 mostVisited.updateDisplayMode(); | 308 case Section.THUMB: |
| 310 mostVisited.layout(); | 309 case Section.LIST: |
| 310 mostVisited.invalidate(); |
| 311 mostVisited.updateDisplayMode(); |
| 312 mostVisited.layout(); |
| 313 break; |
| 314 case Section.RECENT: |
| 315 renderRecentlyClosed(); |
| 316 break; |
| 317 case Section.TIPS: |
| 318 $('tip-line').style.display = ''; |
| 319 break; |
| 320 case Section.SYNC: |
| 321 $('sync-status').style.display = ''; |
| 322 break; |
| 323 } |
| 311 } | 324 } |
| 312 } | 325 } |
| 313 | 326 |
| 314 function hideSection(section) { | 327 function hideSection(section) { |
| 315 if (section & shownSections) { | 328 if (section & shownSections) { |
| 316 shownSections &= ~section; | 329 shownSections &= ~section; |
| 317 | 330 |
| 318 if (section & Section.THUMB || section & Section.LIST) { | 331 switch (section) { |
| 319 mostVisited.invalidate(); | 332 case Section.THUMB: |
| 333 case Section.LIST: |
| 334 mostVisited.invalidate(); |
| 335 mostVisited.updateDisplayMode(); |
| 336 mostVisited.layout(); |
| 337 break; |
| 338 case Section.RECENT: |
| 339 renderRecentlyClosed(); |
| 340 break; |
| 341 case Section.TIPS: |
| 342 $('tip-line').style.display = 'none'; |
| 343 break; |
| 344 case Section.SYNC: |
| 345 $('sync-status').style.display = 'none'; |
| 346 break; |
| 320 } | 347 } |
| 321 | |
| 322 if (section & Section.RECENT) { | |
| 323 renderRecentlyClosed(); | |
| 324 } | |
| 325 | |
| 326 mostVisited.updateDisplayMode(); | |
| 327 mostVisited.layout(); | |
| 328 } | 348 } |
| 329 } | 349 } |
| 330 | 350 |
| 331 var mostVisited = { | 351 var mostVisited = { |
| 332 addPinnedUrl_: function(data, index) { | 352 addPinnedUrl_: function(data, index) { |
| 333 chrome.send('addPinnedURL', [data.url, data.title, data.faviconUrl || '', | 353 chrome.send('addPinnedURL', [data.url, data.title, data.faviconUrl || '', |
| 334 data.thumbnailUrl || '', String(index)]); | 354 data.thumbnailUrl || '', String(index)]); |
| 335 }, | 355 }, |
| 336 getItem: function(el) { | 356 getItem: function(el) { |
| 337 return findAncestorByClass(el, 'thumbnail-container'); | 357 return findAncestorByClass(el, 'thumbnail-container'); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 }, | 558 }, |
| 539 | 559 |
| 540 getRectByIndex: function(index) { | 560 getRectByIndex: function(index) { |
| 541 return getMostVisitedLayoutRects()[index]; | 561 return getMostVisitedLayoutRects()[index]; |
| 542 } | 562 } |
| 543 }; | 563 }; |
| 544 | 564 |
| 545 // Recently closed | 565 // Recently closed |
| 546 | 566 |
| 547 function layoutRecentlyClosed() { | 567 function layoutRecentlyClosed() { |
| 548 var recentElement = $('recently-closed'); | |
| 549 var recentShown = shownSections & Section.RECENT; | 568 var recentShown = shownSections & Section.RECENT; |
| 550 var style = recentElement.style; | 569 updateSimpleSection('recently-closed', Section.RECENT); |
| 551 | 570 |
| 552 if (!recentShown) { | 571 if (recentShown) { |
| 553 addClass(recentElement, 'collapsed'); | 572 var recentElement = $('recently-closed'); |
| 554 } else { | 573 var style = recentElement.style; |
| 555 removeClass(recentElement, 'collapsed'); | |
| 556 | |
| 557 // We cannot use clientWidth here since the width has a transition. | 574 // We cannot use clientWidth here since the width has a transition. |
| 558 var spacing = 20; | 575 var spacing = 20; |
| 559 var headerEl = recentElement.firstElementChild; | 576 var headerEl = recentElement.firstElementChild; |
| 560 var navEl = recentElement.lastElementChild; | 577 var navEl = recentElement.lastElementChild; |
| 561 var navWidth = navEl.offsetWidth; | 578 var navWidth = navEl.offsetWidth; |
| 562 // Subtract 10 for the padding | 579 // Subtract 10 for the padding |
| 563 var availWidth = (useSmallGrid() ? 690 : 918) - navWidth - 10; | 580 var availWidth = (useSmallGrid() ? 690 : 918) - navWidth - 10; |
| 564 | 581 |
| 565 // Now go backwards and hide as many elements as needed. | 582 // Now go backwards and hide as many elements as needed. |
| 566 var elementsToHide = []; | 583 var elementsToHide = []; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 595 * linkurlisset: true if an URL should be set as the href for the link and false | 612 * linkurlisset: true if an URL should be set as the href for the link and false |
| 596 * otherwise. If this field is false, then clicking on the link | 613 * otherwise. If this field is false, then clicking on the link |
| 597 * will result in sending a message to the backend (see | 614 * will result in sending a message to the backend (see |
| 598 * 'SyncLinkClicked'). | 615 * 'SyncLinkClicked'). |
| 599 * linkurl: the URL to use as the element's href (only used if linkurlisset is | 616 * linkurl: the URL to use as the element's href (only used if linkurlisset is |
| 600 * true). | 617 * true). |
| 601 */ | 618 */ |
| 602 function syncMessageChanged(newMessage) { | 619 function syncMessageChanged(newMessage) { |
| 603 var syncStatusElement = $('sync-status'); | 620 var syncStatusElement = $('sync-status'); |
| 604 var style = syncStatusElement.style; | 621 var style = syncStatusElement.style; |
| 622 $('sync-menu-item').style.display = 'block'; |
| 605 | 623 |
| 606 // Hide the section if the message is emtpy. | 624 // Hide the section if the message is emtpy. |
| 607 if (!newMessage.syncsectionisvisible) { | 625 if (!newMessage['syncsectionisvisible'] || !(shownSections & Section.SYNC)) { |
| 608 style.display = 'none'; | 626 style.display = 'none'; |
| 609 return; | 627 return; |
| 610 } | 628 } |
| 611 style.display = 'block'; | 629 style.display = 'block'; |
| 612 | 630 |
| 613 // Set the sync section background color based on the state. | 631 // Set the sync section background color based on the state. |
| 614 if (newMessage.msgtype == 'error') { | 632 if (newMessage.msgtype == 'error') { |
| 615 style.backgroundColor = 'tomato'; | 633 style.backgroundColor = 'tomato'; |
| 616 } else { | 634 } else { |
| 617 style.backgroundColor = ''; | 635 style.backgroundColor = ''; |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 function fixLinkUnderline(el) { | 1581 function fixLinkUnderline(el) { |
| 1564 var span = document.createElement('span'); | 1582 var span = document.createElement('span'); |
| 1565 span.className = 'link-color'; | 1583 span.className = 'link-color'; |
| 1566 while (el.hasChildNodes()) { | 1584 while (el.hasChildNodes()) { |
| 1567 span.appendChild(el.firstChild); | 1585 span.appendChild(el.firstChild); |
| 1568 } | 1586 } |
| 1569 el.appendChild(span); | 1587 el.appendChild(span); |
| 1570 } | 1588 } |
| 1571 | 1589 |
| 1572 updateAttribution(); | 1590 updateAttribution(); |
| OLD | NEW |