inputmask.numeric.extensions.js 28 KB

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