SP/web2py/applications/admin/static/js/calendar.js

43 lines
44 KiB
JavaScript
Raw Permalink Normal View History

2018-10-25 15:33:07 +00:00
/* Copyright Notice for Dynarch Date Time Picker */
/* Copyright Mihai Bazon, 2002-2005 | www.bazon.net/mishoo
* -----------------------------------------------------------
*
* The DHTML Calendar, version 1.0 "It is happening again"
*
* Details and latest version at:
* www.dynarch.com/projects/calendar
*
* This script is developed by Dynarch.com. Visit us at www.dynarch.com.
*
* This script is distributed under the GNU Lesser General Public License.
* Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
*/
// Calendar EN language
// Author: Mihai Bazon, <mihai_bazon@yahoo.com>
// Encoding: any
// Distributed under the same terms as the calendar itself.
/* End Copyright Notice for Dynarch Date Time Picker */
Calendar=function(J,K,H,G){this.activeDiv=null;this.currentDateEl=null;this.getDateStatus=null;this.getDateToolTip=null;this.getDateText=null;this.timeout=null;this.onSelected=H||null;this.onClose=G||null;this.dragging=false;this.hidden=false;this.minYear=1970;this.maxYear=2050;this.dateFormat=Calendar._TT.DEF_DATE_FORMAT;this.ttDateFormat=Calendar._TT.TT_DATE_FORMAT;this.isPopup=true;this.weekNumbers=true;this.firstDayOfWeek=typeof J=="number"?J:Calendar._FD;this.showsOtherMonths=false;this.dateStr=K;this.ar_days=null;this.showsTime=false;this.time24=true;this.yearStep=2;this.hiliteToday=true;this.multiple=null;this.table=null;this.element=null;this.tbody=null;this.firstdayname=null;this.monthsCombo=null;this.yearsCombo=null;this.hilitedMonth=null;this.activeMonth=null;this.hilitedYear=null;this.activeYear=null;this.dateClicked=false;if(typeof Calendar._SDN=="undefined"){if(typeof Calendar._SDN_len=="undefined"){Calendar._SDN_len=3}var L=new Array();for(var I=8;I>0;){L[--I]=Calendar._DN[I].substr(0,Calendar._SDN_len)}Calendar._SDN=L;if(typeof Calendar._SMN_len=="undefined"){Calendar._SMN_len=3}L=new Array();for(var I=12;I>0;){L[--I]=Calendar._MN[I].substr(0,Calendar._SMN_len)}Calendar._SMN=L}};Calendar._C=null;Calendar.is_ie=(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent));Calendar.is_ie5=(Calendar.is_ie&&/msie 5\.0/i.test(navigator.userAgent));Calendar.is_opera=/opera/i.test(navigator.userAgent);Calendar.is_khtml=/Konqueror|Safari|KHTML/i.test(navigator.userAgent);Calendar.getAbsolutePos=function(I){var G=0,J=0;var K=/^div$/i.test(I.tagName);if(K&&I.scrollLeft){G=I.scrollLeft}if(K&&I.scrollTop){J=I.scrollTop}var H={x:I.offsetLeft-G,y:I.offsetTop-J};if(I.offsetParent){var L=this.getAbsolutePos(I.offsetParent);H.x+=L.x;H.y+=L.y}return H};Calendar.isRelated=function(G,E){var F=E.relatedTarget;if(!F){var H=E.type;if(H=="mouseover"){F=E.fromElement}else{if(H=="mouseout"){F=E.toElement}}}while(F){if(F==G){return true}F=F.parentNode}return false};Calendar.removeClass=function(G,H){if(!(G&&G.className)){return }var F=G.className.split(" ");var J=new Array();for(var I=F.length;I>0;){if(F[--I]!=H){J[J.length]=F[I]}}G.className=J.join(" ")};Calendar.addClass=function(D,C){Calendar.removeClass(D,C);D.className+=" "+C};Calendar.getElement=function(C){var D=Calendar.is_ie?window.event.srcElement:C.currentTarget;while(D.nodeType!=1||/^div$/i.test(D.tagName)){D=D.parentNode}return D};Calendar.getTargetElement=function(C){var D=Calendar.is_ie?window.event.srcElement:C.target;while(D.nodeType!=1){D=D.parentNode}return D};Calendar.stopEvent=function(B){B||(B=window.event);if(Calendar.is_ie){B.cancelBubble=true;B.returnValue=false}else{B.preventDefault();B.stopPropagation()}return false};Calendar.addEvent=function(D,E,F){if(D.attachEvent){D.attachEvent("on"+E,F)}else{if(D.addEventListener){D.addEventListener(E,F,true)}else{D["on"+E]=F}}};Calendar.removeEvent=function(D,E,F){if(D.detachEvent){D.detachEvent("on"+E,F)}else{if(D.removeEventListener){D.removeEventListener(E,F,true)}else{D["on"+E]=null}}};Calendar.createElement=function(E,F){var D=null;if(document.createElementNS){D=document.createElementNS("http://www.w3.org/1999/xhtml",E)}else{D=document.createElement(E)}if(typeof F!="undefined"){F.appendChild(D)}return D};Calendar._add_evs=function(el){with(Calendar){addEvent(el,"mouseover",dayMouseOver);addEvent(el,"mousedown",dayMouseDown);addEvent(el,"mouseout",dayMouseOut);if(is_ie){addEvent(el,"dblclick",dayMouseDblClick);el.setAttribute("unselectable",true)}}};Calendar.findMonth=function(B){if(typeof B.month!="undefined"){return B}else{if(typeof B.parentNode.month!="undefined"){return B.parentNode}}return null};Calendar.findYear=function(B){if(typeof B.year!="undefined"){return B}else{if(typeof B.parentNode.year!="undefined"){return B.parentNode}}return null};Calendar.showMonthsCombo=function(){var I=Calendar._C;if(!I){return false}var I=I;var H=I.activeDiv;var J=I.monthsCombo;if(I.hilitedMonth){Calendar.removeClass(I.hilitedMonth,"hilite")}if(I.activeMonth){Calendar.removeClass(I.activeMonth,"active")}var K=I.
/*
http://keith-wood.name/timeEntry.html
Time entry for jQuery v1.4.8.
Written by Keith Wood (kbwood{at}iinet.com.au) June 2007.
Minor changes by Massimo Di Pierro Nov 2010 (simplified and changed behavior)
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
Please attribute the author if you use it.
Turn an input field into an entry point for a time value.
The time can be entered via directly typing the value,
via the arrow keys.
It is configurable to show 12 or 24-hour time, to show or hide seconds,
to enforce a minimum and/or maximum time, to change the spinner image.
Example: jQuery('input.time').timeEntry();
*/
(function(a){var d=12,k="ampmNames",i="show24Hours",m="showSeconds",l="character",b=10,f=false,j="string",e=-1,c=null,h=true,g="timeEntry";function o(){this._disabledInputs=[];this._defaults={showSeconds:h,defaultTime:c,minTime:c,maxTime:c,show24Hours:h,ampmNames:["am","pm"]};a.extend(this._defaults)}a.extend(o.prototype,{markerClassName:"hasTimeEntry",setDefaults:function(a){n(this._defaults,a||{});return this},_connectTimeEntry:function(e,f){var c=this,d=a(e);if(d.hasClass(c.markerClassName))return;var b={};b.options=a.extend({},f);b._selectedHour=0;b._selectedMinute=0;b._selectedSecond=0;b._field=0;b.input=a(e);a.data(e,g,b);d.addClass(c.markerClassName).bind("focus.timeEntry",c._doFocus).bind("blur.timeEntry",c._doBlur).bind("click.timeEntry",c._doClick).bind("keydown.timeEntry",c._doKeyDown).bind("keypress.timeEntry",c._doKeyPress);a.browser.mozilla&&d.bind("input.timeEntry",function(){a.timeEntry._parseTime(b)});a.browser.msie&&d.bind("paste.timeEntry",function(){setTimeout(function(){a.timeEntry._parseTime(b)},1)})},_isDisabledTimeEntry:function(b){return a.inArray(b,this._disabledInputs)>e},_changeTimeEntry:function(e,b,f){var c=a.data(e,g);if(c){if(typeof b==j){var h=b;b={};b[h]=f}var d=this._extractTime(c);n(c.options,b||{});d&&this._setTime(c,new Date(0,0,0,d[0],d[1],d[2]))}a.data(e,g,c)},_destroyTimeEntry:function(d){var b=this;jQueryinput=a(d);if(!jQueryinput.hasClass(b.markerClassName))return;jQueryinput.removeClass(b.markerClassName).unbind(".timeEntry");b._disabledInputs=a.map(b._disabledInputs,function(a){return a==d?c:a});jQueryinput.parent().replaceWith(jQueryinput);a.removeData(d,g)},_setTimeTimeEntry:function(e,b){var d=a.data(e,g);d&&this._setTime(d,b?typeof b=="object"?new Date(b.getTime()):b:c)},_getTimeTimeEntry:function(e){var d=a.data(e,g),b=d?this._extractTime(d):c;return !b?c:new Date(0,0,0,b[0],b[1],b[2])},_getOffsetTimeEntry:function(e){var d=a.data(e,g),b=d?this._extractTime(d):c;return !b?0:(b[0]*3600+b[1]*60+b[2])*1e3},_doFocus:function(e){var d=e.nodeName&&e.nodeName.toLowerCase()=="input"?e:this;if(a.timeEntry._lastInput==d||a.timeEntry._isDisabledTimeEntry(d)){a.timeEntry._focussed=f;return}var i=a.data(d,g);a.timeEntry._focussed=h;a.timeEntry._lastInput=d;a.timeEntry._blurredInput=c;a.data(d,g,i);a.timeEntry._parseTime(i);setTimeout(function(){a.timeEntry._showField(i)},b)},_doBlur:function(){a.timeEntry._blurredInput=a.timeEntry._lastInput;a.timeEntry._lastInput=c},_doClick:function(k){var h=k.target,d=a.data(h,g);if(!a.timeEntry._focussed){var i=3;d._field=0;if(h.selectionStart!=c)for(var e=0;e<=Math.max(1,d._secondField,d._ampmField);e++){var m=e!=d._ampmField?e*i+2:d._ampmField*i+2;d._field=e;if(h.selectionStart<m)break}else if(h.createTextRange)for(var n=a(k.srcElement),j=h.createTextRange(),o=function(a){return ({thin:2,medium:4,thick:6})[a]||a},p=k.clientX+document.documentElement.scrollLeft-(n.offset().left+parseInt(o(n.css("border-left-width")),b))-j.offsetLeft,e=0;e<=Math.max(1,d._secondField,d._ampmField);e++){var m=e!=d._ampmField?e*i+2:d._ampmField*i+2;j.collapse();j.moveEnd(l,m);d._field=e;if(p<j.boundingWidth)break}}a.data(h,g,d);a.timeEntry._showField(d);a.timeEntry._focussed=f},_doKeyDown:function(c){if(c.keyCode>=48)return h;var b=a.data(c.target,g);switch(c.keyCode){case 9:var d=a(":input");d.eq(d.index(this)+(c.shiftKey?e:+1)).focus();break;case 37:a.timeEntry._changeField(b,e,f);break;case 38:a.timeEntry._adjustField(b,e);break;case 16:!c.shiftKey&&a.timeEntry._changeField(b,+1,f);break;case 39:a.timeEntry._changeField(b,+1,f);break;case 40:a.timeEntry._adjustField(b,+1);break;case 32:case 46:a.timeEntry._setValue(b,"")}return f},_doKeyPress:function(b){var c=String.fromCharCode(b.charCode==undefined?b.keyCode:b.charCode);if(c<" ")return h;var d=a.data(b.target,g);a.timeEntry._handleKeyPress(d,c);return f},_get:function(d,b){return d.options[b]!=c?d.options[b]:a.timeEntry._defaults[b]},_parseTime:function(a){var b=this,c=b._extractTime(a),d=b._get(a,m);if(c){a._selectedHour=c[0];a._selectedMinute=c[1];a._selectedSecond=c[2]}else{var f=b._constrainTime(a);a._sele