-
-
Save bendytree/936f6b9b4c0e10138b7e9158b5fd05d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
var onKeyDown = function (e) { | |
var $input = $(e.target); | |
var lastkey = $input.data("ddn-lastkey"); | |
var lastval = $input.data("ddn-lastval"); | |
var key = String.fromCharCode(e.charCode); | |
if (lastkey === "." && key === "."){ | |
$input.val(isNaN(lastval) ? "-0" : String(-1 * lastval)); | |
$input.data("ddn-lastkey", ""); | |
e.preventDefault(); | |
}else{ | |
$input.data("ddn-lastkey", key); | |
} | |
$input.data("ddn-lastval", parseFloat($input.val())); | |
}; | |
$.fn.doubleDotNegative = function() { | |
$(this).each(function(){ | |
var $input = $(this); | |
$input.data("ddn-lastval", parseFloat($input.val())||0); | |
$input.keypress(onKeyDown); | |
}); | |
}; | |
})(jQuery); | |
var isAndroid = /android/i.test(window.navigator.userAgent); | |
if (isAndroid){ | |
$("input[type=number]").doubleDotNegative(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment