/* * jQuery Mobile Framework : plugin to provide number spinbox. * Copyright (c) JTSage * CC 3.0 Attribution. May be relicensed without permission/notification. * https://github.com/jtsage/jquery-mobile-spinbox */ (function($) { $.widget( "mobile.spinbox", $.mobile.widget, { options: { // All widget options, including some internal runtime details dmin: false, dmax: false, step: false, theme: false, repButton: true, version: '1.4.3-2014080200', initSelector: "input[data-role='spinbox']", clickEvent: 'vclick', type: 'horizontal', // or vertical }, _sbox_run: function () { var w = this, timer = 150; if ( w.g.cnt > 10 ) { timer = 100; } if ( w.g.cnt > 30 ) { timer = 50; } if ( w.g.cnt > 60 ) { timer = 20; } w.g.didRun = true; w._offset(this, w.g.delta); w.g.cnt++; w.runButton = setTimeout(function() {w._sbox_run();}, timer); }, _offset: function(obj, direction) { var w = this, o = this.options; if ( !w.disabled ) { if ( direction < 1 ) { tmp = parseInt(w.d.input.val(),10) - o.step; if ( tmp >= o.dmin ) { w.d.input.val(tmp); w.d.input.trigger('change'); } } else { tmp = parseInt(w.d.input.val(),10) + o.step; if ( tmp <= o.dmax ) { w.d.input.val(tmp); w.d.input.trigger('change'); } } } }, _create: function() { var w = this, tmp, o = $.extend(this.options, this.element.jqmData('options')), d = { input: this.element, wrap: this.element.parent() }, touch = ( typeof window.ontouchstart !== 'undefined' ), drag = { eStart : (touch ? 'touchstart' : 'mousedown')+'.spinbox', eMove : (touch ? 'touchmove' : 'mousemove')+'.spinbox', eEnd : (touch ? 'touchend' : 'mouseup')+'.spinbox', eEndA : (touch ? 'mouseup.spinbox touchend.spinbox touchcancel.spinbox touchmove.spinbox' : 'mouseup.spinbox'), move : false, start : false, end : false, pos : false, target : false, delta : false, tmp : false, cnt : 0 }; w.d = d; w.g = drag; if ( w.d.input.jqmData('mini') === true ) { w.d.input.addClass('ui-mini'); } w.d.wrap .removeClass('ui-input-text ui-shadow-inset ui-btn-shadow') .addClass('ui-controlgroup ui-controlgroup-'+o.type); if ( o.type === "horizontal" ) { w.d.wrap.css({'display':'inline', 'whiteSpace':'nowrap', 'border':'none'}); w.d.input.css({'display':'inline-block'}); if ( w.d.input.jqmData('mini') === true ) { w.d.input.css({'width':'30px'}); } else { w.d.input.css({'width':'40px'}); } } else { w.d.input.css({'width':'auto'}); w.d.wrap.css({'width':'auto','display':'inline-block'}); } w.d.input.css({'textAlign':'center'}); if ( o.theme === false ) { o.theme = $(this).closest('[data-theme]').attr('data-theme'); if ( typeof o.theme === 'undefined' ) { o.theme = 'c'; } } if ( o.dmin === false ) { o.dmin = ( typeof w.d.input.attr('min') !== 'undefined' ) ? parseInt(w.d.input.attr('min'),10) : Number.MAX_VALUE * -1; } if ( o.dmax === false ) { o.dmax = ( typeof w.d.input.attr('max') !== 'undefined' ) ? parseInt(w.d.input.attr('max'),10) : Number.MAX_VALUE; } if ( o.step === false) { o.step = (typeof w.d.input.attr('step') !== 'undefined' ) ? parseInt(w.d.input.attr('step'),10) : 1; } w.d.up = $('