inputmask.numeric.extensions.js 28 KB

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