Difference between revisions of "Widget:Calendar"
m (bleh, typo) |
m (added event-kind and auto-color) |
||
Line 59: | Line 59: | ||
{ | { | ||
window.calendarEvents = null; | window.calendarEvents = null; | ||
− | fetch( "/w/index.php?title=Special%3AAsk&q=%5B%5BEventState%3A%3AActive%5D%5D+OR+%5B%5BEventState%3A%3APlanned%5D%5D&po=%3FEventStart%0D%0A%3FEventEnd%0D%0A&eq=yes&p%5Bformat%5D=json&sort_num=&order_num=ASC&p%5Blimit%5D=&p%5Boffset%5D=&p%5Blink%5D=all&p%5Bsort%5D=&p%5Bheaders%5D=show&p%5Bmainlabel%5D=&p%5Bintro%5D=&p%5Boutro%5D=&p%5Bsearchlabel%5D=...+further+results&p%5Bdefault%5D=&eq=yes" ).then( function( _response ) | + | fetch( "/w/index.php?title=Special%3AAsk&q=%5B%5BEventState%3A%3AActive%5D%5D+OR+%5B%5BEventState%3A%3APlanned%5D%5D&po=%3FEventStart%0D%0A%3FEventEnd%0D%0A%3FEventKind%0D%0A&eq=yes&p%5Bformat%5D=json&sort_num=&order_num=ASC&p%5Blimit%5D=&p%5Boffset%5D=&p%5Blink%5D=all&p%5Bsort%5D=&p%5Bheaders%5D=show&p%5Bmainlabel%5D=&p%5Bintro%5D=&p%5Boutro%5D=&p%5Bsearchlabel%5D=...+further+results&p%5Bdefault%5D=&eq=yes" ).then( function( _response ) |
{ | { | ||
return _response.json(); | return _response.json(); | ||
Line 123: | Line 123: | ||
Calendar.prototype._update = function( _event ) | Calendar.prototype._update = function( _event ) | ||
{ | { | ||
− | |||
var oldTable = document.getElementById( this._tblCalendar.id ); | var oldTable = document.getElementById( this._tblCalendar.id ); | ||
this._tblCalendar = document.createElement( "table" ); | this._tblCalendar = document.createElement( "table" ); | ||
Line 190: | Line 189: | ||
Calendar.prototype._determineColor = function( _td, _curDate, _dates ) | Calendar.prototype._determineColor = function( _td, _curDate, _dates ) | ||
{ | { | ||
− | + | var eventKinds = _td.title = _dates.filter( function( _date ) | |
+ | { | ||
+ | var start = new Date( _date.printouts.EventStart[0]*1000 ); | ||
+ | var end = new Date( _date.printouts.EventStart[0]*1000 ); | ||
+ | return ( _curDate.getFullYear() >= start.getUTCFullYear() | ||
+ | && _curDate.getFullYear() <= end.getUTCFullYear() | ||
+ | && _curDate.getMonth() >= start.getUTCMonth() | ||
+ | && _curDate.getMonth() <= end.getUTCMonth() | ||
+ | && _curDate.getDate() >= start.getUTCDate() | ||
+ | && _curDate.getDate() <= end.getUTCDate() ) | ||
+ | } ).map( function( _date ) | ||
+ | { | ||
+ | return _date.printouts.EventKind; | ||
+ | } ); | ||
+ | |||
+ | if ( eventKinds.includes( "Conference" ) ) | ||
+ | _td.className += " purple"; | ||
+ | else if ( eventKinds.includes( "Festival" ) || eventKinds.includes( "Party" ) ) | ||
+ | _td.className += " green"; | ||
+ | else if ( eventKinds.includes( "Meeting" ) ) | ||
+ | _td.className += " yellow"; | ||
+ | else if ( eventKinds.includes( "Lecture" ) ) | ||
+ | _td.className += " blue"; | ||
+ | else | ||
+ | _td.className += " red"; | ||
}; | }; | ||
Revision as of 16:10, 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.