/* Month and Year picker for jQuery UI Datepicker 1.8.21 Written by Anton Ludescher (silverskater{at}gmail.com). 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. */ if (datepicker == undefined){ var datepicker_fn = $.fn.datepicker var datepicker = $.datepicker } (function($, undefined ) { //overriding functions meant to be private (starting with an underscore) $.ui_datepicker = datepicker $.fn.ui_datepicker = datepicker_fn $.ui_datepicker._updateDatepicker_MonthYearPicker = $.ui_datepicker._updateDatepicker; $.ui_datepicker._showDatepicker_MonthYearPicker = $.ui_datepicker._showDatepicker; $.ui_datepicker._doKeyDown_MonthYearPicker = $.ui_datepicker._doKeyDown; $.extend($.ui_datepicker, { _doKeyDown: function(event) { var inst = $.ui_datepicker._getInst(event.target); var handled = true; //var isRTL = inst.dpDiv.is('.ui-datepicker-rtl'); inst._keyEvent = true; if ($.ui_datepicker._datepickerShowing) { switch (event.keyCode) { case 27: if($('.ui-datepicker-select-month').is(':visible')) { $.ui_datepicker._updateDatepicker(inst); } else if($('.ui-datepicker-select-year').is(':visible')) { $.ui_datepicker._toggleDisplay_MonthYearPicker(inst, 2, this); } else { $.ui_datepicker._hideDatepicker(); } break; // hide on escape //TODO prev/next month/year on month/year picker screens default: //call the original function $.ui_datepicker._doKeyDown_MonthYearPicker(event); } } else { //call the original function $.ui_datepicker._doKeyDown_MonthYearPicker(event); } }, _updateDatepicker: function(inst) { //call the original function if (this._get(inst, 'show_view') == 'year' && !$('.ui-datepicker-select-year').is(':visible')){ var current_format = this._get(inst, 'dateFormat') var regex = /\W/, indice = 0; var result = current_format.split(/\W/) for (var i=0;i').append(this.dpDiv.clone()).html()); var uidptitle = inst.dpDiv.find('.ui-datepicker-title'); var uidptitle_link = uidptitle.wrapInner(''); uidptitle_link.click(function(){$.ui_datepicker.select_month = false;$.ui_datepicker._toggleDisplay_MonthYearPicker('#' + inst.id, 2); return false;}); inst.dpDiv.children('table.ui-datepicker-calendar').after(this._generateExtraHTML_MonthYearPicker(inst)); if (!$('.ui-datepicker-select-year').is(':visible') && !$('.ui-datepicker-select-month').is(':visible')){ if (this._get(inst, 'show_view') == 'month') { this._toggleDisplay_MonthYearPicker('#' + inst.id,2) }else if (this._get(inst, 'show_view') == 'year'){ this._toggleDisplay_MonthYearPicker('#' + inst.id,3) } } this._reposition_MonthYearPicker(inst); }, //focus the date input field _instInputFocus_MYP: function(inst) { //code copied from datePicker's _updateDatepicker() if (inst == $.ui_datepicker._curInst && $.ui_datepicker._datepickerShowing && inst.input && // #6694 - don't focus the input if it's already focused // this breaks the change event in IE inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement) inst.input.focus(); }, _generateMonthPickerHTML_MonthYearPicker: function(inst, minDate, maxDate, drawMonth, inMinYear, inMaxYear) { //TODO RTL? var monthNamesShort = this._get(inst, 'monthNamesShort'); var monthPicker = ''; var unselectable = false; for (var month = 0; month < 12; ) { unselectable = (inMinYear && month < minDate.getMonth()) || (inMaxYear && month > maxDate.getMonth()); monthPicker += ''; // display selectable date if(++month % 4 === 0) { monthPicker += ''; if(month != 12) { monthPicker += ''; } } } monthPicker += '
' + // actions ((unselectable ? '' + monthNamesShort[month] + '' : '' + monthNamesShort[month] + '')) + '
'; return monthPicker; }, _generateExtraHTML_MonthYearPicker: function(inst,show_view) { if (show_view != 'year'){ var minDate = this._getMinMaxDate(inst, 'min'); var maxDate = this._getMinMaxDate(inst, 'max'); var drawYear = inst.drawYear; var drawMonth = inst.drawMonth; var inMinYear = (minDate && minDate.getFullYear() == drawYear); var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear); var monthPicker = this._generateMonthPickerHTML_MonthYearPicker(inst, minDate, maxDate, drawMonth, inMinYear, inMaxYear); if (show_view != 'month'){ return '' + ''; //yearPicker gets filled dinamically } else{ return '
' + monthPicker + '
' + ''; } } else{ return '' + '
'; } }, _pickMonthYear_MonthYearPicker: function(id, valueMY, period) { var dummySelect = $(''; // Create the markup for (i = 0, l = this.units.length; i < l; i++) { litem = this.units[i]; uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; // Added by Peter Medeiros: // - Figure out what the hour/minute/second max should be based on the step values. // - Example: if stepMinute is 15, then minMax is 45. max[litem] = parseInt((o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10); gridSize[litem] = 0; html += '
' + o[litem + 'Text'] + '
' + '
'; if (show && o[litem + 'Grid'] > 0) { html += '
'; if (litem === 'hour') { for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) { gridSize[litem]++; var tmph = $.ui_datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o); html += ''; } } else { for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) { gridSize[litem]++; html += ''; } } html += '
' + tmph + '' + ((m < 10) ? '0' : '') + m + '
'; } html += '
'; } // Timezone var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; html += '
' + o.timezoneText + '
'; html += '
'; // Create the elements from string html += ''; var $tp = $(html); // if we only want time picker... if (o.timeOnly === true) { $tp.prepend('
' + '
' + o.timeOnlyTitle + '
' + '
'); $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); } // add sliders, adjust grids, add events for (i = 0, l = tp_inst.units.length; i < l; i++) { litem = tp_inst.units[i]; uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1); show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem]; // add the slider tp_inst[litem + '_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_' + litem + '_slider'), litem, tp_inst[litem], o[litem + 'Min'], max[litem], o['step' + uitem]); // adjust the grid and add click event if (show && o[litem + 'Grid'] > 0) { size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']); $tp.find('.ui_tpicker_' + litem + ' table').css({ width: size + "%", marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', borderCollapse: 'collapse' }).find("td").click(function (e) { var $t = $(this), h = $t.html(), n = parseInt(h.replace(/[^0-9]/g), 10), ap = h.replace(/[^apm]/ig), f = $t.data('for'); // loses scope, so we use data-for if (f === 'hour') { if (ap.indexOf('p') !== -1 && n < 12) { n += 12; } else { if (ap.indexOf('a') !== -1 && n === 12) { n = 0; } } } tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n); tp_inst._onTimeChange(); tp_inst._onSelectHandler(); }).css({ cursor: 'pointer', width: (100 / gridSize[litem]) + '%', textAlign: 'center', overflow: 'hidden' }); } // end if grid > 0 } // end for loop // Add timezone options this.timezone_select = $tp.find('.ui_tpicker_timezone').append('').find("select"); $.fn.append.apply(this.timezone_select, $.map(o.timezoneList, function (val, idx) { return $("