wdgt H I
UANews Top Stories
0.1
org.uanews
(c) 2007 Arizona Board of Regents
Top STories from UANews.org
main_window
400
332
left
255
1
1
bottomRowPicture
2
168
titelRowPicture
2
4
titlerow
9
Helvetica
#000000
left
130
14
255
timetxt
15
Helvetica
#000000
right
245
20
255
info
Helvetica
9
Loading...
#cc0033
left
7
131
175
autoleft
if(updateCounter++ == updateInterval) {
updateCounter = 0;
start = 0;
update(start, true);
}
if(updateCounter >= Number(preferences.prefUpd.value)) {
updateCounter = 0;
}
setUp();
update(0, false);
updateNow();
//swedifyPrefs();
Update Frequency:
text
15
Number of Headlines (max 7):
text
7
Text Color:
popup
Black
Shadow
checkbox
1
Reflection
checkbox
1
Resources/uanews_rss.png
UANews.org
www.uanews.org
Arial
18
135
90
#000000
#666666
1
1
) ) ; H useCurl = false;
itemArr = [];
tmpItemArr = [];
pictureArr = [];
updateCounter = 0;
itemCount = 0;
siteURL = "http://www.uanews.org/";
titleText = "";
function setUp() {
start = 0;
// prefs
limit = Math.min(Number(preferences.prefLimit.value), 7);
preferences.prefLimit.value = limit;
main_window.shadow = Number(preferences.prefShadow.value)
updateInterval = Number(preferences.prefUpd.value) - 1;
// Don't allow black on black or white on white
//if(preferences.prefMid.value == "Black" && preferences.prefTextColor.value == "Black") {
// preferences.prefTextColor.value = "White";
//}
//if(preferences.prefMid.value == "White" && preferences.prefTextColor.value == "White") {
// preferences.prefTextColor.value = "Black";
//}
preferences.prefTextColor.value = "Black";
articleTextColor = (preferences.prefTextColor.value == "Black" ? "#000000" : "#000000");
normalTextColor = "#000000";
mouseOverColorButtons = "#666666";
mouseOverColorArticles = "#cc0033";
// Pictures
titelRowPicture.src = "Resources/uanews_top.png";
titelRowPicture.reload();
bottomRowPicture.src = "Resources/uanews_bottom.png";
bottomRowPicture.reload();
for(var p in pictureArr) {
delete pictureArr[p];
}
pictureArr = [];
pictureTop = 29;
itemHeight = 16;
for(i = 0; i < limit; i++) {
pictureArr.push(new Image());
pictureArr[i].src = "Resources/white_bg.png";
pictureArr[i].reload();
pictureArr[i].vOffset = pictureTop + (itemHeight * i);
pictureArr[i].hOffset = 2;
pictureArr[i].opacity = 255;
}
bottomRowPicture.vOffset = pictureTop + (itemHeight * i);
bottomRowPicture.reload();
// Text
createBottomRowButtons();
titlerow.data = "Loading...";
info.data = "";
updButton.data = "";
prevButton.data = "";
nextButton.data = "";
gotoGalleryButton.data = "";
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 = "Update...";
updButton.data = "";
info.data = "";
if(updateDisplay)
updateNow();
rssURL = "http://uanews.org/front/feed/";
var urlData = fetchData(rssURL);
if(urlData.length && urlData != "Could not load UANews" && 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 = "Failed to fetch data";
theItem.description = "The widget was unable to fetch data.";
theItem.id = 0;
theItem.updDate = "";
itemArr.push(theItem);
}
}
updateDisplayList();
}
function updateDisplayList() {
itemTop = 39;
itemHeight = 16;
for(i = 0; i < itemArr.length; i++) {
// Text
itemArr[i].txtObj = new Text()
itemArr[i].txtObj.data = itemArr[i].title;
itemArr[i].txtObj.font = "Helvetica";
itemArr[i].txtObj.size = 9;
itemArr[i].txtObj.color = articleTextColor;
itemArr[i].txtObj.width = 230;
itemArr[i].txtObj.hOffset = 7;
itemArr[i].txtObj.vOffset = itemTop + (itemHeight * i);
itemArr[i].txtObj.opacity = 255;
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 = "Update Now";
prevButton.data = start > 0 ? "« Prev." : "";
nextButton.data = (start + limit) < itemCount ? "Next »" : "";
gotoGalleryButton.data = "More News";
gotoGalleryButton.onMouseEnter = "gotoGalleryButton.color = '" + mouseOverColorButtons + "';";
gotoGalleryButton.onMouseExit = "gotoGalleryButton.color = '#666666';";
gotoGalleryButton.onMouseUp = "openURL(siteURL);";
}
function distillItems(xml) {
var itemTag = '- ';
var itemEndTag = '
';
var linkTag = '';
var linkEndTag = '';
var titleTag = '
';
var titleEndTag = '';
var descriptionTag = '';
var descriptionEndTag = '';
var dateTag = '';
var dateEndTag = '';
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\[/g,'');
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(/<\;/g,'');
str = str.replace(/p>\;/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="Sun";
if (wDay==1) wDay="Mon";
if (wDay==2) wDay="Tue";
if (wDay==3) wDay="Wed";
if (wDay==4) wDay="Thur";
if (wDay==5) wDay="Fri";
if (wDay==6) wDay="Sat";
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]);
}
//titlerow.data = itemCount;
}
function itemClick(index) {
if(index < itemArr.length) {
openURL(itemArr[index].link);
}
}
function itemMouseEnter(index) {
if(index < itemArr.length) {
info.data = itemArr[index].description;
itemArr[index].txtObj.color = mouseOverColorArticles;
updButton.data = prevButton.data = nextButton.data = '';
}
}
function itemMouseExit(index) {
if(index < itemArr.length) {
info.data = '';
updButton.data = "Update Now";
prevButton.data = start > 0 ? "« Prev." : "";
nextButton.data = (start + limit) < itemCount ? "Next »" : "";
itemArr[index].txtObj.color = articleTextColor;
}
}
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 txtSize = 9;
var txtFont = "Helvetica";
var txtColor = "#000000";
var txtStyle = "Bold";
updButton = new Text();
updButton.size = txtSize;
updButton.font = txtFont;
updButton.style = txtStyle;
updButton.data = "Update Now";
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 = txtSize;
prevButton.font = txtFont;
updButton.style = txtStyle;
prevButton.data = start > 0 ? "« Prev." : "";
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 = txtSize;
nextButton.font = txtFont;
updButton.style = txtStyle;
nextButton.data = (start + limit) < itemCount ? "Next »" : "";
nextButton.color = txtColor;
nextButton.hOffset = 150;
nextButton.width = 40;
nextButton.onMouseEnter = "nextButton.color = '" + mouseOverColorButtons + "';";
nextButton.onMouseExit = "nextButton.color = '" + txtColor + "';";
nextButton.onMouseUp = "next()";
gotoGalleryButton = new Text();
gotoGalleryButton.size = txtSize;
gotoGalleryButton.font = txtFont;
updButton.style = txtStyle;
gotoGalleryButton.data = "Site";
gotoGalleryButton.color = "#000000";
gotoGalleryButton.hOffset = 200;
gotoGalleryButton.width = 50;
gotoGalleryButton.onMouseEnter = "gotoGalleryButton.color = '" + mouseOverColorButtons + "';";
gotoGalleryButton.onMouseExit = "gotoGalleryButton.color = '" + txtColor + "';";
gotoGalleryButton.onMouseUp = "openURL(siteURL);";
updButton.vOffset = prevButton.vOffset = nextButton.vOffset = info.vOffset = gotoGalleryButton.vOffset = bottomRowPicture.vOffset + 11;
}
setUp();
update(start);b B x<