Difference between revisions of "Widget:Calendar"
m (added async update) |
(actual event calendar) |
||
Line 124: | Line 124: | ||
{ | { | ||
console.log( _event.data ); | console.log( _event.data ); | ||
+ | var oldTable = document.getElementById( this._tblCalendar.id ); | ||
+ | this._tblCalendar = document.createElement( "table" ); | ||
+ | this._gen( _event.data ); | ||
+ | oldTable.parentNode.replaceChild( this._tblCalendar, oldTable ); | ||
} | } | ||
− | Calendar.prototype._gen = function( ) | + | Calendar.prototype._gen = function( _dates ) |
{ | { | ||
var date = new Date( this._date.getFullYear(), this._date.getMonth(), 1 ); | var date = new Date( this._date.getFullYear(), this._date.getMonth(), 1 ); | ||
Line 135: | Line 139: | ||
this._tblCalendar.className = "calendar"; | this._tblCalendar.className = "calendar"; | ||
− | + | this._tblCalendar.id = "c" + ( Math.random() * 10e8 | 0 ); | |
+ | |||
// Month and year | // Month and year | ||
row = this._tblCalendar.appendChild( document.createElement( "tr" ) ).appendChild( document.createElement( "th" ) ); | row = this._tblCalendar.appendChild( document.createElement( "tr" ) ).appendChild( document.createElement( "th" ) ); | ||
Line 167: | Line 172: | ||
if ( curDate.getTime() in this.hl ) | if ( curDate.getTime() in this.hl ) | ||
td.className += " " + this.hl[ curDate.getTime() ]; | td.className += " " + this.hl[ curDate.getTime() ]; | ||
+ | else | ||
+ | this._determineColor( td, curDate, _dates || [] ); | ||
if ( curDate.getTime() in this.t ) | if ( curDate.getTime() in this.t ) | ||
{ | { | ||
Line 172: | Line 179: | ||
td.className += " title"; | td.className += " title"; | ||
} | } | ||
+ | else | ||
+ | this._determineTitle( td, curDate, _dates || [] ); | ||
row.appendChild( td ).appendChild( document.createTextNode( curDate.getDate( ) ) ); | row.appendChild( td ).appendChild( document.createTextNode( curDate.getDate( ) ) ); | ||
Line 177: | Line 186: | ||
} | } | ||
} | } | ||
+ | }; | ||
+ | |||
+ | Calendar.prototype._determineColor = function( _td, _curDate, _dates ) | ||
+ | { | ||
+ | //td.className += " " + this.hl[ curDate.getTime() ]; | ||
+ | }; | ||
+ | |||
+ | Calendar.prototype._determineTitle = function( _td, _dates ) | ||
+ | { | ||
+ | td.title = _dates.filter( function( _date ) | ||
+ | { | ||
+ | var start = new Date( _date.printouts.EventStart[0]+"000" ); | ||
+ | var end = new Date( _date.printouts.EventStart[0]+"000" ); | ||
+ | return ( _curDate.getYear() >= start.getUTCFullYear() | ||
+ | && _curDate.getYear() <= end.getUTCFullYear() | ||
+ | && _curDate.getMonth() >= start.getUTCMonth() | ||
+ | && _curDate.getMonth() <= end.getUTCMonth() | ||
+ | && _curDate.getDate() >= start.getUTCDate() | ||
+ | && _curDate.getDate() <= end.getUTCDate() ) | ||
+ | } ).map( function( _date ) | ||
+ | { | ||
+ | return _date.filltext; | ||
+ | } ).join( ", " ); | ||
+ | if ( td.title ) | ||
+ | td.className += " title"; | ||
}; | }; | ||
Revision as of 15:43, 19 July 2018
This widget allows you to display a calendar
Created by Xopr
Using this widget
To insert this widget, use the following code:
{{#widget:Calendar |date=february 26 2011 |w=true |hl.26 february 2011=blue |hl.1 march 2011=red |t.17 february 2011=First peek into ACKspace's new space }}
This will give the following result:
Note:
- all parameters are optional. If date is omitted, the current month will be displayed
- you can highlight dates by using the hl parameter, followed by a dot and the date you want to highlight. Available colors are: red, green, blue, yellow, cyan and purple
- you can also add titles per-day using the 't' parameter, followed by a dot and the date you want to highlight.
- w (show week numbers) is optional
Copy to your site
To use this widget on your site, just install MediaWiki Widgets extension and copy full source code of this page to your wiki as Widget:Calendar article.