// zvents-mini-custom.js
// $Revision: 31656 $ - $Date: 2008-04-29 09:38:43 -0700 (Tue, 29 Apr 2008) $
// This file implements custom event list widgets.
// Include it after zvents-mini-base.js, or concatenate the two files.
(function( Z ) {
// website base UR and partner id - edit these for your site
// We can define these outside in the display code so we don't have
// to change them for every partner.
if (typeof zventsPartnerId == "undefined") {
if (typeof partner_id != "undefined")
{
zventsPartnerId = partner_id;
}
else
{
zventsPartnerId = null;
}
}
if (typeof zventsBaseUrl == "undefined") {
if (typeof base_url != "undefined")
{
zventsBaseUrl = 'http://events.mync.com';
}
else
{
zventsBaseUrl = 'http://events.mync.com';
}
}
Z.partner = zventsPartnerId;
Z.site = zventsBaseUrl;
var today = Z.Date.today();
// Default settings and render functions for all widgets
var base = {
// Render the event date as tomorrow, or Friday, or 1/31
date: function( event ) {
if( this.showDate === false ) return '';
if( event.date == today ) return this.showDate === true ? 'today' : '';
if( event.date == today + Z.Date.oneDay ) return 'tomorrow';
return Z.Date(event.date).format(
event.date < today + Z.Date.oneDay*7 ? '{Sunday}' :
'{M}/{DD}' );
},
// Render the list of events
events: function( events ) {
return [
'
',
events.map(this.event,this).join(''),
'
'
].join('');
},
// Render a single event
event: function( event ) {
var date = this.date( event );
if( date ) {
date = [
'',
this.date( event ),
'',
' '
].join('');
}
return [
'',
this.images ? this.image( event ) : '',
'
',
this.time( event ),
'',
' ',
date,
'
',
Z.String.truncate( event.name, this.maxTitle || 40 ),
'',
'
'
].join('');
},
// Render the image(s) for an event
image: function( event ) {
var image = event.images[0];
return ! image ? '' : [
'',
'
',
''
].join('');
},
// Render the "Loading" indicator
loading: function() {
return [
'',
'

',
'
Loading events…',
'
'
].join('');
},
// Render the event time as Noon, Midnight, 2 pm, or 2:30 pm
// return '' if showTime is false
time: function( event ) {
if( this.showTime === false ) return '';
var start = Z.Date(event.startTime), date = start.date;
var hours = date.getUTCHours(), minutes = date.getUTCMinutes();
return start.format(
minutes ? '{h}:{mm} {am}' :
{ 0:'Midnight', 12:'Noon' }[hours] || '{h} {am}'
);
}
};
function Widget( args ) {
Z.Object.update( this, base, args /*(temp:*/, args.render/*:temp)*/ );
}
// The base event list widget - custom widgets extend this one
var idNext = 1;
Z.widget.eventList = function( args ) {
// Combine the settings, write the container and spinner
var widget = new Widget( args );
if( ! args.id ) {
args.id = 'ZventsWidget' + idNext++;
document.write( [
'',
widget.loading(),
'
'
].join('') );
}
if( args.load ) {
// Call the core event list function with our partner ID
Z.call( Z.EventList, {
yields: function( events ) {
// The event data is ready, sort it if requested
if( widget.sort !== false )
events.sort( 'starttime' );
// Now render and display it
var div = document.getElementById( args.id );
div.innerHTML = widget.events( events );
}
}, args );
}
return args.id;
};
// A simple event list (the same as the base list in this demo)
//Z.widget.customList1 = Z.extend( Z.widget.eventList, {
// // Any settings here would override the base Z.widget.eventList settings
//});
// Another way to code the same widget, allowing setup code before the base call
//Z.widget.customList2 = function( args ) {
// Z.call( Z.widget.eventList, {
// }, args );
//};
//-------------------------------------------------------------------------------------------------
// Simple tab clicker
//-------------------------------------------------------------------------------------------------
//
//
// Tab One Content
//
//
// Tab Two Content
//
//-------------------------------------------------------------------------------------------------
tabber = {
// Click a tab: give it the 'active' class and show its matching DIV
click: function( clicked ) {
var ul = clicked.parentNode.parentNode; // A --> LI --> UL
var tabs = ul.getElementsByTagName('a');
for( i = 0; i < tabs.length; ++i ) {
var a = tabs[i], on = ( a == clicked );
a.className = ( on ? 'active' : '' );
tabber.show( a.id.replace(/^tab/,'div'), on );
}
},
// Special clicker for Zvents Today/Tomorrow/Search tabs:
// hide or show footer, and load tomorrow's events on demand
zclick: function( clicked, when ) {
tabber.click( clicked );
tabber.show( 'zventsFooter', when );
if( ZventsTomorrowID && when == 'Tomorrow' ) {
Z.widget.popular({
id: ZventsTomorrowID,
load: { when: when }
});
ZventsTomorrowID = null;
}
},
// Show or hide a block level element
show: function( id, show ) {
document.getElementById(id).style.display =
show ? 'block' : 'none';
}
};
//-------------------------------------------------------------------------------------------------
})( ZventsMini );