inputmask.phone.extensions.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*!
  2. * inputmask.phone.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.6
  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. return void 0 === opts.phoneCodeCache[opts.url] && (opts.definitions["#"] = opts.definitions[9],
  18. $.ajax({
  19. url: opts.url,
  20. async: !1,
  21. type: "get",
  22. dataType: "json",
  23. success: function(response) {
  24. maskList = response;
  25. },
  26. error: function(xhr, ajaxOptions, thrownError) {
  27. alert(thrownError + " - " + opts.url);
  28. }
  29. }), opts.phoneCodeCache[opts.url] = maskList.sort(function(a, b) {
  30. return (a.mask || a) < (b.mask || b) ? -1 : 1;
  31. })), opts.phoneCodeCache[opts.url];
  32. },
  33. keepStatic: !1,
  34. nojumps: !0,
  35. nojumpsThreshold: 1,
  36. onBeforeMask: function(value, opts) {
  37. var processedValue = value.replace(/^0{1,2}/, "").replace(/[\s]/g, "");
  38. return (processedValue.indexOf(opts.countrycode) > 1 || -1 === processedValue.indexOf(opts.countrycode)) && (processedValue = "+" + opts.countrycode + processedValue),
  39. processedValue;
  40. }
  41. },
  42. phonebe: {
  43. alias: "phone",
  44. url: "phone-codes/phone-be.js",
  45. countrycode: "32",
  46. nojumpsThreshold: 4
  47. }
  48. }), Inputmask;
  49. });