app/soc/content/js/blog-081117.js
changeset 2800 cd9eed2b787e
parent 1308 35b75ffcbb37
equal deleted inserted replaced
2799:0fe7767592d0 2800:cd9eed2b787e
    15 
    15 
    16 function BlogPreview(container) {
    16 function BlogPreview(container) {
    17   this.container_ = container;
    17   this.container_ = container;
    18 }
    18 }
    19 
    19 
    20 BlogPreview.prototype.show = function(url, entries_num, title, title_link) {
    20 BlogPreview.prototype.show = function (url, entries_num, title, title_link) {
    21   var feed = new google.feeds.Feed(url);
    21   var feed = new google.feeds.Feed(url);
    22   var preview = this;
    22   var preview = this;
    23   feed.setNumEntries(entries_num)
    23   feed.setNumEntries(entries_num);
    24   feed.load(function(result) {
    24   feed.load(function (result) {
    25     preview.render_(result, title, title_link);
    25     preview.render_(result, title, title_link);
    26   });
    26   });
    27 }
    27 };
    28 
    28 
    29 BlogPreview.prototype.render_ = function(result, title, title_link) {
    29 BlogPreview.prototype.render_ = function (result, title, title_link) {
    30   if (!result.feed || !result.feed.entries) return;
    30   if (!result.feed || !result.feed.entries) {
       
    31     return;
       
    32   }
    31   while (this.container_.firstChild) {
    33   while (this.container_.firstChild) {
    32     this.container_.removeChild(this.container_.firstChild);
    34     this.container_.removeChild(this.container_.firstChild);
    33   }
    35   }
    34 
    36 
    35   var blog = this.createDiv_(this.container_, "blog");
    37   var blog = this.createDiv_(this.container_, "blog");
    50     if (entry.author) {
    52     if (entry.author) {
    51       this.createDiv_(div, "author", "Posted by " + entry.author);
    53       this.createDiv_(div, "author", "Posted by " + entry.author);
    52     }
    54     }
    53     this.createDiv_(div, "snippet", entry.contentSnippet);
    55     this.createDiv_(div, "snippet", entry.contentSnippet);
    54   }
    56   }
    55 }
    57 };
    56 
    58 
    57 BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
    59 BlogPreview.prototype.createDiv_ = function (parent, className, opt_text) {
    58   return this.createElement_("div", parent, className, opt_text);
    60   return this.createElement_("div", parent, className, opt_text);
    59 }
    61 };
    60 
    62 
    61 BlogPreview.prototype.createLink_ = function(parent, href, text) {
    63 BlogPreview.prototype.createLink_ = function (parent, href, text) {
    62   var link = this.createElement_("a", parent, "", text);
    64   var link = this.createElement_("a", parent, "", text);
    63   link.href = href;
    65   link.href = href;
    64   return link;
    66   return link;
    65 }
    67 };
    66 
    68 
    67 BlogPreview.prototype.createElement_ = function(tagName, parent, className,
    69 BlogPreview.prototype.createElement_ = function (tagName, parent, className,
    68                                                 opt_text) {
    70                                                  opt_text) {
    69   var div = document.createElement(tagName);
    71   var div = document.createElement(tagName);
    70   div.className = className;
    72   div.className = className;
    71   parent.appendChild(div);
    73   parent.appendChild(div);
    72   if (opt_text) {
    74   if (opt_text) {
    73     div.appendChild(document.createTextNode(opt_text));
    75     div.appendChild(document.createTextNode(opt_text));
    74   }
    76   }
    75   return div;
    77   return div;
    76 }
    78 };
    77 
    79