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
|
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, notifier-observer -- done
|
caching, notifier-observer -- done
|
||||||
search
|
search?
|
||||||
new UI, icons, thumbnails
|
new UI, icons, thumbnails
|
||||||
put license
|
put license
|
||||||
|
@ -35,7 +35,7 @@ var DiggSidebar = {
|
|||||||
stories: [],
|
stories: [],
|
||||||
|
|
||||||
fetchData: function(url, handler) {
|
fetchData: function(url, handler) {
|
||||||
DiggSidebar.diggIndicator.style.display = '';
|
DiggSidebar.UI.indicator.style.display = '';
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.onerror = DiggSidebar.errorHandler;
|
request.onerror = DiggSidebar.errorHandler;
|
||||||
@ -54,9 +54,7 @@ var DiggSidebar = {
|
|||||||
var topics = data.topics;
|
var topics = data.topics;
|
||||||
var containers = new Array();
|
var containers = new Array();
|
||||||
|
|
||||||
while (DiggSidebar.topicPopup.firstChild) {
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.topicPopup);
|
||||||
DiggSidebar.topicPopup.removeChild(DiggSidebar.topicPopup.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
topics.forEach(function (topic) {
|
topics.forEach(function (topic) {
|
||||||
var menu = document.createElement('menu');
|
var menu = document.createElement('menu');
|
||||||
@ -78,14 +76,12 @@ var DiggSidebar = {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
menu.appendChild(menupopup);
|
menu.appendChild(menupopup);
|
||||||
DiggSidebar.topicPopup.appendChild(menu);
|
DiggSidebar.UI.topicPopup.appendChild(menu);
|
||||||
|
|
||||||
containers.push(topic.container);
|
containers.push(topic.container);
|
||||||
});
|
});
|
||||||
|
|
||||||
while (DiggSidebar.containerPopup.firstChild) {
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.containerPopup);
|
||||||
DiggSidebar.containerPopup.removeChild(DiggSidebar.containerPopup.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
var filteredContainers = {name: [], short_name: []};
|
var filteredContainers = {name: [], short_name: []};
|
||||||
containers.forEach(function (container) {
|
containers.forEach(function (container) {
|
||||||
@ -119,18 +115,14 @@ var DiggSidebar = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
menu.appendChild(menupopup);
|
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() {
|
populateStoryList: function() {
|
||||||
while (DiggSidebar.storyList.firstChild) {
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.storyListBox);
|
||||||
DiggSidebar.storyList.removeChild(DiggSidebar.storyList.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
var newStoryIds = new Array();
|
var newStoryIds = new Array();
|
||||||
Application.console.log("DiggSidebar.stories.length = " + DiggSidebar.stories.length);
|
|
||||||
|
|
||||||
var jp = new JPath(DiggSidebar.stories);
|
var jp = new JPath(DiggSidebar.stories);
|
||||||
var filteredStories = jp.$(function(story){
|
var filteredStories = jp.$(function(story){
|
||||||
@ -165,20 +157,24 @@ var DiggSidebar = {
|
|||||||
((hr == 0) && (min == 0)) ?
|
((hr == 0) && (min == 0)) ?
|
||||||
"just now" : "";
|
"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.id = "story_" + story.id;
|
||||||
li.setAttribute('title', story.title);
|
var attributes = {
|
||||||
li.setAttribute('date', relativeTime);
|
title: story.title,
|
||||||
li.setAttribute('status', story.status);
|
date: relativeTime,
|
||||||
li.setAttribute('container', story.container.name);
|
status: story.status,
|
||||||
li.setAttribute('topic', story.topic.name);
|
container: story.container.name,
|
||||||
li.setAttribute('username', story.user.name);
|
topic: story.topic.name,
|
||||||
li.setAttribute('userlink', "http://digg.com/users/" + story.user.name);
|
username: story.user.name,
|
||||||
li.setAttribute('diggs', story.diggs);
|
userlink: "http://digg.com/users/" + story.user.name,
|
||||||
li.setAttribute('comments', story.comments);
|
diggs: story.diggs,
|
||||||
li.setAttribute('desc', story.description);
|
comments: story.comments,
|
||||||
li.setAttribute('link', story.link);
|
desc: story.description,
|
||||||
li.setAttribute('href', story.href);
|
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;
|
if (DiggSidebar.storyIds.indexOf(story.id) != -1) li.new = false;
|
||||||
li.read = story.read;
|
li.read = story.read;
|
||||||
@ -192,7 +188,7 @@ var DiggSidebar = {
|
|||||||
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||||
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
||||||
|
|
||||||
DiggSidebar.diggIndicator.style.display = 'none';
|
DiggSidebar.UI.indicator.style.display = 'none';
|
||||||
},
|
},
|
||||||
|
|
||||||
showDescription: function(storyId) {
|
showDescription: function(storyId) {
|
||||||
@ -200,18 +196,16 @@ var DiggSidebar = {
|
|||||||
var story = jp.query('//[id == ' + storyId + ']')[0];
|
var story = jp.query('//[id == ' + storyId + ']')[0];
|
||||||
story.read = true;
|
story.read = true;
|
||||||
|
|
||||||
var listitems = document.getElementsByTagName('richlistitem');
|
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();
|
||||||
|
|
||||||
var li = document.getElementById('story_'+ story.id)
|
document.getElementById('story_'+ story.id).showDescription();
|
||||||
li.read = true;
|
|
||||||
li.showDescription();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getStories: function() {
|
getStories: function() {
|
||||||
var ep = DiggSidebar.prefs.get("endpoint").value || '';
|
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, '') +
|
DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
|
||||||
"?count=30" + "&type=json" +
|
"?count=30" + "&type=json" +
|
||||||
@ -297,14 +291,14 @@ var DiggSidebar = {
|
|||||||
togglePlayPause: function() {
|
togglePlayPause: function() {
|
||||||
if (DiggSidebar.playing) {
|
if (DiggSidebar.playing) {
|
||||||
window.clearTimeout(DiggSidebar.timerId);
|
window.clearTimeout(DiggSidebar.timerId);
|
||||||
DiggSidebar.diggPlayPause.image = "chrome://diggsidebar/content/image/Play.png";
|
DiggSidebar.UI.playPauseButton.image = "chrome://diggsidebar/content/image/Play.png";
|
||||||
DiggSidebar.diggPlayPause.setAttribute("tooltiptext", "Click to Start autoupdate");
|
DiggSidebar.UI.playPauseButton.setAttribute("tooltiptext", "Click to Start autoupdate");
|
||||||
DiggSidebar.playing = false;
|
DiggSidebar.playing = false;
|
||||||
} else {
|
} else {
|
||||||
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
var timeout = Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
||||||
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
DiggSidebar.timerId = window.setTimeout(DiggSidebar.getStories, timeout);
|
||||||
DiggSidebar.diggPlayPause.image = "chrome://diggsidebar/content/image/Pause.png";
|
DiggSidebar.UI.playPauseButton.image = "chrome://diggsidebar/content/image/Pause.png";
|
||||||
DiggSidebar.diggPlayPause.setAttribute("tooltiptext", "Click to Pause autoupdate");
|
DiggSidebar.UI.playPauseButton.setAttribute("tooltiptext", "Click to Pause autoupdate");
|
||||||
DiggSidebar.playing = true;
|
DiggSidebar.playing = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -312,12 +306,14 @@ var DiggSidebar = {
|
|||||||
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.diggIndicator = $('diggIndicator');
|
|
||||||
DiggSidebar.topicPopup = $('topicPopup');
|
DiggSidebar.UI = {};
|
||||||
DiggSidebar.containerPopup = $('containerPopup');
|
DiggSidebar.UI.indicator = $('dsBusyIndicator');
|
||||||
DiggSidebar.storyList = $('storyList');
|
DiggSidebar.UI.topicPopup = $('dsTopicPopup');
|
||||||
DiggSidebar.diggEndPoint = $('diggEndPoint');
|
DiggSidebar.UI.containerPopup = $('dsContainerPopup');
|
||||||
DiggSidebar.diggPlayPause = $('diggPlayPause');
|
DiggSidebar.UI.storyListBox = $('dsStoryListBox');
|
||||||
|
DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');
|
||||||
|
DiggSidebar.UI.playPauseButton = $('dsPlayPauseButton');
|
||||||
|
|
||||||
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
||||||
DiggSidebar.createMenu();
|
DiggSidebar.createMenu();
|
||||||
@ -344,6 +340,11 @@ DiggSidebar.Utils = {
|
|||||||
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) {
|
||||||
|
while (node.firstChild)
|
||||||
|
node.removeChild(node.firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
<hbox>
|
<hbox>
|
||||||
<toolbar flex="1">
|
<toolbar flex="1">
|
||||||
<toolbaritem>
|
<toolbaritem>
|
||||||
<menubar id="diggsidebarMenubar" flex="1" style="width: 100%">
|
<menubar id="dsMenubar" flex="1" style="width: 100%">
|
||||||
<menu id="storiesMenu" label="Stories" accesskey="S">
|
<menu id="dsStoriesMenu" label="Stories" accesskey="S">
|
||||||
<menupopup id="storiesPopup">
|
<menupopup id="dsStoriesPopup">
|
||||||
<menuitem label="All" value="/all"
|
<menuitem label="All" value="/all"
|
||||||
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="A" />
|
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="A" />
|
||||||
<menuitem label="Popular" value="/popular"
|
<menuitem label="Popular" value="/popular"
|
||||||
@ -27,13 +27,13 @@
|
|||||||
<menuitem label="Top" value="/top"
|
<menuitem label="Top" value="/top"
|
||||||
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="T" />
|
oncommand="DiggSidebar.setEndPoint(this.value)" accesskey="T" />
|
||||||
<menuseparator />
|
<menuseparator />
|
||||||
<menu id="containerMenu" label="Containers" accesskey="C">
|
<menu id="dsContainerMenu" label="Containers" accesskey="C">
|
||||||
<menupopup id="containerPopup">
|
<menupopup id="dsContainerPopup">
|
||||||
<menuitem label="Populating..." />
|
<menuitem label="Populating..." />
|
||||||
</menupopup>
|
</menupopup>
|
||||||
</menu>
|
</menu>
|
||||||
<menu id="topicMenu" label="Topics" accesskey="T">
|
<menu id="dsTopicMenu" label="Topics" accesskey="T">
|
||||||
<menupopup id="topicPopup">
|
<menupopup id="dsTopicPopup">
|
||||||
<menuitem label="Populating..." />
|
<menuitem label="Populating..." />
|
||||||
</menupopup>
|
</menupopup>
|
||||||
</menu>
|
</menu>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
</menu>
|
</menu>
|
||||||
</menubar>
|
</menubar>
|
||||||
</toolbaritem>
|
</toolbaritem>
|
||||||
<toolbarbutton id="diggPlayPause"
|
<toolbarbutton id="dsPlayPauseButton"
|
||||||
image="chrome://diggsidebar/content/image/Pause.png"
|
image="chrome://diggsidebar/content/image/Pause.png"
|
||||||
tooltiptext="Click to Pause autoupdate"
|
tooltiptext="Click to Pause autoupdate"
|
||||||
oncommand="DiggSidebar.togglePlayPause()" />
|
oncommand="DiggSidebar.togglePlayPause()" />
|
||||||
@ -50,13 +50,13 @@
|
|||||||
<progressmeter flex="1"
|
<progressmeter flex="1"
|
||||||
width="5"
|
width="5"
|
||||||
mode="undetermined"
|
mode="undetermined"
|
||||||
id="diggIndicator"
|
id="dsBusyIndicator"
|
||||||
style="height: 85% !important; width: 30% !important" />
|
style="height: 85% !important; width: 30% !important" />
|
||||||
</toolbaritem>
|
</toolbaritem>
|
||||||
</toolbar>
|
</toolbar>
|
||||||
</hbox>
|
</hbox>
|
||||||
<description id="diggEndPoint">digg</description>
|
<description id="dsEndPointDesc">digg</description>
|
||||||
<richlistbox flex="1"
|
<richlistbox flex="1"
|
||||||
id="storyList"
|
id="dsStoryListBox"
|
||||||
onselect="DiggSidebar.showDescription(this.selectedItem.id.substr(6))" />
|
onselect="DiggSidebar.showDescription(this.selectedItem.id.substr(6))" />
|
||||||
</page>
|
</page>
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
<content>
|
<content>
|
||||||
<xul:vbox>
|
<xul:vbox>
|
||||||
<html:div class="storyHeader">
|
<html:div class="storyHeader">
|
||||||
<html:span class="storyRead" title="Unread">R</html:span>
|
<html:span class="storyNew" title="New">New</html:span>
|
||||||
<html:span class="storyNew" title="New">N</html:span>
|
<html:span class="storyRead" title="Unread">Unread</html:span>
|
||||||
<html:img src="chrome://diggsidebar/content/image/up.jpg" class="storyCEIcon" />
|
<html:img src="chrome://diggsidebar/content/image/up.jpg" class="storyCEIcon" />
|
||||||
<html:span xbl:inherits="xbl:text=title" class="storyTitle"></html:span>
|
<html:span xbl:inherits="xbl:text=title" class="storyTitle"></html:span>
|
||||||
</html:div>
|
</html:div>
|
||||||
@ -57,6 +57,7 @@
|
|||||||
this.d = {};
|
this.d = {};
|
||||||
this.d.read = false;
|
this.d.read = false;
|
||||||
this.d.new = true;
|
this.d.new = true;
|
||||||
|
this.d.collapsed = true;
|
||||||
]]>
|
]]>
|
||||||
</constructor>
|
</constructor>
|
||||||
<property name="read"
|
<property name="read"
|
||||||
@ -65,25 +66,30 @@
|
|||||||
<property name="new"
|
<property name="new"
|
||||||
onget="return this.d.new;"
|
onget="return this.d.new;"
|
||||||
onset="this.d.new = val; if(val==false) this.markAsOld();"/>
|
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">
|
<method name="markAsRead">
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var storyRead = document.getAnonymousElementByAttribute(this, "class", "storyRead");
|
with (document.getAnonymousElementByAttribute(this, "class", "storyRead")) {
|
||||||
storyRead.style.textDecoration = "line-through";
|
style.backgroundColor = "black";
|
||||||
storyRead.style.backgroundColor = "black";
|
style.color = "white";
|
||||||
storyRead.style.color = "white";
|
title = "Read";
|
||||||
storyRead.title = "Read";
|
textContent = "Read";
|
||||||
|
}
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
<method name="markAsOld">
|
<method name="markAsOld">
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var storyNew = document.getAnonymousElementByAttribute(this, "class", "storyNew");
|
with (document.getAnonymousElementByAttribute(this, "class", "storyNew")) {
|
||||||
storyNew.style.textDecoration = "line-through";
|
style.backgroundColor = "black";
|
||||||
storyNew.style.backgroundColor = "black";
|
style.color = "white";
|
||||||
storyNew.style.color = "white";
|
title = "Old";
|
||||||
storyNew.title = "Old";
|
textContent = "Old";
|
||||||
|
}
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
@ -94,6 +100,7 @@
|
|||||||
"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;
|
this.read = true;
|
||||||
|
this.collapsed = false;
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
@ -103,6 +110,7 @@
|
|||||||
document.getAnonymousElementByAttribute(this, "class", "storyCEIcon").src =
|
document.getAnonymousElementByAttribute(this, "class", "storyCEIcon").src =
|
||||||
"chrome://diggsidebar/content/image/up.jpg";
|
"chrome://diggsidebar/content/image/up.jpg";
|
||||||
document.getAnonymousElementByAttribute(this, "class", "storyDetails").style.display = 'none';
|
document.getAnonymousElementByAttribute(this, "class", "storyDetails").style.display = 'none';
|
||||||
|
this.collapsed = true;
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<!ENTITY diggsidebar.title "Digg Sidebar">
|
<!ENTITY diggsidebar.title "Digg Sidebar">
|
||||||
<!ENTITY openDiggSidebar.commandkey "D">
|
<!ENTITY openDiggSidebar.commandkey "D">
|
||||||
<!ENTITY openDiggSidebar.modifierskey "accel shift">
|
<!ENTITY openDiggSidebar.modifierskey "alt shift">
|
||||||
|
@ -6,7 +6,7 @@ a {
|
|||||||
a img {
|
a img {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
#storyList {
|
#dsStoryListBox {
|
||||||
margin: 1px;
|
margin: 1px;
|
||||||
border-style: solid !important;
|
border-style: solid !important;
|
||||||
border-color: #000;
|
border-color: #000;
|
||||||
@ -37,6 +37,8 @@ a img {
|
|||||||
}
|
}
|
||||||
.storyNew, .storyRead {
|
.storyNew, .storyRead {
|
||||||
padding: 0px 2px;
|
padding: 0px 2px;
|
||||||
|
font-size: xx-small;
|
||||||
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
.storyHref {
|
.storyHref {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@ -56,7 +58,7 @@ a img {
|
|||||||
background-color: blue;
|
background-color: blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#storyList richlistitem{
|
#dsStoryListBox richlistitem{
|
||||||
border-bottom: 1px solid black;
|
border-bottom: 1px solid black;
|
||||||
color: #000000!important;
|
color: #000000!important;
|
||||||
-moz-binding: url("chrome://diggsidebar/content/diggstory.xml#diggstoryitem");
|
-moz-binding: url("chrome://diggsidebar/content/diggstory.xml#diggstoryitem");
|
||||||
|
Loading…
Reference in New Issue
Block a user