Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

431 line
29KB

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