inputmask.numeric.extensions.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*!
  2. * inputmask.numeric.extensions.js
  3. * https://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2016 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.3.4-32
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
  10. }(function($, Inputmask) {
  11. return Inputmask.extendAliases({
  12. numeric: {
  13. mask: function(opts) {
  14. function autoEscape(txt) {
  15. for (var escapedTxt = "", i = 0; i < txt.length; i++) escapedTxt += opts.definitions[txt.charAt(i)] || opts.optionalmarker.start === txt.charAt(i) || opts.optionalmarker.end === txt.charAt(i) || opts.quantifiermarker.start === txt.charAt(i) || opts.quantifiermarker.end === txt.charAt(i) || opts.groupmarker.start === txt.charAt(i) || opts.groupmarker.end === txt.charAt(i) || opts.alternatormarker === txt.charAt(i) ? "\\" + txt.charAt(i) : txt.charAt(i);
  16. return escapedTxt;
  17. }
  18. if (0 !== opts.repeat && isNaN(opts.integerDigits) && (opts.integerDigits = opts.repeat),
  19. opts.repeat = 0, opts.groupSeparator === opts.radixPoint && ("." === opts.radixPoint ? opts.groupSeparator = "," : "," === opts.radixPoint ? opts.groupSeparator = "." : opts.groupSeparator = ""),
  20. " " === opts.groupSeparator && (opts.skipOptionalPartCharacter = void 0), opts.autoGroup = opts.autoGroup && "" !== opts.groupSeparator,
  21. opts.autoGroup && ("string" == typeof opts.groupSize && isFinite(opts.groupSize) && (opts.groupSize = parseInt(opts.groupSize)),
  22. isFinite(opts.integerDigits))) {
  23. var seps = Math.floor(opts.integerDigits / opts.groupSize), mod = opts.integerDigits % opts.groupSize;
  24. opts.integerDigits = parseInt(opts.integerDigits) + (0 === mod ? seps - 1 : seps),
  25. opts.integerDigits < 1 && (opts.integerDigits = "*");
  26. }
  27. opts.placeholder.length > 1 && (opts.placeholder = opts.placeholder.charAt(0)),
  28. "radixFocus" === opts.positionCaretOnClick && "" === opts.placeholder && opts.integerOptional === !1 && (opts.positionCaretOnClick = "lvp"),
  29. opts.definitions[";"] = opts.definitions["~"], opts.definitions[";"].definitionSymbol = "~",
  30. opts.numericInput === !0 && (opts.positionCaretOnClick = "radixFocus" === opts.positionCaretOnClick ? "lvp" : opts.positionCaretOnClick,
  31. opts.digitsOptional = !1, isNaN(opts.digits) && (opts.digits = 2), opts.decimalProtect = !1);
  32. var mask = "[+]";
  33. if (mask += autoEscape(opts.prefix), mask += opts.integerOptional === !0 ? "~{1," + opts.integerDigits + "}" : "~{" + opts.integerDigits + "}",
  34. void 0 !== opts.digits) {
  35. opts.decimalProtect && (opts.radixPointDefinitionSymbol = ":");
  36. var dq = opts.digits.toString().split(",");
  37. isFinite(dq[0] && dq[1] && isFinite(dq[1])) ? mask += (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}" : (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (mask += opts.digitsOptional ? "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{1," + opts.digits + "}]" : (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}");
  38. }
  39. return mask += autoEscape(opts.suffix), mask += "[-]", opts.greedy = !1, null !== opts.min && (opts.min = opts.min.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  40. "," === opts.radixPoint && (opts.min = opts.min.replace(opts.radixPoint, "."))),
  41. null !== opts.max && (opts.max = opts.max.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  42. "," === opts.radixPoint && (opts.max = opts.max.replace(opts.radixPoint, "."))),
  43. mask;
  44. },
  45. placeholder: "",
  46. greedy: !1,
  47. digits: "*",
  48. digitsOptional: !0,
  49. radixPoint: ".",
  50. positionCaretOnClick: "radixFocus",
  51. groupSize: 3,
  52. groupSeparator: "",
  53. autoGroup: !1,
  54. allowPlus: !0,
  55. allowMinus: !0,
  56. negationSymbol: {
  57. front: "-",
  58. back: ""
  59. },
  60. integerDigits: "+",
  61. integerOptional: !0,
  62. prefix: "",
  63. suffix: "",
  64. rightAlign: !0,
  65. decimalProtect: !0,
  66. min: null,
  67. max: null,
  68. step: 1,
  69. insertMode: !0,
  70. autoUnmask: !1,
  71. unmaskAsNumber: !1,
  72. inputmode: "numeric",
  73. postFormat: function(buffer, pos, opts) {
  74. opts.numericInput === !0 && (buffer = buffer.reverse(), isFinite(pos) && (pos = buffer.join("").length - pos - 1));
  75. var i, l;
  76. pos = pos >= buffer.length ? buffer.length - 1 : pos < opts.prefix.length ? opts.prefix.length : pos;
  77. var charAtPos = buffer[pos], cbuf = buffer.slice();
  78. charAtPos === opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]),
  79. cbuf[pos] = "!";
  80. var bufVal = cbuf.join(""), bufValOrigin = bufVal, isNegative = bufVal.match(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)));
  81. if (isNegative = null !== isNegative && 1 === isNegative.length, isNegative && (bufVal = bufVal.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), ""),
  82. bufVal = bufVal.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "")),
  83. bufVal = bufVal.replace(new RegExp(Inputmask.escapeRegex(opts.suffix) + "$"), ""),
  84. bufVal = bufVal.replace(new RegExp("^" + Inputmask.escapeRegex(opts.prefix)), ""),
  85. bufVal.length > 0 && opts.autoGroup || bufVal.indexOf(opts.groupSeparator) !== -1) {
  86. var escapedGroupSeparator = Inputmask.escapeRegex(opts.groupSeparator);
  87. bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), "");
  88. var radixSplit = bufVal.split(charAtPos === opts.radixPoint ? "!" : opts.radixPoint);
  89. if (bufVal = "" === opts.radixPoint ? bufVal : radixSplit[0], charAtPos !== opts.negationSymbol.front && (bufVal = bufVal.replace("!", "?")),
  90. bufVal.length > opts.groupSize) for (var reg = new RegExp("([-+]?[\\d?]+)([\\d?]{" + opts.groupSize + "})"); reg.test(bufVal) && "" !== opts.groupSeparator; ) bufVal = bufVal.replace(reg, "$1" + opts.groupSeparator + "$2"),
  91. bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator);
  92. bufVal = bufVal.replace("?", "!"), "" !== opts.radixPoint && radixSplit.length > 1 && (bufVal += (charAtPos === opts.radixPoint ? "!" : opts.radixPoint) + radixSplit[1]);
  93. }
  94. bufVal = opts.prefix + bufVal + opts.suffix, isNegative && (bufVal = opts.negationSymbol.front + bufVal + opts.negationSymbol.back);
  95. var needsRefresh = bufValOrigin !== bufVal;
  96. if (needsRefresh) for (buffer.length = bufVal.length, i = 0, l = bufVal.length; i < l; i++) buffer[i] = bufVal.charAt(i);
  97. var newPos = $.inArray("!", bufVal);
  98. return buffer[newPos] = charAtPos, newPos = opts.numericInput && isFinite(pos) ? buffer.join("").length - newPos - 1 : newPos,
  99. opts.numericInput && (buffer = buffer.reverse(), $.inArray(opts.radixPoint, buffer) < newPos && buffer.join("").length - opts.suffix.length !== newPos && (newPos -= 1)),
  100. {
  101. pos: newPos,
  102. refreshFromBuffer: needsRefresh,
  103. buffer: buffer
  104. };
  105. },
  106. onBeforeWrite: function(e, buffer, caretPos, opts) {
  107. var rslt;
  108. if (e && ("blur" === e.type || "checkval" === e.type || "keydown" === e.type)) {
  109. var maskedValue = opts.numericInput ? buffer.slice().reverse().join("") : buffer.join(""), processValue = maskedValue.replace(opts.prefix, "");
  110. processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  111. "," === opts.radixPoint && (processValue = processValue.replace(opts.radixPoint, "."));
  112. var isNegative = processValue.match(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"));
  113. if (isNegative = null !== isNegative && 1 === isNegative.length, processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), ""),
  114. processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), ""),
  115. isNaN(opts.placeholder) && (processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.placeholder), "g"), "")),
  116. processValue = processValue === opts.negationSymbol.front ? processValue + "0" : processValue,
  117. "" !== processValue && isFinite(processValue)) {
  118. var floatValue = parseFloat(processValue), signedFloatValue = isNegative ? floatValue * -1 : floatValue;
  119. if (null !== opts.min && isFinite(opts.min) && signedFloatValue < parseFloat(opts.min) ? (floatValue = Math.abs(opts.min),
  120. isNegative = opts.min < 0, maskedValue = void 0) : null !== opts.max && isFinite(opts.max) && signedFloatValue > parseFloat(opts.max) && (floatValue = Math.abs(opts.max),
  121. isNegative = opts.max < 0, maskedValue = void 0), processValue = floatValue.toString().replace(".", opts.radixPoint).split(""),
  122. isFinite(opts.digits)) {
  123. var radixPosition = $.inArray(opts.radixPoint, processValue), rpb = $.inArray(opts.radixPoint, maskedValue);
  124. radixPosition === -1 && (processValue.push(opts.radixPoint), radixPosition = processValue.length - 1);
  125. for (var i = 1; i <= opts.digits; i++) opts.digitsOptional || void 0 !== processValue[radixPosition + i] && processValue[radixPosition + i] !== opts.placeholder.charAt(0) ? rpb !== -1 && void 0 !== maskedValue[rpb + i] && (processValue[radixPosition + i] = processValue[radixPosition + i] || maskedValue[rpb + i]) : processValue[radixPosition + i] = "0";
  126. processValue[processValue.length - 1] === opts.radixPoint && delete processValue[processValue.length - 1];
  127. }
  128. if (floatValue.toString() !== processValue && floatValue.toString() + "." !== processValue || isNegative) return processValue = (opts.prefix + processValue.join("")).split(""),
  129. !isNegative || 0 === floatValue && "blur" === e.type || (processValue.unshift(opts.negationSymbol.front),
  130. processValue.push(opts.negationSymbol.back)), opts.numericInput && (processValue = processValue.reverse()),
  131. rslt = opts.postFormat(processValue, opts.numericInput ? caretPos : caretPos - 1, opts),
  132. rslt.buffer && (rslt.refreshFromBuffer = rslt.buffer.join("") !== buffer.join("")),
  133. rslt;
  134. }
  135. }
  136. if (opts.autoGroup) return rslt = opts.postFormat(buffer, opts.numericInput ? caretPos : caretPos - 1, opts),
  137. rslt.caret = caretPos <= opts.prefix.length ? rslt.pos : rslt.pos + 1, rslt;
  138. },
  139. regex: {
  140. integerPart: function(opts) {
  141. return new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
  142. },
  143. integerNPart: function(opts) {
  144. return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + Inputmask.escapeRegex(opts.placeholder.charAt(0)) + "]+");
  145. }
  146. },
  147. signHandler: function(chrs, maskset, pos, strict, opts) {
  148. if (!strict && opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) {
  149. var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  150. if (matchRslt && matchRslt[0].length > 0) return maskset.buffer[matchRslt.index] === ("-" === chrs ? "+" : opts.negationSymbol.front) ? "-" === chrs ? "" !== opts.negationSymbol.back ? {
  151. pos: 0,
  152. c: opts.negationSymbol.front,
  153. remove: 0,
  154. caret: pos,
  155. insert: {
  156. pos: maskset.buffer.length - 1,
  157. c: opts.negationSymbol.back
  158. }
  159. } : {
  160. pos: 0,
  161. c: opts.negationSymbol.front,
  162. remove: 0,
  163. caret: pos
  164. } : "" !== opts.negationSymbol.back ? {
  165. pos: 0,
  166. c: "+",
  167. remove: [ 0, maskset.buffer.length - 1 ],
  168. caret: pos
  169. } : {
  170. pos: 0,
  171. c: "+",
  172. remove: 0,
  173. caret: pos
  174. } : maskset.buffer[0] === ("-" === chrs ? opts.negationSymbol.front : "+") ? "-" === chrs && "" !== opts.negationSymbol.back ? {
  175. remove: [ 0, maskset.buffer.length - 1 ],
  176. caret: pos - 1
  177. } : {
  178. remove: 0,
  179. caret: pos - 1
  180. } : "-" === chrs ? "" !== opts.negationSymbol.back ? {
  181. pos: 0,
  182. c: opts.negationSymbol.front,
  183. caret: pos + 1,
  184. insert: {
  185. pos: maskset.buffer.length,
  186. c: opts.negationSymbol.back
  187. }
  188. } : {
  189. pos: 0,
  190. c: opts.negationSymbol.front,
  191. caret: pos + 1
  192. } : {
  193. pos: 0,
  194. c: chrs,
  195. caret: pos + 1
  196. };
  197. }
  198. return !1;
  199. },
  200. radixHandler: function(chrs, maskset, pos, strict, opts) {
  201. if (!strict && opts.numericInput !== !0 && chrs === opts.radixPoint && void 0 !== opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
  202. var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
  203. if (radixPos !== -1 && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
  204. caret: radixPos + 1
  205. } : {
  206. pos: integerValue.index,
  207. c: integerValue[0],
  208. caret: radixPos + 1
  209. };
  210. if (!integerValue || "0" === integerValue[0] && integerValue.index + 1 !== pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0",
  211. {
  212. pos: (integerValue ? integerValue.index : pos) + 1,
  213. c: opts.radixPoint
  214. };
  215. }
  216. return !1;
  217. },
  218. leadingZeroHandler: function(chrs, maskset, pos, strict, opts, isSelection) {
  219. if (!strict) {
  220. var buffer = maskset.buffer.slice("");
  221. if (buffer.splice(0, opts.prefix.length), buffer.splice(buffer.length - opts.suffix.length, opts.suffix.length),
  222. opts.numericInput === !0) {
  223. var buffer = buffer.reverse(), bufferChar = buffer[0];
  224. if ("0" === bufferChar && void 0 === maskset.validPositions[pos - 1]) return {
  225. pos: pos,
  226. remove: buffer.length - 1
  227. };
  228. } else {
  229. pos -= opts.prefix.length;
  230. var radixPosition = $.inArray(opts.radixPoint, buffer), matchRslt = buffer.slice(0, radixPosition !== -1 ? radixPosition : void 0).join("").match(opts.regex.integerNPart(opts));
  231. if (matchRslt && (radixPosition === -1 || pos <= radixPosition)) {
  232. var decimalPart = radixPosition === -1 ? 0 : parseInt(buffer.slice(radixPosition + 1).join(""));
  233. if (0 === matchRslt[0].indexOf("" !== opts.placeholder ? opts.placeholder.charAt(0) : "0") && (matchRslt.index + 1 === pos || isSelection !== !0 && 0 === decimalPart)) return maskset.buffer.splice(matchRslt.index + opts.prefix.length, 1),
  234. {
  235. pos: matchRslt.index + opts.prefix.length,
  236. remove: matchRslt.index + opts.prefix.length
  237. };
  238. if ("0" === chrs && pos <= matchRslt.index && matchRslt[0] !== opts.groupSeparator) return !1;
  239. }
  240. }
  241. }
  242. return !0;
  243. },
  244. definitions: {
  245. "~": {
  246. validator: function(chrs, maskset, pos, strict, opts, isSelection) {
  247. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  248. if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts),
  249. !isValid && (isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs),
  250. isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts, isSelection),
  251. isValid === !0)))) {
  252. var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
  253. isValid = radixPosition !== -1 && (opts.digitsOptional === !1 || maskset.validPositions[pos]) && opts.numericInput !== !0 && pos > radixPosition && !strict ? {
  254. pos: pos,
  255. remove: pos
  256. } : {
  257. pos: pos
  258. };
  259. }
  260. return isValid;
  261. },
  262. cardinality: 1
  263. },
  264. "+": {
  265. validator: function(chrs, maskset, pos, strict, opts) {
  266. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  267. return !isValid && (strict && opts.allowMinus && chrs === opts.negationSymbol.front || opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs) && (isValid = !(!strict && "-" === chrs) || ("" !== opts.negationSymbol.back ? {
  268. pos: pos,
  269. c: "-" === chrs ? opts.negationSymbol.front : "+",
  270. caret: pos + 1,
  271. insert: {
  272. pos: maskset.buffer.length,
  273. c: opts.negationSymbol.back
  274. }
  275. } : {
  276. pos: pos,
  277. c: "-" === chrs ? opts.negationSymbol.front : "+",
  278. caret: pos + 1
  279. })), isValid;
  280. },
  281. cardinality: 1,
  282. placeholder: ""
  283. },
  284. "-": {
  285. validator: function(chrs, maskset, pos, strict, opts) {
  286. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  287. return !isValid && strict && opts.allowMinus && chrs === opts.negationSymbol.back && (isValid = !0),
  288. isValid;
  289. },
  290. cardinality: 1,
  291. placeholder: ""
  292. },
  293. ":": {
  294. validator: function(chrs, maskset, pos, strict, opts) {
  295. var isValid = opts.signHandler(chrs, maskset, pos, strict, opts);
  296. if (!isValid) {
  297. var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + "]";
  298. isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint && (isValid = {
  299. caret: pos + 1
  300. });
  301. }
  302. return isValid ? {
  303. c: opts.radixPoint
  304. } : isValid;
  305. },
  306. cardinality: 1,
  307. placeholder: function(opts) {
  308. return opts.radixPoint;
  309. }
  310. }
  311. },
  312. onUnMask: function(maskedValue, unmaskedValue, opts) {
  313. if ("" === unmaskedValue && opts.nullable === !0) return unmaskedValue;
  314. var processValue = maskedValue.replace(opts.prefix, "");
  315. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  316. opts.unmaskAsNumber ? ("" !== opts.radixPoint && processValue.indexOf(opts.radixPoint) !== -1 && (processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".")),
  317. Number(processValue)) : processValue;
  318. },
  319. isComplete: function(buffer, opts) {
  320. var maskedValue = buffer.join(""), bufClone = buffer.slice();
  321. if (opts.postFormat(bufClone, 0, opts), bufClone.join("") !== maskedValue) return !1;
  322. var processValue = maskedValue.replace(opts.prefix, "");
  323. return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), ""),
  324. "," === opts.radixPoint && (processValue = processValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".")),
  325. isFinite(processValue);
  326. },
  327. onBeforeMask: function(initialValue, opts) {
  328. if (opts.numericInput === !0 && (initialValue = initialValue.split("").reverse().join("")),
  329. "" !== opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else {
  330. var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
  331. dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""),
  332. initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""),
  333. initialValue = initialValue.replace(".", opts.radixPoint)) : initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "") : initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
  334. }
  335. if (0 === opts.digits && (initialValue.indexOf(".") !== -1 ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : initialValue.indexOf(",") !== -1 && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))),
  336. "" !== opts.radixPoint && isFinite(opts.digits) && initialValue.indexOf(opts.radixPoint) !== -1) {
  337. var valueParts = initialValue.split(opts.radixPoint), decPart = valueParts[1].match(new RegExp("\\d*"))[0];
  338. if (parseInt(opts.digits) < decPart.toString().length) {
  339. var digitsFactor = Math.pow(10, parseInt(opts.digits));
  340. initialValue = initialValue.replace(Inputmask.escapeRegex(opts.radixPoint), "."),
  341. initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor,
  342. initialValue = initialValue.toString().replace(".", opts.radixPoint);
  343. }
  344. }
  345. return opts.numericInput === !0 && (initialValue = initialValue.split("").reverse().join("")),
  346. initialValue.toString();
  347. },
  348. canClearPosition: function(maskset, position, lvp, strict, opts) {
  349. var positionInput = maskset.validPositions[position].input, canClear = positionInput !== opts.radixPoint || null !== maskset.validPositions[position].match.fn && opts.decimalProtect === !1 || isFinite(positionInput) || position === lvp || positionInput === opts.groupSeparator || positionInput === opts.negationSymbol.front || positionInput === opts.negationSymbol.back;
  350. return canClear;
  351. },
  352. onKeyDown: function(e, buffer, caretPos, opts) {
  353. var $input = $(this);
  354. if (e.ctrlKey) switch (e.keyCode) {
  355. case Inputmask.keyCode.UP:
  356. $input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step)), $input.trigger("setvalue");
  357. break;
  358. case Inputmask.keyCode.DOWN:
  359. $input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step)), $input.trigger("setvalue");
  360. }
  361. }
  362. },
  363. currency: {
  364. prefix: "$ ",
  365. groupSeparator: ",",
  366. alias: "numeric",
  367. placeholder: "0",
  368. autoGroup: !0,
  369. digits: 2,
  370. digitsOptional: !1,
  371. clearMaskOnLostFocus: !1
  372. },
  373. decimal: {
  374. alias: "numeric"
  375. },
  376. integer: {
  377. alias: "numeric",
  378. digits: 0,
  379. radixPoint: ""
  380. },
  381. percentage: {
  382. alias: "numeric",
  383. digits: 2,
  384. radixPoint: ".",
  385. placeholder: "0",
  386. autoGroup: !1,
  387. min: 0,
  388. max: 100,
  389. suffix: " %",
  390. allowPlus: !1,
  391. allowMinus: !1
  392. }
  393. }), Inputmask;
  394. });