diff --git a/main.js b/main.js index a306b69d23..ae41f8f672 100644 --- a/main.js +++ b/main.js @@ -170,100 +170,103 @@ function add_custom_spinners() { $('input[type="number"]').each(function() { var input = $(this); - var isInt = true; - if (input.prop('step') == '') { - isInt = true; - } else { - if (input.prop('step').indexOf('.') == -1) { + // only add new spinner if one doesn't already exist + if (!input.next().hasClass('spinner')) { + var isInt = true; + if (input.prop('step') == '') { isInt = true; } else { - isInt = false; + if (input.prop('step').indexOf('.') == -1) { + isInt = true; + } else { + isInt = false; + } } + + // make space for spinner + input.width(input.width() - 16); + + // add spinner + input.after(spinner_element); + + // get spinner refference + var spinner = input.next(); + + // bind UI hooks to spinner + $('.up', spinner).click(function() { + up(); + }); + + $('.up', spinner).mousedown(function() { + GUI.timeout_add('spinner', function() { + GUI.interval_add('spinner', function() { + up(); + }, 100, true); + }, 250); + }); + + $('.up', spinner).mouseup(function() { + GUI.timeout_remove('spinner'); + GUI.interval_remove('spinner'); + }); + + $('.up', spinner).mouseleave(function() { + GUI.timeout_remove('spinner'); + GUI.interval_remove('spinner'); + }); + + + $('.down', spinner).click(function() { + down(); + }); + + $('.down', spinner).mousedown(function() { + GUI.timeout_add('spinner', function() { + GUI.interval_add('spinner', function() { + down(); + }, 100, true); + }, 250); + }); + + $('.down', spinner).mouseup(function() { + GUI.timeout_remove('spinner'); + GUI.interval_remove('spinner'); + }); + + $('.down', spinner).mouseleave(function() { + GUI.timeout_remove('spinner'); + GUI.interval_remove('spinner'); + }); + + var up = function() { + if (isInt) { + var current_value = parseInt(input.val()); + input.val(current_value + 1); + } else { + var current_value = parseFloat(input.val()); + var step = parseFloat(input.prop('step')); + var step_decimals = input.prop('step').length - 2; + + input.val((current_value + step).toFixed(step_decimals)); + } + + input.change(); + }; + + var down = function() { + if (isInt) { + var current_value = parseInt(input.val()); + input.val(current_value - 1); + } else { + var current_value = parseFloat(input.val()); + var step = parseFloat(input.prop('step')); + var step_decimals = input.prop('step').length - 2; + + input.val((current_value - step).toFixed(step_decimals)); + } + + input.change(); + }; } - - // make space for spinner - input.width(input.width() - 16); - - // add spinner - input.after(spinner_element); - - // get spinner refference - var spinner = input.next(); - - // bind UI hooks to spinner - $('.up', spinner).click(function() { - up(); - }); - - $('.up', spinner).mousedown(function() { - GUI.timeout_add('spinner', function() { - GUI.interval_add('spinner', function() { - up(); - }, 100, true); - }, 250); - }); - - $('.up', spinner).mouseup(function() { - GUI.timeout_remove('spinner'); - GUI.interval_remove('spinner'); - }); - - $('.up', spinner).mouseleave(function() { - GUI.timeout_remove('spinner'); - GUI.interval_remove('spinner'); - }); - - - $('.down', spinner).click(function() { - down(); - }); - - $('.down', spinner).mousedown(function() { - GUI.timeout_add('spinner', function() { - GUI.interval_add('spinner', function() { - down(); - }, 100, true); - }, 250); - }); - - $('.down', spinner).mouseup(function() { - GUI.timeout_remove('spinner'); - GUI.interval_remove('spinner'); - }); - - $('.down', spinner).mouseleave(function() { - GUI.timeout_remove('spinner'); - GUI.interval_remove('spinner'); - }); - - var up = function() { - if (isInt) { - var current_value = parseInt(input.val()); - input.val(current_value + 1); - } else { - var current_value = parseFloat(input.val()); - var step = parseFloat(input.prop('step')); - var step_decimals = input.prop('step').length - 2; - - input.val((current_value + step).toFixed(step_decimals)); - } - - input.change(); - }; - - var down = function() { - if (isInt) { - var current_value = parseInt(input.val()); - input.val(current_value - 1); - } else { - var current_value = parseFloat(input.val()); - var step = parseFloat(input.prop('step')); - var step_decimals = input.prop('step').length - 2; - - input.val((current_value - step).toFixed(step_decimals)); - } - - input.change(); - }; }); } \ No newline at end of file