| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Dependencies that we should remove/formalize: | 5 // Dependencies that we should remove/formalize: |
| 6 // ../shared/js/class_list.js | 6 // ../shared/js/class_list.js |
| 7 // util.js | 7 // util.js |
| 8 // | 8 // |
| 9 // afterTransition | 9 // afterTransition |
| 10 // chrome.send | 10 // chrome.send |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } else { | 34 } else { |
| 35 el.classList.remove('pinned'); | 35 el.classList.remove('pinned'); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 function getThumbnailIndex(el) { | 39 function getThumbnailIndex(el) { |
| 40 var nodes = el.parentNode.querySelectorAll('.thumbnail-container'); | 40 var nodes = el.parentNode.querySelectorAll('.thumbnail-container'); |
| 41 return Array.prototype.indexOf.call(nodes, el); | 41 return Array.prototype.indexOf.call(nodes, el); |
| 42 } | 42 } |
| 43 | 43 |
| 44 function MostVisited(el, useSmallGrid, visible) { | 44 function MostVisited(el, miniview, useSmallGrid, visible) { |
| 45 this.element = el; | 45 this.element = el; |
| 46 this.miniview = miniview; |
| 46 this.useSmallGrid_ = useSmallGrid; | 47 this.useSmallGrid_ = useSmallGrid; |
| 47 this.visible_ = visible; | 48 this.visible_ = visible; |
| 48 | 49 |
| 49 this.createThumbnails_(); | 50 this.createThumbnails_(); |
| 50 this.applyMostVisitedRects_(); | 51 this.applyMostVisitedRects_(); |
| 51 | 52 |
| 52 el.addEventListener('click', bind(this.handleClick_, this)); | 53 el.addEventListener('click', bind(this.handleClick_, this)); |
| 53 el.addEventListener('keydown', bind(this.handleKeyDown_, this)); | 54 el.addEventListener('keydown', bind(this.handleKeyDown_, this)); |
| 54 | 55 |
| 55 document.addEventListener('DOMContentLoaded', | 56 document.addEventListener('DOMContentLoaded', |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 var maxItems = 8; | 495 var maxItems = 8; |
| 495 data.length = Math.min(maxItems, data.length); | 496 data.length = Math.min(maxItems, data.length); |
| 496 var len = data.length; | 497 var len = data.length; |
| 497 for (var i = len; i < maxItems; i++) { | 498 for (var i = len; i < maxItems; i++) { |
| 498 data[i] = {filler: true}; | 499 data[i] = {filler: true}; |
| 499 } | 500 } |
| 500 | 501 |
| 501 // On setting we need to update the items | 502 // On setting we need to update the items |
| 502 this.data_ = data; | 503 this.data_ = data; |
| 503 this.updateMostVisited_(); | 504 this.updateMostVisited_(); |
| 505 this.updateMiniview_(); |
| 504 }, | 506 }, |
| 505 | 507 |
| 506 updateMostVisited_: function() { | 508 updateMostVisited_: function() { |
| 507 | 509 |
| 508 function getThumbnailClassName(item) { | 510 function getThumbnailClassName(item) { |
| 509 return 'thumbnail-container' + | 511 return 'thumbnail-container' + |
| 510 (item.pinned ? ' pinned' : '') + | 512 (item.pinned ? ' pinned' : '') + |
| 511 (item.filler ? ' filler' : ''); | 513 (item.filler ? ' filler' : ''); |
| 512 } | 514 } |
| 513 | 515 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 t.querySelector('.thumbnail-wrapper').style.backgroundImage = | 550 t.querySelector('.thumbnail-wrapper').style.backgroundImage = |
| 549 url(thumbnailUrl); | 551 url(thumbnailUrl); |
| 550 var titleDiv = t.querySelector('.title > div'); | 552 var titleDiv = t.querySelector('.title > div'); |
| 551 titleDiv.xtitle = titleDiv.textContent = d.title; | 553 titleDiv.xtitle = titleDiv.textContent = d.title; |
| 552 var faviconUrl = d.faviconUrl || 'chrome://favicon/' + d.url; | 554 var faviconUrl = d.faviconUrl || 'chrome://favicon/' + d.url; |
| 553 titleDiv.style.backgroundImage = url(faviconUrl); | 555 titleDiv.style.backgroundImage = url(faviconUrl); |
| 554 titleDiv.dir = d.direction; | 556 titleDiv.dir = d.direction; |
| 555 } | 557 } |
| 556 }, | 558 }, |
| 557 | 559 |
| 560 updateMiniview_: function() { |
| 561 this.miniview.textContent = ''; |
| 562 var data = this.data.slice(0, MAX_MINIVIEW_ITEMS); |
| 563 for (var i = 0, item; item = data[i]; i++) { |
| 564 var span = document.createElement('span'); |
| 565 var a = span.appendChild(document.createElement('a')); |
| 566 a.href = item.url; |
| 567 a.textContent = item.title; |
| 568 a.style.backgroundImage = url('chrome://favicon/' + item.url); |
| 569 a.className = 'item'; |
| 570 this.miniview.appendChild(span); |
| 571 } |
| 572 }, |
| 573 |
| 558 handleClick_: function(e) { | 574 handleClick_: function(e) { |
| 559 var target = e.target; | 575 var target = e.target; |
| 560 if (target.classList.contains('pin')) { | 576 if (target.classList.contains('pin')) { |
| 561 this.togglePinned_(getItem(target)); | 577 this.togglePinned_(getItem(target)); |
| 562 e.preventDefault(); | 578 e.preventDefault(); |
| 563 } else if (target.classList.contains('remove')) { | 579 } else if (target.classList.contains('remove')) { |
| 564 this.blacklist(getItem(target)); | 580 this.blacklist(getItem(target)); |
| 565 e.preventDefault(); | 581 e.preventDefault(); |
| 566 } else { | 582 } else { |
| 567 var item = getItem(target); | 583 var item = getItem(target); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 580 handleKeyDown_: function(e) { | 596 handleKeyDown_: function(e) { |
| 581 if (!IS_MAC && e.keyCode == 46 || // Del | 597 if (!IS_MAC && e.keyCode == 46 || // Del |
| 582 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 598 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace |
| 583 this.blacklist(e.target); | 599 this.blacklist(e.target); |
| 584 } | 600 } |
| 585 } | 601 } |
| 586 }; | 602 }; |
| 587 | 603 |
| 588 return MostVisited; | 604 return MostVisited; |
| 589 })(); | 605 })(); |
| OLD | NEW |