Browse Source

made changes in menu structure

git-svn-id: file:///tmp/snv/trunk@15 12951d8a-c33d-4b7c-b961-822215c816e1
master
Abhinav Sarkar 14 years ago
parent
commit
7a6d415228
  1. 3
      chrome/content/TODO.txt
  2. 106
      chrome/content/diggsidebar.js
  3. 10
      chrome/content/diggsidebar.xul

3
chrome/content/TODO.txt

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

106
chrome/content/diggsidebar.js

@ -63,73 +63,54 @@ var DiggSidebar = {
populateMenu: function(e) {
var XHR = e.target;
var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
var topics = data.topics;
var containers = new Array();
var containers = data.containers;
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.topicPopup);
topics.forEach(function (topic) {
var menu = document.createElement('menu');
menu.setAttribute('id', topic.short_name + 'Menu');
menu.setAttribute('label', topic.name);
menu.setAttribute('accesskey', topic.name.charAt(0));
var menupopup = document.createElement('menupopup');
menupopup.setAttribute('id', topic.short_name + 'Popup');
DiggSidebar.categories.forEach(
function (label) {
var menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', label);
menuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + label.toLowerCase());
menuitem.setAttribute('accesskey', label.charAt(0));
menuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
menupopup.appendChild(menuitem);
}
);
menu.appendChild(menupopup);
DiggSidebar.UI.topicPopup.appendChild(menu);
containers.push(topic.container);
});
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.containerPopup);
var filteredContainers = {name: [], short_name: []};
containers.forEach(function (container) {
var name = container.name;
var short_name = container.short_name;
if (filteredContainers.name.indexOf(name) == -1) {
filteredContainers.name.push(name);
filteredContainers.short_name.push(short_name);
}
});
for (var i=0; i<filteredContainers.name.length; i++) {
var menu = document.createElement('menu');
menu.setAttribute('id', filteredContainers.short_name[i] + 'Menu');
menu.setAttribute('label', filteredContainers.name[i]);
menu.setAttribute('accesskey', filteredContainers.name[i].charAt(0));
var cmenu = document.createElement('menu');
cmenu.setAttribute('id', container.short_name + 'Menu');
cmenu.setAttribute('label', container.name);
cmenu.setAttribute('accesskey', container.name.charAt(0));
var menupopup = document.createElement('menupopup');
menupopup.setAttribute('id', filteredContainers.short_name[i] + 'Popup');
var cmenupopup = document.createElement('menupopup');
cmenupopup.setAttribute('id', container.short_name + 'Popup');
DiggSidebar.categories.forEach(
function (label) {
var menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', label);
menuitem.setAttribute('value', '/container/' +
filteredContainers.short_name[i] + '/' + label.toLowerCase());
menuitem.setAttribute('accesskey', label.charAt(0));
menuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
menupopup.appendChild(menuitem);
function (category) {
var cmenuitem = document.createElement('menuitem');
cmenuitem.setAttribute('label', category);
cmenuitem.setAttribute('value', '/container/' + container.short_name + '/' + category.toLowerCase());
cmenuitem.setAttribute('accesskey', category.charAt(0));
cmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
cmenupopup.appendChild(cmenuitem);
}
);
menu.appendChild(menupopup);
DiggSidebar.UI.containerPopup.appendChild(menu);
}
//DiggSidebar.indicateInactivity();
cmenupopup.appendChild(document.createElement('menuseparator'));
var topics = container.topics;
topics.forEach(function (topic) {
var tmenu = document.createElement('menu');
tmenu.setAttribute('id', topic.short_name + 'Menu');
tmenu.setAttribute('label', topic.name);
tmenu.setAttribute('accesskey', topic.name.charAt(0));
var tmenupopup = document.createElement('menupopup');
tmenupopup.setAttribute('id', topic.short_name + 'Popup');
DiggSidebar.categories.forEach(
function (category) {
var tmenuitem = document.createElement('menuitem');
tmenuitem.setAttribute('label', category);
tmenuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + category.toLowerCase());
tmenuitem.setAttribute('accesskey', category.charAt(0));
tmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
tmenupopup.appendChild(tmenuitem);
}
);
tmenu.appendChild(tmenupopup);
cmenupopup.appendChild(tmenu);
});
cmenu.appendChild(cmenupopup);
DiggSidebar.UI.storiesPopup.appendChild(cmenu);
});
},
populateStoryList: function() {
@ -252,7 +233,7 @@ var DiggSidebar = {
},
createMenu: function() {
DiggSidebar.fetchData("http://services.digg.com/topics" + "?type=json" +
DiggSidebar.fetchData("http://services.digg.com/containers" + "?type=json" +
"&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
DiggSidebar.populateMenu);
},
@ -353,8 +334,7 @@ var DiggSidebar = {
DiggSidebar.UI = {};
DiggSidebar.UI.notificationBox = $('dsNotificationBox');
DiggSidebar.UI.indicator = $('dsBusyIndicator');
DiggSidebar.UI.topicPopup = $('dsTopicPopup');
DiggSidebar.UI.containerPopup = $('dsContainerPopup');
DiggSidebar.UI.storiesPopup = $('dsStoriesPopup');
DiggSidebar.UI.storyListBox = $('dsStoryListBox');
DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');

10
chrome/content/diggsidebar.xul

@ -27,16 +27,6 @@
<menuitem label="Top" value="/top"
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="T" />
<menuseparator />
<menu id="dsContainerMenu" label="Containers" accesskey="C">
<menupopup id="dsContainerPopup">
<menuitem label="Populating..." />
</menupopup>
</menu>
<menu id="dsTopicMenu" label="Topics" accesskey="T">
<menupopup id="dsTopicPopup">
<menuitem label="Populating..." />
</menupopup>
</menu>
</menupopup>
</menu>
</menubar>

Loading…
Cancel
Save