|
|
|
@ -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'); |
|
|
|
|
|
|
|
|
|