mockups/content/js/blog.js
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 18 Sep 2009 18:55:57 +0200
changeset 2953 3c024d61290c
parent 58 cee78a1ae672
permissions -rw-r--r--
Use getOrCreateTaskSubscriptionForTask in the TaskSubscription View.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
/* Copyright 2008 the Melange authors.
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
 *
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
 * Licensed under the Apache License, Version 2.0 (the "License");
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
 * you may not use this file except in compliance with the License.
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
 * You may obtain a copy of the License at
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
 * 
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
 *   http://www.apache.org/licenses/LICENSE-2.0
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
 * 
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
 * Unless required by applicable law or agreed to in writing, software
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
 * distributed under the License is distributed on an "AS IS" BASIS,
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
 * See the License for the specific language governing permissions and
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
 * limitations under the License.
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
 */
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
function BlogPreview(container) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
  this.container_ = container;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
BlogPreview.prototype.show = function(url, title, title_link) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  var feed = new google.feeds.Feed(url);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    22
  var preview = this;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  feed.load(function(result) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
    preview.render_(result, title, title_link);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
  });
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
BlogPreview.prototype.render_ = function(result, title, title_link) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
  if (!result.feed || !result.feed.entries) return;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
  while (this.container_.firstChild) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
    this.container_.removeChild(this.container_.firstChild);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
  }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
  var blog = this.createDiv_(this.container_, "blog");
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
  var header = this.createElement_("h2", blog, "");
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
  if (!title) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
    title = result.feed.title;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
  }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
  if (!title_link) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
    title_link = result.feed.link;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
  }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
  this.createLink_(header, title_link, title);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  for (var i = 0; i < result.feed.entries.length; i++) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    var entry = result.feed.entries[i];
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
    var div = this.createDiv_(blog, "entry");
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    47
    var linkDiv = this.createDiv_(div, "title");
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    48
    this.createLink_(linkDiv, entry.link, entry.title);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
    if (entry.author) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
      this.createDiv_(div, "author", "Posted by " + entry.author);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    51
    }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
    this.createDiv_(div, "snippet", entry.contentSnippet);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
  return this.createElement_("div", parent, className, opt_text);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
BlogPreview.prototype.createLink_ = function(parent, href, text) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
  var link = this.createElement_("a", parent, "", text);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
  link.href = href;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  return link;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
BlogPreview.prototype.createElement_ = function(tagName, parent, className,
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
                                                opt_text) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
  var div = document.createElement(tagName);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
  div.className = className;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    70
  parent.appendChild(div);
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
  if (opt_text) {
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
    div.appendChild(document.createTextNode(opt_text));
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    73
  }
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    74
  return div;
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
}
cee78a1ae672 Mockups for some of the Melange views, adapted from the existing GSoC web app
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76