inputmask.numeric.extensions.js 26 KB

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