changed the method to show the description of stories
git-svn-id: file:///tmp/snv/trunk@10 12951d8a-c33d-4b7c-b961-822215c816e1master
джерело
0aa71851ef
коміт
04a1088a4a
|
@ -1,7 +1,7 @@
|
|||
move to JSON data format -- done
|
||||
XBL -- done
|
||||
format JS/refactor JS/Use FUEL -- done
|
||||
caching/db, threading
|
||||
caching/db, notifier-observer -- done
|
||||
search
|
||||
new UI, icons, thumbnails
|
||||
JQuery
|
||||
put license
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
*/
|
||||
|
||||
DiggSidebar = {
|
||||
var DiggSidebar = {
|
||||
prefs: Application.extensions.get("diggsidebar@abhinavsarkar.net").prefs,
|
||||
storyListRefreshEventTopic: "extension-diggsidebar-abhinavsarkar-net-storylist-refresh",
|
||||
endpoint: {
|
||||
|
@ -130,7 +130,7 @@ DiggSidebar = {
|
|||
}
|
||||
|
||||
var newStoryIds = new Array();
|
||||
Application.console.log(DiggSidebar.stories.length);
|
||||
Application.console.log("DiggSidebar.stories.length = " + DiggSidebar.stories.length);
|
||||
|
||||
var jp = new JPath(DiggSidebar.stories);
|
||||
var filtedStories = DiggSidebar.stories;
|
||||
|
@ -145,64 +145,65 @@ DiggSidebar = {
|
|||
|
||||
filtedStories.forEach(function (story, index) {
|
||||
if (index < DiggSidebar.shownStoriesCount) {
|
||||
var listitem = DiggSidebar.storyList.appendChild(document.createElement('richlistitem'));
|
||||
listitem.id = "story_" + story.id;
|
||||
listitem.setAttribute('title', story.title);
|
||||
if (DiggSidebar.storyIds.indexOf(story.id) != -1) listitem.new = false;
|
||||
var now = new Date();
|
||||
if (story.promote_date != null)
|
||||
var then = new Date(story.promote_date*1000);
|
||||
else
|
||||
var then = new Date(story.submit_date*1000);
|
||||
var diff = Math.max(now - then, 0)
|
||||
|
||||
var hr = Math.floor(diff/(1000*3600));
|
||||
var min = Math.floor(diff/(1000*60)) - 60*hr;
|
||||
|
||||
var relativeTime = ((hr > 0) && (min > 0)) ?
|
||||
(hr + " hr " + min + " mins ago") :
|
||||
((hr == 0) && (min > 0)) ?
|
||||
(min + " mins ago") :
|
||||
((hr == 0) && (min == 0)) ?
|
||||
"just now" : "";
|
||||
|
||||
var li = DiggSidebar.storyList.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);
|
||||
|
||||
if (DiggSidebar.storyIds.indexOf(story.id) != -1) li.new = false;
|
||||
li.read = story.read;
|
||||
}
|
||||
if (DiggSidebar.storyIds.indexOf(story.id) == -1) newStoryIds.push(story.id);
|
||||
});
|
||||
DiggSidebar.storyIds = DiggSidebar.storyIds.concat(newStoryIds);
|
||||
DiggSidebar.setUpdateInterval(DiggSidebar.stories.slice(-5));
|
||||
DiggSidebar.setUpdateInterval(DiggSidebar.stories.slice(0,5));
|
||||
|
||||
window.clearTimeout(DiggSidebar.timerId);
|
||||
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
||||
|
||||
DiggSidebar.diggIndicator.style.display = 'none';
|
||||
},
|
||||
|
||||
populateDescription: function(e) {
|
||||
var XHR = e.target;
|
||||
//Application.console.log(XHR.responseText);
|
||||
var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
|
||||
var story = data.stories[0];
|
||||
|
||||
var now = new Date();
|
||||
if (story.promote_date != null)
|
||||
var then = new Date(story.promote_date*1000);
|
||||
else
|
||||
var then = new Date(story.submit_date*1000);
|
||||
var diff = Math.max(now - then, 0)
|
||||
|
||||
var hr = Math.floor(diff/(1000*3600));
|
||||
var min = Math.floor(diff/(1000*60)) - 60*hr;
|
||||
showDescription: function(storyId) {
|
||||
var jp = new JPath(DiggSidebar.stories);
|
||||
var story = jp.query('//[id == ' + storyId + ']')[0];
|
||||
story.read = true;
|
||||
|
||||
var listitems = document.getElementsByTagName('richlistitem');
|
||||
for (var i=0; i<listitems.length; i++) {
|
||||
listitems[i].hideDesc();
|
||||
}
|
||||
for (var i=0; i<listitems.length; i++)
|
||||
listitems[i].hideDescription();
|
||||
|
||||
var li = document.getElementById('story_'+ story.id)
|
||||
|
||||
var relativeTime = ((hr > 0) && (min > 0)) ?
|
||||
(hr + " hr " + min + " mins ago") :
|
||||
((hr == 0) && (min > 0)) ?
|
||||
(min + " mins ago") :
|
||||
((hr == 0) && (min == 0)) ?
|
||||
"just now" : "";
|
||||
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);
|
||||
|
||||
li.read = true;
|
||||
li.new = false;
|
||||
li.showDesc()
|
||||
|
||||
DiggSidebar.diggIndicator.style.display = 'none';
|
||||
li.showDescription();
|
||||
},
|
||||
|
||||
getStories: function() {
|
||||
|
@ -228,13 +229,6 @@ DiggSidebar = {
|
|||
});
|
||||
},
|
||||
|
||||
getDescription: function(storyId) {
|
||||
if (storyId == null) return;
|
||||
DiggSidebar.fetchData("http://services.digg.com/story/" + storyId + "?type=json" +
|
||||
"&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
||||
DiggSidebar.populateDescription);
|
||||
},
|
||||
|
||||
createMenu: function() {
|
||||
DiggSidebar.fetchData("http://services.digg.com/topics" + "?type=json" +
|
||||
"&appkey=" + encodeURIComponent("http://diggsidebar.googlepages.com"),
|
||||
|
@ -243,12 +237,7 @@ DiggSidebar = {
|
|||
|
||||
setUpdateInterval: function(stories) {
|
||||
//Adaptive update interval code START
|
||||
if (stories.length == 0) {
|
||||
window.clearTimeout(DiggSidebar.timerId);
|
||||
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
||||
return;
|
||||
}
|
||||
if (stories.length == 0) return;
|
||||
var sum = 0;
|
||||
var weights = [4, 3, 2, 1]
|
||||
var date = (stories[0].promote_date != null) ? 'promote_date' : 'submit_date';
|
||||
|
@ -261,28 +250,21 @@ DiggSidebar = {
|
|||
var diff = stories[i][date] - stories[i+1][date];
|
||||
sum += weights[i]*diff;
|
||||
}
|
||||
var updateInterval = Math.round(
|
||||
var newUpdateInterval = Math.round(
|
||||
sum*1000/weights
|
||||
.splice(0,Math.min(4, stories.length-1))
|
||||
.reduce(function(a, b){return a + b;})
|
||||
);
|
||||
//Application.console.log(updateInterval);
|
||||
|
||||
if (updateInterval > 0) {
|
||||
if (newUpdateInterval > 0) {
|
||||
var previousUpdateInterval = DiggSidebar.updateInterval;
|
||||
DiggSidebar.updateInterval = updateInterval;
|
||||
DiggSidebar.updateInterval = newUpdateInterval;
|
||||
|
||||
var updateIntervalDecay = DiggSidebar.updateIntervalDecay;
|
||||
|
||||
if (previousUpdateInterval == updateInterval)
|
||||
DiggSidebar.updateIntervalDecay = updateIntervalDecay + 1;
|
||||
if (previousUpdateInterval == newUpdateInterval)
|
||||
DiggSidebar.updateIntervalDecay += 1;
|
||||
else
|
||||
DiggSidebar.updateIntervalDecay = 0;
|
||||
}
|
||||
window.clearTimeout(DiggSidebar.timerId);
|
||||
|
||||
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
||||
//Adaptive update interval code END
|
||||
},
|
||||
|
||||
|
@ -299,7 +281,7 @@ DiggSidebar = {
|
|||
container: null,
|
||||
category: "all"
|
||||
};
|
||||
parts = ep.split("/");
|
||||
var parts = ep.split("/");
|
||||
if (parts.length == 2)
|
||||
tmp.category = parts[1];
|
||||
else if (parts.length == 4) {
|
||||
|
@ -334,7 +316,7 @@ DiggSidebar = {
|
|||
DiggSidebar.diggEndPoint = $('diggEndPoint');
|
||||
DiggSidebar.diggPlayPause = $('diggPlayPause');
|
||||
|
||||
DiggSidebar.storyListObserver = new StoryListObserver();
|
||||
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
||||
DiggSidebar.createMenu();
|
||||
DiggSidebar.getStories();
|
||||
},
|
||||
|
@ -362,12 +344,12 @@ DiggSidebar.Utils = {
|
|||
}
|
||||
}
|
||||
|
||||
var StoryListObserver = function() {
|
||||
DiggSidebar.StoryListObserver = function() {
|
||||
this.registered = false;
|
||||
this.register();
|
||||
}
|
||||
|
||||
StoryListObserver.prototype = {
|
||||
DiggSidebar.StoryListObserver.prototype = {
|
||||
observe: function(subject, topic, data) {
|
||||
if (topic == window.DiggSidebar.storyListRefreshEventTopic) {
|
||||
window.DiggSidebar.populateStoryList();
|
||||
|
|
|
@ -58,5 +58,5 @@
|
|||
<description id="diggEndPoint">digg</description>
|
||||
<richlistbox flex="1"
|
||||
id="storyList"
|
||||
onselect="DiggSidebar.getDescription(this.selectedItem.id.substr(6))" />
|
||||
onselect="DiggSidebar.showDescription(this.selectedItem.id.substr(6))" />
|
||||
</page>
|
||||
|
|
|
@ -87,16 +87,17 @@
|
|||
]]>
|
||||
</body>
|
||||
</method>
|
||||
<method name="showDesc">
|
||||
<method name="showDescription">
|
||||
<body>
|
||||
<![CDATA[
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyCEIcon").src =
|
||||
"chrome://diggsidebar/content/image/down.jpg";
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyDetails").style.display = 'block';
|
||||
this.read = true;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
<method name="hideDesc">
|
||||
<method name="hideDescription">
|
||||
<body>
|
||||
<![CDATA[
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyCEIcon").src =
|
||||
|
|
Завантаження…
Посилання в новій задачі