bonsoir,
j'aimerais savoir comment je peux faire un widget qui affiche des news avec des onglets sachant que j'ai un widget yahoo qui affiche un flux rss .
voila le code js:
useCurl = false;
itemArr = [];
tmpItemArr = [];
pictureArr = [];
updateCounter = 0;
itemCount = 0;
txtSize = 10;
txtFont = "Arial";
siteURL = "
http://www.codelyoko.net/ ";
titleText = "";
function setUp() {
start = 0;
showDescription = 0;
// prefs
limit = Math.min(Number(preferences.prefLimit.value), 15);
preferences.prefLimit.value = limit;
main_window.shadow = Number(preferences.prefShadow.value)
updateInterval = Number(preferences.prefUpd.value) - 1;
reflectionPicture.opacity = (Number(preferences.prefReflection.value) ? 255 : 0);
txtSize = preferences.prefTextSize.value;
txtFont = preferences.prefTextFont.value;
switch (preferences.prefSkin.value) {
case "Vert" :
mouseOverColorArticles = "#C6C23D";
break;
case "Rouge" :
mouseOverColorArticles = "#A40011";
break;
case "Orange" :
mouseOverColorArticles = "#E1AB3B";
break;
case "Bleu" :
mouseOverColorArticles = "#7AB4D5";
break;
case "Violet" :
mouseOverColorArticles = "#B28BEC";
break;
default:
mouseOverColorArticles = "#A40011";
}
// Don't allow black on black or white on white if(preferences.prefMid.value
"Noir" && preferences.prefTextColor.value "Noir") {
preferences.prefTextColor.value = "Blanc";
} if(preferences.prefMid.value
"Blanc" && preferences.prefTextColor.value "Blanc") {
preferences.prefTextColor.value = "Noir";
}
articleTextColor
(preferences.prefTextColor.value "Blanc" ? "#FFFFFF" : "#000000");
normalTextColor = "#000000";
mouseOverColorButtons = "#FFFFFF";
// Pictures
titelRowPicture.src = "Resources/" + preferences.prefSkin.value + "_top.png";
titelRowPicture.reload();
bottomRowPicture.src = "Resources/" + preferences.prefSkin.value + "_bottom.png";
bottomRowPicture.reload();
for(var p in pictureArr) {
delete pictureArr[p];
}
pictureArr = [];
pictureTop = 21;
itemHeight = 18;
for(i = 0; i < limit; i++) {
pictureArr.push(new Image());
pictureArr[i].src = "Resources/" + preferences.prefMid.value + "_middle.png";
pictureArr[i].reload();
pictureArr[i].vOffset = pictureTop + (itemHeight * i);
pictureArr[i].hOffset = 2;
}
bottomRowPicture.vOffset = pictureTop + (itemHeight * i);
bottomRowPicture.reload();
// Text
createBottomRowButtons();
titlerow.data = "Chargement...";
info.data = "";
info.color = 0;
info.vOffset = pictureTop;
info.height = (itemHeight * i);
info.hOffset = 255;
info.font = txtFont;
info.size = Number(txtSize)+1;
timetxt.size = Number(txtSize)-1;;
timetxt.font = txtFont;
updButton.data = "";
prevButton.data = "";
nextButton.data = "";
ShowDescriptionButton.data = "Details >>"; ShowDescriptionButton.onMouseEnter
"ShowDescriptionButton.color '" + mouseOverColorButtons + "';"; ShowDescriptionButton.onMouseExit
"ShowDescriptionButton.color '#000000';"; ShowDescriptionButton.onMouseUp
"showDescription !showDescription; info.opacity = showDescription?255:0; ShowDescriptionButton.data = showDescription?"Details <<":"Details >>"; ";
CodeLyokoPicture.onMouseUp = "openURL(siteURL);";
if(!main_window.visible) {
main_window.visible = true;
}
//main_window.recalcShadow();
updateNow();
}
function fetchData(theURL) {
if(useCurl) {
return runCommand("curl -s -S '" + theURL + "'");
} else {
return (new URL()).fetch(theURL);
}
}
function update(startVal, updateDisplay) {
start = startVal;
titlerow.data = "Recharger...";
updButton.data = "";
info.data = "";
if(updateDisplay)
updateNow();
rssURL = "
http://127.0.0.1/news.xml ";
var urlData = fetchData(rssURL);
if(urlData.length && urlData !
"Chargement impossible" && urlData.indexOf("curl: (") -1) {
for(i in itemArr) {
delete itemArr[i].txtObj;
delete itemArr[i].dateTxtObj;
delete itemArr[i];
}
for(i in tmpItemArr)
delete tmpItemArr[i];
itemArr = [];
tmpItemArr = [];
distillItems(urlData);
} else {
if(!itemArr.length) {
theItem = new Object();
theItem.title = "Chargement impossible";
theItem.description = "Information introuvable.";
theItem.id = 0;
theItem.updDate = "";
itemArr.push(theItem);
}
}
updateDisplayList();
}
function updateDisplayList() {
itemTop = 31;
itemHeight = 18;
for(i = 0; i < itemArr.length; i++) {
// Text
itemArr[i].txtObj = new Text()
itemArr[i].txtObj.data = itemArr[i].title;
itemArr[i].txtObj.font = txtFont;
itemArr[i].txtObj.size = txtSize;
itemArr[i].txtObj.color = articleTextColor;
itemArr[i].txtObj.width = 240;
itemArr[i].txtObj.hOffset = 7;
itemArr[i].txtObj.vOffset = itemTop + (itemHeight * i);
itemArr[i].txtObj.onMouseUp = "itemClick(" + i + ");";
itemArr[i].txtObj.onMouseEnter = "itemMouseEnter(" + i + ");";
itemArr[i].txtObj.onMouseExit = "itemMouseExit(" + i + ");";
}
titlerow.data = titleText;
timetxt.data = (dateToWeekDay(new Date())) + " " + (new Date()).toString().substr(16,5);
updButton.data = "Recharger";
prevButton.data = start > 0 ? "<< Prec." : "";
nextButton.data = (start + limit) < itemCount ? "Suiv. >>" : "";
}
function draw_settings() {
var v_o = 0;
var h_o = 2;
var curr_gr = undefined;
var curr_gr_cnt = 0;
var gr_i = 0;
var font_size_gr = 14;
var font_size_label = 11;
for(var i in pn_sites) {
gr_i++;
var gr_id = pn_sites[i]['group'];
if(gr_id!=curr_gr) {
curr_gr = gr_id;
gr_i = 1;
curr_gr_cnt = get_gr_items_cnt(gr_id)
h_o = 2;
var text = new Text();
text.color = "#000000";
text.font = "Verdana";
text.size = font_size_gr;
text.style = 'bold';
text.data = pn_sites_gr[curr_gr];
text.name = get_name('header', curr_gr);
text_ref[text.name] = text;
v_o += 25;
text.hOffset = h_o;
text.vOffset = v_o;
v_o += 10;
frm_setting.addSubview(text);
}
text = new Text();
text.color = "#000000";
text.font = "Verdana";
text.size = font_size_label;
text.data = pn_sites[i]['title'];
text.name = get_name('txt', i);
text.hOffset = h_o + img.width + 2;
text.vOffset = v_o + font_size_label;
text.onMouseUp = 'check_site("' + i + '");';
frm_setting.addSubview(text);
text_ref[text.name] = text;
var tmp = gr_i%2;
if(tmp) {
h_o = frm_setting.width/2;
if(gr_i==curr_gr_cnt) v_o += img.height + 2;
}
else {
h_o = 2;
v_o += img.height + 2;
}
}
apply_settings();
}
function distillItems(xml) {
var itemTag = '<sport>';
var itemEndTag = '</sport>';
var linkTag = '<news>';
var linkEndTag = '</news>';
var titleTag = '<resultat>';
var titleEndTag = '</resultat>';
var descriptionTag = '<tv>';
var descriptionEndTag = '</tv>';
var dateTag = '<dateinsertion>';
var dateEndTag = '</dateinsertion>';
var item = '';
xml = CDATAFix(xml);
bailOut = 0;
var itemIndex = xml.indexOf(itemTag);
while(itemIndex > -1 && bailOut++ < 100) {
startIndex = itemIndex + itemTag.length;
item = xml.substring(startIndex, xml.indexOf(itemEndTag, startIndex));
theItem = new Object();
// Title
startIndex = item.indexOf(titleTag) + titleTag.length;
theItem.title = item.substring(startIndex, item.indexOf(titleEndTag, startIndex));
// Link
startIndex = item.indexOf(linkTag) + linkTag.length;
theItem.link = item.substring(startIndex, item.indexOf(linkEndTag, startIndex));
// Description
startIndex = item.indexOf(descriptionTag) + descriptionTag.length;
theItem.description = item.substring(startIndex, item.indexOf(descriptionEndTag));
// Date
startIndex = item.indexOf(dateTag) + dateTag.length;
theItem.updDate = dateFix(item.substring(startIndex, item.indexOf(dateEndTag)));
tmpItemArr.push(theItem);
// Next
itemIndex = xml.indexOf(itemTag, itemIndex + item.length);
}
fillList();
}
function CDATAFix(str) {
str = str.replace(/\<\!\[CDATA\
'>str = str.replace(/]>/g,'');
str = str.replace(/
/g,'');
str = str.replace(//g,'(Live)');
str = str.replace(/hspace=4>/g,'');
str = str.replace(/http:\/\//g,'');
str = str.replace(/espn.go.com\/i\//g,'');
str = str.replace(/&(amp|#38);/g,'&');
return str;
}
function dateFix(dateString) {
// 2004-07-09T09:32:22+02:00
var year = dateString.substr(0, 4);
var mon = dateString.substr(5, 2);
var day = dateString.substr(8, 2);
var time = dateString.substr(11, 5);
var date = new Date();
date.setYear(year);
date.setMonth(Number(mon) - 1);
date.setDate(day);
date.setHours(12);
var wDay = dateToWeekDay(date);
return wDay + " " + time;
}
function dateToWeekDay(date) {
date.setHours(12);
var wDay = date.getDay()
if (wDay==0) wDay="Dim";
if (wDay==1) wDay="Lun";
if (wDay==2) wDay="Mar";
if (wDay==3) wDay="Mer";
if (wDay==4) wDay="Jeu";
if (wDay==5) wDay="Ven";
if (wDay==6) wDay="Sam";
return wDay;
}
function fillList() {
for(i in itemArr) {
delete itemArr[i].txtObj;
delete itemArr[i].dateTxtObj;
delete itemArr[i];
}
itemArr = [];
itemCount = tmpItemArr.length;
for(var i = start; i < (start+limit) && i < itemCount; i++) {
itemArr.push(tmpItemArr[i]);
}
}
function itemClick(index) {
if(index < itemArr.length) {
openURL(itemArr[index].link);
}
}
function itemMouseEnter(index) {
if(index < itemArr.length) {
info.data = itemArr[index].title + "\n" + itemArr[index].description;
itemArr[index].txtObj.color = mouseOverColorArticles;
itemArr[index].txtObj.scrolling = "autoLeft"; updButton.data
prevButton.data nextButton.data = '';
}
}
function itemMouseExit(index) {
if(index < itemArr.length) {
info.data = "";
updButton.data = "Recharger";
prevButton.data = start > 0 ? "<< Prec." : "";
nextButton.data = (start + limit) < itemCount ? "Suiv. >>" : "";
itemArr[index].txtObj.color = articleTextColor;
itemArr[index].txtObj.scrolling = "off";
}
}
function prev() {
if(start > 0) {
start -= limit;
fillList();
updateDisplayList();
}
}
function next() {
if((start + limit) < itemCount) {
start += limit;
fillList();
updateDisplayList();
}
}
function createBottomRowButtons() {
// Bottom row buttons (text elements)
var txtColor = "#000000";
var txtStyle = "Bold";
updButton = new Text();
updButton.size = Number(txtSize)-1;
updButton.font = txtFont;
updButton.style = txtStyle;
updButton.data = "Recharger";
updButton.color = txtColor;
updButton.hOffset = 7;
updButton.width = 70; updButton.onMouseEnter
"updButton.color '" + mouseOverColorButtons + "';"; updButton.onMouseExit
"updButton.color '" + txtColor + "';"; updButton.onMouseUp
"updButton.color '" + txtColor + "';update(0, true);";
prevButton = new Text();
prevButton.size = Number(txtSize)-1;
prevButton.font = txtFont;
prevButton.style = txtStyle;
prevButton.data = start > 0 ? "<< Prec." : "";
prevButton.color = txtColor;
prevButton.hOffset = 100;
prevButton.width = 40; prevButton.onMouseEnter
"prevButton.color '" + mouseOverColorButtons + "';"; prevButton.onMouseExit
"prevButton.color '" + txtColor + "';";
prevButton.onMouseUp = "prev()";
nextButton = new Text();
nextButton.size = Number(txtSize)-1;
nextButton.font = txtFont;
nextButton.style = txtStyle;
nextButton.data = (start + limit) < itemCount ? "Suiv. >>" : "";
nextButton.color = txtColor;
nextButton.hOffset = 150;
nextButton.width = 40; nextButton.onMouseEnter
"nextButton.color '" + mouseOverColorButtons + "';"; nextButton.onMouseExit
"nextButton.color '" + txtColor + "';";
nextButton.onMouseUp = "next()";
ShowDescriptionButton = new Text();
ShowDescriptionButton.size = Number(txtSize)-1;
ShowDescriptionButton.font = txtFont;
ShowDescriptionButton.style = txtStyle;
ShowDescriptionButton.data = "ESPN";
ShowDescriptionButton.color = "#000000";
ShowDescriptionButton.hOffset = 248;
ShowDescriptionButton.alignment = "right";
ShowDescriptionButton.width = 50; ShowDescriptionButton.onMouseEnter
"ShowDescriptionButton.color '" + mouseOverColorButtons + "';"; ShowDescriptionButton.onMouseExit
"ShowDescriptionButton.color '" + txtColor + "';";
ShowDescriptionButton.onMouseUp = "openURL(siteURL);";
updButton.vOffset
prevButton.vOffset nextButton.vOffset = ShowDescriptionButton.vOffset = bottomRowPicture.vOffset + 11;
}
setUp();
update(start);
s'il vous plait pourriez vous m'aider??
merci
Afficher la suite