comparison ambnews/content/blank.js @ 1:44bcb4975ead

Added more files.
author Atul Varma <varmaa@toolness.com>
date Thu, 21 Aug 2008 15:39:57 -0700
parents
children ec86d1e59d44
comparison
equal deleted inserted replaced
0:66b00b4c37a6 1:44bcb4975ead
1 function loadNews() {
2 var Cc = Components.classes;
3 var Ci = Components.interfaces;
4 var historyService = Cc["@mozilla.org/browser/nav-history-service;1"]
5 .getService(Ci.nsINavHistoryService);
6
7 // no query parameters will get all history
8 // XXX default sorting is... ?
9 var options = historyService.getNewQueryOptions();
10
11 options.resultType = options.RESULTS_AS_URI;
12 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
13
14 // no query parameters will return everything
15 var query = historyService.getNewQuery();
16 query.annotation = "AmbNews/feed";
17
18 // execute the query
19 var result = historyService.executeQuery(query, options);
20
21 var root = result.root;
22 root.containerOpen = true;
23
24 var childNum = 0;
25 var childrenShown = 0;
26 var maxChildrenToShow = 20;
27 var shownFeeds = {};
28
29 function getNextFeed() {
30 if (childrenShown == maxChildrenToShow ||
31 childNum == root.childCount) {
32 root.containerOpen = false;
33 } else {
34 var annSvc = AmbNews.__getAnnSvc();
35 var child = root.getChild(childNum);
36 var feedUri = annSvc.getPageAnnotation(AmbNews.url(child.uri),
37 "AmbNews/feed");
38 childNum++;
39 if (feedUri in shownFeeds) {
40 getNextFeed();
41 } else {
42 shownFeeds[feedUri] = true;
43 childrenShown++;
44 AmbNews.getFeed(feedUri, onFeed);
45 }
46 }
47 }
48
49 function onFeed(feed) {
50 var text = "";
51 if (feed) {
52 var entriesToShow = 4;
53 if (feed.entries.length < entriesToShow)
54 entriesToShow = feed.entries.length;
55 var feedLink = feed.link ? feed.link.spec : "";
56 text += ('<div class="feed"><div class="feed-title"><a ' +
57 'href="' + feedLink + '">' +
58 feed.title.text + '</a></div><ul>');
59 for (var i = 0; i < entriesToShow; i++) {
60 var entryTitle = feed.entries[i].title.text;
61 if (entryTitle.length > 100) {
62 entryTitle = entryTitle.slice(0, 100) + '\u2026';
63 }
64 text += ('<li class="feed-entry"> \u00b7 <a href="' +
65 feed.entries[i].link.spec +
66 '">' +
67 entryTitle + '</a></li>');
68 }
69 text += '</ul></div>';
70 } else
71 text = "An error occurred.";
72 //$("#content").append(text);
73 $(text).hide().fadeIn("slow", getNextFeed).appendTo("#content");
74 }
75
76 getNextFeed();
77 }
78
79 $(window).ready(loadNews);