From bdaec66a3ca85b7c1a86490b1749c26d9c5f926d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Ujj-M=C3=A9sz=C3=A1ros?= Date: Sun, 30 Mar 2014 23:10:00 +0200 Subject: [PATCH] Cleanup and styling according to https://github.com/airbnb/javascript style guide. Tagging 2.8.0 --- bootstrap-touchspin.jquery.json | 2 +- bootstrap-touchspin/bootstrap.touchspin.js | 1080 ++++++++++---------- bower.json | 2 +- 3 files changed, 540 insertions(+), 544 deletions(-) diff --git a/bootstrap-touchspin.jquery.json b/bootstrap-touchspin.jquery.json index 241d623..3817821 100644 --- a/bootstrap-touchspin.jquery.json +++ b/bootstrap-touchspin.jquery.json @@ -10,7 +10,7 @@ "spinbutton", "spinner" ], - "version": "2.7.1", + "version": "2.8.0", "author": { "name": "István Ujj-Mészáros", "url": "https://github.com/istvan-ujjmeszaros" diff --git a/bootstrap-touchspin/bootstrap.touchspin.js b/bootstrap-touchspin/bootstrap.touchspin.js index 0474e17..bff51f9 100644 --- a/bootstrap-touchspin/bootstrap.touchspin.js +++ b/bootstrap-touchspin/bootstrap.touchspin.js @@ -3,7 +3,7 @@ /*!========================================================================= * Bootstrap TouchSpin - * v2.7.1 + * v2.8.0 * * A mobile and touch friendly input spinner component for Bootstrap 3. * @@ -30,626 +30,622 @@ * * ====================================================================== */ -(function ($) { - "use strict"; +(function($) { + "use strict"; + + var _currentSpinnerId = 0; + + function _scopedEventName(name, id) { + return name + '.touchspin_' + id; + } + + function _scopeEventNames(names, id) { + return $.map(names, function(name) { + return _scopedEventName(name, id); + }); + } + + $.fn.TouchSpin = function(options) { + + if (options === 'destroy') { + this.each(function() { + var originalinput = $(this), + originalinput_data = originalinput.data(); + $(document).off(_scopeEventNames([ + 'mouseup', + 'touchend', + 'touchcancel', + 'mousemove', + 'touchmove', + 'scroll', + 'scrollstart'], originalinput_data.spinnerid).join(' ')); + }); + return; + } - var _currentSpinnerId = 0; + var defaults = { + min: 0, + max: 100, + initval: '', + step: 1, + decimals: 0, + stepinterval: 100, + forcestepdivisibility: 'round', // none | floor | round | ceil + stepintervaldelay: 500, + prefix: '', + postfix: '', + prefix_extraclass: '', + postfix_extraclass: '', + booster: true, + boostat: 10, + maxboostedstep: false, + mousewheel: true, + buttondown_class: 'btn btn-default', + buttonup_class: 'btn btn-default' + }; + + var attributeMap = { + min: 'min', + max: 'max', + initval: 'init-val', + step: 'step', + decimals: 'decimals', + stepinterval: 'step-interval', + forcestepdivisibility: 'force-step-divisibility', + stepintervaldelay: 'step-interval-delay', + prefix: 'prefix', + postfix: 'postfix', + prefix_extraclass: 'prefix-extra-class', + postfix_extraclass: 'postfix-extra-class', + booster: 'booster', + boostat: 'boostat', + maxboostedstep: 'max-boosted-step', + mousewheel: 'mouse-wheel', + buttondown_class: 'button-down-class', + buttonup_class: 'button-up-class' + }; + + return this.each(function() { + + var settings, + originalinput = $(this), + originalinput_data = originalinput.data(), + container, + elements, + value, + downSpinTimer, + upSpinTimer, + downDelayTimeout, + upDelayTimeout, + spincount = 0, + spinning = false; + + init(); - function _scopedEventName(name, id) { - return name + ".touchspin_" + id; - } - function _scopeEventNames(names, id) { - return $.map(names, function (name) { - return _scopedEventName(name, id); + function init() { + if (originalinput.data('alreadyinitialized')) { + return; + } + + originalinput.data('alreadyinitialized', true); + _currentSpinnerId += 1; + originalinput.data('spinnerid', _currentSpinnerId); + + + if (!originalinput.is('input')) { + console.log('Must be an input.'); + return; + } + + _initSettings(); + _setInitval(); + _checkValue(); + _buildHtml(); + _initElements(); + _hideEmptyPrefixPostfix(); + _bindEvents(); + _bindEventsInterface(); + elements.input.css('display', 'block'); + } + + function _setInitval() { + if (settings.initval !== '' && originalinput.val() === '') { + originalinput.val(settings.initval); + } + } + + function changeSettings(newsettings) { + _updateSettings(newsettings); + _checkValue(); + + var value = elements.input.val(); + + if (value !== '') { + value = Number(elements.input.val()); + elements.input.val(value.toFixed(settings.decimals)); + } + } + + function _initSettings() { + settings = $.extend({}, defaults, originalinput_data, _parseAttributes(), options); + } + + function _parseAttributes() { + var data = {}; + $.each(attributeMap, function(key, value) { + var attrName = 'bts-' + value + ''; + if (originalinput.is('[data-' + attrName + ']')) { + data[key] = originalinput.data(attrName); + } }); - } + return data; + } - $.fn.TouchSpin = function (options) { - - if (options === "destroy") { - this.each(function () { - var originalinput = $(this), - originalinput_data = originalinput.data(); - $(document).off(_scopeEventNames([ - "mouseup", - "touchend", - "touchcancel", - "mousemove", - "touchmove", - "scroll", - "scrollstart"], originalinput_data.spinnerid).join(" ")); - }); - return; + function _updateSettings(newsettings) { + settings = $.extend({}, settings, newsettings); + } + + function _buildHtml() { + var initval = originalinput.val(), + parentelement = originalinput.parent(); + + if (initval !== '') { + initval = Number(initval).toFixed(settings.decimals); } - var defaults = { - min: 0, - max: 100, - initval: "", - step: 1, - decimals: 0, - stepinterval: 100, - forcestepdivisibility: 'round', // none | floor | round | ceil - stepintervaldelay: 500, - prefix: "", - postfix: "", - prefix_extraclass: "", - postfix_extraclass: "", - booster: true, - boostat: 10, - maxboostedstep: false, - mousewheel: true, - buttondown_class: "btn btn-default", - buttonup_class: "btn btn-default" - }; + originalinput.data('initvalue', initval).val(initval); + originalinput.addClass('form-control'); + + if (parentelement.hasClass('input-group')) { + _advanceInputGroup(parentelement); + } + else { + _buildInputGroup(); + } + } + + function _advanceInputGroup(parentelement) { + parentelement.addClass('bootstrap-touchspin'); + + var prev = originalinput.prev(), + next = originalinput.next(); - var attributeMap = { - min: 'min', - max: 'max', - initval: 'init-val', - step: 'step', - decimals: 'decimals', - stepinterval: 'step-interval', - forcestepdivisibility: 'force-step-divisibility', - stepintervaldelay: 'step-interval-delay', - prefix: "prefix", - postfix: "postfix", - prefix_extraclass: "prefix-extra-class", - postfix_extraclass: "postfix-extra-class", - booster: 'booster', - boostat: 'boostat', - maxboostedstep: 'max-boosted-step', - mousewheel: 'mouse-wheel', - buttondown_class: "button-down-class", - buttonup_class: "button-up-class" + var downhtml, + uphtml, + prefixhtml = '' + settings.prefix + '', + postfixhtml = '' + settings.postfix + ''; + + if (prev.hasClass('input-group-btn')) { + downhtml = ''; + prev.append(downhtml); + } + else { + downhtml = ''; + $(downhtml).insertBefore(originalinput); + } + + if (next.hasClass('input-group-btn')) { + uphtml = ''; + next.prepend(uphtml); + } + else { + uphtml = ''; + $(uphtml).insertAfter(originalinput); + } + + $(prefixhtml).insertBefore(originalinput); + $(postfixhtml).insertAfter(originalinput); + + container = parentelement; + } + + function _buildInputGroup() { + var html = '
' + settings.prefix + '' + settings.postfix + '
'; + + container = $(html).insertBefore(originalinput); + + $('.bootstrap-touchspin-prefix', container).after(originalinput); + + if (originalinput.hasClass('input-sm')) { + container.addClass('input-group-sm'); + } + else if (originalinput.hasClass('input-lg')) { + container.addClass('input-group-lg'); + } + } + + function _initElements() { + elements = { + down: $('.bootstrap-touchspin-down', container), + up: $('.bootstrap-touchspin-up', container), + input: $('input', container), + prefix: $('.bootstrap-touchspin-prefix', container).addClass(settings.prefix_extraclass), + postfix: $('.bootstrap-touchspin-postfix', container).addClass(settings.postfix_extraclass) }; + } - return this.each(function () { - - var settings, - originalinput = $(this), - originalinput_data = originalinput.data(), - container, - elements, - value, - downSpinTimer, - upSpinTimer, - downDelayTimeout, - upDelayTimeout, - spincount = 0, - spinning = false; - - init(); - - - function init() { - if (originalinput.data("alreadyinitialized")) { - return; - } - - originalinput.data("alreadyinitialized", true); - _currentSpinnerId += 1; - originalinput.data("spinnerid", _currentSpinnerId); - - - if (!originalinput.is("input")) { - console.log("Must be an input."); - return; - } - - _initSettings(); - _setInitval(); - _checkValue(); - _buildHtml(); - _initElements(); - _hideEmptyPrefixPostfix(); - _bindEvents(); - _bindEventsInterface(); - elements.input.css("display", "block"); - } + function _hideEmptyPrefixPostfix() { + if (settings.prefix == '') { + elements.prefix.hide(); + } + + if (settings.postfix == '') { + elements.postfix.hide(); + } + } + + function _bindEvents() { + originalinput.on('keydown', function(ev) { + var code = ev.keyCode || ev.which; - function _setInitval() { - if (settings.initval !== "" && originalinput.val() === "") { - originalinput.val(settings.initval); - } + if (code === 38) { + if (spinning !== 'up') { + upOnce(); + startUpSpin(); } + ev.preventDefault(); + } + else if (code === 40) { + if (spinning !== 'down') { + downOnce(); + startDownSpin(); + } + ev.preventDefault(); + } + }); + + originalinput.on('keyup', function(ev) { + var code = ev.keyCode || ev.which; - function changeSettings(newsettings) { - _updateSettings(newsettings); - _checkValue(); + if (code === 38) { + stopSpin(); + } + else if (code === 40) { + stopSpin(); + } + }); - var value = elements.input.val(); + originalinput.on('blur', function() { + _checkValue(); + }); - if (value !== "") { - value = Number(elements.input.val()); - elements.input.val(value.toFixed(settings.decimals)); - } - } + elements.down.on('keydown', function(ev) { + var code = ev.keyCode || ev.which; - function _initSettings() { - settings = $.extend({}, defaults, originalinput_data, _parseAttributes(), options); + if (code === 32 || code === 13) { + if (spinning !== 'down') { + downOnce(); + startDownSpin(); } + ev.preventDefault(); + } + }); - function _parseAttributes() { - var data = {}; - $.each(attributeMap, function (key, value) { - var attrName = 'bts-' + value + ''; - if (originalinput.is('[data-' + attrName + ']')) { - data[key] = originalinput.data(attrName); - } - }); - console.log(data); - return data; - } + elements.down.on('keyup', function(ev) { + var code = ev.keyCode || ev.which; + + if (code === 32 || code === 13) { + stopSpin(); + } + }); - function _updateSettings(newsettings) { - settings = $.extend({}, settings, newsettings); + elements.up.on('keydown', function(ev) { + var code = ev.keyCode || ev.which; + + if (code === 32 || code === 13) { + if (spinning !== 'up') { + upOnce(); + startUpSpin(); } + ev.preventDefault(); + } + }); - function _buildHtml() { - var initval = originalinput.val(), - parentelement = originalinput.parent(); + elements.up.on('keyup', function(ev) { + var code = ev.keyCode || ev.which; - if (initval !== "") { - initval = Number(initval).toFixed(settings.decimals); - } + if (code === 32 || code === 13) { + stopSpin(); + } + }); - originalinput.data("initvalue", initval).val(initval); - originalinput.addClass("form-control"); + elements.down.on('mousedown touchstart', function(ev) { + downOnce(); + startDownSpin(); - if (parentelement.hasClass("input-group")) { - _advanceInputGroup(parentelement); - } - else { - _buildInputGroup(); - } - } + ev.preventDefault(); + ev.stopPropagation(); + }); - function _advanceInputGroup(parentelement) { - parentelement.addClass("bootstrap-touchspin"); - - var prev = originalinput.prev(), - next = originalinput.next(); - - var downhtml, - uphtml, - prefixhtml = '' + settings.prefix + '', - postfixhtml = '' + settings.postfix + ''; - - if (prev.hasClass("input-group-btn")) { - downhtml = '', - prev.append(downhtml); - } - else { - downhtml = ''; - $(downhtml).insertBefore(originalinput); - } - - if (next.hasClass("input-group-btn")) { - uphtml = '', - next.prepend(uphtml); - } - else { - uphtml = ''; - $(uphtml).insertAfter(originalinput); - } - - $(prefixhtml).insertBefore(originalinput); - $(postfixhtml).insertAfter(originalinput); - - container = parentelement; - } + elements.up.on('mousedown touchstart', function(ev) { + upOnce(); + startUpSpin(); - function _buildInputGroup() { - var html = '
' + settings.prefix + '' + settings.postfix + '
'; + ev.preventDefault(); + ev.stopPropagation(); + }); - container = $(html).insertBefore(originalinput); + elements.up.on('mouseout touchleave touchend touchcancel', function(ev) { + if (!spinning) { + return; + } - $(".bootstrap-touchspin-prefix", container).after(originalinput); + ev.stopPropagation(); + stopSpin(); + }); - if (originalinput.hasClass("input-sm")) { - container.addClass("input-group-sm"); - } - else if (originalinput.hasClass("input-lg")) { - container.addClass("input-group-lg"); - } - } + elements.down.on('mouseout touchleave touchend touchcancel', function(ev) { + if (!spinning) { + return; + } - function _initElements() { - elements = { - down: $(".bootstrap-touchspin-down", container), - up: $(".bootstrap-touchspin-up", container), - input: $("input", container), - prefix: $(".bootstrap-touchspin-prefix", container).addClass(settings.prefix_extraclass), - postfix: $(".bootstrap-touchspin-postfix", container).addClass(settings.postfix_extraclass) - }; - } + ev.stopPropagation(); + stopSpin(); + }); - function _hideEmptyPrefixPostfix() { - if (settings.prefix == "") { - elements.prefix.hide(); - } + elements.down.on('mousemove touchmove', function(ev) { + if (!spinning) { + return; + } - if (settings.postfix == "") { - elements.postfix.hide(); - } - } + ev.stopPropagation(); + ev.preventDefault(); + }); - function _bindEvents() { - originalinput.on("keydown", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 38) { - if (spinning !== "up") { - upOnce(); - startUpSpin(); - } - ev.preventDefault(); - } - else if (code === 40) { - if (spinning !== "down") { - downOnce(); - startDownSpin(); - } - ev.preventDefault(); - } - }); - - originalinput.on("keyup", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 38) { - stopSpin(); - } - else if (code === 40) { - stopSpin(); - } - }); - - originalinput.on("blur", function () { - _checkValue(); - }); - - elements.down.on("keydown", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 32 || code === 13) { - if (spinning !== "down") { - downOnce(); - startDownSpin(); - } - ev.preventDefault(); - } - }); - - elements.down.on("keyup", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 32 || code === 13) { - stopSpin(); - } - }); - - elements.up.on("keydown", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 32 || code === 13) { - if (spinning !== "up") { - upOnce(); - startUpSpin(); - } - ev.preventDefault(); - } - }); - - elements.up.on("keyup", function (ev) { - var code = ev.keyCode || ev.which; - - if (code === 32 || code === 13) { - stopSpin(); - } - }); - - elements.down.on("mousedown touchstart", function (ev) { - downOnce(); - startDownSpin(); - - ev.preventDefault(); - ev.stopPropagation(); - }); - - elements.up.on("mousedown touchstart", function (ev) { - upOnce(); - startUpSpin(); - - ev.preventDefault(); - ev.stopPropagation(); - }); - - elements.up.on("mouseout touchleave touchend touchcancel", function (ev) { - if (!spinning) { - return; - } - - ev.stopPropagation(); - stopSpin(); - }); - - elements.down.on("mouseout touchleave touchend touchcancel", function (ev) { - if (!spinning) { - return; - } - - ev.stopPropagation(); - stopSpin(); - }); - - elements.down.on("mousemove touchmove", function (ev) { - if (!spinning) { - return; - } - - ev.stopPropagation(); - ev.preventDefault(); - }); - - elements.up.on("mousemove touchmove", function (ev) { - if (!spinning) { - return; - } - - ev.stopPropagation(); - ev.preventDefault(); - }); - - $(document).on(_scopeEventNames(["mouseup", "touchend", "touchcancel"], _currentSpinnerId).join(" "), function (ev) { - if (!spinning) { - return; - } - - ev.preventDefault(); - stopSpin(); - }); - - $(document).on(_scopeEventNames(["mousemove", "touchmove", "scroll", "scrollstart"], _currentSpinnerId).join(" "), function (ev) { - if (!spinning) { - return; - } - - ev.preventDefault(); - stopSpin(); - }); - - if (settings.mousewheel) { - originalinput.on("mousewheel DOMMouseScroll", function (ev) { - var delta = ev.originalEvent.wheelDelta || -ev.originalEvent.detail; - - ev.stopPropagation(); - ev.preventDefault(); - - if (delta < 0) { - downOnce(); - } - else { - upOnce(); - } - }); - } - } + elements.up.on('mousemove touchmove', function(ev) { + if (!spinning) { + return; + } + + ev.stopPropagation(); + ev.preventDefault(); + }); + + $(document).on(_scopeEventNames(['mouseup', 'touchend', 'touchcancel'], _currentSpinnerId).join(' '), function(ev) { + if (!spinning) { + return; + } - function _bindEventsInterface() { - originalinput.on('touchspin.uponce', function () { - stopSpin(); - upOnce(); - }); + ev.preventDefault(); + stopSpin(); + }); - originalinput.on('touchspin.downonce', function () { - stopSpin(); - downOnce(); - }); + $(document).on(_scopeEventNames(['mousemove', 'touchmove', 'scroll', 'scrollstart'], _currentSpinnerId).join(' '), function(ev) { + if (!spinning) { + return; + } - originalinput.on('touchspin.startupspin', function (e) { - startUpSpin(); - }); + ev.preventDefault(); + stopSpin(); + }); - originalinput.on('touchspin.startdownspin', function () { - startDownSpin(); - }); + if (settings.mousewheel) { + originalinput.on('mousewheel DOMMouseScroll', function(ev) { + var delta = ev.originalEvent.wheelDelta || -ev.originalEvent.detail; - originalinput.on('touchspin.stopspin', function () { - stopSpin(); - }); + ev.stopPropagation(); + ev.preventDefault(); - originalinput.on('touchspin.updatesettings', function (e, newsettings) { - changeSettings(newsettings); - }); + if (delta < 0) { + downOnce(); } - - function _forcestepdivisibility(value) { - switch (settings.forcestepdivisibility) { - case 'round': - return (Math.round(value / settings.step) * settings.step).toFixed(settings.decimals); - break; - case 'floor': - return (Math.floor(value / settings.step) * settings.step).toFixed(settings.decimals); - break; - case 'ceil': - return (Math.ceil(value / settings.step) * settings.step).toFixed(settings.decimals); - break; - default: - return value; - } + else { + upOnce(); } + }); + } + } - function _checkValue() { - var val, parsedval, returnval; + function _bindEventsInterface() { + originalinput.on('touchspin.uponce', function() { + stopSpin(); + upOnce(); + }); - val = originalinput.val(); + originalinput.on('touchspin.downonce', function() { + stopSpin(); + downOnce(); + }); - if (val === "") { - return; - } + originalinput.on('touchspin.startupspin', function() { + startUpSpin(); + }); - if (settings.decimals > 0 && val === ".") { - return; - } + originalinput.on('touchspin.startdownspin', function() { + startDownSpin(); + }); - parsedval = parseFloat(val); + originalinput.on('touchspin.stopspin', function() { + stopSpin(); + }); - if (isNaN(parsedval)) { - parsedval = 0; - } + originalinput.on('touchspin.updatesettings', function(e, newsettings) { + changeSettings(newsettings); + }); + } + + function _forcestepdivisibility(value) { + switch (settings.forcestepdivisibility) { + case 'round': + return (Math.round(value / settings.step) * settings.step).toFixed(settings.decimals); + case 'floor': + return (Math.floor(value / settings.step) * settings.step).toFixed(settings.decimals); + case 'ceil': + return (Math.ceil(value / settings.step) * settings.step).toFixed(settings.decimals); + default: + return value; + } + } - returnval = parsedval; + function _checkValue() { + var val, parsedval, returnval; - if (parsedval.toString() !== val) { - returnval = parsedval; - } + val = originalinput.val(); - if (parsedval < settings.min) { - returnval = settings.min; - } + if (val === '') { + return; + } - if (parsedval > settings.max) { - returnval = settings.max; - } + if (settings.decimals > 0 && val === '.') { + return; + } - returnval = _forcestepdivisibility(returnval); + parsedval = parseFloat(val); - if (Number(val).toString() !== returnval.toString()) { - originalinput.val(returnval); - originalinput.trigger("change"); - } - } + if (isNaN(parsedval)) { + parsedval = 0; + } - function _getBoostedStep() { - if (!settings.booster) { - return settings.step; - } - else { - var boosted = Math.pow(2, Math.floor(spincount / settings.boostat)) * settings.step; - - if (settings.maxboostedstep) { - if (boosted > settings.maxboostedstep) { - boosted = settings.maxboostedstep; - value = Math.round((value / boosted) * boosted); - } - } - - return Math.max(settings.step, boosted); - } - } + returnval = parsedval; - function upOnce() { - _checkValue(); + if (parsedval.toString() !== val) { + returnval = parsedval; + } - value = parseFloat(elements.input.val()); - if (isNaN(value)) { - value = 0; - } + if (parsedval < settings.min) { + returnval = settings.min; + } - var initvalue = value, - boostedstep = _getBoostedStep(); + if (parsedval > settings.max) { + returnval = settings.max; + } - value = value + boostedstep; + returnval = _forcestepdivisibility(returnval); - if (value > settings.max) { - value = settings.max; - originalinput.trigger("touchspin.on.max"); - stopSpin(); - } + if (Number(val).toString() !== returnval.toString()) { + originalinput.val(returnval); + originalinput.trigger('change'); + } + } - elements.input.val(Number(value).toFixed(settings.decimals)); + function _getBoostedStep() { + if (!settings.booster) { + return settings.step; + } + else { + var boosted = Math.pow(2, Math.floor(spincount / settings.boostat)) * settings.step; - if (initvalue !== value) { - originalinput.trigger("change"); - } + if (settings.maxboostedstep) { + if (boosted > settings.maxboostedstep) { + boosted = settings.maxboostedstep; + value = Math.round((value / boosted) * boosted); } + } - function downOnce() { - _checkValue(); + return Math.max(settings.step, boosted); + } + } - value = parseFloat(elements.input.val()); - if (isNaN(value)) { - value = 0; - } + function upOnce() { + _checkValue(); - var initvalue = value, - boostedstep = _getBoostedStep(); + value = parseFloat(elements.input.val()); + if (isNaN(value)) { + value = 0; + } - value = value - boostedstep; + var initvalue = value, + boostedstep = _getBoostedStep(); - if (value < settings.min) { - value = settings.min; - originalinput.trigger("touchspin.on.min"); - stopSpin(); - } + value = value + boostedstep; - elements.input.val(value.toFixed(settings.decimals)); + if (value > settings.max) { + value = settings.max; + originalinput.trigger('touchspin.on.max'); + stopSpin(); + } - if (initvalue !== value) { - originalinput.trigger("change"); - } - } + elements.input.val(Number(value).toFixed(settings.decimals)); - function startDownSpin() { - stopSpin(); + if (initvalue !== value) { + originalinput.trigger('change'); + } + } - spincount = 0; - spinning = "down"; + function downOnce() { + _checkValue(); - originalinput.trigger("touchspin.on.startspin"); - originalinput.trigger("touchspin.on.startdownspin"); + value = parseFloat(elements.input.val()); + if (isNaN(value)) { + value = 0; + } - downDelayTimeout = setTimeout(function () { - downSpinTimer = setInterval(function () { - spincount++; - downOnce(); - }, settings.stepinterval); - }, settings.stepintervaldelay); - } + var initvalue = value, + boostedstep = _getBoostedStep(); - function startUpSpin() { - stopSpin(); + value = value - boostedstep; - spincount = 0; - spinning = "up"; + if (value < settings.min) { + value = settings.min; + originalinput.trigger('touchspin.on.min'); + stopSpin(); + } - originalinput.trigger("touchspin.on.startspin"); - originalinput.trigger("touchspin.on.startupspin"); + elements.input.val(value.toFixed(settings.decimals)); - upDelayTimeout = setTimeout(function () { - upSpinTimer = setInterval(function () { - spincount++; - upOnce(); - }, settings.stepinterval); - }, settings.stepintervaldelay); - } + if (initvalue !== value) { + originalinput.trigger('change'); + } + } + + function startDownSpin() { + stopSpin(); + + spincount = 0; + spinning = 'down'; + + originalinput.trigger('touchspin.on.startspin'); + originalinput.trigger('touchspin.on.startdownspin'); + + downDelayTimeout = setTimeout(function() { + downSpinTimer = setInterval(function() { + spincount++; + downOnce(); + }, settings.stepinterval); + }, settings.stepintervaldelay); + } + + function startUpSpin() { + stopSpin(); + + spincount = 0; + spinning = 'up'; + + originalinput.trigger('touchspin.on.startspin'); + originalinput.trigger('touchspin.on.startupspin'); + + upDelayTimeout = setTimeout(function() { + upSpinTimer = setInterval(function() { + spincount++; + upOnce(); + }, settings.stepinterval); + }, settings.stepintervaldelay); + } + + function stopSpin() { + clearTimeout(downDelayTimeout); + clearTimeout(upDelayTimeout); + clearInterval(downSpinTimer); + clearInterval(upSpinTimer); + + switch (spinning) { + case 'up': + originalinput.trigger('touchspin.on.stopupspin'); + originalinput.trigger('touchspin.on.stopspin'); + break; + case 'down': + originalinput.trigger('touchspin.on.stopdownspin'); + originalinput.trigger('touchspin.on.stopspin'); + break; + } - function stopSpin() { - clearTimeout(downDelayTimeout); - clearTimeout(upDelayTimeout); - clearInterval(downSpinTimer); - clearInterval(upSpinTimer); - - switch (spinning) { - case "up": - originalinput.trigger("touchspin.on.stopupspin"); - originalinput.trigger("touchspin.on.stopspin"); - break; - case "down": - originalinput.trigger("touchspin.on.stopdownspin"); - originalinput.trigger("touchspin.on.stopspin"); - break; - } - - spincount = 0; - spinning = false; - } + spincount = 0; + spinning = false; + } - }); + }); - }; + }; })(jQuery); diff --git a/bower.json b/bower.json index 029cf31..05decd3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-touchspin", - "version": "2.7.2", + "version": "2.8.0", "authors": [ "István Ujj-Mészáros " ],