function NewsPreview(container) { this.container_ = container; } NewsPreview.prototype.showTitle = function(url, opt_noTitle) { var feed = new google.feeds.Feed(url); var preview = this; feed.load(function(result) { preview.renderTitle_(result, opt_noTitle); }); } NewsPreview.prototype.renderTitle_ = function(result, opt_noTitle) { if (!result.feed || !result.feed.entries) return; while (this.container_.firstChild) { this.container_.removeChild(this.container_.firstChild); } for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; this.createLink_(this.container_, "news.html", "newsHeading", entry.title); // if (entry.author) { // this.createP_(this.container_, "author", "Posted by " + entry.author); // } this.createP_(this.container_, "newsDate", entry.publishedDate); // this.createP_(this.container_, "newsSummary", entry.contentSnippet); } } NewsPreview.prototype.show = function(url, opt_noTitle) { var feed = new google.feeds.Feed(url); var preview = this; feed.load(function(result) { preview.render_(result, opt_noTitle); }); } NewsPreview.prototype.render_ = function(result, opt_noTitle) { if (!result.feed || !result.feed.entries) return; while (this.container_.firstChild) { this.container_.removeChild(this.container_.firstChild); } for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; this.createLink_(this.container_, "", "newsHeading", entry.title); // if (entry.author) { // this.createP_(this.container_, "author", "Posted by " + entry.author); // } this.createP_(this.container_, "newsDate", entry.publishedDate); this.createHTMLElement_("p", this.container_, "newsSummary", entry.content); } } NewsPreview.prototype.createDiv_ = function(parent, className, opt_text) { return this.createElement_("div", parent, className, opt_text); } NewsPreview.prototype.createP_ = function(parent, className, opt_text) { return this.createElement_("p", parent, className, opt_text); } NewsPreview.prototype.createLink_ = function(parent, href, className, text) { var link = this.createElement_("a", parent, className, text); link.href = href; return link; } NewsPreview.prototype.createElement_ = function(tagName, parent, className, opt_text) { var div = document.createElement(tagName); div.className = className; parent.appendChild(div); if (opt_text) { div.appendChild(document.createTextNode(opt_text)); } return div; } NewsPreview.prototype.createHTMLElement_ = function(tagName, parent, className, HTMLstring) { var elem = document.createElement(tagName); elem.className = className; parent.appendChild(elem); elem.appendChild(this.extractContent(HTMLstring)); elem.firstChild.removeChild(elem.firstChild.firstChild); return elem; } NewsPreview.prototype.extractContent = function(HTMLstring) { var d = document.createElement('div'); d.innerHTML = HTMLstring; return d.firstChild.childNodes[3]; }