Mercurial > planet-ubiquity-redesign
view about-mozilla.js @ 30:eee8b9a861a8
Feeds can now include historical entries.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 03 Mar 2009 07:07:35 -0800 |
parents | 31fa3c03cda3 |
children | 66765faeeb86 |
line wrap: on
line source
var BUILDBOT_BASE = "http://ubiquity.mozilla.com/buildbot/"; var HG_BASE = "https://ubiquity.mozilla.com/hg/ubiquity-firefox/"; function getBuildInfo(page) { var builds = []; $("li", page).each( function(i) { var revRegexp = /.*rev=\[([0-9a-f]+)\].*/; builds.push({rev: $(this).text().match(revRegexp)[1], href: (BUILDBOT_BASE + $("a:not(:first)", this).attr("href")), isSuccessful: $(".success", this).length > 0 }); } ); return builds; } function mashupBuildbotWithHgData(hgLog, buildbotPage) { var builds = getBuildInfo(buildbotPage); builds.forEach( function(build) { var revUrl = HG_BASE + "rev/" + build.rev; var revSelector = ("a[href='" + revUrl + "']"); var link = jQuery(revSelector, hgLog); var className = "build-errors"; var title = "This build may have errors."; if (build.isSuccessful) { className = "build-success"; title = "This build passed all tests."; } var status = jQuery('<span></span>'); status.addClass(className); status.addClass("build"); link.before(status); status.wrap('<a title="' + title + '" href="' + build.href + '"></a>'); }); } function processHgFeed(feed, content, cb) { processBlogFeed( feed, content, function() { jQuery.get( ("http://about-mozilla.appspot.com/?url=" + BUILDBOT_BASE + "one_line_per_build&jsonp=?"), null, function(result) { mashupBuildbotWithHgData(content, $(result.data)); cb(); }, "jsonp" ); }); } function processBlogFeed(feed, content, cb) { jQuery.each( feed.entries, function(i) { var item = $('<div class="blog-item">' + '<span class="title"></span> ' + '<span class="author"></span></div>'); $('.title', item).html(this.title); var linkTitle = ""; if (this.contentSnippet) linkTitle =this.contentSnippet ; var link = $('<a title="' + linkTitle + '" href="' + this.link + '"></a>'); $('.title', item).wrap(link); if (this.author) { var author = this.author; var authorFilters = [ // Filter out e.g. "Robert Jones <robert@jones.com>" /(.+)\s*<.+>/, // Filter out e.g. "rob...@jones.com (Robert Jones)" /.+\.\.\.@.+\s+\((.+)\)/ ]; jQuery.each( authorFilters, function() { var match = author.match(this); if (match) author = match[1]; }); $('.author', item).html('by ' + author); } $(item).attr("published", this.publishedDate); content.append(item); }); cb(); } var FEEDS = [ {name: "Blogs", url: "http://ubiquity.mozilla.com/planet/?feed=rss2", processFeed: processBlogFeed, entries: 10}, {name: "Bugs", url: "https://ubiquity.mozilla.com/trac/timeline?ticket=on&milestone=on&wiki=on&max=50&daysback=90&format=rss", processFeed: processBlogFeed, entries: 10}, {name: "Code", url: HG_BASE + "rss-log", processFeed: processHgFeed, entries: 15}, {name: "Discussions", url: "http://groups.google.com/group/ubiquity-firefox/feed/rss_v2_0_msgs.xml", processFeed: processBlogFeed, entries: 30}, {name: "Support", url: "http://getsatisfaction.com/mozilla/products/mozilla_ubiquity.rss?sort=recently_created", processFeed: processBlogFeed, entries: 10} ]; function doneLoadingFeeds() { function fixHeights(daysAgo) { var tallestHeight = 0; var elements = $(".days-ago-" + i); elements.each( function(i) { var height = $(this).height(); if (height > tallestHeight) tallestHeight = height; }); elements.height(tallestHeight); } $("#issue").fadeIn(); for (var i = 0; i < 10; i++) fixHeights(i); var entries = $("#issue .entry"); $(document.body).width(entries.outerWidth() * entries.length); } function splitByDate(rawContent, content) { var now = new Date(); $(".blog-item", rawContent).each( function(i) { var pub = new Date($(this).attr("published")); var msAgo = now - pub; var hoursAgo = msAgo / (1000 * 60 * 60); var daysAgo = Math.floor(hoursAgo / 8); if (daysAgo < 0) daysAgo = 0; if (daysAgo > 9) daysAgo = 9; var div = $(".days-ago-" + daysAgo, content); div.append(this); }); } function showFeed(feedInfo, cb) { var entry = $('<div class="entry"></div>'); var headline = $('<div class="headline"></div>'); headline.text(feedInfo.name); entry.append(headline); $("#body").append(entry); var feed = new google.feeds.Feed(feedInfo.url); feed.setNumEntries(feedInfo.entries); feed.includeHistoricalEntries(); feed.load( function(result) { var rawContent = $('<div class="content"></div>'); var content = $('<div class="content"></div>'); for (var i = 0; i < 10; i++) content.append('<div class="days-ago-' + i + '"></div>'); feedInfo.processFeed( result.feed, rawContent, function() { splitByDate(rawContent, content); entry.append(content); cb(); }); }); } google.load("feeds", "1"); google.setOnLoadCallback( function() { var feedsLeftToLoad = FEEDS.length; jQuery.each( FEEDS, function(i) { showFeed(this, function() { feedsLeftToLoad--; if (!feedsLeftToLoad) { doneLoadingFeeds(); } }); } ); });