/* * 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 */ /* DurationBox Mode */ (function($) { $.extend( $.mobile.datebox.prototype.options, { themeButton: 'a', themeInput: 'a', useSetButton: true, repButton: true, durationSteppers: {'d': 1, 'h': 1, 'i': 1, 's': 1} }); $.extend( $.mobile.datebox.prototype, { _durbox_run: function() { var w = this, timer = 150; if ( w.drag.cnt > 10 ) { timer = 100; } if ( w.drag.cnt > 30 ) { timer = 50; } if ( w.drag.cnt > 60 ) { timer = 20; } if ( w.drag.cnt > 120 ) { timer = 10; } if ( w.drag.cnt > 240 ) { timer = 3; } w.drag.cnt++; w.drag.didRun = true; w._offset(w.drag.target[0], w.drag.target[1], false); w._durbox_run_update(); w.runButton = setTimeout(function() {w._durbox_run();}, timer); }, _durbox_run_update: function () { var w = this, i, cDur = [], ival = {'d': 60*60*24, 'h': 60*60, 'i': 60}; i = w.theDate.getEpoch() - w.initDate.getEpoch(); if ( i<0 ) { i = 0; w.theDate.setTime(w.initDate.getTime()); } w.lastDuration = i; // Let the number of seconds be sort of public. // DAYS cDur[0] = parseInt( i / ival.d,10); i = i % ival.d; // HOURS cDur[1] = parseInt( i / ival.h, 10); i = i % ival.h; // MINS AND SECS cDur[2] = parseInt( i / ival.i, 10); cDur[3] = i % ival.i; w.d.divIn.find('input').each(function () { switch ( $(this).parent().data('field') ) { case 'd': $(this).val(cDur[0]); break; case 'h': $(this).val(cDur[1]); break; case 'i': $(this).val(cDur[2]); break; case 's': $(this).val(cDur[3]); break; } }); }, _durbox_valid: function (num) { if ( num.toString().search(/^[0-9]+$/) === 0 ) { return parseInt(num,10); } return 0; }, _durbox_enter: function (item) { var w = this, t = w.initDate.getEpoch(); w.d.intHTML.find('input').each( function() { switch ( $(this).parent().data('field') ) { case 'd': t += (60*60*24) * w._durbox_valid($(this).val()); break; case 'h': t += (60*60) * w._durbox_valid($(this).val()); break; case 'i': t += (60) * w._durbox_valid($(this).val()); break; case 's': t += w._durbox_valid($(this).val()); break; } }); w.theDate.setTime( t * 1000 ); w.refresh(); } }); $.extend( $.mobile.datebox.prototype._build, { 'durationbox': function () { var w = this, g = this.drag, o = this.options, i, y, cDur = [0,0,0,0], tmp, ival = {'d': 60*60*24, 'h': 60*60, 'i': 60}, uid = 'ui-datebox-', divBase = $("