more refactoring
git-svn-id: file:///tmp/snv/trunk@12 12951d8a-c33d-4b7c-b961-822215c816e1
This commit is contained in:
parent
4a260ec737
commit
cd689e8948
@ -1,7 +1,7 @@
|
||||
move to JSON data format -- done
|
||||
XBL -- done
|
||||
format JS/refactor JS/Use FUEL -- done
|
||||
caching/db, notifier-observer -- done
|
||||
search
|
||||
caching, notifier-observer -- done
|
||||
search?
|
||||
new UI, icons, thumbnails
|
||||
put license
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@
|
||||
<hbox>
|
||||
<toolbar flex="1">
|
||||
<toolbaritem>
|
||||
<menubar id="diggsidebarMenubar" flex="1" style="width: 100%">
|
||||
<menu id="storiesMenu" label="Stories" accesskey="S">
|
||||
<menupopup id="storiesPopup">
|
||||
<menubar id="dsMenubar" flex="1" style="width: 100%">
|
||||
<menu id="dsStoriesMenu" label="Stories" accesskey="S">
|
||||
<menupopup id="dsStoriesPopup">
|
||||
<menuitem label="All" value="/all"
|
||||
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="A" />
|
||||
<menuitem label="Popular" value="/popular"
|
||||
@ -27,13 +27,13 @@
|
||||
<menuitem label="Top" value="/top"
|
||||
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="T" />
|
||||
<menuseparator />
|
||||
<menu id="containerMenu" label="Containers" accesskey="C">
|
||||
<menupopup id="containerPopup">
|
||||
<menu id="dsContainerMenu" label="Containers" accesskey="C">
|
||||
<menupopup id="dsContainerPopup">
|
||||
<menuitem label="Populating..." />
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="topicMenu" label="Topics" accesskey="T">
|
||||
<menupopup id="topicPopup">
|
||||
<menu id="dsTopicMenu" label="Topics" accesskey="T">
|
||||
<menupopup id="dsTopicPopup">
|
||||
<menuitem label="Populating..." />
|
||||
</menupopup>
|
||||
</menu>
|
||||
@ -41,7 +41,7 @@
|
||||
</menu>
|
||||
</menubar>
|
||||
</toolbaritem>
|
||||
<toolbarbutton id="diggPlayPause"
|
||||
<toolbarbutton id="dsPlayPauseButton"
|
||||
image="chrome://diggsidebar/content/image/Pause.png"
|
||||
tooltiptext="Click to Pause autoupdate"
|
||||
oncommand="DiggSidebar.togglePlayPause()" />
|
||||
@ -50,13 +50,13 @@
|
||||
<progressmeter flex="1"
|
||||
width="5"
|
||||
mode="undetermined"
|
||||
id="diggIndicator"
|
||||
id="dsBusyIndicator"
|
||||
style="height: 85% !important; width: 30% !important" />
|
||||
</toolbaritem>
|
||||
</toolbar>
|
||||
</hbox>
|
||||
<description id="diggEndPoint">digg</description>
|
||||
<description id="dsEndPointDesc">digg</description>
|
||||
<richlistbox flex="1"
|
||||
id="storyList"
|
||||
id="dsStoryListBox"
|
||||
onselect="DiggSidebar.showDescription(this.selectedItem.id.substr(6))" />
|
||||
</page>
|
||||
|
@ -11,8 +11,8 @@
|
||||
<content>
|
||||
<xul:vbox>
|
||||
<html:div class="storyHeader">
|
||||
<html:span class="storyRead" title="Unread">R</html:span>
|
||||
<html:span class="storyNew" title="New">N</html:span>
|
||||
<html:span class="storyNew" title="New">New</html:span>
|
||||
<html:span class="storyRead" title="Unread">Unread</html:span>
|
||||
<html:img src="chrome://diggsidebar/content/image/up.jpg" class="storyCEIcon" />
|
||||
<html:span xbl:inherits="xbl:text=title" class="storyTitle"></html:span>
|
||||
</html:div>
|
||||
@ -57,6 +57,7 @@
|
||||
this.d = {};
|
||||
this.d.read = false;
|
||||
this.d.new = true;
|
||||
this.d.collapsed = true;
|
||||
]]>
|
||||
</constructor>
|
||||
<property name="read"
|
||||
@ -65,25 +66,30 @@
|
||||
<property name="new"
|
||||
onget="return this.d.new;"
|
||||
onset="this.d.new = val; if(val==false) this.markAsOld();"/>
|
||||
<property name="collapsed"
|
||||
onget="return this.d.collapsed;"
|
||||
onset="this.d.collapsed = val;"/>
|
||||
<method name="markAsRead">
|
||||
<body>
|
||||
<![CDATA[
|
||||
var storyRead = document.getAnonymousElementByAttribute(this, "class", "storyRead");
|
||||
storyRead.style.textDecoration = "line-through";
|
||||
storyRead.style.backgroundColor = "black";
|
||||
storyRead.style.color = "white";
|
||||
storyRead.title = "Read";
|
||||
with (document.getAnonymousElementByAttribute(this, "class", "storyRead")) {
|
||||
style.backgroundColor = "black";
|
||||
style.color = "white";
|
||||
title = "Read";
|
||||
textContent = "Read";
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
<method name="markAsOld">
|
||||
<body>
|
||||
<![CDATA[
|
||||
var storyNew = document.getAnonymousElementByAttribute(this, "class", "storyNew");
|
||||
storyNew.style.textDecoration = "line-through";
|
||||
storyNew.style.backgroundColor = "black";
|
||||
storyNew.style.color = "white";
|
||||
storyNew.title = "Old";
|
||||
with (document.getAnonymousElementByAttribute(this, "class", "storyNew")) {
|
||||
style.backgroundColor = "black";
|
||||
style.color = "white";
|
||||
title = "Old";
|
||||
textContent = "Old";
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
@ -94,6 +100,7 @@
|
||||
"chrome://diggsidebar/content/image/down.jpg";
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyDetails").style.display = 'block';
|
||||
this.read = true;
|
||||
this.collapsed = false;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
@ -103,6 +110,7 @@
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyCEIcon").src =
|
||||
"chrome://diggsidebar/content/image/up.jpg";
|
||||
document.getAnonymousElementByAttribute(this, "class", "storyDetails").style.display = 'none';
|
||||
this.collapsed = true;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -1,3 +1,3 @@
|
||||
<!ENTITY diggsidebar.title "Digg Sidebar">
|
||||
<!ENTITY openDiggSidebar.commandkey "D">
|
||||
<!ENTITY openDiggSidebar.modifierskey "accel shift">
|
||||
<!ENTITY openDiggSidebar.modifierskey "alt shift">
|
||||
|
@ -6,7 +6,7 @@ a {
|
||||
a img {
|
||||
border: none;
|
||||
}
|
||||
#storyList {
|
||||
#dsStoryListBox {
|
||||
margin: 1px;
|
||||
border-style: solid !important;
|
||||
border-color: #000;
|
||||
@ -37,6 +37,8 @@ a img {
|
||||
}
|
||||
.storyNew, .storyRead {
|
||||
padding: 0px 2px;
|
||||
font-size: xx-small;
|
||||
font-family: monospace;
|
||||
}
|
||||
.storyHref {
|
||||
font-weight: bold;
|
||||
@ -56,7 +58,7 @@ a img {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
#storyList richlistitem{
|
||||
#dsStoryListBox richlistitem{
|
||||
border-bottom: 1px solid black;
|
||||
color: #000000!important;
|
||||
-moz-binding: url("chrome://diggsidebar/content/diggstory.xml#diggstoryitem");
|
||||
|
Loading…
Reference in New Issue
Block a user