/**********************************************************************/
/**********************************************************************/
/********************* PLUGIN ************************************/
/**********************************************************************/
(function ($) {
/*
* Plugin numérico para meter los millares, y que el separador decimal sea
* la coma en lugar del punto.
*/
$.fn.numeric = function (config, callback) {
if (typeof config === 'boolean') {
config = {
decimal: config
};
}
config = config || {};
// if config.negative undefined, set to true (default is to allow negative numbers)
if (typeof config.negative == "undefined") config.negative = true;
// set decimal point
var decimal = (config.decimal === false) ? "" : config.decimal || ".";
// allow negatives
var negative = (config.negative === true) ? true : false;
// callback function
var callback = typeof callback == "function" ? callback : function () {};
// set data and methods
return this.data("numeric.decimal", decimal).data("numeric.negative", negative).data("numeric.callback", callback).keypress($.fn.numeric.keypress).keyup($.fn.numeric.keyup).blur($.fn.numeric.blur);
}
$.fn.numeric.keypress = function (e) {
// get decimal character and determine if negatives are allowed
var decimal = $.data(this, "numeric.decimal");
var negative = $.data(this, "numeric.negative");
// get the key that was pressed
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
// allow enter/return key (only when in an input box)
if (key == 13 && this.nodeName.toLowerCase() == "input") {
return true;
} else if (key == 13) {
return false;
}
var allow = false;
// allow Ctrl+A
if ((e.ctrlKey...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.