Welcome to mirror list, hosted at ThFree Co, Russian Federation.

jquery-calendar.js « jquery « libs - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b80456d299c7ffc4da1cefb6bb239be01f4a6ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

function PopUpCal(){this._nextId=0;this._inst=[];this._curInst=null;this._disabledInputs=[];this._popUpShowing=false;this._inDialog=false;this.regional=[];this.regional['']={clearText:'Clear',closeText:'Close',prevText:'&lt;Prev',nextText:'Next&gt;',currentText:'Today',dayNames:['Su','Mo','Tu','We','Th','Fr','Sa'],monthNames:['January','February','March','April','May','June','July','August','September','October','November','December'],dateFormat:'DMY/'};this._defaults={autoPopUp:'focus',appendText:'',buttonText:'...',buttonImage:'',buttonImageOnly:false,closeAtTop:true,hideIfNoPrevNext:false,changeMonth:true,changeYear:true,yearRange:'-10:+10',firstDay:0,changeFirstDay:true,showOtherMonths:false,minDate:null,maxDate:null,speed:'medium',customDate:null,fieldSettings:null,onSelect:null};$.extend(this._defaults,this.regional['']);this._calendarDiv=$('<div id="calendar_div"></div>');$(document.body).append(this._calendarDiv);$(document.body).mousedown(this._checkExternalClick);}
$.extend(PopUpCal.prototype,{_register:function(inst){var id=this._nextId++;this._inst[id]=inst;return id;},_getInst:function(id){return this._inst[id]||id;},setDefaults:function(settings){$.extend(this._defaults,settings||{});},_doKeyDown:function(e){var inst=popUpCal._getInst(this._calId);if(popUpCal._popUpShowing){switch(e.keyCode){case 9:popUpCal.hideCalendar(inst,'');break;case 13:popUpCal._selectDate(inst);break;case 27:popUpCal.hideCalendar(inst,inst._get('speed'));break;case 33:popUpCal._adjustDate(inst,-1,(e.ctrlKey?'Y':'M'));break;case 34:popUpCal._adjustDate(inst,+1,(e.ctrlKey?'Y':'M'));break;case 35:if(e.ctrlKey)popUpCal._clearDate(inst);break;case 36:if(e.ctrlKey)popUpCal._gotoToday(inst);break;case 37:if(e.ctrlKey)popUpCal._adjustDate(inst,-1,'D');break;case 38:if(e.ctrlKey)popUpCal._adjustDate(inst,-7,'D');break;case 39:if(e.ctrlKey)popUpCal._adjustDate(inst,+1,'D');break;case 40:if(e.ctrlKey)popUpCal._adjustDate(inst,+7,'D');break;}}
else if(e.keyCode==36&&e.ctrlKey){popUpCal.showFor(this);}},_doKeyPress:function(e){var inst=popUpCal._getInst(this._calId);var chr=String.fromCharCode(e.charCode==undefined?e.keyCode:e.charCode);return(chr<' '||chr==inst._get('dateFormat').charAt(3)||(chr>='0'&&chr<='9'));},_connectCalendar:function(target,inst){var $input=$(target);var appendText=inst._get('appendText');if(appendText){$input.after('<span class="calendar_append">'+appendText+'</span>');}
var autoPopUp=inst._get('autoPopUp');if(autoPopUp=='focus'||autoPopUp=='both'){$input.focus(this.showFor);}
if(autoPopUp=='button'||autoPopUp=='both'){var buttonText=inst._get('buttonText');var buttonImage=inst._get('buttonImage');var buttonImageOnly=inst._get('buttonImageOnly');var trigger=$(buttonImageOnly?'<img class="calendar_trigger" src="'+
buttonImage+'" alt="'+buttonText+'" title="'+buttonText+'"/>':'<button type="button" class="calendar_trigger">'+(buttonImage!=''?'<img src="'+buttonImage+'" alt="'+buttonText+'" title="'+buttonText+'"/>':buttonText)+'</button>');$input.wrap('<span class="calendar_wrap"></span>').after(trigger);trigger.click(this.showFor);}
$input.keydown(this._doKeyDown).keypress(this._doKeyPress);$input[0]._calId=inst._id;},_inlineCalendar:function(target,inst,defaultDate){$(target).append(inst._calendarDiv);target._calId=inst._id;var date=defaultDate;inst._selectedDay=date.getDate();inst._selectedMonth=date.getMonth();inst._selectedYear=date.getFullYear();popUpCal._adjustDate(inst);},dialogCalendar:function(dateText,onSelect,settings,pos){var inst=this._dialogInst;if(!inst){inst=this._dialogInst=new PopUpCalInstance({},false);this._dialogInput=$('<input type="text" size="1" style="position: absolute; top: -100px;"/>');this._dialogInput.keydown(this._doKeyDown);$('body').append(this._dialogInput);this._dialogInput[0]._calId=inst._id;}
$.extend(inst._settings,settings||{});this._dialogInput.val(dateText);if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
this._pos=pos||[(windowWidth/2)-100,(windowHeight/2)-100];this._dialogInput.css('left',this._pos[0]+'px').css('top',this._pos[1]+'px');inst._settings.onSelect=onSelect;this._inDialog=true;this._calendarDiv.addClass('calendar_dialog');this.showFor(this._dialogInput[0]);if($.blockUI){$.blockUI(this._calendarDiv);}},enableFor:function(inputs){inputs=(inputs.jquery?inputs:$(inputs));inputs.each(function(){this.disabled=false;$('../button.calendar_trigger',this).each(function(){this.disabled=false;});$('../img.calendar_trigger',this).css({opacity:'1.0',cursor:''});var $this=this;popUpCal._disabledInputs=$.map(popUpCal._disabledInputs,function(value){return(value==$this?null:value);});});},disableFor:function(inputs){inputs=(inputs.jquery?inputs:$(inputs));inputs.each(function(){this.disabled=true;$('../button.calendar_trigger',this).each(function(){this.disabled=true;});$('../img.calendar_trigger',this).css({opacity:'0.5',cursor:'default'});var $this=this;popUpCal._disabledInputs=$.map(popUpCal._disabledInputs,function(value){return(value==$this?null:value);});popUpCal._disabledInputs[popUpCal._disabledInputs.length]=this;});},reconfigureFor:function(control,settings){var inst=this._getInst(control._calId);if(inst){$.extend(inst._settings,settings||{});this._updateCalendar(inst);}},setDateFor:function(control,date){var inst=this._getInst(control._calId);if(inst){inst._setDate(date);}},getDateFor:function(control){var inst=this._getInst(control._calId);return(inst?inst._getDate():null);},showFor:function(target){var input=(target.nodeName&&target.nodeName.toLowerCase()=='input'?target:this);if(input.nodeName.toLowerCase()!='input'){input=$('input',input.parentNode)[0];}
if(popUpCal._lastInput==input){return;}
for(var i=0;i<popUpCal._disabledInputs.length;i++){if(popUpCal._disabledInputs[i]==input){return;}}
var inst=popUpCal._getInst(input._calId);popUpCal.hideCalendar(inst,'');popUpCal._lastInput=input;inst._setDateFromField(input);if(popUpCal._inDialog){input.value='';}
if(!popUpCal._pos){popUpCal._pos=popUpCal._findPos(input);popUpCal._pos[1]+=input.offsetHeight;}
inst._calendarDiv.css('position',(popUpCal._inDialog&&$.blockUI?'static':'absolute')).css('left',popUpCal._pos[0]+'px').css('top',popUpCal._pos[1]+'px');popUpCal._pos=null;var fieldSettings=inst._get('fieldSettings');$.extend(inst._settings,(fieldSettings?fieldSettings(input):{}));popUpCal._showCalendar(inst);},_showCalendar:function(id){var inst=this._getInst(id);popUpCal._updateCalendar(inst);if(!inst._inline){var speed=inst._get('speed');inst._calendarDiv.show(speed,function(){popUpCal._popUpShowing=true;popUpCal._afterShow(inst);});if(speed==''){popUpCal._popUpShowing=true;popUpCal._afterShow(inst);}
if(inst._input[0].type!='hidden'){inst._input[0].focus();}
this._curInst=inst;}},_updateCalendar:function(inst){inst._calendarDiv.empty().append(inst._generateCalendar());if(inst._input&&inst._input!='hidden'){inst._input[0].focus();}},_afterShow:function(inst){if($.browser.msie){$('#calendar_cover').css({width:inst._calendarDiv[0].offsetWidth+4,height:inst._calendarDiv[0].offsetHeight+4});}},hideCalendar:function(id,speed){var inst=this._getInst(id);if(popUpCal._popUpShowing){speed=(speed!=null?speed:inst._get('speed'));inst._calendarDiv.hide(speed,function(){popUpCal._tidyDialog(inst);});if(speed==''){popUpCal._tidyDialog(inst);}
popUpCal._popUpShowing=false;popUpCal._lastInput=null;inst._settings.prompt=null;if(popUpCal._inDialog){popUpCal._dialogInput.css('position','absolute').css('left','0px').css('top','-100px');if($.blockUI){$.unblockUI();$('body').append(this._calendarDiv);}}
popUpCal._inDialog=false;}
popUpCal._curInst=null;},_tidyDialog:function(inst){inst._calendarDiv.removeClass('calendar_dialog');$('.calendar_prompt',inst._calendarDiv).remove();},_checkExternalClick:function(event){if(!popUpCal._curInst){return;}
var target=$(event.target);if((target.parents("#calendar_div").length==0)&&(target.attr('class')!='calendar_trigger')&&popUpCal._popUpShowing&&!(popUpCal._inDialog&&$.blockUI))
{popUpCal.hideCalendar(popUpCal._curInst,'');}},_adjustDate:function(id,offset,period){var inst=this._getInst(id);inst._adjustDate(offset,period);this._updateCalendar(inst);},_gotoToday:function(id){var date=new Date();var inst=this._getInst(id);inst._selectedDay=date.getDate();inst._selectedMonth=date.getMonth();inst._selectedYear=date.getFullYear();this._adjustDate(inst);},_selectMonthYear:function(id,select,period){var inst=this._getInst(id);inst._selectingMonthYear=false;inst[period=='M'?'_selectedMonth':'_selectedYear']=select.options[select.selectedIndex].value-0;this._adjustDate(inst);},_clickMonthYear:function(id){var inst=this._getInst(id);if(inst._input&&inst._selectingMonthYear&&!$.browser.msie){inst._input[0].focus();}
inst._selectingMonthYear=!inst._selectingMonthYear;},_changeFirstDay:function(id,a){var inst=this._getInst(id);var dayNames=inst._get('dayNames');var value=a.firstChild.nodeValue;for(var i=0;i<7;i++){if(dayNames[i]==value){inst._settings.firstDay=i;break;}}
this._updateCalendar(inst);},_selectDay:function(id,td){var inst=this._getInst(id);inst._selectedDay=$("a",td).html();this._selectDate(id);},_clearDate:function(id){this._selectDate(id,'');},_selectDate:function(id,dateStr){var inst=this._getInst(id);dateStr=(dateStr!=null?dateStr:inst._formatDate());if(inst._input){inst._input.val(dateStr);}
var onSelect=inst._get('onSelect');if(onSelect){onSelect(dateStr);}
else{inst._input.trigger('change');}
if(inst._inline){this._updateCalendar(inst);}
else{this.hideCalendar(inst,inst._get('speed'));}},noWeekends:function(date){var day=date.getDay();return[(day>0&&day<6),''];},_findPos:function(obj){if(obj.type=='hidden'){obj=obj.nextSibling;}
var curleft=curtop=0;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){var origcurleft=curleft;curleft+=obj.offsetLeft;if(curleft<0){curleft=origcurleft;}
curtop+=obj.offsetTop;}}
return[curleft,curtop];}});function PopUpCalInstance(settings,inline,defaultDate){this._id=popUpCal._register(this);this._selectedDay=0;this._selectedMonth=0;this._selectedYear=0;this._input=null;this._inline=inline;this._calendarDiv=(!inline?popUpCal._calendarDiv:$('<div id="calendar_div_'+this._id+'" class="calendar_inline"></div>'));if(inline){var date=defaultDate;this._currentDate=defaultDate;this._currentDay=date.getDate();this._currentMonth=date.getMonth();this._currentYear=date.getFullYear();}
this._settings=$.extend({},settings||{});}
$.extend(PopUpCalInstance.prototype,{_get:function(name){return(this._settings[name]!=null?this._settings[name]:popUpCal._defaults[name]);},_setDateFromField:function(input){this._input=$(input);var dateFormat=this._get('dateFormat');var currentDate=this._input.val().split(dateFormat.charAt(3));if(currentDate.length==3){this._currentDay=parseInt(currentDate[dateFormat.indexOf('D')],10);this._currentMonth=parseInt(currentDate[dateFormat.indexOf('M')],10)-1;this._currentYear=parseInt(currentDate[dateFormat.indexOf('Y')],10);}
else{var date=new Date();this._currentDay=date.getDate();this._currentMonth=date.getMonth();this._currentYear=date.getFullYear();}
this._selectedDay=this._currentDay;this._selectedMonth=this._currentMonth;this._selectedYear=this._currentYear;this._adjustDate();},_setDate:function(date){this._selectedDay=this._currentDay=date.getDate();this._selectedMonth=this._currentMonth=date.getMonth();this._selectedYear=this._currentYear=date.getFullYear();this._adjustDate();},_getDate:function(){return new Date(this._currentYear,this._currentMonth,this._currentDay);},_generateCalendar:function(){var today=this._currentDate;today=new Date(today.getFullYear(),today.getMonth(),today.getDate());var controls='<div class="calendar_control">'+'<a class="calendar_clear" onclick="popUpCal._clearDate('+this._id+');">'+
this._get('clearText')+'</a>'+'<a class="calendar_close" onclick="popUpCal.hideCalendar('+this._id+');">'+
this._get('closeText')+'</a></div>';var prompt=this._get('prompt');var closeAtTop=this._get('closeAtTop');var hideIfNoPrevNext=this._get('hideIfNoPrevNext');var html=(prompt?'<div class="calendar_prompt">'+prompt+'</div>':'')+
(closeAtTop&&!this._inline?controls:'')+'<div class="calendar_links">'+
(this._canAdjustMonth(-1)?'<a class="calendar_prev" '+'onclick="popUpCal._adjustDate('+this._id+', -1, \'M\');">'+this._get('prevText')+'</a>':(hideIfNoPrevNext?'':'<label class="calendar_prev">'+this._get('prevText')+'</label>'))+
(this._isInRange(today)?'<a class="calendar_current" '+'onclick="popUpCal._gotoToday('+this._id+');">'+this._get('currentText')+'</a>':'')+
(this._canAdjustMonth(+1)?'<a class="calendar_next" '+'onclick="popUpCal._adjustDate('+this._id+', +1, \'M\');">'+this._get('nextText')+'</a>':(hideIfNoPrevNext?'':'<label class="calendar_next">'+this._get('nextText')+'</label>'))+'</div><div class="calendar_header">';var minDate=this._get('minDate');var maxDate=this._get('maxDate');var monthNames=this._get('monthNames');if(!this._get('changeMonth')){html+=monthNames[this._selectedMonth]+'&nbsp;';}
else{var inMinYear=(minDate&&minDate.getFullYear()==this._selectedYear);var inMaxYear=(maxDate&&maxDate.getFullYear()==this._selectedYear);html+='<select class="calendar_newMonth" '+'onchange="popUpCal._selectMonthYear('+this._id+', this, \'M\');" '+'onclick="popUpCal._clickMonthYear('+this._id+');">';for(var month=0;month<12;month++){if((!inMinYear||month>=minDate.getMonth())&&(!inMaxYear||month<=maxDate.getMonth())){html+='<option value="'+month+'"'+
(month==this._selectedMonth?' selected="selected"':'')+'>'+monthNames[month]+'</option>';}}
html+='</select>';}
if(!this._get('changeYear')){html+=this._selectedYear;}
else{var years=this._get('yearRange').split(':');var year=0;var endYear=0;if(years.length!=2){year=this._selectedYear-10;endYear=this._selectedYear+10;}
else if(years[0].charAt(0)=='+'||years[0].charAt(0)=='-'){year=this._selectedYear+parseInt(years[0],10);endYear=this._selectedYear+parseInt(years[1],10);}
else{year=parseInt(years[0],10);endYear=parseInt(years[1],10);}
year=(minDate?Math.max(year,minDate.getFullYear()):year);endYear=(maxDate?Math.min(endYear,maxDate.getFullYear()):endYear);html+='<select class="calendar_newYear" onchange="popUpCal._selectMonthYear('+
this._id+', this, \'Y\');" '+'onclick="popUpCal._clickMonthYear('+
this._id+');">';for(;year<=endYear;year++){html+='<option value="'+year+'"'+
(year==this._selectedYear?' selected="selected"':'')+'>'+year+'</option>';}
html+='</select>';}
html+='</div><table class="calendar" cellpadding="0" cellspacing="0"><thead>'+'<tr class="calendar_titleRow">';var firstDay=this._get('firstDay');var changeFirstDay=this._get('changeFirstDay');var dayNames=this._get('dayNames');for(var dow=0;dow<7;dow++){html+='<td>'+(!changeFirstDay?'':'<a onclick="popUpCal._changeFirstDay('+
this._id+', this);">')+dayNames[(dow+firstDay)%7]+
(changeFirstDay?'</a>':'')+'</td>';}
html+='</tr></thead><tbody>';var daysInMonth=this._getDaysInMonth(this._selectedYear,this._selectedMonth);this._selectedDay=Math.min(this._selectedDay,daysInMonth);var leadDays=(this._getFirstDayOfMonth(this._selectedYear,this._selectedMonth)-firstDay+7)%7;var currentDate=new Date(this._currentYear,this._currentMonth,this._currentDay);var selectedDate=new Date(this._selectedYear,this._selectedMonth,this._selectedDay);var printDate=new Date(this._selectedYear,this._selectedMonth,1-leadDays);var numRows=Math.ceil((leadDays+daysInMonth)/7);var customDate=this._get('customDate');var showOtherMonths=this._get('showOtherMonths');for(var row=0;row<numRows;row++){html+='<tr class="calendar_daysRow">';for(var dow=0;dow<7;dow++){var customSettings=(customDate?customDate(printDate):[true,'']);var otherMonth=(printDate.getMonth()!=this._selectedMonth);var unselectable=otherMonth||!customSettings[0]||(minDate&&printDate<minDate)||(maxDate&&printDate>maxDate);html+='<td class="calendar_daysCell'+
((dow+firstDay+6)%7>=5?' calendar_weekEndCell':'')+
(otherMonth?' calendar_otherMonth':'')+
(unselectable?' calendar_unselectable':'')+
(!otherMonth||showOtherMonths?' '+customSettings[1]:'')+
(printDate.getTime()==currentDate.getTime()?' calendar_currentDay':(printDate.getTime()==today.getTime()?' calendar_today':''))+'"'+
(unselectable?'':' onmouseover="$(this).addClass(\'calendar_daysCellOver\');"'+' onmouseout="$(this).removeClass(\'calendar_daysCellOver\');"'+' onclick="popUpCal._selectDay('+this._id+', this);"')+'>'+
(otherMonth?(showOtherMonths?printDate.getDate():'&nbsp;'):(unselectable?printDate.getDate():'<a>'+printDate.getDate()+'</a>'))+'</td>';printDate.setDate(printDate.getDate()+1);}
html+='</tr>';}
html+='</tbody></table>'+(!closeAtTop&&!this._inline?controls:'')+'<div style="clear: both;"></div>'+(!$.browser.msie?'':'<!--[if lte IE 6.5]><iframe src="javascript:false;" class="calendar_cover"></iframe><![endif]-->');return html;},_adjustDate:function(offset,period){var date=new Date(this._selectedYear+(period=='Y'?offset:0),this._selectedMonth+(period=='M'?offset:0),this._selectedDay+(period=='D'?offset:0));var minDate=this._get('minDate');var maxDate=this._get('maxDate');date=(minDate&&date<minDate?minDate:date);date=(maxDate&&date>maxDate?maxDate:date);this._selectedDay=date.getDate();this._selectedMonth=date.getMonth();this._selectedYear=date.getFullYear();},_getDaysInMonth:function(year,month){return 32-new Date(year,month,32).getDate();},_getFirstDayOfMonth:function(year,month){return new Date(year,month,1).getDay();},_canAdjustMonth:function(offset){var date=new Date(this._selectedYear,this._selectedMonth+offset,1);if(offset<0){date.setDate(this._getDaysInMonth(date.getFullYear(),date.getMonth()));}
return this._isInRange(date);},_isInRange:function(date){var minDate=this._get('minDate');var maxDate=this._get('maxDate');return((!minDate||date>=minDate)&&(!maxDate||date<=maxDate));},_formatDate:function(){var day=this._currentDay=this._selectedDay;var month=this._currentMonth=this._selectedMonth;var year=this._currentYear=this._selectedYear;month++;var dateFormat=this._get('dateFormat');var dateString='';for(var i=0;i<3;i++){dateString+=dateFormat.charAt(3)+
(dateFormat.charAt(i)=='D'?(day<10?'0':'')+day:(dateFormat.charAt(i)=='M'?(month<10?'0':'')+month:(dateFormat.charAt(i)=='Y'?year:'?')));}
return dateString.substring(dateFormat.charAt(3)?1:0);}});$.fn.calendar=function(settings,defaultDate){return this.each(function(){var inlineSettings=null;for(attrName in popUpCal._defaults){var attrValue=this.getAttribute('cal:'+attrName);if(attrValue){inlineSettings=inlineSettings||{};try{inlineSettings[attrName]=eval(attrValue);}
catch(err){inlineSettings[attrName]=attrValue;}}}
var nodeName=this.nodeName.toLowerCase();if(nodeName=='input'){var instSettings=(inlineSettings?$.extend($.extend({},settings||{}),inlineSettings||{}):settings);var inst=(inst&&!inlineSettings?inst:new PopUpCalInstance(instSettings,false,defaultDate));popUpCal._connectCalendar(this,inst);}
else if(nodeName=='div'||nodeName=='span'){var instSettings=$.extend($.extend({},settings||{}),inlineSettings||{});var inst=new PopUpCalInstance(instSettings,true,defaultDate);popUpCal._inlineCalendar(this,inst,defaultDate);}});};$(document).ready(function(){popUpCal=new PopUpCal();});