/* * 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", { options: { // All widget options dmin: false, dmax: false, step: false, theme: false, mini: null, repButton: true, version: "1.4.4-2015092400", initSelector: "input[data-role='spinbox']", clickEvent: "vclick", type: "horizontal", // or vertical }, _decimalPlaces: function (num) { var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); if (!match) { return 0; } return Math.max( 0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0) ); }, _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 tmp, w = this, o = this.options; if ( !w.disabled ) { if ( direction < 1 ) { tmp = (parseFloat( w.d.input.val() ) - o.step).toFixed(w.places); if ( tmp >= o.dmin ) { w.d.input.val( tmp ).trigger( "change" ); } } else { tmp = (parseFloat( w.d.input.val() ) + o.step).toFixed(w.places); if ( tmp <= o.dmax ) { w.d.input.val( tmp ).trigger( "change" ); } } } }, _create: function() { var w = this, o = $.extend( this.options, this.element.data( "options" ) ), d = { input: this.element, inputWrap: 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; o.theme = ( ( o.theme === false ) ? $.mobile.getInheritedTheme( this.element, "a" ) : o.theme ); if ( w.d.input.prop( "disabled" ) ) { o.disabled = true; } 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" ) ? parseFloat( w.d.input.attr( "step" ) ) : 1; w.places = w._decimalPlaces(o.step); } o.mini = ( o.mini === null ? ( w.d.input.data("mini") ? true : false ) : o.mini ); w.d.wrap = $( "