Skip to content

Commit e06dc0a

Browse files
committed
News are finally read from BBC
1 parent fe9687a commit e06dc0a

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

js/samples/web_block_page_problem.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,34 @@
2020
var divGr = new Array();
2121
var divGA = new Array();
2222
var news = new Array();
23+
var colors=new Array( "#00FF00", "#BFFF00", "#FFBF00", "#FF4000", "#FF0000")
2324
var numDivs = 0;
2425
function createDivs() {
25-
var w = parseInt(Math.random() * 300) + 20;
26+
var w = parseInt(Math.random() * 300) + 100;
2627
var myRequest = new Request({
2728
url: jsEOUtils.getProxyURL() + "?rss=http://feeds.bbci.co.uk/news/rss.xml",
2829
method: 'get',
2930
async: false,
30-
onSuccess: function(responseText, XMLDoc) {
31-
items = XMLDoc.getElementsByTagName('item');
31+
onSuccess: function(responseText, responseXML) {
32+
items = responseXML.getElementsByTagName('item');
33+
news=new Array();
3234
numDivs = items.length;
33-
for (var i = 0; i < items.length; ++i) {
35+
for (var i = 0; i < numDivs; ++i) {
36+
title=
3437
news[i] = new Object;
35-
news[i].title = items[i].getElementsByTagName('title');
36-
news[i].content = titulo[0].firstChild.nodeValue;
38+
news[i].title = items[i].getElementsByTagName( "title" )[0].textContent;
39+
news[i].content = items[i].getElementsByTagName('description')[0].textContent;
3740
}
3841
for (var i = 0; i < numDivs; ++i) {
3942
divGr[i] = new Object;
4043
divGr[i].w = w;
41-
divGr[i].h = parseInt(news[i].title.length*10 )/w*20+
42-
parseInt(news[i].content.length*10 )/w*20;
43-
divGr[i].c = "rgb( " + parseInt(Math.random() * 240) + "," +
44+
divGr[i].h = parseInt(news[i].title.length * 25 / w) * 25 +
45+
parseInt(news[i].content.length * 15 / w )* 15;
46+
/*divGr[i].c = "rgba( " + parseInt(Math.random() * 240) + "," +
4447
parseInt(Math.random() * 240) + "," +
45-
parseInt(Math.random() * 240) + ")";
48+
parseInt(Math.random() * 240) + ", 0.5)";
49+
*/
50+
divGr[i].c=colors[parseInt(Math.random()*colors.length )];
4651

4752
divGA[i] = new Object;
4853
divGA[i].w = divGr[i].w;
@@ -51,9 +56,12 @@ function createDivs() {
5156
}
5257
},
5358
onFailure: function() {
59+
alert("error ");
5460
}
5561
});
5662

63+
myRequest.send();
64+
5765

5866
}
5967
function writeSizes() {
@@ -96,8 +104,8 @@ function showDivsH(_divs, _label, _divId) {
96104
top + "px; left: " + lef + "px;" +
97105
"background-color: " + c + ";" +
98106
"border: 5px solid #fff;" +
99-
"'>" + w + ", " + h + " / " + top + "," + lef +
100-
"<br/>"+
107+
"'>" + w + ", " + h + " / " + top + "," + lef +
108+
"<br/>" +
101109
"</div>";
102110
lef += w;
103111
} else {
@@ -138,12 +146,14 @@ function showDivsV(_divs, _label, _divId, _borderColor, _paint) {
138146
w + "px; height: " + h + "px; position: absolute; top: " +
139147
top + "px; left: " + lef + "px;" +
140148
"background-color: " + c + ";" +
141-
"border: 5px solid " + _borderColor + ";" +
142-
"'>" + w + ", " + h + " / " + top + "," + lef +
143-
"<br/>"+
144-
"<h3>"+news[i].title+"</h3>"+
145-
"<p>"+news[i].content+"</p>"+
149+
"opacity: 1; "+
150+
"border: 5px solid " + _borderColor + ";" +"'>" +
151+
"<h3>" + news[i].title + "</h3>" +
152+
"<p>" + news[i].content + "</p>" +
146153
"</div>";
154+
//+ w + ", " + h + " / " + top + "," + lef +
155+
//"<br/>" +
156+
147157
}
148158
top += h;
149159
} else {
@@ -304,7 +314,7 @@ function main() {
304314
createDivs();
305315
//showDivsV(divGr, "Original", "forTotal", "#fff", false);
306316
greedyV();
307-
showDivsV(divGr, "greedy V", "forGreedyV", "#fff", false);
317+
showDivsV(divGr, "greedy V", "forGreedyV", "#fff", true);
308318
/*greedyW();
309319
showDivsV(divGr, "greedy W", "forGreedyW");
310320
*/

web_block_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-->
77
<html>
88
<head>
9-
<title>jsEO Testing: 256 Royal Road Function.</title>
9+
<title>jsEO Testing: Web Block Page.</title>
1010
<meta charset="UTF-8">
1111
<meta name="viewport" content="width=device-width">
1212
<!--Including CSS -->

0 commit comments

Comments
 (0)