PageSourceSearch

https://www.brunssum.nl/wro/calendar.js

js brunssum.nl collected 2026-10-02 18:48:58 UTC 17,599 bytes, 46 lines download raw bytes

1
2var Calendar=Class.create({version:"2012.1",lang:'nl',id:0,wrapper:null,anchor:null,element:null,body:null,title:null,date:null,targetIsSelect:false,possibleValues:[],isDrawn:false,container:null,position:'bottom',showWeeks:true,sourceFormat:null,returnFormat:'yyyy-MM-dd',targetInput:null,hideTargetInput:true,allowEmpty:false,useYearLinks:true,className:'',allowNextYear:true,allowNextMonth:true,allowPreviousYear:true,allowPreviousMonth:true,initialize:function constructor(opts){if(!Date.CultureInfo){throw('The calendar requires date.js!');}
3if(opts){Object.extend(this,opts);}
4this.selectDate=opts.selectDate||this.selectDate;this.selectDateObserver=opts.selectDateObserver||this.selectDateObserver;this.selectWeek=opts.selectWeek||this.selectWeek;this.selectWeekObserver=opts.selectWeekObserver||this.selectWeekObserver;this.onUpdate=opts.onUpdate||this.onUpdate;this.onCreate=opts.onCreate||this.onCreate;this.onBeforeUpdate=opts.onBeforeUpdate||this.onBeforeUpdate;if(this.date){if(this.sourceFormat){this.date=Date.parseExact(this.date,this.sourceFormat);}else{this.date=Date.parse(this.date);}}else{if(this.sourceFormat){this.date=this.targetInput?Date.parseExact($F(this.targetInput),this.sourceFormat):Date.today();}else{this.date=this.targetInput?Date.parse($F(this.targetInput)):Date.today();}
5if(this.targetInput&&$(this.targetInput).tagName.toLowerCase()==='select'){this.targetIsSelect=true;this.possibleValues=$(this.targetInput).select('option').pluck('value');}}
6if(!this.targetIsSelect){if(this.targetInput&&this.hideTargetInput){try{$(this.targetInput).writeAttribute('type','hidden');}catch(e){$(this.targetInput).addClassName('hidden');}
7$(this.targetInput).addClassName('hidden');}}else if(this.targetInput&&this.hideTargetInput){$(this.targetInput).addClassName('hidden');}
8if(!this.date){this.date=Date.today();}
9if(this.sourceFormat&&!opts.returnFormat){this.returnFormat=this.sourceFormat;}
10this.id=this.targetInput.identify();this.create();this.observeTypedInput();},observeTypedInput:function(){if(this.targetInput){let datePatternRexeg="^(0?[1-9]|[12][0-9]|3[01])[\\-](0?[1-9]|1[012])[\\-]\\d{4}$";let errorMessageUl=document.createElement("UL");errorMessageUl.classList.add("warnings",'hidden');errorMessageUl.setAttribute("role","alert");let errorMessageLi=document.createElement("LI");errorMessageLi.innerHTML="Gebruik dd-mm-jjjj"
11errorMessageUl.appendChild(errorMessageLi);this.wrapper.after(errorMessageUl);this.targetInput.observe('keyup',function keyBoardObserver(event){if(event.target.value&&event.target.value!==""){if(event.target.value.match(datePatternRexeg)){errorMessageUl.classList.add('hidden');}else{errorMessageUl.classList.remove('hidden');}}else{errorMessageUl.classList.add('hidden');}});}},create:function create(){var header,thead,tfoot,days,daynames,i,insert={},value=$F(this.targetInput);this.summaryTemplate=new Template(Calendar.i18n[this.lang].summary);this.element=new Element('table',{id:'calendar-'+this.id}).addClassName('calendar');
11this.element.wrap(this.wrapper=new Element('div',{id:'calendar-wrapper-'+this.id}).addClassName('calendar-wrapper rs_preserve rs_skip'));this.wrapper.insert({top:(header=new Element('div')).addClassName('calendar-header')});if(!this.className.empty()){this.element.addClassName(this.className);}
12if(this.anchor){this.hide();this.anchor=$(this.anchor);this.anchor.observe('click',this.anchorClickObserver.bind(this));}
13if(this.container){insert[this.position]=this.wrapper;$(this.container).insert(insert);}else{$(document.body).insert({bottom:this.wrapper});}
14header.insert(new Element('div').addClassName('header').insert({top:new Element('span',{id:'previousMonth-'+this.id}).insert((this.previousMonthLink=new Element('a',{href:'calendar:previous-month','aria-label':Calendar.i18n[this.lang].previous_month,title:Calendar.i18n[this.lang].previous_month}).update(Calendar.i18n[this.lang].previous_month_display))),bottom:new Element('span',{id:'nextMonth-'+this.id}).insert((this.nextMonthLink=new Element('a',{href:'calendar:next-month','aria-label':Calendar.i18n[this.lang].next_month,title:Calendar.i18n[this.lang].next_month}).update(Calendar.i18n[this.lang].next_month_display)))}));this.previousMonthLink.observe('click',function previousMonthObserver(event){event.stop();this.previousMonth();}.bind(this));this.nextMonthLink.observe('click',function nextMonthObserver(event){event.stop();this.nextMonth();}.bind(this));if(this.useYearLinks){this.previousMonthLink.up().insert({before:new Element('span',{id:'previousYear-'+this.id}).update((this.previousYearLink=new Element('a',{href:'calendar:previous-year','aria-label':Calendar.i18n[this.lang].previous_year,title:Calendar.i18n[this.lang].previous_year}).update(Calendar.i18n[this.lang].previous_year_display)))});this.nextMonthLink.up().insert({after:new Element('span',{id:'nextYear-'+this.id}).insert((this.nextYearLink=new Element('a',{href:'calendar:next-year','aria-label':Calendar.i18n[this.lang].next_year,title:Calendar.i18n[this.lang].next_year}).update(Calendar.i18n[this.lang].next_year_display)))});this.previousYearLink.observe('click',function previousYearObserver(event){event.stop();this.previousYear();}.bind(this));this.nextYearLink.observe('click',function nextYearObserver(event){event.stop();this.nextYear();}.bind(this));}
15this.previousMonthLink.up().insert({after:(this.title=new Element('span',{id:'titleCalendar-'+this.id,class:'titleCalendar'}))});if(this.allowEmpty){this.element.insert((tfoot=new Element('tfoot')));tfoot.insert(new Element('tr').addClassName('footer').insert(new Element('th',{colspan:(this.showWeeks?8:7)-(this.useYearLinks?2:0)}).insert(new Element('a',{href:'calendar:empty'}).update(Calendar.i18n.select_empty_date).observe('click',this.selectEmptyObserver.bind(this)))));}
16this.element.insert((thead=new Element('thead')));this.element.insert((this.body=new Element('tbody')));this.element.observe('keyup',function keyBoardObserver(event){var acted=false,e;switch(event.keyCode){case Event.KEY_RIGHT:this.nextMonth();acted=true;break;case Event.KEY_LEFT:this.previousMonth();acted=true;break;case Event.KEY_UP:this.nextYear();acted=true;break;case Event.KEY_DOWN:this.previousYear();acted=true;break;}
17if(acted){event.stop();e=this.body.down('a[href]');if(e){e.focus();}}}.bind(this));days=new Element('tr').addClassName('days');if(this.showWeeks){days.insert('<th>w</th>');}
18daynames=Date.CultureInfo.abbreviatedDayNames;for(i=1;i<daynames.size();i+=1){days.insert(new Element('th',{id:this.id+'-day-'+i}).update(daynames[i]));if(i===daynames.size()-1){days.insert(new Element('th',{id:this.id+'-day-7'}).update(daynames[0]));}}
19thead.insert(days);this.update();if(this.targetInput&&value&&!value.empty()){this.targetInput.setValue(this.date.toString(this.returnFormat));}
20this.onCreate(this);},update:function update(){this.onBeforeUpdate(this);this.body.update('');var date=Date.parse(this.date.toString('D')),dayNumber=0,tr=new Element('tr'),title=this.date.toString('MMMM yyyy'),day,lastDay,clickable,dayIsToday,classNames,dayLink,dayLinkAttributes,dayCellAttributes;this.element.writeAttribute('summary',this.summaryTemplate.evaluate({month:title}));this.title.update(title);if(!(day=date.moveToFirstDayOfMonth()).is().monday()){day.last().monday();}
21date=Date.parse(this.date.toString('D'));if(!(lastDay=date.moveToLastDayOfMonth()).is().sunday()){lastDay=lastDay.next().sunday();}
22if(this.showWeeks){tr.insert(new Element('th').addClassName('week').insert(new Element('a',{href:'calendar:'+day.getWeek()}).update(day.getWeek()).observe('click',this.selectWeekObserver.bindAsEventListener(this,day.toString('D')))));}
23while(day.compareTo(lastDay)<1){clickable=(this.targetIsSelect||this.possibleValues.size()>0)?(this.possibleValues.indexOf(day.toString(this.sourceFormat))>-1):true;dayIsToday=day.equals(Date.today());classNames='day'+(day.is().weekday()?'':' weekend')+
24(day.toString('M')<this.date.toString('M')?' other-month previous-month':'')+
25(day.toString('M')>this.date.toString('M')?' other-month next-month':'')+
26(dayIsToday?' today':'')+
27(day.equals(this.date)?' selected':'')+
28(!clickable?' disabled':'');dayLink=null;dayLinkAttributes={id:this.id+day.toString('_dd_MM_yyyy'),title:day.toString('dddd d MMMM, yyyy')};dayNumber+=1;
28dayCellAttributes={headers:this.id+'-day-'+dayNumber};if(dayIsToday){dayCellAttributes.title=Calendar.i18n[this.lang].today;}
29if(clickable){dayLinkAttributes.href='calendar:'+day.toString('yyyy-MM-dd');}
30if(clickable){dayLink=new Element('a',dayLinkAttributes).update(day.toString('d')).observe('click',(!clickable?Event.stop:this.selectDateObserver.bindAsEventListener(this,day.toString('D'))));if(day.equals(this.date)){dayLink.setAttribute('aria-label','Geselecteerde datum: '+day.toString('dddd d MMMM yyyy'));}
31if(day.equals(lastDay)){dayLink.addEventListener('blur',(event)=>{this.anchor.focus();});}
32tr.insert(this.onDrawDay(new Element('td',dayCellAttributes).addClassName(classNames).insert(dayLink),day));}else{tr.insert(this.onDrawDay(new Element('td',dayCellAttributes).addClassName(classNames).update(day.toString('d')),day));}
33if(day.is().sunday()){day.add(1).day();this.body.insert(tr);tr=new Element('tr');dayNumber=0;if(this.showWeeks){tr.insert(new Element('th').addClassName('week').insert(new Element('a',{href:'calendar:'+day.getWeek()}).update(day.getWeek()).observe('click',this.selectWeekObserver.bindAsEventListener(this,day.toString('D')))));}}else{day.add(1).day();}}
34if(this.possibleValues.size()>0){[this.previousMonthLink,this.previousYearLink,this.nextMonthLink,this.nextYearLink].invoke('addClassName','disabled');this.allowPreviousMonth=this.allowPreviousYear=false;this.allowNextMonth=this.allowNextYear=false;this.possibleValues.each(function(currentMonth,currentYear,value,index){var value=Date.parse(value),valueMonth=parseInt(value.toString('MM')),valueYear=parseInt(value.toString('yyyy'));if(valueMonth<currentMonth){this.previousMonthLink.removeClassName('disabled');this.allowPreviousMonth=true;}else if(valueMonth>currentMonth){this.nextMonthLink.removeClassName('disabled');this.allowNextMonth=true;}
35if(valueYear<currentYear){this.previousMonthLink.removeClassName('disabled');this.previousYearLink.removeClassName('disabled');this.allowPreviousMonth=this.allowPreviousYear=true;}else if(valueYear>currentYear){this.nextMonthLink.removeClassName('disabled');this.nextYearLink.removeClassName('disabled');this.allowNextMonth=this.allowNextYear=true;}}.curry(parseInt(this.date.toString('MM')),parseInt(this.date.toString('yyyy'))),this);}
36this.isDrawn=true;return this.onUpdate(this);},anchorClickObserver:function anchorClickObserver(event){event.stop();if(Date.parse($F(this.targetInput))){this.date=Date.parse($F(this.targetInput));}
37if(!this.wrapper.visible()){this.showAtAnchor();this.update();}else{this.hide();}},clearSelection:function clearSelection(){this.body.select('.selected').invoke('removeClassName','selected');},selectDateObserver:function selectDateObserver(event,date){event.stop();date=Date.parse(date);if(this.selectDate(date.toString(this.returnFormat))!==false){if(date.toString('M')!==this.date.toString('M')){this.date=date;this.update();}else{var eSelected=Element.extend(this.body.select('.selected')[0]);if(eSelected){eSelected.insert(eSelected.down("a"));eSelected.down("a").removeClassName('selected_a');var emElement=eSelected.down("em");if(emElement)emElement.remove();}
38eSelected.removeClassName('selected');event.findElement('td').addClassName('selected');event.findElement('a').addClassName('selected_a');event.findElement('a').wrap(this.onDrawDay(new Element('em')));}}},selectDate:function selectDate(date){if(this.targetInput){this.targetInput.setValue(date);if($j("#datetillwarning").length){$j("datetillwarning").addClassName('hidden');}
39if($j("#datefrom").length&&$j("#datetill").length){if($j("#datefrom").val().length!=0&&$j("#datetill").val().length!=0){var datefromparse=Date.parse($j("#datefrom").val());var datetillparse=Date.parse($j("#datetill").val());if(datetillparse.compareTo(datefromparse)<0){if($j("#datetillwarning").length){$j("#datetillwarning").removeClassName('hidden');}else{var date_from_till_compareTemplate=Calendar.i18n[this.lang].date_from_till_compare;$j("#datetill").parent().append('<ul id="datetillwarning" class=\"warnings\"><li>'+date_from_till_compareTemplate+'</li></ul>');$j('.submit-buttons input[type="submit"].submit').attr('disabled','disabled');}}else{if($j("#datetillwarning").length){$j("#datetillwarning").addClassName('hidden');$j('.submit-buttons input[type="submit"].submit').removeAttr('disabled');}}}}
40this.onUpdate(this);if(this.anchor){this.hide();}
41this.wrapper.nextSibling.addClassName('hidden');}},selectWeekObserver:function selectWeekObserver(event,week){event.stop();if(this.selectWeek(week)!==false){this.body.select('.selected').invoke('removeClassName','selected');event.findElement('th.week').addClassName('selected').up('tr').addClassName('selected');}},selectWeek:function selectWeek(value){if(this.targetInput){this.targetInput.setValue(value);this.onUpdate(this);if(this.anchor){this.hide();}}},selectEmptyObserver:function selectEmpty(event){event.stop();if(this.targetInput){this.targetInput.setValue('');this.onUpdate(this);if(this.anchor){this.hide();}}},onBeforeUpdate:function onBeforeUpdate(calendar){return calendar;},onUpdate:function onUpdate(calendar){return calendar;},onCreate:function onCreate(calendar){return calendar;},onDrawDay:function onDrawDay(dayCell,date){return dayCell;},set:function set(opts){this.date.set(opts);this.update();return this;},setDate:function setDate(date){this.date.parse(date);this.update();return this;},previousMonth:function previousMonth(){if(this.allowPreviousMonth){this.date.addMonths(-1);this.update();}return this;},nextMonth:function nextMonth(){if(this.allowNextMonth){this.date.addMonths(1);this.update();}return this;},previousYear:function previousYear(){if(this.allowPreviousYear){this.date.addYears(-1);this.update();}return this;},nextYear:function nextYear(){if(this.allowNextYear){this.date.addYears(1);this.update();}return this;},today:function today(){this.date=Date.today();this.update();return this;},show:function show(){this.wrapper.removeClassName('hidden');this.anchor.setAttribute('aria-expanded','true');this.anchor.setAttribute('aria-controls','calendar-wrapper-'+this.id
41);if(this.anchor){this.addCloseObserver();}
42return this;},showAtAnchor:function showAtAnchor(){this.wrapper.addClassName('static');this.show();},hide:function hide(){this.wrapper.addClassName('hidden');this.anchor.setAttribute('aria-expanded','false');return this;},toggle:function toggle(){this.wrapper.toggle();return this;},boundCloseObserver:null,addCloseObserver:function addCloseObserver(){if(!this.boundCloseObserver){this.boundCloseObserver=this.closeObserver.bind(this);}
43$(document.body).observe('click',this.boundCloseObserver);},removeCloseObserver:function removeCloseObserver(){$(document.body).stopObserving('click',this.boundCloseObserver);},closeObserver:function closeObserver(event){if(event.findElement('table.calendar')!==this.element){this.hide();$(document.body).stopObserving('click',this.boundCloseObserver);}},toElement:function toElement(){return this.element;}});Calendar.i18n={en:{summary:'Dynamic generated table with dates of #{month}, follow a link to use this date in the inputfield.',date_from_till_compare:'The end date is before the start date. Ensure that the end date is after the start date.',previous_year:'Previous year',previous_year_display:'&laquo;',next_year:'Next year',next_year_display:'&raquo;',previous_month:'Previous month',previous_month_display:'&lsaquo;',next_month:'Next month',next_month_display:'&rsaquo;',select_empty_date:'Date unkown',today:'Today',clear:'Clear the selection'},nl:{summary:'Dynamisch gegenereerde tabel met datums in #{month}, volg een link van een dag om deze in te vullen in het invoerveld.',date_from_till_compare:'De einddatum ligt voor de startdatum. Zorg er voor dat de einddatum na de startdatum ligt.',previous_year:'Vorig jaar',previous_year_display:'&laquo;',next_year:'Volgend jaar',next_year_display:'&raquo;',previous_month:'Vorige maand',previous_month_display:'&lsaquo;',next_month:'Volgende maand',next_month_display:'&rsaquo;',select_empty_date:'Datum onbekend',today:'Vandaag',clear:'Selectie ongedaan maken'}};var WeekSelectCalendar=Class.create(Calendar,{selectDateObserver:function customSelectDateObserver(event,date){event.stop();date=Date.parse(date);if(this.selectDate(date.toString(this.returnFormat))!==false){this.body.select('.selected').invoke('removeClassName','selected');event.findElement('td').addClassName('selected').up('tr').addClassName('selected');}},selectWeekObserver:function customSelectWeekObserver(event,date){date=Date.parse(date);event.stop();this.body.select('.selected').invoke('removeClassName','selected');event.findElement('tr').addClassName('selected');this.date=date;this.selectDate(this.date.toString(this.returnFormat));},onCreate:function onCreate(calendar){var td=calendar.element.down('td.selected');if(td){if(!calendar.targetInput.hasClassName("empty")){td.up('tr').addClassName('selected');}
44td.removeClassName("selected");}
45if(calendar.targetInput.hasClassName("empty")){calendar.targetInput.clear();}
46calendar.element.addClassName('weekselect');calendar.element.insert({before:new Element('a',{'class':'icon-link remove','href':'calendar:'+calendar.element.identify()}).update(Calendar.i18n[calendar.lang].clear).observe('click',function clear(event){event.stop();calendar.clearSelection();})});}});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.