[debian] cubicweb works with python 2.7 (which become the standard on some distros). Closes #2142050
/* * A time picker for jQuery * Based on original timePicker by Sam Collet (http://www.texotela.co.uk) - * copyright (c) 2006 Sam Collett (http://www.texotela.co.uk) * * Dual licensed under the MIT and GPL licenses. * Copyright (c) 2010 Anders Fajerson * @name timePicker * @version 0.2 * @author Anders Fajerson (http://perifer.se) * @example $("#mytime").timePicker(); * @example $("#mytime").timePicker({step:30, startTime:"15:00", endTime:"18:00"}); */(function($){$.fn.timePicker=function(options){// Build main options before element iterationvarsettings=$.extend({},$.fn.timePicker.defaults,options);returnthis.each(function(){$.timePicker(this,settings);});};$.timePicker=function(elm,settings){vare=$(elm)[0];returne.timePicker||(e.timePicker=newjQuery._timePicker(e,settings));};$._timePicker=function(elm,settings){vartpOver=false;varkeyDown=false;varstartTime=timeToDate(settings.startTime,settings);varendTime=timeToDate(settings.endTime,settings);$(elm).attr('autocomplete','OFF');// Disable browser autocompletevartimes=[];vartime=newDate(startTime);// Create a new date object.while(time<=endTime){times[times.length]=formatTime(time,settings);time=newDate(time.setMinutes(time.getMinutes()+settings.step));}var$tpDiv=$('<div class="time-picker'+(settings.show24Hours?'':' time-picker-12hours')+'"></div>');var$tpList=$('<ul></ul>');// Build the list.for(vari=0;i<times.length;i++){if(times[i]==settings.selectedTime){$tpList.append('<li class="selected">'+times[i]+"</li>");}else{$tpList.append("<li>"+times[i]+"</li>");}}$tpDiv.append($tpList);// Append the timPicker to the body and position it.varelmOffset=$(elm).offset();$tpDiv.appendTo('body').css({'top':elmOffset.top+20,'left':elmOffset.left}).hide();// Store the mouse state, used by the blur event. Use mouseover instead of// mousedown since Opera fires blur before mousedown.$tpDiv.mouseover(function(){tpOver=true;}).mouseout(function(){tpOver=false;});$("li",$tpList).mouseover(function(){if(!keyDown){$("li.selected",$tpDiv).removeClass("selected");$(this).addClass("selected");}}).mousedown(function(){tpOver=true;}).click(function(){setTimeVal(elm,this,$tpDiv,settings);tpOver=false;});varshowPicker=function(){if($tpDiv.is(":visible")){returnfalse;}$("li",$tpDiv).removeClass("selected");// Show picker. This has to be done before scrollTop is set since that// can't be done on hidden elements.$tpDiv.show();// Try to find a time in the list that matches the entered time.vartime=elm.value?timeStringToDate(elm.value,settings):startTime;varstartMin=startTime.getHours()*60+startTime.getMinutes();varmin=(time.getHours()*60+time.getMinutes())-startMin;varsteps=Math.round(min/settings.step);varroundTime=normaliseTime(newDate(0,0,0,0,(steps*settings.step+startMin),0));roundTime=(startTime<roundTime&&roundTime<=endTime)?roundTime:startTime;var$matchedTime=$("li:contains("+formatTime(roundTime,settings)+")",$tpDiv);if($matchedTime.length){$matchedTime.addClass("selected");// Scroll to matched time.$tpDiv[0].scrollTop=$matchedTime[0].offsetTop;}returntrue;};// Attach to click as well as focus so timePicker can be shown again when// clicking on the input when it already has focus.$(elm).focus(showPicker).click(showPicker);// Hide timepicker on blur$(elm).blur(function(){if(!tpOver){$tpDiv.hide();}});// Keypress doesn't repeat on Safari for non-text keys.// Keydown doesn't repeat on Firefox and Opera on Mac.// Using kepress for Opera and Firefox and keydown for the rest seems to// work with up/down/enter/esc.varevent=($.browser.opera||$.browser.mozilla)?'keypress':'keydown';$(elm)[event](function(e){var$selected;keyDown=true;vartop=$tpDiv[0].scrollTop;switch(e.keyCode){case38:// Up arrow.// Just show picker if it's hidden.if(showPicker()){returnfalse;};$selected=$("li.selected",$tpList);varprev=$selected.prev().addClass("selected")[0];if(prev){$selected.removeClass("selected");// Scroll item into view.if(prev.offsetTop<top){$tpDiv[0].scrollTop=top-prev.offsetHeight;}}else{// Loop to next item.$selected.removeClass("selected");prev=$("li:last",$tpList).addClass("selected")[0];$tpDiv[0].scrollTop=prev.offsetTop-prev.offsetHeight;}returnfalse;break;case40:// Down arrow, similar in behaviour to up arrow.if(showPicker()){returnfalse;};$selected=$("li.selected",$tpList);varnext=$selected.next().addClass("selected")[0];if(next){$selected.removeClass("selected");if(next.offsetTop+next.offsetHeight>top+$tpDiv[0].offsetHeight){$tpDiv[0].scrollTop=top+next.offsetHeight;}}else{$selected.removeClass("selected");next=$("li:first",$tpList).addClass("selected")[0];$tpDiv[0].scrollTop=0;}returnfalse;break;case13:// Enterif($tpDiv.is(":visible")){varsel=$("li.selected",$tpList)[0];setTimeVal(elm,sel,$tpDiv,settings);}returnfalse;break;case27:// Esc$tpDiv.hide();returnfalse;break;}returntrue;});$(elm).keyup(function(e){keyDown=false;});// Helper function to get an inputs current time as Date object.// Returns a Date object.this.getTime=function(){returntimeStringToDate(elm.value,settings);};// Helper function to set a time input.// Takes a Date object.this.setTime=function(time){elm.value=formatTime(normaliseTime(time),settings);// Trigger element's change events.$(elm).change();};};// End fn;// Plugin defaults.$.fn.timePicker.defaults={step:30,startTime:newDate(0,0,0,0,0,0),endTime:newDate(0,0,0,23,30,0),selectedTime:newDate(0,0,0,0,0,0),separator:':',show24Hours:true};// Private functions.functionsetTimeVal(elm,sel,$tpDiv,settings){// Update input fieldelm.value=$(sel).text();// Trigger element's change events.$(elm).change();// Keep focus for all but IE (which doesn't like it)if(!$.browser.msie){elm.focus();}// Hide picker$tpDiv.hide();}functionformatTime(time,settings){varh=time.getHours();varhours=settings.show24Hours?h:(((h+11)%12)+1);varminutes=time.getMinutes();returnformatNumber(hours)+settings.separator+formatNumber(minutes)+(settings.show24Hours?'':((h<12)?' AM':' PM'));}functionformatNumber(value){return(value<10?'0':'')+value;}functiontimeToDate(input,settings){return(typeofinput=='object')?normaliseTime(input):timeStringToDate(input,settings);}functiontimeStringToDate(input,settings){if(input){vararray=input.split(settings.separator);varhours=parseFloat(array[0]);varminutes=parseFloat(array[1]);// Convert AM/PM hour to 24-hour format.if(!settings.show24Hours){if(hours===12&&input.substr('AM')!==-1){hours=0;}elseif(hours!==12&&input.indexOf('PM')!==-1){hours+=12;}}vartime=newDate(0,0,0,hours,minutes,0);returnnormaliseTime(time);}returnnull;}/* Normalise time object to a common date. */functionnormaliseTime(time){time.setFullYear(2001);time.setMonth(0);time.setDate(0);returntime;}})(jQuery);