1 /* Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 Use of this source code is governed by a BSD-style license that can be
3 found in the LICENSE file.
6 /* Use only multi-line comments in this file, since during testing
7 its contents will get read from disk and stuffed into the
8 iframe .src tag, which is a process that doesn't preserve line
9 breaks and makes single-line comment out the rest of the code.
12 /* The maximum number of feed items to show in the preview. */
13 var maxFeedItems = 10;
15 /* The maximum number of characters to show in the feed item title. */
16 var maxTitleCount = 1024;
18 window.addEventListener("message", function(e) {
19 var parser = new DOMParser();
20 var doc = parser.parseFromString(e.data, "text/xml");
25 /* Already handled in subscribe.html */
29 function buildPreview(doc) {
30 /* Start building the part we render inside an IFRAME. We use a table to
31 ensure that items are separated vertically from each other. */
32 var table = document.createElement("table");
33 var tbody = document.createElement("tbody");
34 table.appendChild(tbody);
36 /* Now parse the rest. Some use <entry> for each feed item, others use
38 var entries = doc.getElementsByTagName('entry');
39 if (entries.length == 0)
40 entries = doc.getElementsByTagName('item');
42 for (i = 0; i < entries.length && i < maxFeedItems; ++i) {
43 item = entries.item(i);
45 /* Grab the title for the feed item. */
46 var itemTitle = item.getElementsByTagName('title')[0];
48 itemTitle = itemTitle.textContent;
50 itemTitle = "Unknown title";
52 /* Ensure max length for title. */
53 if (itemTitle.length > maxTitleCount)
54 itemTitle = itemTitle.substring(0, maxTitleCount) + "...";
56 /* Grab the description.
57 TODO(aa): Do we need to check for type=html here? */
58 var itemDesc = item.getElementsByTagName('description')[0];
60 itemDesc = item.getElementsByTagName('summary')[0];
62 itemDesc = item.getElementsByTagName('content')[0];
65 itemDesc = itemDesc.textContent;
69 /* Grab the link URL. */
70 var itemLink = item.getElementsByTagName('link');
72 if (itemLink.length > 0) {
73 link = itemLink[0].childNodes[0];
75 link = itemLink[0].childNodes[0].nodeValue;
77 link = itemLink[0].getAttribute('href');
80 var tr = document.createElement("tr");
81 var td = document.createElement("td");
83 /* If we found a link we'll create an anchor element,
84 otherwise just use a bold headline for the title. */
85 var anchor = (link != "") ? document.createElement("a") :
86 document.createElement("strong");
87 anchor.id = "anchor_" + String(i);
90 anchor.innerHTML = itemTitle;
91 anchor.target = "_top";
92 anchor.className = "item_title";
94 var span = document.createElement("span");
95 span.id = "desc_" + String(i);
96 span.className = "item_desc";
97 span.innerHTML = itemDesc;
99 td.appendChild(anchor);
100 td.appendChild(document.createElement("br"));
101 td.appendChild(span);
102 td.appendChild(document.createElement("br"));
103 td.appendChild(document.createElement("br"));
106 tbody.appendChild(tr);
109 table.appendChild(tbody);
110 document.body.appendChild(table);