20
20
var divGr = new Array ( ) ;
21
21
var divGA = new Array ( ) ;
22
22
var news = new Array ( ) ;
23
+ var colors = new Array ( "#00FF00" , "#BFFF00" , "#FFBF00" , "#FF4000" , "#FF0000" )
23
24
var numDivs = 0 ;
24
25
function createDivs ( ) {
25
- var w = parseInt ( Math . random ( ) * 300 ) + 20 ;
26
+ var w = parseInt ( Math . random ( ) * 300 ) + 100 ;
26
27
var myRequest = new Request ( {
27
28
url : jsEOUtils . getProxyURL ( ) + "?rss=http://feeds.bbci.co.uk/news/rss.xml" ,
28
29
method : 'get' ,
29
30
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 ( ) ;
32
34
numDivs = items . length ;
33
- for ( var i = 0 ; i < items . length ; ++ i ) {
35
+ for ( var i = 0 ; i < numDivs ; ++ i ) {
36
+ title =
34
37
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 ;
37
40
}
38
41
for ( var i = 0 ; i < numDivs ; ++ i ) {
39
42
divGr [ i ] = new Object ;
40
43
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) + "," +
44
47
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 ) ] ;
46
51
47
52
divGA [ i ] = new Object ;
48
53
divGA [ i ] . w = divGr [ i ] . w ;
@@ -51,9 +56,12 @@ function createDivs() {
51
56
}
52
57
} ,
53
58
onFailure : function ( ) {
59
+ alert ( "error " ) ;
54
60
}
55
61
} ) ;
56
62
63
+ myRequest . send ( ) ;
64
+
57
65
58
66
}
59
67
function writeSizes ( ) {
@@ -96,8 +104,8 @@ function showDivsH(_divs, _label, _divId) {
96
104
top + "px; left: " + lef + "px;" +
97
105
"background-color: " + c + ";" +
98
106
"border: 5px solid #fff;" +
99
- "'>" + w + ", " + h + " / " + top + "," + lef +
100
- "<br/>" +
107
+ "'>" + w + ", " + h + " / " + top + "," + lef +
108
+ "<br/>" +
101
109
"</div>" ;
102
110
lef += w ;
103
111
} else {
@@ -138,12 +146,14 @@ function showDivsV(_divs, _label, _divId, _borderColor, _paint) {
138
146
w + "px; height: " + h + "px; position: absolute; top: " +
139
147
top + "px; left: " + lef + "px;" +
140
148
"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>" +
146
153
"</div>" ;
154
+ //+ w + ", " + h + " / " + top + "," + lef +
155
+ //"<br/>" +
156
+
147
157
}
148
158
top += h ;
149
159
} else {
@@ -304,7 +314,7 @@ function main() {
304
314
createDivs ( ) ;
305
315
//showDivsV(divGr, "Original", "forTotal", "#fff", false);
306
316
greedyV ( ) ;
307
- showDivsV ( divGr , "greedy V" , "forGreedyV" , "#fff" , false ) ;
317
+ showDivsV ( divGr , "greedy V" , "forGreedyV" , "#fff" , true ) ;
308
318
/*greedyW();
309
319
showDivsV(divGr, "greedy W", "forGreedyW");
310
320
*/
0 commit comments