Browse Source

made changes in menu structure

git-svn-id: file:///tmp/snv/trunk@15 12951d8a-c33d-4b7c-b961-822215c816
Abhinav Sarkar 13 years ago
parent
commit
7a6d415228
3 changed files with 44 additions and 75 deletions
  1. 1
    2
      chrome/content/TODO.txt
  2. 43
    63
      chrome/content/diggsidebar.js
  3. 0
    10
      chrome/content/diggsidebar.xul

+ 1
- 2
chrome/content/TODO.txt View File

@@ -2,6 +2,5 @@ move to JSON data format -- done
2 2
 XBL -- done
3 3
 format JS/refactor JS/Use FUEL -- done
4 4
 caching, notifier-observer -- done
5
-search?
6
-new UI, icons, thumbnails
5
+new UI, icons -- done
7 6
 put license

+ 43
- 63
chrome/content/diggsidebar.js View File

@@ -63,73 +63,54 @@ var DiggSidebar = {
63 63
     populateMenu: function(e) {
64 64
         var XHR = e.target;
65 65
         var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
66
-        var topics = data.topics;
67
-        var containers = new Array();
66
+        var containers = data.containers;
68 67
 
69
-        DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.topicPopup);
70
-
71
-        topics.forEach(function (topic) {
72
-            var menu = document.createElement('menu');
73
-            menu.setAttribute('id', topic.short_name + 'Menu');
74
-            menu.setAttribute('label', topic.name);
75
-            menu.setAttribute('accesskey', topic.name.charAt(0));
76
-
77
-            var menupopup = document.createElement('menupopup');
78
-            menupopup.setAttribute('id', topic.short_name + 'Popup');
79
-
80
-            DiggSidebar.categories.forEach(
81
-                function (label) {
82
-                    var menuitem = document.createElement('menuitem');
83
-                    menuitem.setAttribute('label', label);
84
-                    menuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + label.toLowerCase());
85
-                    menuitem.setAttribute('accesskey', label.charAt(0));
86
-                    menuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
87
-                    menupopup.appendChild(menuitem);
88
-                }
89
-            );
90
-            menu.appendChild(menupopup);
91
-            DiggSidebar.UI.topicPopup.appendChild(menu);
92
-
93
-            containers.push(topic.container);
94
-        });
95
-
96
-        DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.containerPopup);
97
-
98
-        var filteredContainers = {name: [], short_name: []};
99 68
         containers.forEach(function (container) {
100
-            var name = container.name;
101
-            var short_name = container.short_name;
102
-            if (filteredContainers.name.indexOf(name) == -1) {
103
-                filteredContainers.name.push(name);
104
-                filteredContainers.short_name.push(short_name);
105
-            }
106
-        });
107
-
108
-        for (var i=0; i<filteredContainers.name.length; i++) {
109
-            var menu = document.createElement('menu');
110
-            menu.setAttribute('id', filteredContainers.short_name[i] + 'Menu');
111
-            menu.setAttribute('label', filteredContainers.name[i]);
112
-            menu.setAttribute('accesskey', filteredContainers.name[i].charAt(0));
69
+            var cmenu = document.createElement('menu');
70
+            cmenu.setAttribute('id', container.short_name + 'Menu');
71
+            cmenu.setAttribute('label', container.name);
72
+            cmenu.setAttribute('accesskey', container.name.charAt(0));
113 73
 
114
-            var menupopup = document.createElement('menupopup');
115
-            menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
74
+            var cmenupopup = document.createElement('menupopup');
75
+            cmenupopup.setAttribute('id', container.short_name + 'Popup');
116 76
 
117 77
             DiggSidebar.categories.forEach(
118
-                function (label) {
119
-                    var menuitem = document.createElement('menuitem');
120
-                    menuitem.setAttribute('label', label);
121
-                    menuitem.setAttribute('value', '/container/' +
122
-                        filteredContainers.short_name[i] + '/' + label.toLowerCase());
123
-                    menuitem.setAttribute('accesskey', label.charAt(0));
124
-                    menuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
125
-                    menupopup.appendChild(menuitem);
78
+                function (category) {
79
+                    var cmenuitem = document.createElement('menuitem');
80
+                    cmenuitem.setAttribute('label', category);
81
+                    cmenuitem.setAttribute('value', '/container/' + container.short_name + '/' + category.toLowerCase());
82
+                    cmenuitem.setAttribute('accesskey', category.charAt(0));
83
+                    cmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
84
+                    cmenupopup.appendChild(cmenuitem);
126 85
                 }
127 86
             );
128
-
129
-            menu.appendChild(menupopup);
130
-            DiggSidebar.UI.containerPopup.appendChild(menu);
131
-        }
132
-        //DiggSidebar.indicateInactivity();
87
+            cmenupopup.appendChild(document.createElement('menuseparator'));
88
+            var topics = container.topics;
89
+            topics.forEach(function (topic) {
90
+                var tmenu = document.createElement('menu');
91
+                tmenu.setAttribute('id', topic.short_name + 'Menu');
92
+                tmenu.setAttribute('label', topic.name);
93
+                tmenu.setAttribute('accesskey', topic.name.charAt(0));
94
+
95
+                var tmenupopup = document.createElement('menupopup');
96
+                tmenupopup.setAttribute('id', topic.short_name + 'Popup');
97
+
98
+                DiggSidebar.categories.forEach(
99
+                    function (category) {
100
+                        var tmenuitem = document.createElement('menuitem');
101
+                        tmenuitem.setAttribute('label', category);
102
+                        tmenuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + category.toLowerCase());
103
+                        tmenuitem.setAttribute('accesskey', category.charAt(0));
104
+                        tmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
105
+                        tmenupopup.appendChild(tmenuitem);
106
+                    }
107
+                );
108
+                tmenu.appendChild(tmenupopup);
109
+                cmenupopup.appendChild(tmenu);
110
+            });
111
+            cmenu.appendChild(cmenupopup);
112
+            DiggSidebar.UI.storiesPopup.appendChild(cmenu);
113
+        });
133 114
     },
134 115
 
135 116
     populateStoryList: function() {
@@ -252,7 +233,7 @@ var DiggSidebar = {
252 233
     },
253 234
 
254 235
     createMenu: function() {
255
-        DiggSidebar.fetchData("http://services.digg.com/topics" + "?type=json" +
236
+        DiggSidebar.fetchData("http://services.digg.com/containers" + "?type=json" +
256 237
             "&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
257 238
             DiggSidebar.populateMenu);
258 239
     },
@@ -353,8 +334,7 @@ var DiggSidebar = {
353 334
         DiggSidebar.UI = {};
354 335
         DiggSidebar.UI.notificationBox = $('dsNotificationBox');
355 336
         DiggSidebar.UI.indicator = $('dsBusyIndicator');
356
-        DiggSidebar.UI.topicPopup = $('dsTopicPopup');
357
-        DiggSidebar.UI.containerPopup = $('dsContainerPopup');
337
+        DiggSidebar.UI.storiesPopup = $('dsStoriesPopup');
358 338
         DiggSidebar.UI.storyListBox = $('dsStoryListBox');
359 339
         DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');
360 340
 

+ 0
- 10
chrome/content/diggsidebar.xul View File

@@ -27,16 +27,6 @@
27 27
                             <menuitem label="Top" value="/top"
28 28
                                       oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="T" />
29 29
                             <menuseparator />
30
-                            <menu id="dsContainerMenu" label="Containers" accesskey="C">
31
-                                <menupopup id="dsContainerPopup">
32
-                                    <menuitem label="Populating..." />
33
-                                </menupopup>
34
-                            </menu>
35
-                            <menu id="dsTopicMenu" label="Topics" accesskey="T">
36
-                                <menupopup id="dsTopicPopup">
37
-                                    <menuitem label="Populating..." />
38
-                                </menupopup>
39
-                            </menu>
40 30
                         </menupopup>
41 31
                     </menu>
42 32
                 </menubar>

Loading…
Cancel
Save