Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: chrome/browser/resources/ntp/most_visited.js

Issue 3455007: Make it possible to hide "most visited" on nnnnnnntp (Closed)
Patch Set: fix revert reasons Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/ntp/apps.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, miniview, useSmallGrid, visible) { 44 function MostVisited(el, miniview, menu, useSmallGrid, visible) {
45 this.element = el; 45 this.element = el;
46 this.miniview = miniview; 46 this.miniview = miniview;
47 this.menu = menu;
47 this.useSmallGrid_ = useSmallGrid; 48 this.useSmallGrid_ = useSmallGrid;
48 this.visible_ = visible; 49 this.visible_ = visible;
49 50
50 this.createThumbnails_(); 51 this.createThumbnails_();
51 this.applyMostVisitedRects_(); 52 this.applyMostVisitedRects_();
52 53
53 el.addEventListener('click', this.handleClick_.bind(this)); 54 el.addEventListener('click', this.handleClick_.bind(this));
54 el.addEventListener('keydown', this.handleKeyDown_.bind(this)); 55 el.addEventListener('keydown', this.handleKeyDown_.bind(this));
55 56
56 document.addEventListener('DOMContentLoaded', 57 document.addEventListener('DOMContentLoaded',
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 data.length = Math.min(maxItems, data.length); 530 data.length = Math.min(maxItems, data.length);
530 var len = data.length; 531 var len = data.length;
531 for (var i = len; i < maxItems; i++) { 532 for (var i = len; i < maxItems; i++) {
532 data[i] = {filler: true}; 533 data[i] = {filler: true};
533 } 534 }
534 535
535 // On setting we need to update the items 536 // On setting we need to update the items
536 this.data_ = data; 537 this.data_ = data;
537 this.updateMostVisited_(); 538 this.updateMostVisited_();
538 this.updateMiniview_(); 539 this.updateMiniview_();
540 this.updateMenu_();
539 }, 541 },
540 542
541 updateMostVisited_: function() { 543 updateMostVisited_: function() {
542 544
543 function getThumbnailClassName(item) { 545 function getThumbnailClassName(item) {
544 return 'thumbnail-container' + 546 return 'thumbnail-container' +
545 (item.pinned ? ' pinned' : '') + 547 (item.pinned ? ' pinned' : '') +
546 (item.filler ? ' filler' : ''); 548 (item.filler ? ' filler' : '');
547 } 549 }
548 550
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 var a = span.appendChild(document.createElement('a')); 604 var a = span.appendChild(document.createElement('a'));
603 a.href = item.url; 605 a.href = item.url;
604 a.textContent = item.title; 606 a.textContent = item.title;
605 a.style.backgroundImage = url('chrome://favicon/' + item.url); 607 a.style.backgroundImage = url('chrome://favicon/' + item.url);
606 a.className = 'item'; 608 a.className = 'item';
607 this.miniview.appendChild(span); 609 this.miniview.appendChild(span);
608 } 610 }
609 updateMiniviewClipping(this.miniview); 611 updateMiniviewClipping(this.miniview);
610 }, 612 },
611 613
614 updateMenu_: function() {
615 clearClosedMenu(this.menu);
616 var data = this.data.slice(0, MAX_MINIVIEW_ITEMS);
617 for (var i = 0, item; item = data[i]; i++) {
618 if (!item.filler) {
619 addClosedMenuEntry(
620 this.menu, item.url, item.title, 'chrome://favicon/' + item.url);
621 }
622 }
623 addClosedMenuFooter(
624 this.menu, 'most-visited', MINIMIZED_THUMB, Section.THUMB);
625 },
626
612 handleClick_: function(e) { 627 handleClick_: function(e) {
613 var target = e.target; 628 var target = e.target;
614 if (target.classList.contains('pin')) { 629 if (target.classList.contains('pin')) {
615 this.togglePinned_(getItem(target)); 630 this.togglePinned_(getItem(target));
616 e.preventDefault(); 631 e.preventDefault();
617 } else if (target.classList.contains('remove')) { 632 } else if (target.classList.contains('remove')) {
618 this.blacklist(getItem(target)); 633 this.blacklist(getItem(target));
619 e.preventDefault(); 634 e.preventDefault();
620 } else { 635 } else {
621 var item = getItem(target); 636 var item = getItem(target);
(...skipping 12 matching lines...) Expand all
634 handleKeyDown_: function(e) { 649 handleKeyDown_: function(e) {
635 if (!IS_MAC && e.keyCode == 46 || // Del 650 if (!IS_MAC && e.keyCode == 46 || // Del
636 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace 651 IS_MAC && e.metaKey && e.keyCode == 8) { // Cmd + Backspace
637 this.blacklist(e.target); 652 this.blacklist(e.target);
638 } 653 }
639 } 654 }
640 }; 655 };
641 656
642 return MostVisited; 657 return MostVisited;
643 })(); 658 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp/apps.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698