Did some code cleanup and refactoring.
git-svn-id: file:///tmp/snv/trunk@21 12951d8a-c33d-4b7c-b961-822215c816e1
This commit is contained in:
parent
86c3cab652
commit
629914c24b
7
DiggSidebar.kpf
Normal file
7
DiggSidebar.kpf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Komodo Project File - DO NOT EDIT -->
|
||||||
|
<project id="d272e43a-a401-4d85-9ab3-917139df3867" kpf_version="4" name="DiggSidebar.kpf">
|
||||||
|
<preference-set idref="d272e43a-a401-4d85-9ab3-917139df3867">
|
||||||
|
<boolean id="import_live">1</boolean>
|
||||||
|
</preference-set>
|
||||||
|
</project>
|
@ -32,14 +32,17 @@ var DiggSidebar = {
|
|||||||
updateIntervalDecay: 0,
|
updateIntervalDecay: 0,
|
||||||
lastUpdateAt: new Date().getTime(),
|
lastUpdateAt: new Date().getTime(),
|
||||||
shownStoriesCount: 30,
|
shownStoriesCount: 30,
|
||||||
categories: ['All', 'Popular', 'Upcoming', 'Hot', 'Top'],
|
categories: ["All", "Popular", "Upcoming", "Hot", "Top"],
|
||||||
timerId: null,
|
timerId: null,
|
||||||
storyIds: [],
|
storyIds: [],
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
stories: [],
|
stories: [],
|
||||||
expandedStory: null,
|
expandedStory: null,
|
||||||
|
observerService: Components.classes["@mozilla.org/observer-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIObserverService),
|
||||||
|
|
||||||
fetchData: function(url, handler) {
|
|
||||||
|
fetchData: function (url, handler) {
|
||||||
DiggSidebar.indicateActivity();
|
DiggSidebar.indicateActivity();
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
@ -49,7 +52,7 @@ var DiggSidebar = {
|
|||||||
request.send(null);
|
request.send(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
errorHandler: function(e) {
|
errorHandler: function (e) {
|
||||||
/*if (DiggSidebar.UI.notificationBox.allNotifications.length > 0)
|
/*if (DiggSidebar.UI.notificationBox.allNotifications.length > 0)
|
||||||
DiggSidebar.UI.notificationBox.removeAllNotifications(true);*/
|
DiggSidebar.UI.notificationBox.removeAllNotifications(true);*/
|
||||||
DiggSidebar.UI.notificationBox.appendNotification(
|
DiggSidebar.UI.notificationBox.appendNotification(
|
||||||
@ -57,54 +60,62 @@ var DiggSidebar = {
|
|||||||
"dsAccessFailNotification",
|
"dsAccessFailNotification",
|
||||||
null,
|
null,
|
||||||
"PRIORITY_CRITICAL_HIGH",
|
"PRIORITY_CRITICAL_HIGH",
|
||||||
[{callback:DiggSidebar.getStories, label: "Retry", accessKey: "R"}]
|
[{callback: DiggSidebar.getStories, label: "Retry", accessKey: "R"}]
|
||||||
);
|
);
|
||||||
DiggSidebar.refreshing = false;
|
DiggSidebar.refreshing = false;
|
||||||
DiggSidebar.indicateInactivity();
|
DiggSidebar.indicateInactivity();
|
||||||
},
|
},
|
||||||
|
|
||||||
populateMenu: function(e) {
|
populateMenu: function (e) {
|
||||||
var XHR = e.target;
|
var XHR = e.target;
|
||||||
var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
|
var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
|
||||||
var containers = data.containers;
|
var containers = data.containers;
|
||||||
|
|
||||||
containers.forEach(function (container) {
|
containers.forEach(function (container) {
|
||||||
var cmenu = document.createElement('menu');
|
var cmenu = document.createElement("menu");
|
||||||
cmenu.setAttribute('id', container.short_name + 'Menu');
|
with (cmenu) {
|
||||||
cmenu.setAttribute('label', container.name);
|
setAttribute("id", container.short_name + "Menu");
|
||||||
cmenu.setAttribute('accesskey', container.name.charAt(0));
|
setAttribute("label", container.name);
|
||||||
|
setAttribute("accesskey", container.name.charAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
var cmenupopup = document.createElement('menupopup');
|
var cmenupopup = document.createElement("menupopup");
|
||||||
cmenupopup.setAttribute('id', container.short_name + 'Popup');
|
cmenupopup.setAttribute("id", container.short_name + "Popup");
|
||||||
|
|
||||||
DiggSidebar.categories.forEach(
|
DiggSidebar.categories.forEach(
|
||||||
function (category) {
|
function (category) {
|
||||||
var cmenuitem = document.createElement('menuitem');
|
var cmenuitem = document.createElement("menuitem");
|
||||||
cmenuitem.setAttribute('label', category);
|
with (cmenuitem) {
|
||||||
cmenuitem.setAttribute('value', '/container/' + container.short_name + '/' + category.toLowerCase());
|
setAttribute("label", category);
|
||||||
cmenuitem.setAttribute('accesskey', category.charAt(0));
|
setAttribute("value", "/container/" + container.short_name + "/" + category.toLowerCase());
|
||||||
cmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
|
setAttribute("accesskey", category.charAt(0));
|
||||||
|
setAttribute("oncommand", "DiggSidebar.setEndPoint(this.value)");
|
||||||
|
}
|
||||||
cmenupopup.appendChild(cmenuitem);
|
cmenupopup.appendChild(cmenuitem);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
cmenupopup.appendChild(document.createElement('menuseparator'));
|
cmenupopup.appendChild(document.createElement("menuseparator"));
|
||||||
var topics = container.topics;
|
var topics = container.topics;
|
||||||
topics.forEach(function (topic) {
|
topics.forEach(function (topic) {
|
||||||
var tmenu = document.createElement('menu');
|
var tmenu = document.createElement("menu");
|
||||||
tmenu.setAttribute('id', topic.short_name + 'Menu');
|
with (tmenu) {
|
||||||
tmenu.setAttribute('label', topic.name);
|
setAttribute("id", topic.short_name + "Menu");
|
||||||
tmenu.setAttribute('accesskey', topic.name.charAt(0));
|
setAttribute("label", topic.name);
|
||||||
|
setAttribute("accesskey", topic.name.charAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
var tmenupopup = document.createElement('menupopup');
|
var tmenupopup = document.createElement("menupopup");
|
||||||
tmenupopup.setAttribute('id', topic.short_name + 'Popup');
|
tmenupopup.setAttribute("id", topic.short_name + "Popup");
|
||||||
|
|
||||||
DiggSidebar.categories.forEach(
|
DiggSidebar.categories.forEach(
|
||||||
function (category) {
|
function (category) {
|
||||||
var tmenuitem = document.createElement('menuitem');
|
var tmenuitem = document.createElement("menuitem");
|
||||||
tmenuitem.setAttribute('label', category);
|
with (tmenuitem) {
|
||||||
tmenuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + category.toLowerCase());
|
setAttribute("label", category);
|
||||||
tmenuitem.setAttribute('accesskey', category.charAt(0));
|
setAttribute("value", "/topic/" + topic.short_name + "/" + category.toLowerCase());
|
||||||
tmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
|
setAttribute("accesskey", category.charAt(0));
|
||||||
|
setAttribute("oncommand", "DiggSidebar.setEndPoint(this.value)");
|
||||||
|
}
|
||||||
tmenupopup.appendChild(tmenuitem);
|
tmenupopup.appendChild(tmenuitem);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -116,37 +127,41 @@ var DiggSidebar = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
populateStoryList: function() {
|
populateStoryList: function () {
|
||||||
var newStoryIds = new Array();
|
var newStoryIds = [];
|
||||||
|
|
||||||
var jp = new JPath(DiggSidebar.stories);
|
var jp = new JPath(DiggSidebar.stories);
|
||||||
var filteredStories = jp.$(function(story){
|
var filteredStories = jp.$(function (story) {
|
||||||
return (story.$("category").json == DiggSidebar.endpoint.category) ;
|
return (story.$("category").json == DiggSidebar.endpoint.category);
|
||||||
}).json;
|
}).json;
|
||||||
jp = new JPath(filteredStories);
|
jp = new JPath(filteredStories);
|
||||||
if (DiggSidebar.endpoint.topic)
|
if (DiggSidebar.endpoint.topic) {
|
||||||
filteredStories = jp.$(function(story){
|
filteredStories = jp.$(function (story) {
|
||||||
return (story.$("topic/short_name").json == DiggSidebar.endpoint.topic);
|
return (story.$("topic/short_name").json == DiggSidebar.endpoint.topic);
|
||||||
}).json;
|
}).json;
|
||||||
if (DiggSidebar.endpoint.container)
|
}
|
||||||
filteredStories = jp.$(function(story){
|
if (DiggSidebar.endpoint.container) {
|
||||||
|
filteredStories = jp.$(function (story) {
|
||||||
return story.$("container/short_name").json == DiggSidebar.endpoint.container;
|
return story.$("container/short_name").json == DiggSidebar.endpoint.container;
|
||||||
}).json;
|
}).json;
|
||||||
|
}
|
||||||
|
|
||||||
if (filteredStories.length > 0)
|
if (filteredStories.length > 0) {
|
||||||
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.storyListBox);
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.storyListBox);
|
||||||
|
}
|
||||||
|
|
||||||
filteredStories.forEach(function (story, index) {
|
filteredStories.forEach(function (story, index) {
|
||||||
if (index < DiggSidebar.shownStoriesCount) {
|
if (index < DiggSidebar.shownStoriesCount) {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
if (story.promote_date != null)
|
if (story.promote_date != null) {
|
||||||
var then = new Date(story.promote_date*1000);
|
var then = new Date(story.promote_date * 1000);
|
||||||
else
|
} else {
|
||||||
var then = new Date(story.submit_date*1000);
|
var then = new Date(story.submit_date * 1000);
|
||||||
var diff = Math.max(now - then, 0)
|
}
|
||||||
|
var diff = Math.max(now - then, 0);
|
||||||
|
|
||||||
var hr = Math.floor(diff/(1000*3600));
|
var hr = Math.floor(diff / (1000 * 3600));
|
||||||
var min = Math.floor(diff/(1000*60)) - 60*hr;
|
var min = Math.floor(diff / (1000 * 60)) - 60 * hr;
|
||||||
|
|
||||||
var relativeTime = ((hr > 0) && (min > 0)) ?
|
var relativeTime = ((hr > 0) && (min > 0)) ?
|
||||||
(hr + " hr " + min + " mins ago") :
|
(hr + " hr " + min + " mins ago") :
|
||||||
@ -155,7 +170,7 @@ var DiggSidebar = {
|
|||||||
((hr == 0) && (min == 0)) ?
|
((hr == 0) && (min == 0)) ?
|
||||||
"just now" : "";
|
"just now" : "";
|
||||||
|
|
||||||
var li = DiggSidebar.UI.storyListBox.appendChild(document.createElement('richlistitem'));
|
var li = DiggSidebar.UI.storyListBox.appendChild(document.createElement("richlistitem"));
|
||||||
li.id = "story_" + story.id;
|
li.id = "story_" + story.id;
|
||||||
var attributes = {
|
var attributes = {
|
||||||
title: story.title,
|
title: story.title,
|
||||||
@ -170,56 +185,59 @@ var DiggSidebar = {
|
|||||||
desc: story.description,
|
desc: story.description,
|
||||||
link: story.link,
|
link: story.link,
|
||||||
href: story.href
|
href: story.href
|
||||||
}
|
};
|
||||||
for (var attr in attributes)
|
for (var attr in attributes) {
|
||||||
li.setAttribute(attr, attributes[attr]);
|
li.setAttribute(attr, attributes[attr]);
|
||||||
|
}
|
||||||
|
|
||||||
li.read = story.read;
|
li.read = story.read;
|
||||||
if (story.id == DiggSidebar.expandedStory)
|
if (story.id == DiggSidebar.expandedStory) {
|
||||||
li.showDescription();
|
li.showDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (DiggSidebar.storyIds.indexOf(story.id) == -1) {
|
||||||
|
newStoryIds.push(story.id);
|
||||||
}
|
}
|
||||||
if (DiggSidebar.storyIds.indexOf(story.id) == -1) newStoryIds.push(story.id);
|
|
||||||
});
|
});
|
||||||
DiggSidebar.storyIds = DiggSidebar.storyIds.concat(newStoryIds);
|
DiggSidebar.storyIds = DiggSidebar.storyIds.concat(newStoryIds);
|
||||||
},
|
},
|
||||||
|
|
||||||
showDescription: function(storyId) {
|
showDescription: function (storyId) {
|
||||||
var jp = new JPath(DiggSidebar.stories);
|
var jp = new JPath(DiggSidebar.stories);
|
||||||
var story = jp.query('//[id == ' + storyId + ']')[0];
|
var story = jp.query("//[id == " + storyId + "]")[0];
|
||||||
story.read = true;
|
story.read = true;
|
||||||
DiggSidebar.expandedStory = parseInt(storyId);
|
DiggSidebar.expandedStory = parseInt(storyId);
|
||||||
|
|
||||||
var listitems = DiggSidebar.UI.storyListBox.children;
|
var listitems = DiggSidebar.UI.storyListBox.children;
|
||||||
for (var i=0; i<listitems.length; i++)
|
for (var i = 0; i < listitems.length; i++) {
|
||||||
listitems[i].hideDescription();
|
listitems[i].hideDescription();
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('story_'+ story.id).showDescription();
|
document.getElementById("story_" + story.id).showDescription();
|
||||||
},
|
},
|
||||||
|
|
||||||
getStories: function() {
|
getStories: function () {
|
||||||
if (!DiggSidebar.refreshing) {
|
if (!DiggSidebar.refreshing) {
|
||||||
DiggSidebar.refreshing = true;
|
DiggSidebar.refreshing = true;
|
||||||
var ep = DiggSidebar.prefs.get("endpoint").value || '';
|
var ep = DiggSidebar.prefs.get("endpoint").value || "";
|
||||||
|
|
||||||
DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
|
DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, "") +
|
||||||
"?count=30" + "&type=json" +
|
"?count=30" + "&type=json" +
|
||||||
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
||||||
function(e) {
|
function (e) {
|
||||||
DiggSidebar.UI.endPointDesc.value = "digg" + ep;
|
DiggSidebar.UI.endPointDesc.value = "digg" + ep;
|
||||||
|
|
||||||
var stories = DiggSidebar.Utils.decodeJson(e.target.responseText).stories;
|
var stories = DiggSidebar.Utils.decodeJson(e.target.responseText).stories;
|
||||||
var newStories = stories.filter(
|
var newStories = stories.filter(
|
||||||
function(story) {
|
function (story) {
|
||||||
return !(DiggSidebar.storyIds.indexOf(story.id) != -1);
|
return !(DiggSidebar.storyIds.indexOf(story.id) != -1);
|
||||||
});
|
});
|
||||||
newStories.forEach(function(story) {
|
newStories.forEach(function (story) {
|
||||||
story.category = DiggSidebar.endpoint.category;
|
story.category = DiggSidebar.endpoint.category;
|
||||||
story.read = false;
|
story.read = false;
|
||||||
});
|
});
|
||||||
DiggSidebar.stories = newStories.concat(DiggSidebar.stories);
|
DiggSidebar.stories = newStories.concat(DiggSidebar.stories);
|
||||||
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
DiggSidebar.observerService.notifyObservers(null, DiggSidebar.storyListRefreshEventTopic, null);
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
|
||||||
observerService.notifyObservers(null, DiggSidebar.storyListRefreshEventTopic, null);
|
|
||||||
|
|
||||||
DiggSidebar.refreshing = false;
|
DiggSidebar.refreshing = false;
|
||||||
DiggSidebar.setUpdateInterval(stories);
|
DiggSidebar.setUpdateInterval(stories);
|
||||||
@ -235,171 +253,179 @@ var DiggSidebar = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createMenu: function() {
|
createMenu: function () {
|
||||||
DiggSidebar.fetchData("http://services.digg.com/containers" + "?type=json" +
|
DiggSidebar.fetchData("http://services.digg.com/containers" + "?type=json" +
|
||||||
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
||||||
DiggSidebar.populateMenu);
|
DiggSidebar.populateMenu);
|
||||||
},
|
},
|
||||||
|
|
||||||
setUpdateInterval: function(stories) {
|
setUpdateInterval: function (stories) {
|
||||||
//Adaptive update interval code START
|
//Adaptive update interval code START
|
||||||
if (stories.length == 0) return;
|
if (stories.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
var weights = [4, 3, 2, 1]
|
var weights = [4, 3, 2, 1];
|
||||||
var date = (stories[0].promote_date != null) ? 'promote_date' : 'submit_date';
|
var date = (stories[0].promote_date != null) ? "promote_date" : "submit_date";
|
||||||
stories.sort(function (a, b) {
|
stories.sort(function (a, b) {
|
||||||
if (a[date] > b[date]) return -1;
|
if (a[date] > b[date]) {
|
||||||
else if (a[date] < b[date]) return 1;
|
return -1;
|
||||||
return 0;
|
} else if (a[date] < b[date]) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
for (var i=0; i<Math.min(4, stories.length-1); i++) {
|
for (var i = 0; i < Math.min(4, stories.length - 1); i++) {
|
||||||
var diff = stories[i][date] - stories[i+1][date];
|
var diff = stories[i][date] - stories[i + 1][date];
|
||||||
sum += weights[i]*diff;
|
sum += weights[i] * diff;
|
||||||
}
|
}
|
||||||
var newUpdateInterval = Math.round(
|
var newUpdateInterval = Math.round(
|
||||||
sum*1000/weights
|
sum * 1000 / weights
|
||||||
.splice(0,Math.min(4, stories.length-1))
|
.splice(0, Math.min(4, stories.length - 1))
|
||||||
.reduce(function(a, b){return a + b;})
|
.reduce(function (a, b) {
|
||||||
|
return a + b;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newUpdateInterval > 0) {
|
if (newUpdateInterval > 0) {
|
||||||
var previousUpdateInterval = DiggSidebar.updateInterval;
|
var previousUpdateInterval = DiggSidebar.updateInterval;
|
||||||
DiggSidebar.updateInterval = newUpdateInterval;
|
DiggSidebar.updateInterval = newUpdateInterval;
|
||||||
|
|
||||||
if (previousUpdateInterval == newUpdateInterval)
|
if (previousUpdateInterval == newUpdateInterval) {
|
||||||
DiggSidebar.updateIntervalDecay += 1;
|
DiggSidebar.updateIntervalDecay += 1;
|
||||||
else
|
} else {
|
||||||
DiggSidebar.updateIntervalDecay = 0;
|
DiggSidebar.updateIntervalDecay = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Adaptive update interval code END
|
//Adaptive update interval code END
|
||||||
},
|
},
|
||||||
|
|
||||||
calculateTimeout: function() {
|
calculateTimeout: function () {
|
||||||
return Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)))
|
return Math.round(DiggSidebar.updateInterval * (Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||||
},
|
},
|
||||||
|
|
||||||
setEndPoint: function(ep) {
|
setEndPoint: function (ep) {
|
||||||
DiggSidebar.prefs.get("endpoint").value = ep;
|
DiggSidebar.prefs.get("endpoint").value = ep;
|
||||||
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(ep);
|
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(ep);
|
||||||
window.clearTimeout(DiggSidebar.timerId);
|
window.clearTimeout(DiggSidebar.timerId);
|
||||||
DiggSidebar.getStories();
|
DiggSidebar.getStories();
|
||||||
},
|
},
|
||||||
|
|
||||||
getEndpointParts: function(ep) {
|
getEndpointParts: function (ep) {
|
||||||
var tmp = {
|
var tmp = {
|
||||||
topic: null,
|
topic: null,
|
||||||
container: null,
|
container: null,
|
||||||
category: "all"
|
category: "all"
|
||||||
};
|
};
|
||||||
var parts = ep.split("/");
|
var parts = ep.split("/");
|
||||||
if (parts.length == 2)
|
if (parts.length == 2) {
|
||||||
tmp.category = parts[1];
|
tmp.category = parts[1];
|
||||||
else if (parts.length == 4) {
|
} else if (parts.length == 4) {
|
||||||
tmp[parts[1]] = parts[2];
|
tmp[parts[1]] = parts[2];
|
||||||
tmp.category = parts[3];
|
tmp.category = parts[3];
|
||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
},
|
},
|
||||||
|
|
||||||
indicateActivity: function() {
|
indicateActivity: function () {
|
||||||
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/loading_16.png";
|
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/loading_16.png";
|
||||||
with (DiggSidebar.UI.indicator.parentNode) {
|
with (DiggSidebar.UI.indicator.parentNode) {
|
||||||
disabled = true;
|
disabled = true;
|
||||||
setAttribute('tooltiptext', "Refreshing");
|
setAttribute("tooltiptext", "Refreshing");
|
||||||
onmouseover = null;
|
onmouseover = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
indicateInactivity: function() {
|
indicateInactivity: function () {
|
||||||
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/notloading_16.png";
|
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/notloading_16.png";
|
||||||
with (DiggSidebar.UI.indicator.parentNode) {
|
with (DiggSidebar.UI.indicator.parentNode) {
|
||||||
disabled = false;
|
disabled = false;
|
||||||
onmouseover = function() {
|
onmouseover = function () {
|
||||||
var autoRefreshTime = Math.round(
|
var autoRefreshTime = Math.round(
|
||||||
(DiggSidebar.lastUpdateAt + DiggSidebar.calculateTimeout() - new Date().getTime())/1000
|
(DiggSidebar.lastUpdateAt + DiggSidebar.calculateTimeout() - new Date().getTime()) / 1000
|
||||||
);
|
);
|
||||||
autoRefreshTime = (autoRefreshTime > 3600) ?
|
autoRefreshTime = (autoRefreshTime > 3600) ?
|
||||||
Math.round(autoRefreshTime/3600) + " hours":
|
Math.round(autoRefreshTime / 3600) + " hours":
|
||||||
(autoRefreshTime > 60) ?
|
(autoRefreshTime > 60) ?
|
||||||
Math.round(autoRefreshTime/60) + " minutes":
|
Math.round(autoRefreshTime / 60) + " minutes":
|
||||||
autoRefreshTime + " seconds";
|
autoRefreshTime + " seconds";
|
||||||
setAttribute('tooltiptext', "Click to refresh now.\n" +
|
setAttribute("tooltiptext", "Click to refresh now.\n" +
|
||||||
"Autorefreshing in " + autoRefreshTime);
|
"Autorefreshing in " + autoRefreshTime);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
DiggSidebar.lastUpdateAt = new Date().getTime();
|
DiggSidebar.lastUpdateAt = new Date().getTime();
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(){
|
initialize: function () {
|
||||||
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(DiggSidebar.prefs.get("endpoint").value);
|
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(DiggSidebar.prefs.get("endpoint").value);
|
||||||
var $ = function(id) {return document.getElementById(id)};
|
var $ = function (id) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
};
|
||||||
|
|
||||||
DiggSidebar.UI = {};
|
DiggSidebar.UI = {};
|
||||||
DiggSidebar.UI.notificationBox = $('dsNotificationBox');
|
DiggSidebar.UI.notificationBox = $("dsNotificationBox");
|
||||||
DiggSidebar.UI.indicator = $('dsBusyIndicator');
|
DiggSidebar.UI.indicator = $("dsBusyIndicator");
|
||||||
DiggSidebar.UI.storiesPopup = $('dsStoriesPopup');
|
DiggSidebar.UI.storiesPopup = $("dsStoriesPopup");
|
||||||
DiggSidebar.UI.storyListBox = $('dsStoryListBox');
|
DiggSidebar.UI.storyListBox = $("dsStoryListBox");
|
||||||
DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');
|
DiggSidebar.UI.endPointDesc = $("dsEndPointDesc");
|
||||||
|
|
||||||
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
||||||
DiggSidebar.createMenu();
|
DiggSidebar.createMenu();
|
||||||
DiggSidebar.getStories();
|
DiggSidebar.getStories();
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function(){
|
destroy: function () {
|
||||||
DiggSidebar.storyListObserver.unregister();
|
DiggSidebar.storyListObserver.unregister();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DiggSidebar.Utils = {
|
DiggSidebar.Utils = {
|
||||||
url: function(spec) {
|
url: function (spec) {
|
||||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||||
.getService(Components.interfaces.nsIIOService);
|
.getService(Components.interfaces.nsIIOService);
|
||||||
return ios.newURI(spec, null, null);
|
return ios.newURI(spec, null, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
openUrlInTab: function(url) {
|
openUrlInTab: function (url) {
|
||||||
Application.activeWindow.open(DiggSidebar.Utils.url(url));
|
Application.activeWindow.open(DiggSidebar.Utils.url(url));
|
||||||
},
|
},
|
||||||
|
|
||||||
decodeJson: function(string) {
|
decodeJson: function (string) {
|
||||||
var json = Components.classes["@mozilla.org/dom/json;1"]
|
var json = Components.classes["@mozilla.org/dom/json;1"]
|
||||||
.createInstance(Components.interfaces.nsIJSON);
|
.createInstance(Components.interfaces.nsIJSON);
|
||||||
return json.decode(string);
|
return json.decode(string);
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAllChildren: function(node) {
|
removeAllChildren: function (node) {
|
||||||
while (node.firstChild)
|
while (node.firstChild) {
|
||||||
node.removeChild(node.firstChild);
|
node.removeChild(node.firstChild);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
DiggSidebar.StoryListObserver = function() {
|
DiggSidebar.StoryListObserver = function () {
|
||||||
this.registered = false;
|
this.registered = false;
|
||||||
this.register();
|
this.register();
|
||||||
}
|
};
|
||||||
|
|
||||||
DiggSidebar.StoryListObserver.prototype = {
|
DiggSidebar.StoryListObserver.prototype = {
|
||||||
observe: function(subject, topic, data) {
|
observe: function (subject, topic, data) {
|
||||||
if (topic == window.DiggSidebar.storyListRefreshEventTopic) {
|
if (topic == window.DiggSidebar.storyListRefreshEventTopic) {
|
||||||
window.DiggSidebar.populateStoryList();
|
window.DiggSidebar.populateStoryList();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
register: function() {
|
register: function () {
|
||||||
if (this.registered == false) {
|
if (!this.registered) {
|
||||||
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
DiggSidebar.observerService.addObserver(this, DiggSidebar.storyListRefreshEventTopic, false);
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
|
||||||
observerService.addObserver(this, DiggSidebar.storyListRefreshEventTopic, false);
|
|
||||||
this.registered = true;
|
this.registered = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
unregister: function() {
|
unregister: function () {
|
||||||
if (this.registered == true) {
|
if (this.registered) {
|
||||||
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
DiggSidebar.observerService.removeObserver(this, DiggSidebar.storyListRefreshEventTopic);
|
||||||
.getService(Components.interfaces.nsIObserverService);
|
|
||||||
observerService.removeObserver(this, DiggSidebar.storyListRefreshEventTopic);
|
|
||||||
this.registered = false;
|
this.registered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
<RDF:Description RDF:about="rdf:#$55wJ23"
|
<RDF:Description RDF:about="rdf:#$55wJ23"
|
||||||
em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
|
em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
|
||||||
em:minVersion="3.0"
|
em:minVersion="3.0"
|
||||||
em:maxVersion="3.1b2" />
|
em:maxVersion="3.5.*" />
|
||||||
<RDF:Description RDF:about="urn:mozilla:install-manifest"
|
<RDF:Description RDF:about="urn:mozilla:install-manifest"
|
||||||
em:id="diggsidebar@abhin4v.myinfo.ws"
|
em:id="diggsidebar@abhinavsarkar.net"
|
||||||
em:name="Digg Sidebar"
|
em:name="Digg Sidebar"
|
||||||
em:version="0.7"
|
em:version="0.7"
|
||||||
em:creator="Abhinav Sarkar"
|
em:creator="Abhinav Sarkar"
|
||||||
|
Loading…
Reference in New Issue
Block a user