/* * jQuery Mobile Framework : plugin to provide a date and time picker. * Copyright (c) JTSage * CC 3.0 Attribution. May be relicensed without permission/notification. * https://github.com/jtsage/jquery-mobile-datebox */ (function($) { $.extend( $.mobile.datebox.prototype.options, { themeButton: 'a', themeInput: 'a', useSetButton: true, validHours: false, repButton: true }); $.extend( $.mobile.datebox.prototype, { _dbox_run: function() { var w = this; w.drag.didRun = true; w._offset(w.drag.target[0], w.drag.target[1], false); w._dbox_run_update(); w.runButton = setTimeout(function() {w._dbox_run();}, 150); }, _dbox_run_update: function() { var w = this, o = this.options; if ( o.mode === 'datebox' ) { w.d.intHTML.find('.ui-datebox-header').find('h4').text(w._formatter(w.__('headerFormat'), w.theDate)); } w.d.divIn.find('input').each(function () { switch ( $(this).jqmData('field') ) { case 'y': $(this).val(w.theDate.getFullYear()); break; case 'm': $(this).val(w.theDate.getMonth() + 1); break; case 'd': $(this).val(w.theDate.getDate()); break; case 'h': if ( w.__('timeFormat') === 12 ) { if ( w.theDate.getHours() > 12 ) { $(this).val(w.theDate.getHours()-12); break; } else if ( w.theDate.getHours() === 0 ) { $(this).val(12); break; } } $(this).val(w.theDate.getHours()); break; case 'i': $(this).val(w._zPad(w.theDate.getMinutes())); break; case 'M': $(this).val(w.__('monthsOfYearShort')[w.theDate.getMonth()]); break; case 'a': $(this).val((w.theDate.getHours() > 11)?w.__('meridiem')[1]:w.__('meridiem')[0]); break; } }); }, _dbox_vhour: function (delta) { var w = this, o = this.options, tmp, closeya = [25,0], closenay = [25,0]; if ( o.validHours === false ) { return true; } if ( $.inArray(w.theDate.getHours(), o.validHours) > -1 ) { return true; } tmp = w.theDate.getHours(); $.each(o.validHours, function(){ if ( ((tmp < this)?1:-1) === delta ) { if ( closeya[0] > Math.abs(this-tmp) ) { closeya = [Math.abs(this-tmp),parseInt(this,10)]; } } else { if ( closenay[0] > Math.abs(this-tmp) ) { closenay = [Math.abs(this-tmp),parseInt(this,10)]; } } }); if ( closeya[1] !== 0 ) { w.theDate.setHours(closeya[1]); } else { w.theDate.setHours(closenay[1]); } }, _dbox_enter: function (item) { var w = this; if ( item.jqmData('field') === 'M' && $.inArray(item.val(), w.__('monthsOfYearShort')) > -1 ) { w.theDate.setMonth($.inArray(item.val(), w.__('monthsOfYearShort'))); } if ( item.val() !== '' && item.val().toString().search(/^[0-9]+$/) === 0 ) { switch ( item.jqmData('field') ) { case 'y': w.theDate.setFullYear(parseInt(item.val(),10)); break; case 'm': w.theDate.setMonth(parseInt(item.val(),10)-1); break; case 'd': w.theDate.setDate(parseInt(item.val(),10)); break; case 'h': w.theDate.setHours(parseInt(item.val(),10)); break; case 'i': w.theDate.setMinutes(parseInt(item.val(),10)); break; } } w.refresh(); } }); $.extend( $.mobile.datebox.prototype._build, { 'timebox': function () { this._build.datebox.apply(this,[]); }, 'datebox': function () { var w = this, g = this.drag, o = this.options, i, y, tmp, cnt = -2, uid = 'ui-datebox-', divBase = $("