|
|
|
@ -35,7 +35,7 @@ var DiggSidebar = {
|
|
|
|
|
stories: [],
|
|
|
|
|
|
|
|
|
|
fetchData: function(url, handler) {
|
|
|
|
|
DiggSidebar.diggIndicator.style.display = '';
|
|
|
|
|
DiggSidebar.UI.indicator.style.display = '';
|
|
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
|
request.onerror = DiggSidebar.errorHandler;
|
|
|
|
@ -54,9 +54,7 @@ var DiggSidebar = {
|
|
|
|
|
var topics = data.topics;
|
|
|
|
|
var containers = new Array();
|
|
|
|
|
|
|
|
|
|
while (DiggSidebar.topicPopup.firstChild) {
|
|
|
|
|
DiggSidebar.topicPopup.removeChild(DiggSidebar.topicPopup.firstChild);
|
|
|
|
|
}
|
|
|
|
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.topicPopup);
|
|
|
|
|
|
|
|
|
|
topics.forEach(function (topic) {
|
|
|
|
|
var menu = document.createElement('menu');
|
|
|
|
@ -78,14 +76,12 @@ var DiggSidebar = {
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
menu.appendChild(menupopup);
|
|
|
|
|
DiggSidebar.topicPopup.appendChild(menu);
|
|
|
|
|
DiggSidebar.UI.topicPopup.appendChild(menu);
|
|
|
|
|
|
|
|
|
|
containers.push(topic.container);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
while (DiggSidebar.containerPopup.firstChild) {
|
|
|
|
|
DiggSidebar.containerPopup.removeChild(DiggSidebar.containerPopup.firstChild);
|
|
|
|
|
}
|
|
|
|
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.containerPopup);
|
|
|
|
|
|
|
|
|
|
var filteredContainers = {name: [], short_name: []};
|
|
|
|
|
containers.forEach(function (container) {
|
|
|
|
@ -119,18 +115,14 @@ var DiggSidebar = {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
menu.appendChild(menupopup);
|
|
|
|
|
DiggSidebar.containerPopup.appendChild(menu);
|
|
|
|
|
DiggSidebar.UI.containerPopup.appendChild(menu);
|
|
|
|
|
}
|
|
|
|
|
DiggSidebar.diggIndicator.style.display = 'none';
|
|
|
|
|
DiggSidebar.UI.indicator.style.display = 'none';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
populateStoryList: function() {
|
|
|
|
|
while (DiggSidebar.storyList.firstChild) {
|
|
|
|
|
DiggSidebar.storyList.removeChild(DiggSidebar.storyList.firstChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.storyListBox);
|
|
|
|
|
var newStoryIds = new Array();
|
|
|
|
|
Application.console.log("DiggSidebar.stories.length = " + DiggSidebar.stories.length);
|
|
|
|
|
|
|
|
|
|
var jp = new JPath(DiggSidebar.stories);
|
|
|
|
|
var filteredStories = jp.$(function(story){
|
|
|
|
@ -165,20 +157,24 @@ var DiggSidebar = {
|
|
|
|
|
((hr == 0) && (min == 0)) ?
|
|
|
|
|
"just now" : "";
|
|
|
|
|
|
|
|
|
|
var li = DiggSidebar.storyList.appendChild(document.createElement('richlistitem'));
|
|
|
|
|
var li = DiggSidebar.UI.storyListBox.appendChild(document.createElement('richlistitem'));
|
|
|
|
|
li.id = "story_" + story.id;
|
|
|
|
|
li.setAttribute('title', story.title);
|
|
|
|
|
li.setAttribute('date', relativeTime);
|
|
|
|
|
li.setAttribute('status', story.status);
|
|
|
|
|
li.setAttribute('container', story.container.name);
|
|
|
|
|
li.setAttribute('topic', story.topic.name);
|
|
|
|
|
li.setAttribute('username', story.user.name);
|
|
|
|
|
li.setAttribute('userlink', "http://digg.com/users/" + story.user.name);
|
|
|
|
|
li.setAttribute('diggs', story.diggs);
|
|
|
|
|
li.setAttribute('comments', story.comments);
|
|
|
|
|
li.setAttribute('desc', story.description);
|
|
|
|
|
li.setAttribute('link', story.link);
|
|
|
|
|
li.setAttribute('href', story.href);
|
|
|
|
|
var attributes = {
|
|
|
|
|
title: story.title,
|
|
|
|
|
date: relativeTime,
|
|
|
|
|
status: story.status,
|
|
|
|
|
container: story.container.name,
|
|
|
|
|
topic: story.topic.name,
|
|
|
|
|
username: story.user.name,
|
|
|
|
|
userlink: "http://digg.com/users/" + story.user.name,
|
|
|
|
|
diggs: story.diggs,
|
|
|
|
|
comments: story.comments,
|
|
|
|
|
desc: story.description,
|
|
|
|
|
link: story.link,
|
|
|
|
|
href: story.href
|
|
|
|
|
}
|
|
|
|
|
for (attr in attributes)
|
|
|
|
|
li.setAttribute(attr, attributes[attr]);
|
|
|
|
|
|
|
|
|
|
if (DiggSidebar.storyIds.indexOf(story.id) != -1) li.new = false;
|
|
|
|
|
li.read = story.read;
|
|
|
|
@ -192,7 +188,7 @@ var DiggSidebar = {
|
|
|
|
|
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
|
|
|
|
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
|
|
|
|
|
|
|
|
|
DiggSidebar.diggIndicator.style.display = 'none';
|
|
|
|
|
DiggSidebar.UI.indicator.style.display = 'none';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showDescription: function(storyId) {
|
|
|
|
@ -200,18 +196,16 @@ var DiggSidebar = {
|
|
|
|
|
var story = jp.query('//[id == ' + storyId + ']')[0];
|
|
|
|
|
story.read = true;
|
|
|
|
|
|
|
|
|
|
var listitems = document.getElementsByTagName('richlistitem');
|
|
|
|
|
var listitems = DiggSidebar.UI.storyListBox.children;
|
|
|
|
|
for (var i=0; i<listitems.length; i++)
|
|
|
|
|
listitems[i].hideDescription();
|
|
|
|
|
|
|
|
|
|
var li = document.getElementById('story_'+ story.id)
|
|
|
|
|
li.read = true;
|
|
|
|
|
li.showDescription();
|
|
|
|
|
document.getElementById('story_'+ story.id).showDescription();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getStories: function() {
|
|
|
|
|
var ep = DiggSidebar.prefs.get("endpoint").value || '';
|
|
|
|
|
DiggSidebar.diggEndPoint.value = "digg" + ep;
|
|
|
|
|
DiggSidebar.UI.endPointDesc.value = "digg" + ep;
|
|
|
|
|
|
|
|
|
|
DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
|
|
|
|
|
"?count=30" + "&type=json" +
|
|
|
|
@ -297,14 +291,14 @@ var DiggSidebar = {
|
|
|
|
|
togglePlayPause: function() {
|
|
|
|
|
if (DiggSidebar.playing) {
|
|
|
|
|
window.clearTimeout(DiggSidebar.timerId);
|
|
|
|
|
DiggSidebar.diggPlayPause.image = "chrome://diggsidebar/content/image/Play.png";
|
|
|
|
|
DiggSidebar.diggPlayPause.setAttribute("tooltiptext", "Click to Start autoupdate");
|
|
|
|
|
DiggSidebar.UI.playPauseButton.image = "chrome://diggsidebar/content/image/Play.png";
|
|
|
|
|
DiggSidebar.UI.playPauseButton.setAttribute("tooltiptext", "Click to Start autoupdate");
|
|
|
|
|
DiggSidebar.playing = false;
|
|
|
|
|
} else {
|
|
|
|
|
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
|
|
|
|
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
|
|
|
|
DiggSidebar.diggPlayPause.image = "chrome://diggsidebar/content/image/Pause.png";
|
|
|
|
|
DiggSidebar.diggPlayPause.setAttribute("tooltiptext", "Click to Pause autoupdate");
|
|
|
|
|
DiggSidebar.UI.playPauseButton.image = "chrome://diggsidebar/content/image/Pause.png";
|
|
|
|
|
DiggSidebar.UI.playPauseButton.setAttribute("tooltiptext", "Click to Pause autoupdate");
|
|
|
|
|
DiggSidebar.playing = true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
@ -312,12 +306,14 @@ var DiggSidebar = {
|
|
|
|
|
initialize: function(){
|
|
|
|
|
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(DiggSidebar.prefs.get("endpoint").value);
|
|
|
|
|
var $ = function(id) {return document.getElementById(id)};
|
|
|
|
|
DiggSidebar.diggIndicator = $('diggIndicator');
|
|
|
|
|
DiggSidebar.topicPopup = $('topicPopup');
|
|
|
|
|
DiggSidebar.containerPopup = $('containerPopup');
|
|
|
|
|
DiggSidebar.storyList = $('storyList');
|
|
|
|
|
DiggSidebar.diggEndPoint = $('diggEndPoint');
|
|
|
|
|
DiggSidebar.diggPlayPause = $('diggPlayPause');
|
|
|
|
|
|
|
|
|
|
DiggSidebar.UI = {};
|
|
|
|
|
DiggSidebar.UI.indicator = $('dsBusyIndicator');
|
|
|
|
|
DiggSidebar.UI.topicPopup = $('dsTopicPopup');
|
|
|
|
|
DiggSidebar.UI.containerPopup = $('dsContainerPopup');
|
|
|
|
|
DiggSidebar.UI.storyListBox = $('dsStoryListBox');
|
|
|
|
|
DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');
|
|
|
|
|
DiggSidebar.UI.playPauseButton = $('dsPlayPauseButton');
|
|
|
|
|
|
|
|
|
|
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
|
|
|
|
DiggSidebar.createMenu();
|
|
|
|
@ -344,6 +340,11 @@ DiggSidebar.Utils = {
|
|
|
|
|
var json = Components.classes["@mozilla.org/dom/json;1"]
|
|
|
|
|
.createInstance(Components.interfaces.nsIJSON);
|
|
|
|
|
return json.decode(string);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeAllChildren: function(node) {
|
|
|
|
|
while (node.firstChild)
|
|
|
|
|
node.removeChild(node.firstChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|