mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update autoNumeric.js to 1.9.18
This commit is contained in:
parent
f0a64f2f2e
commit
674e24fe3e
1 changed files with 1244 additions and 1212 deletions
232
dashboard-ui/thirdparty/autoNumeric.js
vendored
232
dashboard-ui/thirdparty/autoNumeric.js
vendored
|
@ -2,13 +2,12 @@
|
|||
* autoNumeric.js
|
||||
* @author: Bob Knothe
|
||||
* @author: Sokolov Yura aka funny_falcon
|
||||
* @version: 1.9.6 - 2013-04-20 GMT 3:00 PM
|
||||
* @version: 1.9.18 - 2013-12-03 GMT 9:00 PM
|
||||
*
|
||||
* Created by Robert J. Knothe on 2010-10-25. Please report any bug at http://www.decorplanit.com/plugin/
|
||||
* Created by Sokolov Yura on 2010-11-07. http://github.com/funny_falcon
|
||||
* Created by Robert J. Knothe on 2010-10-25. Please report any bugs to https://github.com/BobKnothe/autoNumeric
|
||||
* Created by Sokolov Yura on 2010-11-07
|
||||
*
|
||||
* Copyright (c) 2011 Robert J. Knothe http://www.decorplanit.com/plugin/
|
||||
* Copyright (c) 2011 Sokolov Yura aka funny_falcon
|
||||
*
|
||||
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*
|
||||
|
@ -35,10 +34,9 @@
|
|||
*/
|
||||
(function ($) {
|
||||
"use strict";
|
||||
/**jslint browser: true*/
|
||||
/**global jQuery*/
|
||||
/**
|
||||
* Cross browser routine for getting selected range/cursor position
|
||||
/*jslint browser: true*/
|
||||
/*global jQuery: false*/
|
||||
/* Cross browser routine for getting selected range/cursor position
|
||||
*/
|
||||
function getElementSelection(that) {
|
||||
var position = {};
|
||||
|
@ -95,7 +93,6 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function convertKeyToNumber(settings, key) {
|
||||
if (typeof (settings[key]) === 'string') {
|
||||
settings[key] *= 1;
|
||||
|
@ -103,12 +100,12 @@
|
|||
}
|
||||
/**
|
||||
* Preparing user defined options for further usage
|
||||
* merge them with defaults appropriatly
|
||||
* merge them with defaults appropriately
|
||||
*/
|
||||
function autoCode($this, settings) {
|
||||
runCallbacks($this, settings);
|
||||
settings.oEvent = null;
|
||||
settings.tagList = ['DD', 'DT', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'LABEL', 'P', 'SPAN', 'TD', 'TH'];
|
||||
settings.tagList = ['B', 'CAPTION', 'CITE', 'CODE', 'DD', 'DEL', 'DIV', 'DFN', 'DT', 'EM', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'INS', 'KDB', 'LABEL', 'LI', 'OUTPUT', 'P', 'Q', 'S', 'SAMPLE', 'SPAN', 'STRONG', 'TD', 'TH', 'U', 'VAR'];
|
||||
var vmax = settings.vMax.toString().split('.'),
|
||||
vmin = (!settings.vMin && settings.vMin !== 0) ? [] : settings.vMin.toString().split('.');
|
||||
convertKeyToNumber(settings, 'vMax');
|
||||
|
@ -233,19 +230,20 @@
|
|||
return s;
|
||||
}
|
||||
/**
|
||||
* function to handle numbers less than 0 that are stored in Exponential notaion ex: .0000001 stored as 1e-7
|
||||
* function to handle numbers less than 0 that are stored in Exponential notation ex: .0000001 stored as 1e-7
|
||||
*/
|
||||
function checkValue(value) {
|
||||
var decimal = value.indexOf('.');
|
||||
function checkValue(value, settings) {
|
||||
var decimal = value.indexOf('.'),
|
||||
checkSmall = +value;
|
||||
if (decimal !== -1) {
|
||||
if (decimal === 1 && value.charAt(0) === '0') {
|
||||
if (checkSmall < 0.000001 && checkSmall > -1) {
|
||||
value = +value;
|
||||
if (value < 0.000001 && value > 0) {
|
||||
value = (value + 1).toString();
|
||||
value = (value + 10).toString();
|
||||
value = value.substring(1);
|
||||
}
|
||||
if (value < 0 && value > -1) {
|
||||
value = (value - 1).toString();
|
||||
value = (value - 10).toString();
|
||||
value = '-' + value.substring(2);
|
||||
}
|
||||
value = value.toString();
|
||||
|
@ -261,7 +259,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
return value.replace(/^0*(\d)/, '$1');
|
||||
return (settings.lZero === 'keep') ? value : value.replace(/^0*(\d)/, '$1');
|
||||
}
|
||||
/**
|
||||
* prepare real number to be converted to our format
|
||||
|
@ -310,7 +308,7 @@
|
|||
*/
|
||||
function autoGroup(iv, settings) {
|
||||
iv = autoStrip(iv, settings);
|
||||
var testNeg = iv,
|
||||
var testNeg = iv.replace(',', '.'),
|
||||
empty = checkEmpty(iv, settings, true);
|
||||
if (empty !== null) {
|
||||
return empty;
|
||||
|
@ -338,7 +336,7 @@
|
|||
ivSplit[1] = ivSplit[1].substring(0, settings.mDec);
|
||||
} /** joins the whole number with the deciaml value */
|
||||
iv = s + settings.aDec + ivSplit[1];
|
||||
} else { /** if whole numers only */
|
||||
} else { /** if whole numbers only */
|
||||
iv = s;
|
||||
}
|
||||
if (settings.aSign) {
|
||||
|
@ -357,8 +355,8 @@
|
|||
/**
|
||||
* round number after setting by pasting or $().autoNumericSet()
|
||||
* private function for round the number
|
||||
* please note this handled as text - Javascript math function can return inaccurate values
|
||||
* also this offers multiple rounding metods that are not easily accomplished in javascript
|
||||
* please note this handled as text - JavaScript math function can return inaccurate values
|
||||
* also this offers multiple rounding methods that are not easily accomplished in JavaScript
|
||||
*/
|
||||
function autoRound(iv, settings) { /** value to string */
|
||||
iv = (iv === '') ? '0' : iv.toString();
|
||||
|
@ -388,9 +386,9 @@
|
|||
if ((+iv > 0 && settings.lZero !== 'keep') || (iv.length > 0 && settings.lZero === 'allow')) { /** trims leading zero's if needed */
|
||||
iv = iv.replace(/^0*(\d)/, '$1');
|
||||
}
|
||||
var dPos = iv.lastIndexOf('.'); /** virtual decimal position */
|
||||
var vdPos = dPos === -1 ? iv.length - 1 : dPos; /** checks decimal places to determine if rounding is required */
|
||||
var cDec = (iv.length - 1) - vdPos; /** check if no rounding is required */
|
||||
var dPos = iv.lastIndexOf('.'), /** virtual decimal position */
|
||||
vdPos = dPos === -1 ? iv.length - 1 : dPos, /** checks decimal places to determine if rounding is required */
|
||||
cDec = (iv.length - 1) - vdPos; /** check if no rounding is required */
|
||||
if (cDec <= settings.mDec) {
|
||||
ivRounded = iv; /** check if we need to pad with zeros */
|
||||
if (cDec < rDec) {
|
||||
|
@ -409,10 +407,10 @@
|
|||
}
|
||||
return nSign + ivRounded;
|
||||
} /** rounded length of the string after rounding */
|
||||
var rLength = dPos + settings.mDec; /** test round */
|
||||
var tRound = +iv.charAt(rLength + 1);
|
||||
var ivArray = iv.substring(0, rLength + 1).split('');
|
||||
var odd = (iv.charAt(rLength) === '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2);
|
||||
var rLength = dPos + settings.mDec, /** test round */
|
||||
tRound = +iv.charAt(rLength + 1),
|
||||
ivArray = iv.substring(0, rLength + 1).split(''),
|
||||
odd = (iv.charAt(rLength) === '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2);
|
||||
if ((tRound > 4 && settings.mRound === 'S') || (tRound > 4 && settings.mRound === 'A' && nSign === '') || (tRound > 5 && settings.mRound === 'A' && nSign === '-') || (tRound > 5 && settings.mRound === 's') || (tRound > 5 && settings.mRound === 'a' && nSign === '') || (tRound > 4 && settings.mRound === 'a' && nSign === '-') || (tRound > 5 && settings.mRound === 'B') || (tRound === 5 && settings.mRound === 'B' && odd === 1) || (tRound > 0 && settings.mRound === 'C' && nSign === '') || (tRound > 0 && settings.mRound === 'F' && nSign === '-') || (tRound > 0 && settings.mRound === 'U')) {
|
||||
/** Round up the last digit if required, and continue until no more 9's are found */
|
||||
for (i = (ivArray.length - 1) ; i >= 0; i -= 1) {
|
||||
|
@ -420,7 +418,8 @@
|
|||
ivArray[i] = +ivArray[i] + 1;
|
||||
if (ivArray[i] < 10) {
|
||||
break;
|
||||
} else if (i > 0) {
|
||||
}
|
||||
if (i > 0) {
|
||||
ivArray[i] = '0';
|
||||
}
|
||||
}
|
||||
|
@ -428,7 +427,7 @@
|
|||
} /** Reconstruct the string, converting any 10's to 0's */
|
||||
ivArray = ivArray.slice(0, rLength + 1);
|
||||
ivRounded = truncateZeros(ivArray.join('')); /** return rounded value */
|
||||
return nSign + ivRounded;
|
||||
return (+ivRounded === 0) ? ivRounded : nSign + ivRounded;
|
||||
}
|
||||
/**
|
||||
* Holder object for field properties
|
||||
|
@ -448,7 +447,7 @@
|
|||
this.ctrlKey = e.ctrlKey;
|
||||
this.cmdKey = e.metaKey;
|
||||
this.shiftKey = e.shiftKey;
|
||||
this.selection = getElementSelection(this.that); /** keypress event overwrites meaningfull value of e.keyCode */
|
||||
this.selection = getElementSelection(this.that); /** keypress event overwrites meaningful value of e.keyCode */
|
||||
if (e.type === 'keydown' || e.type === 'keyup') {
|
||||
this.kdCode = e.keyCode;
|
||||
}
|
||||
|
@ -472,9 +471,9 @@
|
|||
this.setSelection(pos, pos, setReal);
|
||||
},
|
||||
getBeforeAfter: function () {
|
||||
var value = this.value;
|
||||
var left = value.substring(0, this.selection.start);
|
||||
var right = value.substring(this.selection.end, value.length);
|
||||
var value = this.value,
|
||||
left = value.substring(0, this.selection.start),
|
||||
right = value.substring(this.selection.end, value.length);
|
||||
return [left, right];
|
||||
},
|
||||
getBeforeAfterStriped: function () {
|
||||
|
@ -514,10 +513,10 @@
|
|||
* set part of number to value keeping position of cursor
|
||||
*/
|
||||
setValueParts: function (left, right) {
|
||||
var settingsClone = this.settingsClone;
|
||||
var parts = this.normalizeParts(left, right);
|
||||
var new_value = parts.join('');
|
||||
var position = parts[0].length;
|
||||
var settingsClone = this.settingsClone,
|
||||
parts = this.normalizeParts(left, right),
|
||||
new_value = parts.join(''),
|
||||
position = parts[0].length;
|
||||
if (autoCheck(new_value, settingsClone)) {
|
||||
new_value = truncateDecimal(new_value, settingsClone.aDec, settingsClone.mDec);
|
||||
if (position > new_value.length) {
|
||||
|
@ -550,11 +549,11 @@
|
|||
},
|
||||
/**
|
||||
* expands selection to cover whole sign
|
||||
* prevents partial deletion/copying/overwritting of a sign
|
||||
* prevents partial deletion/copying/overwriting of a sign
|
||||
*/
|
||||
expandSelectionOnSign: function (setReal) {
|
||||
var sign_position = this.signPosition();
|
||||
var selection = this.selection;
|
||||
var sign_position = this.signPosition(),
|
||||
selection = this.selection;
|
||||
if (selection.start < sign_position[1] && selection.end > sign_position[0]) { /** if selection catches something except sign and catches only space from sign */
|
||||
if ((selection.start < sign_position[0] || selection.end > sign_position[1]) && this.value.substring(Math.max(selection.start, sign_position[0]), Math.min(selection.end, sign_position[1])).match(/^\s*$/)) { /** then select without empty space */
|
||||
if (selection.start < sign_position[0]) {
|
||||
|
@ -572,8 +571,8 @@
|
|||
*/
|
||||
checkPaste: function () {
|
||||
if (this.valuePartsBeforePaste !== undefined) {
|
||||
var parts = this.getBeforeAfter();
|
||||
var oldParts = this.valuePartsBeforePaste;
|
||||
var parts = this.getBeforeAfter(),
|
||||
oldParts = this.valuePartsBeforePaste;
|
||||
delete this.valuePartsBeforePaste; /** try to strip pasted value first */
|
||||
parts[0] = parts[0].substr(0, oldParts[0].length) + autoStrip(parts[0].substr(oldParts[0].length), this.settingsClone);
|
||||
if (!this.setValueParts(parts[0], parts[1])) {
|
||||
|
@ -587,7 +586,11 @@
|
|||
* if returns true, futher processing is not performed
|
||||
*/
|
||||
skipAllways: function (e) {
|
||||
var kdCode = this.kdCode, which = this.which, ctrlKey = this.ctrlKey, cmdKey = this.cmdKey, shiftKey = this.shiftKey; /** catch the ctrl up on ctrl-v */
|
||||
var kdCode = this.kdCode,
|
||||
which = this.which,
|
||||
ctrlKey = this.ctrlKey,
|
||||
cmdKey = this.cmdKey,
|
||||
shiftKey = this.shiftKey; /** catch the ctrl up on ctrl-v */
|
||||
if (((ctrlKey || cmdKey) && e.type === 'keyup' && this.valuePartsBeforePaste !== undefined) || (shiftKey && kdCode === 45)) {
|
||||
this.checkPaste();
|
||||
return false;
|
||||
|
@ -626,7 +629,7 @@
|
|||
if (e.type === 'keydown' && aSep && !this.shiftKey) {
|
||||
if (kdCode === 37 && value.charAt(start - 2) === aSep) {
|
||||
this.setPosition(start - 1);
|
||||
} else if (kdCode === 39 && value.charAt(start) === aSep) {
|
||||
} else if (kdCode === 39 && value.charAt(start + 1) === aSep) {
|
||||
this.setPosition(start + 1);
|
||||
}
|
||||
}
|
||||
|
@ -666,11 +669,11 @@
|
|||
* returns true if processing performed
|
||||
*/
|
||||
processKeypress: function () {
|
||||
var settingsClone = this.settingsClone;
|
||||
var cCode = String.fromCharCode(this.which);
|
||||
var parts = this.getBeforeAfterStriped();
|
||||
var left = parts[0],
|
||||
right = parts[1]; /** start rules when the decimal charactor key is pressed */
|
||||
var settingsClone = this.settingsClone,
|
||||
cCode = String.fromCharCode(this.which),
|
||||
parts = this.getBeforeAfterStriped(),
|
||||
left = parts[0],
|
||||
right = parts[1]; /** start rules when the decimal character key is pressed */
|
||||
/** always use numeric pad dot to insert decimal separator */
|
||||
if (cCode === settingsClone.aDec || (settingsClone.altDec && cCode === settingsClone.altDec) || ((cCode === '.' || cCode === ',') && this.kdCode === 110)) { /** do not allow decimal character if no decimal part allowed */
|
||||
if (!settingsClone.mDec || !settingsClone.aDec) {
|
||||
|
@ -691,10 +694,11 @@
|
|||
this.setValueParts(left + settingsClone.aDec, right);
|
||||
return true;
|
||||
} /** start rule on negative sign */
|
||||
|
||||
if (cCode === '-' || cCode === '+') { /** prevent minus if not allowed */
|
||||
if (!settingsClone.aNeg) {
|
||||
return true;
|
||||
} /** carret is always after minus */
|
||||
} /** caret is always after minus */
|
||||
if (left === '' && right.indexOf(settingsClone.aNeg) > -1) {
|
||||
left = settingsClone.aNeg;
|
||||
right = right.substring(1, right.length);
|
||||
|
@ -724,9 +728,9 @@
|
|||
* formatting of just processed value with keeping of cursor position
|
||||
*/
|
||||
formatQuick: function () {
|
||||
var settingsClone = this.settingsClone;
|
||||
var parts = this.getBeforeAfterStriped();
|
||||
var leftLength = this.value;
|
||||
var settingsClone = this.settingsClone,
|
||||
parts = this.getBeforeAfterStriped(),
|
||||
leftLength = this.value;
|
||||
if ((settingsClone.aSep === '' || (settingsClone.aSep !== '' && leftLength.indexOf(settingsClone.aSep) === -1)) && (settingsClone.aSign === '' || (settingsClone.aSign !== '' && leftLength.indexOf(settingsClone.aSign) === -1))) {
|
||||
var subParts = [],
|
||||
nSign = '';
|
||||
|
@ -741,12 +745,12 @@
|
|||
}
|
||||
parts[0] = nSign + parts[0];
|
||||
}
|
||||
var value = autoGroup(this.value, this.settingsClone);
|
||||
var position = value.length;
|
||||
var value = autoGroup(this.value, this.settingsClone),
|
||||
position = value.length;
|
||||
if (value) {
|
||||
/** prepare regexp which searches for cursor position from unformatted left part */
|
||||
var left_ar = parts[0].split('');
|
||||
var i = 0;
|
||||
var left_ar = parts[0].split(''),
|
||||
i = 0;
|
||||
for (i; i < left_ar.length; i += 1) { /** thanks Peter Kovari */
|
||||
if (!left_ar[i].match('\\d')) {
|
||||
left_ar[i] = '\\' + left_ar[i];
|
||||
|
@ -800,10 +804,10 @@
|
|||
var methods = {
|
||||
init: function (options) {
|
||||
return this.each(function () {
|
||||
var $this = $(this);
|
||||
var settings = $this.data('autoNumeric'); /** attempt to grab 'autoNumeric' settings, if they don't exist returns "undefined". */
|
||||
var tagData = $this.data(); /** attempt to grab HTML5 data, if they don't exist we'll get "undefined".*/
|
||||
if (typeof settings !== 'object') { /** If we could't grab settings, create them from defaults and passed options. */
|
||||
var $this = $(this),
|
||||
settings = $this.data('autoNumeric'), /** attempt to grab 'autoNumeric' settings, if they don't exist returns "undefined". */
|
||||
tagData = $this.data(); /** attempt to grab HTML5 data, if they don't exist we'll get "undefined".*/
|
||||
if (typeof settings !== 'object') { /** If we couldn't grab settings, create them from defaults and passed options. */
|
||||
var defaults = {
|
||||
/** allowed numeric values
|
||||
* please do not modify
|
||||
|
@ -847,13 +851,13 @@
|
|||
* value must be enclosed in quotes and use the period for the decimal point
|
||||
* value must be larger than vMin
|
||||
*/
|
||||
vMax: '999999999999.99',
|
||||
vMax: '999999999.99',
|
||||
/** minimum possible value
|
||||
* value must be enclosed in quotes and use the period for the decimal point
|
||||
* value must be smaller than vMax
|
||||
*/
|
||||
vMin: '0.00',
|
||||
/** max number of decimal places = used to overide deciaml places set by the vMin & vMax values
|
||||
/** max number of decimal places = used to override decimal places set by the vMin & vMax values
|
||||
* value must be enclosed in quotes example mDec: '3',
|
||||
* This can also set the value via a call back function mDec: 'css:#
|
||||
*/
|
||||
|
@ -865,7 +869,7 @@
|
|||
* mRound: 'a', Round-Half-Down Asymmetric (lower case a)
|
||||
* mRound: 'B', Round-Half-Even "Bankers Rounding"
|
||||
* mRound: 'U', Round Up "Round-Away-From-Zero"
|
||||
* mRound: 'D', Round Down "Round-Toward-Zero" - same as trancate
|
||||
* mRound: 'D', Round Down "Round-Toward-Zero" - same as truncate
|
||||
* mRound: 'C', Round to Ceiling "Toward Positive Infinity"
|
||||
* mRound: 'F', Round to Floor "Toward Negative Infinity"
|
||||
*/
|
||||
|
@ -895,7 +899,7 @@
|
|||
*/
|
||||
lZero: 'allow',
|
||||
/** determine if the default value will be formatted on page ready.
|
||||
* true = atomatically formats the default value on page ready
|
||||
* true = automatically formats the default value on page ready
|
||||
* false = will not format the default value
|
||||
*/
|
||||
aForm: true,
|
||||
|
@ -904,41 +908,45 @@
|
|||
};
|
||||
settings = $.extend({}, defaults, tagData, options); /** Merge defaults, tagData and options */
|
||||
if (settings.aDec === settings.aSep) {
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand seperater aSep: '" + settings.aSep + "' are the same character");
|
||||
return this;
|
||||
}
|
||||
if ($.inArray($this.prop('tagName'), settings.tagList) !== -1) {
|
||||
$.error("The <" + $this.prop('tagName') + "> is not supported by autoNumeric()");
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand separator aSep: '" + settings.aSep + "' are the same character");
|
||||
return this;
|
||||
}
|
||||
$this.data('autoNumeric', settings); /** Save our new settings */
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
settings.lastSetValue = '';
|
||||
settings.runOnce = false;
|
||||
var holder = getHolder($this, settings);
|
||||
if (settings.runOnce === undefined && settings.aForm && ($this[0].value || $this.text() !== '')) {
|
||||
if ($this.is('input[type=text], input[type=hidden], input:not([type])')) { /**added hidden type */
|
||||
if (settings.nBracket !== null && ($this[0].value || settings.wEmpty !== 'empty')) { /** routine to handle page refresh */
|
||||
settings.oEvent = "pageLoad";
|
||||
$this[0].value = negativeBracket($this[0].value, settings.nBracket, settings.oEvent);
|
||||
$this[0].value = autoStrip($this[0].value, settings);
|
||||
if ($.inArray($this.prop('tagName'), settings.tagList) === -1 && $this.prop('tagName') !== 'INPUT') {
|
||||
$.error("The <" + $this.prop('tagName') + "> is not supported by autoNumeric()");
|
||||
return this;
|
||||
}
|
||||
if ($this[0].value !== $($this[0]).attr("value")) {
|
||||
$this.autoNumeric('set', autoStrip($this.val(), settings));
|
||||
} else {
|
||||
if (settings.runOnce === false && settings.aForm) {/** routine to format default value on page load */
|
||||
if ($this.is('input[type=text], input[type=hidden], input:not([type])')) {
|
||||
var setValue = true;
|
||||
if ($this[0].value === '' && settings.wEmpty === 'empty') {
|
||||
$this[0].value = '';
|
||||
setValue = false;
|
||||
}
|
||||
if ($this[0].value === '' && settings.wEmpty === 'sign') {
|
||||
$this[0].value = settings.aSign;
|
||||
setValue = false;
|
||||
}
|
||||
if (setValue) {
|
||||
$this.autoNumeric('set', $this.val());
|
||||
}
|
||||
}
|
||||
if ($.inArray($this.prop('tagName'), settings.tagList) !== -1) {
|
||||
if ($.inArray($this.prop('tagName'), settings.tagList) !== -1 && $this.text() !== '') {
|
||||
$this.autoNumeric('set', $this.text());
|
||||
}
|
||||
}
|
||||
settings.runOnce = true;
|
||||
if ($this.is('input[type=text], input[type=hidden], input:not([type])')) { /**added hidden type */
|
||||
$this.bind('keydown.autoNumeric', function(e) {
|
||||
$this.on('keydown.autoNumeric', function (e) {
|
||||
holder = getHolder($this);
|
||||
if (holder.settings.aDec === holder.settings.aSep) {
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + holder.settings.aDec + "' and thousand seperater aSep: '" + holder.settings.aSep + "' are the same character");
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + holder.settings.aDec + "' and thousand separator aSep: '" + holder.settings.aSep + "' are the same character");
|
||||
return this;
|
||||
}
|
||||
if (holder.that.readOnly) {
|
||||
|
@ -965,8 +973,9 @@
|
|||
holder.formatted = false;
|
||||
return true;
|
||||
});
|
||||
$this.bind('keypress.autoNumeric', function(e) {
|
||||
var holder = getHolder($this), processed = holder.processed;
|
||||
$this.on('keypress.autoNumeric', function (e) {
|
||||
var holder = getHolder($this),
|
||||
processed = holder.processed;
|
||||
holder.init(e);
|
||||
holder.settings.oEvent = 'keypress';
|
||||
if (holder.skipAllways(e)) {
|
||||
|
@ -982,15 +991,21 @@
|
|||
return false;
|
||||
}
|
||||
holder.formatted = false;
|
||||
|
||||
});
|
||||
$this.bind('keyup.autoNumeric', function(e) {
|
||||
$this.on('keyup.autoNumeric', function (e) {
|
||||
var holder = getHolder($this);
|
||||
holder.init(e);
|
||||
holder.settings.oEvent = 'keyup';
|
||||
var skip = holder.skipAllways(e);
|
||||
holder.kdCode = 0;
|
||||
delete holder.valuePartsBeforePaste;
|
||||
if ($this[0].value === holder.settings.aSign) { /** added to properly place the caret when only the currency is present */
|
||||
if (holder.settings.pSign === 's') {
|
||||
setElementSelection(this, 0, 0);
|
||||
} else {
|
||||
setElementSelection(this, holder.settings.aSign.length, holder.settings.aSign.length);
|
||||
}
|
||||
}
|
||||
if (skip) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1001,7 +1016,7 @@
|
|||
holder.formatQuick();
|
||||
}
|
||||
});
|
||||
$this.bind('focusin.autoNumeric', function() {
|
||||
$this.on('focusin.autoNumeric', function () {
|
||||
var holder = getHolder($this);
|
||||
holder.settingsClone.oEvent = 'focusin';
|
||||
if (holder.settingsClone.nBracket !== null) {
|
||||
|
@ -1012,9 +1027,14 @@
|
|||
var onempty = checkEmpty(holder.inVal, holder.settingsClone, true);
|
||||
if (onempty !== null) {
|
||||
$this.val(onempty);
|
||||
if (holder.settings.pSign === 's') {
|
||||
setElementSelection(this, 0, 0);
|
||||
} else {
|
||||
setElementSelection(this, holder.settings.aSign.length, holder.settings.aSign.length);
|
||||
}
|
||||
}
|
||||
});
|
||||
$this.bind('focusout.autoNumeric', function() {
|
||||
$this.on('focusout.autoNumeric', function () {
|
||||
var holder = getHolder($this),
|
||||
settingsClone = holder.settingsClone,
|
||||
value = $this.val(),
|
||||
|
@ -1058,7 +1078,7 @@
|
|||
destroy: function () {
|
||||
return $(this).each(function () {
|
||||
var $this = $(this);
|
||||
$this.unbind('.autoNumeric');
|
||||
$this.off('.autoNumeric');
|
||||
$this.removeData('autoNumeric');
|
||||
});
|
||||
},
|
||||
|
@ -1075,7 +1095,7 @@
|
|||
settings = $.extend(settings, options);
|
||||
getHolder($this, settings, true);
|
||||
if (settings.aDec === settings.aSep) {
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand seperater aSep: '" + settings.aSep + "' are the same character");
|
||||
$.error("autoNumeric will not function properly when the decimal character aDec: '" + settings.aDec + "' and thousand separator aSep: '" + settings.aSep + "' are the same character");
|
||||
return this;
|
||||
}
|
||||
$this.data('autoNumeric', settings);
|
||||
|
@ -1085,20 +1105,32 @@
|
|||
return;
|
||||
});
|
||||
},
|
||||
/** returns a formated strings for "input:text" fields Uses jQuery's .val() method*/
|
||||
/** returns a formatted strings for "input:text" fields Uses jQuery's .val() method*/
|
||||
set: function (valueIn) {
|
||||
return $(this).each(function () {
|
||||
var $this = autoGet($(this)), settings = $this.data('autoNumeric'), value = valueIn.toString();
|
||||
var $this = autoGet($(this)),
|
||||
settings = $this.data('autoNumeric'),
|
||||
value = valueIn.toString(),
|
||||
testValue = valueIn.toString();
|
||||
if (typeof settings !== 'object') {
|
||||
$.error("You must initialize autoNumeric('init', {options}) prior to calling the 'set' method");
|
||||
return this;
|
||||
}
|
||||
/** allows locale decimal separator to be a comma */
|
||||
if ((testValue === $this.attr('value') || testValue === $this.text()) && settings.runOnce === false) {
|
||||
value = value.replace(',', '.');
|
||||
}
|
||||
/** routine to handle page re-load from back button */
|
||||
if (testValue !== $this.attr('value') && $this.prop('tagName') === 'INPUT' && settings.runOnce === false) {
|
||||
value = autoStrip(value, settings);
|
||||
}
|
||||
/** returns a empty string if the value being 'set' contains non-numeric characters and or more than decimal point (full stop) and will not be formatted */
|
||||
if (!$.isNumeric(+value)) {
|
||||
return '';
|
||||
}
|
||||
value = checkValue(value);
|
||||
value = checkValue(value, settings);
|
||||
settings.oEvent = 'set';
|
||||
settings.lastSetValue = value; /** saves the unrounded value from the set method - $('selector').data('autoNumeric').lastSetValue; - helpful when you need to change the rounding accuracy*/
|
||||
value.toString();
|
||||
if (value !== '') {
|
||||
value = autoRound(value, settings);
|
||||
|
@ -1118,7 +1150,7 @@
|
|||
return false;
|
||||
});
|
||||
},
|
||||
/** method to get the unformated value from a specific input field, returns a numeric value */
|
||||
/** method to get the unformatted value from a specific input field, returns a numeric value */
|
||||
get: function () {
|
||||
var $this = autoGet($(this)),
|
||||
settings = $this.data('autoNumeric');
|
||||
|
@ -1137,7 +1169,7 @@
|
|||
$.error("The <" + $this.prop('tagName') + "> is not supported by autoNumeric()");
|
||||
return false;
|
||||
}
|
||||
if ((getValue === '' && settings.wEmpty === 'empty') || (getValue === settings.aSign && settings.wEmpty === 'sign')) {
|
||||
if ((getValue === '' && settings.wEmpty === 'empty') || (getValue === settings.aSign && (settings.wEmpty === 'sign' || settings.wEmpty === 'empty'))) {
|
||||
return '';
|
||||
}
|
||||
if (settings.nBracket !== null && getValue !== '') {
|
||||
|
@ -1153,10 +1185,10 @@
|
|||
if (settings.lZero === 'keep') {
|
||||
return getValue;
|
||||
}
|
||||
getValue = checkValue(getValue);
|
||||
getValue = checkValue(getValue, settings);
|
||||
return getValue; /** returned Numeric String */
|
||||
},
|
||||
/** method to get the unformated value from multiple fields */
|
||||
/** method to get the unformatted value from multiple fields */
|
||||
getString: function () {
|
||||
var isAutoNumeric = false,
|
||||
$this = autoGet($(this)),
|
||||
|
@ -1180,7 +1212,7 @@
|
|||
$.error("You must initialize autoNumeric('init', {options}) prior to calling the 'getString' method");
|
||||
return this;
|
||||
},
|
||||
/** method to get the unformated value from multiple fields */
|
||||
/** method to get the unformatted value from multiple fields */
|
||||
getArray: function () {
|
||||
var isAutoNumeric = false,
|
||||
$this = autoGet($(this)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue