cityspot.lzx
<library>
<class name="cityspot">
<attribute name="label" value="San Francisco
" type="string"/>
<attribute name="position" value="2
" type="number"/>
<view name="dothilite" resource="images/dothilite.png" stretches="both" visible="false" x="-6" y="-6"/>
<view name="dot" resource="images/dot.png" stretches="both" x="-4" y="-4" onmouseover="this.parent.dothilite.setAttribute('visible', true)" onmouseout="this.parent.dothilite.setAttribute('visible', false)" onclick="this.parent.activateclock( myclock )"/>
<text name="titlesdhw" x="${parent.title.x + 1}" y="${parent.title.y + 1}" font="Kgr,Lucida Sans Unicode,Lucida Grande,sans-serif" fontsize="8" fgcolor="0xFFFFFF" datapath="name/text()" opacity=".5"/>
<text name="title" x="${-this.getTextWidth() -3}" y="-3" font="Kgr,Lucida Sans Unicode,Lucida Grande,sans-serif" fontsize="8" datapath="name/text()">
<method name="setLabelPosition">
if ( this.parent.position == 1) {
this.setAttribute('x', -this.getTextWidth() - 7);
this.setAttribute('y', -9);
} else if ( this.parent.position == 2) {
this.setAttribute('x', Math.round(-this.getTextWidth()/2 ));
this.setAttribute('y', -19);
} else if ( this.parent.position == 3) {
this.setAttribute('x', 4);
this.setAttribute('y', -8);
} else {
this.setAttribute('x', Math.round(-this.getTextWidth()/2 - 2 ));
this.setAttribute('y', 0);
}
</method>
</text>
<method name="makeDate" args="dateparts">
var currentYear = new Date();
currentYear = 1900 + currentYear.getYear();
// dateparts is month,day,hours,mins
var datepartsarray = dateparts.split( ',' );
return new Date( currentYear,
datepartsarray[0],
datepartsarray[1],
datepartsarray[2],
datepartsarray[3] );
</method>
<handler name="ondata">
// First, position the dot for the city
this.setAttribute('x', 1*this.datapath.xpathQuery('@x'));
this.setAttribute('y', 1*this.datapath.xpathQuery('@y'));
this.position = (1*this.datapath.xpathQuery('@labelposition'));
// Now set the timezone for the city
this.timezoneoffset = (1*this.datapath.xpathQuery('@timezoneoffset'));
this.dst_start = this.datapath.xpathQuery('@dst_start');
this.dst_end = this.datapath.xpathQuery('@dst_end');
var cd = new Date();
var currentGMTDate = cd.getTime() + ( 1000 * 60 * cd.getTimezoneOffset() );
// Adjust time for city's offset from GMT.
var localDate = currentGMTDate + ( this.timezoneoffset * 60 * 60 * 1000 );
// Are we in Daylight Savings Time (DST)?
this.isDST = false;
var dstStart = this.makeDate( this.dst_start );
var dstEnd = this.makeDate( this.dst_end );
if ( (localDate > dstStart.getTime()) && (localDate < dstEnd.getTime()) ) {
this.isDST = true;
}
// Southern hemisphere - invert DST
if ( dstStart.getMonth() > dstEnd.getMonth() ) {
this.isDST = !true;
}
this.title.setLabelPosition()
</handler>
<method name="syncclock" args="clockObj">
var myOffset = this.timezoneoffset;
if ( this.isDST ) { // in daylight savings time
myOffset += 1;
}
clockObj.setTimeZone( myOffset );
</method>
<method name="activateclock" args="clockObj">
this.syncclock(clockObj);
myclocktext.setAttribute('text', this.title.text );
</method>
</class>
</library>