|
@@ -32,14 +32,17 @@ var DiggSidebar = {
|
32
|
32
|
updateIntervalDecay: 0,
|
33
|
33
|
lastUpdateAt: new Date().getTime(),
|
34
|
34
|
shownStoriesCount: 30,
|
35
|
|
- categories: ['All', 'Popular', 'Upcoming', 'Hot', 'Top'],
|
|
35
|
+ categories: ["All", "Popular", "Upcoming", "Hot", "Top"],
|
36
|
36
|
timerId: null,
|
37
|
37
|
storyIds: [],
|
38
|
38
|
refreshing: false,
|
39
|
39
|
stories: [],
|
40
|
40
|
expandedStory: null,
|
|
41
|
+ observerService: Components.classes["@mozilla.org/observer-service;1"]
|
|
42
|
+ .getService(Components.interfaces.nsIObserverService),
|
41
|
43
|
|
42
|
|
- fetchData: function(url, handler) {
|
|
44
|
+
|
|
45
|
+ fetchData: function (url, handler) {
|
43
|
46
|
DiggSidebar.indicateActivity();
|
44
|
47
|
|
45
|
48
|
var request = new XMLHttpRequest();
|
|
@@ -49,7 +52,7 @@ var DiggSidebar = {
|
49
|
52
|
request.send(null);
|
50
|
53
|
},
|
51
|
54
|
|
52
|
|
- errorHandler: function(e) {
|
|
55
|
+ errorHandler: function (e) {
|
53
|
56
|
/*if (DiggSidebar.UI.notificationBox.allNotifications.length > 0)
|
54
|
57
|
DiggSidebar.UI.notificationBox.removeAllNotifications(true);*/
|
55
|
58
|
DiggSidebar.UI.notificationBox.appendNotification(
|
|
@@ -57,54 +60,62 @@ var DiggSidebar = {
|
57
|
60
|
"dsAccessFailNotification",
|
58
|
61
|
null,
|
59
|
62
|
"PRIORITY_CRITICAL_HIGH",
|
60
|
|
- [{callback:DiggSidebar.getStories, label: "Retry", accessKey: "R"}]
|
|
63
|
+ [{callback: DiggSidebar.getStories, label: "Retry", accessKey: "R"}]
|
61
|
64
|
);
|
62
|
65
|
DiggSidebar.refreshing = false;
|
63
|
66
|
DiggSidebar.indicateInactivity();
|
64
|
67
|
},
|
65
|
68
|
|
66
|
|
- populateMenu: function(e) {
|
|
69
|
+ populateMenu: function (e) {
|
67
|
70
|
var XHR = e.target;
|
68
|
71
|
var data = DiggSidebar.Utils.decodeJson(XHR.responseText);
|
69
|
72
|
var containers = data.containers;
|
70
|
73
|
|
71
|
74
|
containers.forEach(function (container) {
|
72
|
|
- var cmenu = document.createElement('menu');
|
73
|
|
- cmenu.setAttribute('id', container.short_name + 'Menu');
|
74
|
|
- cmenu.setAttribute('label', container.name);
|
75
|
|
- cmenu.setAttribute('accesskey', container.name.charAt(0));
|
|
75
|
+ var cmenu = document.createElement("menu");
|
|
76
|
+ with (cmenu) {
|
|
77
|
+ setAttribute("id", container.short_name + "Menu");
|
|
78
|
+ setAttribute("label", container.name);
|
|
79
|
+ setAttribute("accesskey", container.name.charAt(0));
|
|
80
|
+ }
|
76
|
81
|
|
77
|
|
- var cmenupopup = document.createElement('menupopup');
|
78
|
|
- cmenupopup.setAttribute('id', container.short_name + 'Popup');
|
|
82
|
+ var cmenupopup = document.createElement("menupopup");
|
|
83
|
+ cmenupopup.setAttribute("id", container.short_name + "Popup");
|
79
|
84
|
|
80
|
85
|
DiggSidebar.categories.forEach(
|
81
|
86
|
function (category) {
|
82
|
|
- var cmenuitem = document.createElement('menuitem');
|
83
|
|
- cmenuitem.setAttribute('label', category);
|
84
|
|
- cmenuitem.setAttribute('value', '/container/' + container.short_name + '/' + category.toLowerCase());
|
85
|
|
- cmenuitem.setAttribute('accesskey', category.charAt(0));
|
86
|
|
- cmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
|
|
87
|
+ var cmenuitem = document.createElement("menuitem");
|
|
88
|
+ with (cmenuitem) {
|
|
89
|
+ setAttribute("label", category);
|
|
90
|
+ setAttribute("value", "/container/" + container.short_name + "/" + category.toLowerCase());
|
|
91
|
+ setAttribute("accesskey", category.charAt(0));
|
|
92
|
+ setAttribute("oncommand", "DiggSidebar.setEndPoint(this.value)");
|
|
93
|
+ }
|
87
|
94
|
cmenupopup.appendChild(cmenuitem);
|
88
|
95
|
}
|
89
|
96
|
);
|
90
|
|
- cmenupopup.appendChild(document.createElement('menuseparator'));
|
|
97
|
+ cmenupopup.appendChild(document.createElement("menuseparator"));
|
91
|
98
|
var topics = container.topics;
|
92
|
99
|
topics.forEach(function (topic) {
|
93
|
|
- var tmenu = document.createElement('menu');
|
94
|
|
- tmenu.setAttribute('id', topic.short_name + 'Menu');
|
95
|
|
- tmenu.setAttribute('label', topic.name);
|
96
|
|
- tmenu.setAttribute('accesskey', topic.name.charAt(0));
|
|
100
|
+ var tmenu = document.createElement("menu");
|
|
101
|
+ with (tmenu) {
|
|
102
|
+ setAttribute("id", topic.short_name + "Menu");
|
|
103
|
+ setAttribute("label", topic.name);
|
|
104
|
+ setAttribute("accesskey", topic.name.charAt(0));
|
|
105
|
+ }
|
97
|
106
|
|
98
|
|
- var tmenupopup = document.createElement('menupopup');
|
99
|
|
- tmenupopup.setAttribute('id', topic.short_name + 'Popup');
|
|
107
|
+ var tmenupopup = document.createElement("menupopup");
|
|
108
|
+ tmenupopup.setAttribute("id", topic.short_name + "Popup");
|
100
|
109
|
|
101
|
110
|
DiggSidebar.categories.forEach(
|
102
|
111
|
function (category) {
|
103
|
|
- var tmenuitem = document.createElement('menuitem');
|
104
|
|
- tmenuitem.setAttribute('label', category);
|
105
|
|
- tmenuitem.setAttribute('value', '/topic/' + topic.short_name + '/' + category.toLowerCase());
|
106
|
|
- tmenuitem.setAttribute('accesskey', category.charAt(0));
|
107
|
|
- tmenuitem.setAttribute('oncommand', "DiggSidebar.setEndPoint(this.value)");
|
|
112
|
+ var tmenuitem = document.createElement("menuitem");
|
|
113
|
+ with (tmenuitem) {
|
|
114
|
+ setAttribute("label", category);
|
|
115
|
+ setAttribute("value", "/topic/" + topic.short_name + "/" + category.toLowerCase());
|
|
116
|
+ setAttribute("accesskey", category.charAt(0));
|
|
117
|
+ setAttribute("oncommand", "DiggSidebar.setEndPoint(this.value)");
|
|
118
|
+ }
|
108
|
119
|
tmenupopup.appendChild(tmenuitem);
|
109
|
120
|
}
|
110
|
121
|
);
|
|
@@ -116,37 +127,41 @@ var DiggSidebar = {
|
116
|
127
|
});
|
117
|
128
|
},
|
118
|
129
|
|
119
|
|
- populateStoryList: function() {
|
120
|
|
- var newStoryIds = new Array();
|
|
130
|
+ populateStoryList: function () {
|
|
131
|
+ var newStoryIds = [];
|
121
|
132
|
|
122
|
133
|
var jp = new JPath(DiggSidebar.stories);
|
123
|
|
- var filteredStories = jp.$(function(story){
|
124
|
|
- return (story.$("category").json == DiggSidebar.endpoint.category) ;
|
|
134
|
+ var filteredStories = jp.$(function (story) {
|
|
135
|
+ return (story.$("category").json == DiggSidebar.endpoint.category);
|
125
|
136
|
}).json;
|
126
|
137
|
jp = new JPath(filteredStories);
|
127
|
|
- if (DiggSidebar.endpoint.topic)
|
128
|
|
- filteredStories = jp.$(function(story){
|
|
138
|
+ if (DiggSidebar.endpoint.topic) {
|
|
139
|
+ filteredStories = jp.$(function (story) {
|
129
|
140
|
return (story.$("topic/short_name").json == DiggSidebar.endpoint.topic);
|
130
|
141
|
}).json;
|
131
|
|
- if (DiggSidebar.endpoint.container)
|
132
|
|
- filteredStories = jp.$(function(story){
|
|
142
|
+ }
|
|
143
|
+ if (DiggSidebar.endpoint.container) {
|
|
144
|
+ filteredStories = jp.$(function (story) {
|
133
|
145
|
return story.$("container/short_name").json == DiggSidebar.endpoint.container;
|
134
|
146
|
}).json;
|
|
147
|
+ }
|
135
|
148
|
|
136
|
|
- if (filteredStories.length > 0)
|
|
149
|
+ if (filteredStories.length > 0) {
|
137
|
150
|
DiggSidebar.Utils.removeAllChildren(DiggSidebar.UI.storyListBox);
|
|
151
|
+ }
|
138
|
152
|
|
139
|
153
|
filteredStories.forEach(function (story, index) {
|
140
|
154
|
if (index < DiggSidebar.shownStoriesCount) {
|
141
|
155
|
var now = new Date();
|
142
|
|
- if (story.promote_date != null)
|
143
|
|
- var then = new Date(story.promote_date*1000);
|
144
|
|
- else
|
145
|
|
- var then = new Date(story.submit_date*1000);
|
146
|
|
- var diff = Math.max(now - then, 0)
|
|
156
|
+ if (story.promote_date != null) {
|
|
157
|
+ var then = new Date(story.promote_date * 1000);
|
|
158
|
+ } else {
|
|
159
|
+ var then = new Date(story.submit_date * 1000);
|
|
160
|
+ }
|
|
161
|
+ var diff = Math.max(now - then, 0);
|
147
|
162
|
|
148
|
|
- var hr = Math.floor(diff/(1000*3600));
|
149
|
|
- var min = Math.floor(diff/(1000*60)) - 60*hr;
|
|
163
|
+ var hr = Math.floor(diff / (1000 * 3600));
|
|
164
|
+ var min = Math.floor(diff / (1000 * 60)) - 60 * hr;
|
150
|
165
|
|
151
|
166
|
var relativeTime = ((hr > 0) && (min > 0)) ?
|
152
|
167
|
(hr + " hr " + min + " mins ago") :
|
|
@@ -155,7 +170,7 @@ var DiggSidebar = {
|
155
|
170
|
((hr == 0) && (min == 0)) ?
|
156
|
171
|
"just now" : "";
|
157
|
172
|
|
158
|
|
- var li = DiggSidebar.UI.storyListBox.appendChild(document.createElement('richlistitem'));
|
|
173
|
+ var li = DiggSidebar.UI.storyListBox.appendChild(document.createElement("richlistitem"));
|
159
|
174
|
li.id = "story_" + story.id;
|
160
|
175
|
var attributes = {
|
161
|
176
|
title: story.title,
|
|
@@ -170,56 +185,59 @@ var DiggSidebar = {
|
170
|
185
|
desc: story.description,
|
171
|
186
|
link: story.link,
|
172
|
187
|
href: story.href
|
173
|
|
- }
|
174
|
|
- for (var attr in attributes)
|
|
188
|
+ };
|
|
189
|
+ for (var attr in attributes) {
|
175
|
190
|
li.setAttribute(attr, attributes[attr]);
|
|
191
|
+ }
|
176
|
192
|
|
177
|
193
|
li.read = story.read;
|
178
|
|
- if (story.id == DiggSidebar.expandedStory)
|
|
194
|
+ if (story.id == DiggSidebar.expandedStory) {
|
179
|
195
|
li.showDescription();
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+ if (DiggSidebar.storyIds.indexOf(story.id) == -1) {
|
|
199
|
+ newStoryIds.push(story.id);
|
180
|
200
|
}
|
181
|
|
- if (DiggSidebar.storyIds.indexOf(story.id) == -1) newStoryIds.push(story.id);
|
182
|
201
|
});
|
183
|
202
|
DiggSidebar.storyIds = DiggSidebar.storyIds.concat(newStoryIds);
|
184
|
203
|
},
|
185
|
204
|
|
186
|
|
- showDescription: function(storyId) {
|
|
205
|
+ showDescription: function (storyId) {
|
187
|
206
|
var jp = new JPath(DiggSidebar.stories);
|
188
|
|
- var story = jp.query('//[id == ' + storyId + ']')[0];
|
|
207
|
+ var story = jp.query("//[id == " + storyId + "]")[0];
|
189
|
208
|
story.read = true;
|
190
|
209
|
DiggSidebar.expandedStory = parseInt(storyId);
|
191
|
210
|
|
192
|
211
|
var listitems = DiggSidebar.UI.storyListBox.children;
|
193
|
|
- for (var i=0; i<listitems.length; i++)
|
|
212
|
+ for (var i = 0; i < listitems.length; i++) {
|
194
|
213
|
listitems[i].hideDescription();
|
|
214
|
+ }
|
195
|
215
|
|
196
|
|
- document.getElementById('story_'+ story.id).showDescription();
|
|
216
|
+ document.getElementById("story_" + story.id).showDescription();
|
197
|
217
|
},
|
198
|
218
|
|
199
|
|
- getStories: function() {
|
|
219
|
+ getStories: function () {
|
200
|
220
|
if (!DiggSidebar.refreshing) {
|
201
|
221
|
DiggSidebar.refreshing = true;
|
202
|
|
- var ep = DiggSidebar.prefs.get("endpoint").value || '';
|
|
222
|
+ var ep = DiggSidebar.prefs.get("endpoint").value || "";
|
203
|
223
|
|
204
|
|
- DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, '') +
|
|
224
|
+ DiggSidebar.fetchData("http://services.digg.com/stories" + ep.replace(/\/all/g, "") +
|
205
|
225
|
"?count=30" + "&type=json" +
|
206
|
226
|
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
207
|
|
- function(e) {
|
|
227
|
+ function (e) {
|
208
|
228
|
DiggSidebar.UI.endPointDesc.value = "digg" + ep;
|
209
|
229
|
|
210
|
230
|
var stories = DiggSidebar.Utils.decodeJson(e.target.responseText).stories;
|
211
|
231
|
var newStories = stories.filter(
|
212
|
|
- function(story) {
|
|
232
|
+ function (story) {
|
213
|
233
|
return !(DiggSidebar.storyIds.indexOf(story.id) != -1);
|
214
|
234
|
});
|
215
|
|
- newStories.forEach(function(story) {
|
|
235
|
+ newStories.forEach(function (story) {
|
216
|
236
|
story.category = DiggSidebar.endpoint.category;
|
217
|
237
|
story.read = false;
|
218
|
238
|
});
|
219
|
239
|
DiggSidebar.stories = newStories.concat(DiggSidebar.stories);
|
220
|
|
- var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
221
|
|
- .getService(Components.interfaces.nsIObserverService);
|
222
|
|
- observerService.notifyObservers(null, DiggSidebar.storyListRefreshEventTopic, null);
|
|
240
|
+ DiggSidebar.observerService.notifyObservers(null, DiggSidebar.storyListRefreshEventTopic, null);
|
223
|
241
|
|
224
|
242
|
DiggSidebar.refreshing = false;
|
225
|
243
|
DiggSidebar.setUpdateInterval(stories);
|
|
@@ -235,171 +253,179 @@ var DiggSidebar = {
|
235
|
253
|
}
|
236
|
254
|
},
|
237
|
255
|
|
238
|
|
- createMenu: function() {
|
|
256
|
+ createMenu: function () {
|
239
|
257
|
DiggSidebar.fetchData("http://services.digg.com/containers" + "?type=json" +
|
240
|
258
|
"&appkey=" + encodeURIComponent(DiggSidebar.homepageURL),
|
241
|
259
|
DiggSidebar.populateMenu);
|
242
|
260
|
},
|
243
|
261
|
|
244
|
|
- setUpdateInterval: function(stories) {
|
|
262
|
+ setUpdateInterval: function (stories) {
|
245
|
263
|
//Adaptive update interval code START
|
246
|
|
- if (stories.length == 0) return;
|
|
264
|
+ if (stories.length == 0) {
|
|
265
|
+ return;
|
|
266
|
+ }
|
247
|
267
|
var sum = 0;
|
248
|
|
- var weights = [4, 3, 2, 1]
|
249
|
|
- var date = (stories[0].promote_date != null) ? 'promote_date' : 'submit_date';
|
|
268
|
+ var weights = [4, 3, 2, 1];
|
|
269
|
+ var date = (stories[0].promote_date != null) ? "promote_date" : "submit_date";
|
250
|
270
|
stories.sort(function (a, b) {
|
251
|
|
- if (a[date] > b[date]) return -1;
|
252
|
|
- else if (a[date] < b[date]) return 1;
|
253
|
|
- return 0;
|
|
271
|
+ if (a[date] > b[date]) {
|
|
272
|
+ return -1;
|
|
273
|
+ } else if (a[date] < b[date]) {
|
|
274
|
+ return 1;
|
|
275
|
+ } else {
|
|
276
|
+ return 0;
|
|
277
|
+ }
|
254
|
278
|
});
|
255
|
|
- for (var i=0; i<Math.min(4, stories.length-1); i++) {
|
256
|
|
- var diff = stories[i][date] - stories[i+1][date];
|
257
|
|
- sum += weights[i]*diff;
|
|
279
|
+ for (var i = 0; i < Math.min(4, stories.length - 1); i++) {
|
|
280
|
+ var diff = stories[i][date] - stories[i + 1][date];
|
|
281
|
+ sum += weights[i] * diff;
|
258
|
282
|
}
|
259
|
283
|
var newUpdateInterval = Math.round(
|
260
|
|
- sum*1000/weights
|
261
|
|
- .splice(0,Math.min(4, stories.length-1))
|
262
|
|
- .reduce(function(a, b){return a + b;})
|
|
284
|
+ sum * 1000 / weights
|
|
285
|
+ .splice(0, Math.min(4, stories.length - 1))
|
|
286
|
+ .reduce(function (a, b) {
|
|
287
|
+ return a + b;
|
|
288
|
+ })
|
263
|
289
|
);
|
264
|
290
|
|
265
|
291
|
if (newUpdateInterval > 0) {
|
266
|
292
|
var previousUpdateInterval = DiggSidebar.updateInterval;
|
267
|
293
|
DiggSidebar.updateInterval = newUpdateInterval;
|
268
|
294
|
|
269
|
|
- if (previousUpdateInterval == newUpdateInterval)
|
|
295
|
+ if (previousUpdateInterval == newUpdateInterval) {
|
270
|
296
|
DiggSidebar.updateIntervalDecay += 1;
|
271
|
|
- else
|
|
297
|
+ } else {
|
272
|
298
|
DiggSidebar.updateIntervalDecay = 0;
|
|
299
|
+ }
|
273
|
300
|
}
|
274
|
301
|
//Adaptive update interval code END
|
275
|
302
|
},
|
276
|
303
|
|
277
|
|
- calculateTimeout: function() {
|
278
|
|
- return Math.round(DiggSidebar.updateInterval*(Math.pow(1.5, DiggSidebar.updateIntervalDecay)))
|
|
304
|
+ calculateTimeout: function () {
|
|
305
|
+ return Math.round(DiggSidebar.updateInterval * (Math.pow(1.5, DiggSidebar.updateIntervalDecay)));
|
279
|
306
|
},
|
280
|
307
|
|
281
|
|
- setEndPoint: function(ep) {
|
|
308
|
+ setEndPoint: function (ep) {
|
282
|
309
|
DiggSidebar.prefs.get("endpoint").value = ep;
|
283
|
310
|
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(ep);
|
284
|
311
|
window.clearTimeout(DiggSidebar.timerId);
|
285
|
312
|
DiggSidebar.getStories();
|
286
|
313
|
},
|
287
|
314
|
|
288
|
|
- getEndpointParts: function(ep) {
|
|
315
|
+ getEndpointParts: function (ep) {
|
289
|
316
|
var tmp = {
|
290
|
317
|
topic: null,
|
291
|
318
|
container: null,
|
292
|
319
|
category: "all"
|
293
|
320
|
};
|
294
|
321
|
var parts = ep.split("/");
|
295
|
|
- if (parts.length == 2)
|
|
322
|
+ if (parts.length == 2) {
|
296
|
323
|
tmp.category = parts[1];
|
297
|
|
- else if (parts.length == 4) {
|
|
324
|
+ } else if (parts.length == 4) {
|
298
|
325
|
tmp[parts[1]] = parts[2];
|
299
|
326
|
tmp.category = parts[3];
|
300
|
327
|
}
|
301
|
328
|
return tmp;
|
302
|
329
|
},
|
303
|
330
|
|
304
|
|
- indicateActivity: function() {
|
|
331
|
+ indicateActivity: function () {
|
305
|
332
|
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/loading_16.png";
|
306
|
333
|
with (DiggSidebar.UI.indicator.parentNode) {
|
307
|
334
|
disabled = true;
|
308
|
|
- setAttribute('tooltiptext', "Refreshing");
|
|
335
|
+ setAttribute("tooltiptext", "Refreshing");
|
309
|
336
|
onmouseover = null;
|
310
|
337
|
}
|
311
|
338
|
},
|
312
|
339
|
|
313
|
|
- indicateInactivity: function() {
|
|
340
|
+ indicateInactivity: function () {
|
314
|
341
|
DiggSidebar.UI.indicator.src = "chrome://global/skin/icons/notloading_16.png";
|
315
|
342
|
with (DiggSidebar.UI.indicator.parentNode) {
|
316
|
343
|
disabled = false;
|
317
|
|
- onmouseover = function() {
|
|
344
|
+ onmouseover = function () {
|
318
|
345
|
var autoRefreshTime = Math.round(
|
319
|
|
- (DiggSidebar.lastUpdateAt + DiggSidebar.calculateTimeout() - new Date().getTime())/1000
|
|
346
|
+ (DiggSidebar.lastUpdateAt + DiggSidebar.calculateTimeout() - new Date().getTime()) / 1000
|
320
|
347
|
);
|
321
|
348
|
autoRefreshTime = (autoRefreshTime > 3600) ?
|
322
|
|
- Math.round(autoRefreshTime/3600) + " hours":
|
|
349
|
+ Math.round(autoRefreshTime / 3600) + " hours":
|
323
|
350
|
(autoRefreshTime > 60) ?
|
324
|
|
- Math.round(autoRefreshTime/60) + " minutes":
|
|
351
|
+ Math.round(autoRefreshTime / 60) + " minutes":
|
325
|
352
|
autoRefreshTime + " seconds";
|
326
|
|
- setAttribute('tooltiptext', "Click to refresh now.\n" +
|
|
353
|
+ setAttribute("tooltiptext", "Click to refresh now.\n" +
|
327
|
354
|
"Autorefreshing in " + autoRefreshTime);
|
328
|
|
- }
|
|
355
|
+ };
|
329
|
356
|
}
|
330
|
357
|
DiggSidebar.lastUpdateAt = new Date().getTime();
|
331
|
358
|
},
|
332
|
359
|
|
333
|
|
- initialize: function(){
|
|
360
|
+ initialize: function () {
|
334
|
361
|
DiggSidebar.endpoint = DiggSidebar.getEndpointParts(DiggSidebar.prefs.get("endpoint").value);
|
335
|
|
- var $ = function(id) {return document.getElementById(id)};
|
|
362
|
+ var $ = function (id) {
|
|
363
|
+ return document.getElementById(id);
|
|
364
|
+ };
|
336
|
365
|
|
337
|
366
|
DiggSidebar.UI = {};
|
338
|
|
- DiggSidebar.UI.notificationBox = $('dsNotificationBox');
|
339
|
|
- DiggSidebar.UI.indicator = $('dsBusyIndicator');
|
340
|
|
- DiggSidebar.UI.storiesPopup = $('dsStoriesPopup');
|
341
|
|
- DiggSidebar.UI.storyListBox = $('dsStoryListBox');
|
342
|
|
- DiggSidebar.UI.endPointDesc = $('dsEndPointDesc');
|
|
367
|
+ DiggSidebar.UI.notificationBox = $("dsNotificationBox");
|
|
368
|
+ DiggSidebar.UI.indicator = $("dsBusyIndicator");
|
|
369
|
+ DiggSidebar.UI.storiesPopup = $("dsStoriesPopup");
|
|
370
|
+ DiggSidebar.UI.storyListBox = $("dsStoryListBox");
|
|
371
|
+ DiggSidebar.UI.endPointDesc = $("dsEndPointDesc");
|
343
|
372
|
|
344
|
373
|
DiggSidebar.storyListObserver = new DiggSidebar.StoryListObserver();
|
345
|
374
|
DiggSidebar.createMenu();
|
346
|
375
|
DiggSidebar.getStories();
|
347
|
376
|
},
|
348
|
377
|
|
349
|
|
- destroy: function(){
|
|
378
|
+ destroy: function () {
|
350
|
379
|
DiggSidebar.storyListObserver.unregister();
|
351
|
380
|
}
|
352
|
381
|
};
|
353
|
382
|
|
354
|
383
|
DiggSidebar.Utils = {
|
355
|
|
- url: function(spec) {
|
|
384
|
+ url: function (spec) {
|
356
|
385
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
357
|
386
|
.getService(Components.interfaces.nsIIOService);
|
358
|
387
|
return ios.newURI(spec, null, null);
|
359
|
388
|
},
|
360
|
389
|
|
361
|
|
- openUrlInTab: function(url) {
|
|
390
|
+ openUrlInTab: function (url) {
|
362
|
391
|
Application.activeWindow.open(DiggSidebar.Utils.url(url));
|
363
|
392
|
},
|
364
|
393
|
|
365
|
|
- decodeJson: function(string) {
|
|
394
|
+ decodeJson: function (string) {
|
366
|
395
|
var json = Components.classes["@mozilla.org/dom/json;1"]
|
367
|
396
|
.createInstance(Components.interfaces.nsIJSON);
|
368
|
397
|
return json.decode(string);
|
369
|
398
|
},
|
370
|
399
|
|
371
|
|
- removeAllChildren: function(node) {
|
372
|
|
- while (node.firstChild)
|
|
400
|
+ removeAllChildren: function (node) {
|
|
401
|
+ while (node.firstChild) {
|
373
|
402
|
node.removeChild(node.firstChild);
|
|
403
|
+ }
|
374
|
404
|
}
|
375
|
|
-}
|
|
405
|
+};
|
376
|
406
|
|
377
|
|
-DiggSidebar.StoryListObserver = function() {
|
378
|
|
- this.registered = false;
|
379
|
|
- this.register();
|
380
|
|
-}
|
|
407
|
+DiggSidebar.StoryListObserver = function () {
|
|
408
|
+ this.registered = false;
|
|
409
|
+ this.register();
|
|
410
|
+};
|
381
|
411
|
|
382
|
412
|
DiggSidebar.StoryListObserver.prototype = {
|
383
|
|
- observe: function(subject, topic, data) {
|
|
413
|
+ observe: function (subject, topic, data) {
|
384
|
414
|
if (topic == window.DiggSidebar.storyListRefreshEventTopic) {
|
385
|
415
|
window.DiggSidebar.populateStoryList();
|
386
|
416
|
}
|
387
|
417
|
},
|
388
|
418
|
|
389
|
|
- register: function() {
|
390
|
|
- if (this.registered == false) {
|
391
|
|
- var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
392
|
|
- .getService(Components.interfaces.nsIObserverService);
|
393
|
|
- observerService.addObserver(this, DiggSidebar.storyListRefreshEventTopic, false);
|
|
419
|
+ register: function () {
|
|
420
|
+ if (!this.registered) {
|
|
421
|
+ DiggSidebar.observerService.addObserver(this, DiggSidebar.storyListRefreshEventTopic, false);
|
394
|
422
|
this.registered = true;
|
395
|
423
|
}
|
396
|
424
|
},
|
397
|
425
|
|
398
|
|
- unregister: function() {
|
399
|
|
- if (this.registered == true) {
|
400
|
|
- var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
401
|
|
- .getService(Components.interfaces.nsIObserverService);
|
402
|
|
- observerService.removeObserver(this, DiggSidebar.storyListRefreshEventTopic);
|
|
426
|
+ unregister: function () {
|
|
427
|
+ if (this.registered) {
|
|
428
|
+ DiggSidebar.observerService.removeObserver(this, DiggSidebar.storyListRefreshEventTopic);
|
403
|
429
|
this.registered = false;
|
404
|
430
|
}
|
405
|
431
|
}
|