inputmask.phone.extensions.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. * inputmask.phone.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.1
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "jquery", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
  10. }(function($, Inputmask) {
  11. return Inputmask.extendAliases({
  12. phone: {
  13. url: "phone-codes/phone-codes.js",
  14. countrycode: "",
  15. phoneCodeCache: {},
  16. mask: function(opts) {
  17. if (void 0 === opts.phoneCodeCache[opts.url]) {
  18. var maskList = [];
  19. opts.definitions["#"] = opts.definitions[9], $.ajax({
  20. url: opts.url,
  21. async: !1,
  22. type: "get",
  23. dataType: "json",
  24. success: function(response) {
  25. maskList = response;
  26. },
  27. error: function(xhr, ajaxOptions, thrownError) {
  28. alert(thrownError + " - " + opts.url);
  29. }
  30. }), opts.phoneCodeCache[opts.url] = maskList.sort(function(a, b) {
  31. return (a.mask || a) < (b.mask || b) ? -1 : 1;
  32. });
  33. }
  34. return opts.phoneCodeCache[opts.url];
  35. },
  36. keepStatic: !1,
  37. nojumps: !0,
  38. nojumpsThreshold: 1,
  39. onBeforeMask: function(value, opts) {
  40. var processedValue = value.replace(/^0{1,2}/, "").replace(/[\s]/g, "");
  41. return (processedValue.indexOf(opts.countrycode) > 1 || -1 === processedValue.indexOf(opts.countrycode)) && (processedValue = "+" + opts.countrycode + processedValue),
  42. processedValue;
  43. }
  44. },
  45. phonebe: {
  46. alias: "phone",
  47. url: "phone-codes/phone-be.js",
  48. countrycode: "32",
  49. nojumpsThreshold: 4
  50. }
  51. }), Inputmask;
  52. });