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

Side by Side Diff: chrome/browser/resources/new_new_tab.js

Issue 165107: NNTP: Add a menu item that allows the user to restore all blacklisted... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/new_new_tab.html ('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 1
2 // Helpers 2 // Helpers
3 3
4 function $(id) { 4 function $(id) {
5 return document.getElementById(id); 5 return document.getElementById(id);
6 } 6 }
7 7
8 // TODO(arv): Remove these when classList is available in HTML5. 8 // TODO(arv): Remove these when classList is available in HTML5.
9 // https://bugs.webkit.org/show_bug.cgi?id=20709 9 // https://bugs.webkit.org/show_bug.cgi?id=20709
10 function hasClass(el, name) { 10 function hasClass(el, name) {
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 741 }
742 742
743 console.log(lines.join('\n')); 743 console.log(lines.join('\n'));
744 } 744 }
745 745
746 // Updates the visibility of the menu items. 746 // Updates the visibility of the menu items.
747 function updateOptionMenu() { 747 function updateOptionMenu() {
748 var menuItems = $('option-menu').children; 748 var menuItems = $('option-menu').children;
749 for (var i = 0; i < menuItems.length; i++) { 749 for (var i = 0; i < menuItems.length; i++) {
750 var item = menuItems[i]; 750 var item = menuItems[i];
751 var section = Section[item.getAttribute('section')]; 751 var command = item.getAttribute('command');
752 var show = item.getAttribute('show') == 'true'; 752 if (command == 'show' || command == 'hide') {
753 // Hide show items if already shown. Hide hide items if already hidden. 753 var show = command == 'show';
754 var hideMenuItem = show == !!(shownSections & section); 754 var section = Section[item.getAttribute('section')];
755 item.style.display = hideMenuItem ? 'none' : ''; 755 // Hide show items if already shown. Hide hide items if already hidden.
756 var hideMenuItem = show == !!(shownSections & section);
757 item.style.display = hideMenuItem ? 'none' : '';
758 }
756 } 759 }
757 } 760 }
758 761
759 // We apply the size class here so that we don't trigger layout animations 762 // We apply the size class here so that we don't trigger layout animations
760 // onload. 763 // onload.
761 764
762 handleWindowResize(); 765 handleWindowResize();
763 766
764 var localStrings = new LocalStrings(); 767 var localStrings = new LocalStrings();
765 768
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 handleMouseDown: function(e) { 891 handleMouseDown: function(e) {
889 if (this.isShown()) { 892 if (this.isShown()) {
890 this.hide(); 893 this.hide();
891 } else { 894 } else {
892 this.show(); 895 this.show();
893 } 896 }
894 }, 897 },
895 898
896 handleMouseOver: function(e) { 899 handleMouseOver: function(e) {
897 var el = e.target; 900 var el = e.target;
898 var index = Array.prototype.indexOf.call(this.menu.children, el); 901 if (!el.hasAttribute('command')) {
899 this.setSelectedIndex(index); 902 this.setSelectedIndex(-1);
903 } else {
904 var index = Array.prototype.indexOf.call(this.menu.children, el);
905 this.setSelectedIndex(index);
906 }
900 }, 907 },
901 908
902 handleMouseOut: function(e) { 909 handleMouseOut: function(e) {
903 this.setSelectedIndex(-1); 910 this.setSelectedIndex(-1);
904 }, 911 },
905 912
906 handleMouseUp: function(e) { 913 handleMouseUp: function(e) {
907 var item = this.getSelectedItem(); 914 var item = this.getSelectedItem();
908 if (item) { 915 if (item) {
909 this.executeItem(item); 916 this.executeItem(item);
910 } 917 }
911 }, 918 },
912 919
913 handleKeyDown: function(e) { 920 handleKeyDown: function(e) {
914 var item = this.getSelectedItem(); 921 var item = this.getSelectedItem();
915 922
916 var self = this; 923 var self = this;
917 function selectNextVisible(m) { 924 function selectNextVisible(m) {
918 var children = self.menu.children; 925 var children = self.menu.children;
919 var len = children.length; 926 var len = children.length;
920 var i = self.selectedIndex_; 927 var i = self.selectedIndex_;
921 if (i == -1 && m == -1) { 928 if (i == -1 && m == -1) {
922 // Edge case when we need to go the last item fisrt. 929 // Edge case when we need to go the last item fisrt.
923 i = 0; 930 i = 0;
924 } 931 }
925 while (true) { 932 while (true) {
926 i = (i + m + len) % len; 933 i = (i + m + len) % len;
927 item = children[i]; 934 item = children[i];
928 if (item && item.style.display != 'none') { 935 if (item && item.hasAttribute('command') &&
936 item.style.display != 'none') {
929 break; 937 break;
930 } 938 }
931 } 939 }
932 if (item) { 940 if (item) {
933 self.setSelectedIndex(i); 941 self.setSelectedIndex(i);
934 } 942 }
935 } 943 }
936 944
937 switch (e.keyIdentifier) { 945 switch (e.keyIdentifier) {
938 case 'Down': 946 case 'Down':
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 } 991 }
984 this.selectedIndex_ = i; 992 this.selectedIndex_ = i;
985 } 993 }
986 }, 994 },
987 995
988 getSelectedItem: function() { 996 getSelectedItem: function() {
989 return this.menu.children[this.selectedIndex_] || null; 997 return this.menu.children[this.selectedIndex_] || null;
990 }, 998 },
991 999
992 executeItem: function(item) { 1000 executeItem: function(item) {
993 var section = Section[item.getAttribute('section')]; 1001 var command = item.getAttribute('command');
994 var show = item.getAttribute('show') == 'true'; 1002 if (command in this.commands) {
995 if (show) { 1003 this.commands[command].call(this, item);
996 showSection(section);
997 } else {
998 hideSection(section);
999 } 1004 }
1000 1005
1001 this.hide(); 1006 this.hide();
1007 }
1008 };
1009
1010 var optionMenu = new OptionMenu($('option-button'), $('option-menu'));
1011 optionMenu.commands = {
1012 'clear-all-blacklisted' : function() {
1013 mostVisited.clearAllBlacklisted();
1014 chrome.send('getMostVisited');
1015 },
1016 'show': function(item) {
1017 var section = Section[item.getAttribute('section')];
1018 showSection(section);
1019 saveShownSections();
1020 },
1021 'hide': function(item) {
1022 var section = Section[item.getAttribute('section')];
1023 hideSection(section);
1002 saveShownSections(); 1024 saveShownSections();
1003 } 1025 }
1004 }; 1026 };
1005 1027
1006 var optionMenu = new OptionMenu($('option-button'), $('option-menu'));
1007
1008 $('most-visited').addEventListener('click', function(e) { 1028 $('most-visited').addEventListener('click', function(e) {
1009 var target = e.target; 1029 var target = e.target;
1010 if (hasClass(target, 'pin')) { 1030 if (hasClass(target, 'pin')) {
1011 mostVisited.togglePinned(mostVisited.getItem(target)); 1031 mostVisited.togglePinned(mostVisited.getItem(target));
1012 e.preventDefault(); 1032 e.preventDefault();
1013 } else if (hasClass(target, 'remove')) { 1033 } else if (hasClass(target, 'remove')) {
1014 mostVisited.blacklist(mostVisited.getItem(target)); 1034 mostVisited.blacklist(mostVisited.getItem(target));
1015 e.preventDefault(); 1035 e.preventDefault();
1016 } 1036 }
1017 }); 1037 });
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 el.addEventListener('dragover', bind(this.handleDragOver, this)); 1400 el.addEventListener('dragover', bind(this.handleDragOver, this));
1381 el.addEventListener('dragleave', bind(this.handleDragLeave, this)); 1401 el.addEventListener('dragleave', bind(this.handleDragLeave, this));
1382 el.addEventListener('drop', bind(this.handleDrop, this)); 1402 el.addEventListener('drop', bind(this.handleDrop, this));
1383 el.addEventListener('dragend', bind(this.handleDragEnd, this)); 1403 el.addEventListener('dragend', bind(this.handleDragEnd, this));
1384 el.addEventListener('drag', bind(this.handleDrag, this)); 1404 el.addEventListener('drag', bind(this.handleDrag, this));
1385 el.addEventListener('mousedown', bind(this.handleMouseDown, this)); 1405 el.addEventListener('mousedown', bind(this.handleMouseDown, this));
1386 } 1406 }
1387 }; 1407 };
1388 1408
1389 dnd.init(); 1409 dnd.init();
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698