Difference between revisions of "Widget:Calendar"

From Hackerspace ACKspace
Jump to: navigation, search
m (renamed calendar widget due to wiki header name conflict)
(Rework date script)
Line 58: Line 58:
 
     if ( typeof CalendarWidget === "undefined" )
 
     if ( typeof CalendarWidget === "undefined" )
 
     {
 
     {
         window.calendarEvents = null;
+
         async function loadEvents()
        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();
+
             window.calendarEvents = Object.values((await (await fetch(`/wiki/Special:Ask/format%3Djson/limit%3D500/link%3Dall/headers%3Dshow/searchlabel%3DJSON/class%3Dsortable-20wikitable-20smwtable/sort%3D/order%3Dasc/offset%3D0/-5B-5BEventState::!Stalled-5D-5D-20-5B-5BEventStart::%E2%89%A431-20December-20${year}-5D-5D-20-5B-5BEventEnd::%E2%89%A51-20January-20${year}-5D-5D/-3FEventKind/-3FEventLocation/-3FURL/-3FEventStart/-3FEventEnd/mainlabel%3D/prettyprint%3Dtrue/unescape%3Dtrue`)).json()).results);
        } ).then( function( _response )
+
 
        {
+
            // Repeating events: place at beginning of array to let other events override it.
             window.calendarEvents = Object.keys( _response.results ).map( function( _event )
+
            const pizzaMeet = window.calendarEvents.find(event=>event.fulltext === "Pizza-meet");
             {
+
            const ackSession = window.calendarEvents.find(event=>event.fulltext === "ACKsession");
                 return _response.results[ _event ];
+
 
             } );
+
            // ACKsession: every month
             window.postMessage( window.calendarEvents, "*" );
+
             window.calendarEvents.unshift(...Array(12).fill("").map((_, n)=>{
         } );
+
                const item = JSON.parse(JSON.stringify(ackSession));
 +
                item.printouts.EventStart = item.printouts.EventEnd = [{ timestamp: getLastWeekdayInMonth(year,n,6) / 1000 }];
 +
                return item;
 +
            }));
 +
            // Pizza-meet: every quarter (0, 3, 6, 9)
 +
             window.calendarEvents.unshift(...[0, 3, 6, 9].map((n)=>{
 +
                 const item = JSON.parse(JSON.stringify(pizzaMeet));
 +
                item.printouts.EventStart = item.printouts.EventEnd = [{ timestamp: getFirstWeekdayInMonth(year,n,6) / 1000 }];
 +
                return item;
 +
             }));
 +
             window.postMessage( window.calendarEvents, "*" );      
 +
         }
 +
        loadEvents();
  
 
         window.CalendarWidget = function( _date, _showWeekNumber )
 
         window.CalendarWidget = function( _date, _showWeekNumber )
Line 192: Line 203:
 
             var eventKinds = _td.title = _dates.filter( function( _date )
 
             var eventKinds = _td.title = _dates.filter( function( _date )
 
             {
 
             {
                 var start = new Date( _date.printouts.EventStart[0]*1000 );
+
                 var start = new Date( _date.printouts.EventStart[0].timestamp*1000 );
                 var end = new Date( _date.printouts.EventEnd[0]*1000 );
+
                 var end = new Date( _date.printouts.EventEnd[0].timestamp*1000 );
 
                 // 'Fix' timezone
 
                 // 'Fix' timezone
 
                 start.setHours( 0, 0, 0, 0 );
 
                 start.setHours( 0, 0, 0, 0 );
Line 219: Line 230:
 
             var dates = _dates.filter( function( _date )
 
             var dates = _dates.filter( function( _date )
 
             {
 
             {
                 var start = new Date( _date.printouts.EventStart[0]*1000 );
+
                 var start = new Date( _date.printouts.EventStart[0].timestamp*1000 );
                 var end = new Date( _date.printouts.EventEnd[0]*1000 );
+
                 var end = new Date( _date.printouts.EventEnd[0].timestamp*1000 );
 
                 // 'Fix' timezone
 
                 // 'Fix' timezone
 
                 start.setHours( 0, 0, 0, 0 );
 
                 start.setHours( 0, 0, 0, 0 );

Revision as of 20:57, 14 October 2023

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.