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