You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.3KB

  1. /*!
  2. * jquery.inputmask.phone.extensions.js
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2015 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.1.61
  7. */
  8. !function(factory) {
  9. "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : factory(jQuery);
  10. }(function($) {
  11. return $.extend($.inputmask.defaults.aliases, {
  12. phone: {
  13. url: "phone-codes/phone-codes.js",
  14. maskInit: "+pp(pp)pppppppp",
  15. countrycode: "",
  16. mask: function(opts) {
  17. opts.definitions = {
  18. p: {
  19. validator: function() {
  20. return !1;
  21. },
  22. cardinality: 1
  23. },
  24. "#": {
  25. validator: "[0-9]",
  26. cardinality: 1
  27. }
  28. };
  29. var maskList = [];
  30. return $.ajax({
  31. url: opts.url,
  32. async: !1,
  33. dataType: "json",
  34. success: function(response) {
  35. maskList = response;
  36. },
  37. error: function(xhr, ajaxOptions, thrownError) {
  38. alert(thrownError + " - " + opts.url);
  39. }
  40. }), maskList = maskList.sort(function(a, b) {
  41. return (a.mask || a) < (b.mask || b) ? -1 : 1;
  42. }), "" != opts.countrycode && (opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3)),
  43. maskList.splice(0, 0, opts.maskInit), maskList;
  44. },
  45. nojumps: !0,
  46. nojumpsThreshold: 1,
  47. onBeforeMask: function(value, opts) {
  48. var processedValue = value.replace(/^0/g, "");
  49. return (processedValue.indexOf(opts.countrycode) > 1 || -1 == processedValue.indexOf(opts.countrycode)) && (processedValue = "+" + opts.countrycode + processedValue),
  50. processedValue;
  51. }
  52. },
  53. phonebe: {
  54. alias: "phone",
  55. url: "phone-codes/phone-be.js",
  56. countrycode: "32",
  57. nojumpsThreshold: 4
  58. }
  59. }), $.fn.inputmask;
  60. });