author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Mon, 17 Nov 2008 22:12:34 +0000 | |
changeset 501 | be89bf307478 |
parent 426 | app/soc/content/js/blog-080819.js@114fe0f840c8 |
child 1307 | 091a21cf3627 |
permissions | -rw-r--r-- |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
1 |
/* Copyright 2008 the Melange authors. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
2 |
* |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
4 |
* you may not use this file except in compliance with the License. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
5 |
* You may obtain a copy of the License at |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
6 |
* |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
8 |
* |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
9 |
* Unless required by applicable law or agreed to in writing, software |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
12 |
* See the License for the specific language governing permissions and |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
13 |
* limitations under the License. |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
14 |
*/ |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
15 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
16 |
function BlogPreview(container) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
17 |
this.container_ = container; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
18 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
19 |
|
501
be89bf307478
Fix not working feed display for home settings public view. Modify blog javascript so that we can define how many feed entries we want to display. Change default number of entries to 3 as suggested by Leslie and Chris.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
426
diff
changeset
|
20 |
BlogPreview.prototype.show = function(url, entries_num, title, title_link) { |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
21 |
var feed = new google.feeds.Feed(url); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
22 |
var preview = this; |
501
be89bf307478
Fix not working feed display for home settings public view. Modify blog javascript so that we can define how many feed entries we want to display. Change default number of entries to 3 as suggested by Leslie and Chris.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
426
diff
changeset
|
23 |
feed.setNumEntries(entries_num) |
79
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
24 |
feed.load(function(result) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
25 |
preview.render_(result, title, title_link); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
26 |
}); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
27 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
28 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
29 |
BlogPreview.prototype.render_ = function(result, title, title_link) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
30 |
if (!result.feed || !result.feed.entries) return; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
31 |
while (this.container_.firstChild) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
32 |
this.container_.removeChild(this.container_.firstChild); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
33 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
34 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
35 |
var blog = this.createDiv_(this.container_, "blog"); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
36 |
var header = this.createElement_("h2", blog, ""); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
37 |
if (!title) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
38 |
title = result.feed.title; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
39 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
40 |
if (!title_link) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
41 |
title_link = result.feed.link; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
42 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
43 |
this.createLink_(header, title_link, title); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
44 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
45 |
for (var i = 0; i < result.feed.entries.length; i++) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
46 |
var entry = result.feed.entries[i]; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
47 |
var div = this.createDiv_(blog, "entry"); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
48 |
var linkDiv = this.createDiv_(div, "title"); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
49 |
this.createLink_(linkDiv, entry.link, entry.title); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
50 |
if (entry.author) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
51 |
this.createDiv_(div, "author", "Posted by " + entry.author); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
52 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
53 |
this.createDiv_(div, "snippet", entry.contentSnippet); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
54 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
55 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
56 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
57 |
BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
58 |
return this.createElement_("div", parent, className, opt_text); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
59 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
60 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
61 |
BlogPreview.prototype.createLink_ = function(parent, href, text) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
62 |
var link = this.createElement_("a", parent, "", text); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
63 |
link.href = href; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
64 |
return link; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
65 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
66 |
|
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
67 |
BlogPreview.prototype.createElement_ = function(tagName, parent, className, |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
68 |
opt_text) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
69 |
var div = document.createElement(tagName); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
70 |
div.className = className; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
71 |
parent.appendChild(div); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
72 |
if (opt_text) { |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
73 |
div.appendChild(document.createTextNode(opt_text)); |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
74 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
75 |
return div; |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
76 |
} |
58001ec7720c
Home site templates and basic view.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff
changeset
|
77 |