{"size": 9404, "ext": "js", "max_stars_repo_path": "static/scripts/web2py/timeentry.js", "max_stars_repo_name": "flavour/lacity", "max_stars_repo_stars_event_min_datetime": "2016-12-22T09:31:22.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-22T09:31:22.000Z", "max_issues_repo_path": "static/scripts/web2py/timeentry.js", "max_issues_repo_name": "flavour/lacity", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/scripts/web2py/timeentry.js", "max_forks_repo_name": "flavour/lacity", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 494.9473684211, "max_line_length": 8619, "alphanum_fraction": 0.7150148873}
/*
   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._selectedHour=f[0];a._selectedMinute=f[1];a._selectedSecond=d?f[2]:0}a._secondField=d?2:e;a._ampmField=b._get(a,i)?e:d?3:2;a._lastChr="";a._field=Math.max(0,Math.min(Math.max(1,a._secondField,a._ampmField),0));a.input.val()!=""&&b._showTime(a)},_extractTime:function(h,g){var n=this;g=g||h.input.val();var f=g.split(":"),p=n._get(h,k),o=n._get(h,i);if(f.length>=2){var r=!o&&g.indexOf(p[0])>e,q=!o&&g.indexOf(p[1])>e,a=parseInt(f[0],b);a=isNaN(a)?0:a;a=((r||q)&&a==d?0:a)+(q?d:0);var j=parseInt(f[1],b);j=isNaN(j)?0:j;var l=f.length>=3?parseInt(f[2],b):0;l=isNaN(l)||!n._get(h,m)?0:l;return n._constrainTime(h,[a,j,l])}return c},_constrainTime:function(d,a){var e=a!=c;if(!e){var b=this._determineTime(d,this._get(d,"defaultTime"))||new Date;a=[b.getHours(),b.getMinutes(),b.getSeconds()]}return a},_showTime:function(a){var b=this,c=b._get(a,i),e=b._formatNumber(c?a._selectedHour:(a._selectedHour+11)%d+1)+":"+b._formatNumber(a._selectedMinute)+(b._get(a,m)?":"+b._formatNumber(a._selectedSecond):"")+(c?"":b._get(a,k)[a._selectedHour<d?0:1]);b._setValue(a,e);b._showField(a)},_showField:function(b){var c=b.input[0];if(b.input.is(":hidden")||a.timeEntry._lastInput!=c)return;var f=3,e=b._field==b._ampmField?b._ampmField*f-1:b._field*f,g=e+(b._field==b._ampmField?2:2);if(c.setSelectionRange)c.setSelectionRange(e,g);else if(c.createTextRange){var d=c.createTextRange();d.moveStart(l,e);d.moveEnd(l,g-b.input.val().length);d.select()}!c.disabled&&c.focus()},_formatNumber:function(a){return (a<b?"0":"")+a},_setValue:function(b,a){a!=b.input.val()&&b.input.val(a).trigger("change")},_changeField:function(b,d,f){var c=b.input.val()==""||b._field==(d==e?0:Math.max(1,b._secondField,b._ampmField));if(!c)b._field+=d;this._showField(b);b._lastChr="";a.data(b.input[0],g,b);return c&&f},_adjustField:function(a,b){if(a.input.val()=="")b=0;this._setTime(a,new Date(0,0,0,a._selectedHour+(a._field==0?b:0)+(a._field==a._ampmField?b*d:0),a._selectedMinute+(a._field==1?b:0),a._selectedSecond+(a._field==a._secondField?b:0)))},_setTime:function(d,b){var e=this;b=e._determineTime(d,b);var i=e._constrainTime(d,b?[b.getHours(),b.getMinutes(),b.getSeconds()]:c);b=new Date(0,0,0,i[0],i[1],i[2]);var b=e._normaliseTime(b),h=e._normaliseTime(e._determineTime(d,e._get(d,"minTime"))),f=e._normaliseTime(e._determineTime(d,e._get(d,"maxTime")));b=h&&b<h?h:f&&b>f?f:b;d._selectedHour=b.getHours();d._selectedMinute=b.getMinutes();d._selectedSecond=b.getSeconds();e._showTime(d);a.data(d.input[0],g,d)},_normaliseTime:function(a){if(!a)return c;a.setFullYear(1900);a.setMonth(0);a.setDate(0);return a},_determineTime:function(g,d){var e=function(b){var a=new Date;a.setTime(a.getTime()+b*1e3);return a},f=function(f){var d=a.timeEntry._extractTime(g,f),c=new Date,k=d?d[0]:c.getHours(),i=d?d[1]:c.getMinutes(),j=d?d[2]:c.getSeconds();if(!d){var h=/([+-]?[0-9]+)\s*(s|S|m|M|h|H)?/g,e=h.exec(f);while(e){switch(e[2]||"s"){case "s":case "S":j+=parseInt(e[1],b);break;case "m":case "M":i+=parseInt(e[1],b);break;case "h":case "H":k+=parseInt(e[1],b)}e=h.exec(f)}}c=new Date(0,0,b,k,i,j,0);if(/^!/.test(f))if(c.getDate()>b)c=new Date(0,0,b,23,59,59);else if(c.getDate()<b)c=new Date(0,0,b,0,0,0);return c};return d?typeof d==j?f(d):typeof d=="number"?e(d):d:c},_handleKeyPress:function(a,c){var g=this;if(c==":")g._changeField(a,+1,f);else if(c>="0"&&c<="9"){var h=parseInt(c,b),e=parseInt(a._lastChr+c,b),m=g._get(a,i),q=a._field!=0?a._selectedHour:m?e<24?e:h:(e>=1&&e<=d?e:h>0?h:a._selectedHour)%d+(a._selectedHour>=d?d:0),o=a._field!=1?a._selectedMinute:e<60?e:h,p=a._field!=a._secondField?a._selectedSecond:e<60?e:h,j=g._constrainTime(a,[q,o,p]);g._setTime(a,new Date(0,0,0,j[0],j[1],j[2]));a._lastChr=c}else if(!g._get(a,i)){c=c.toLowerCase();var l=g._get(a,k);if(c==l[0].substring(0,1).toLowerCase()&&a._selectedHour>=d||c==l[1].substring(0,1).toLowerCase()&&a._selectedHour<d){var n=a._field;a._field=a._ampmField;g._adjustField(a,+1);a._field=n;g._showField(a)}}}});function n(b,d){a.extend(b,d);for(var e in d)if(d[e]==c)b[e]=c;return b}var p=["getOffset","getTime","isDisabled"];a.fn.timeEntry=function(b){var c="TimeEntry",d=Array.prototype.slice.call(arguments,1);if(typeof b==j&&a.inArray(b,p)>e)return a.timeEntry["_"+b+c].apply(a.timeEntry,[this[0]].concat(d));return this.each(function(){var e=this,g=e.nodeName.toLowerCase();if(g=="input")if(typeof b==j)a.timeEntry["_"+b+c].apply(a.timeEntry,[e].concat(d));else{var f=a.fn.metadata?a(e).metadata():{};a.timeEntry._connectTimeEntry(e,a.extend(f,b))}})};a.timeEntry=new o})(jQuery)