jquery.inputmask.phone.extensions.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * jquery.inputmask.phone.extensions.js
  3. * http://github.com/RobinHerbots/jquery.inputmask
  4. * Copyright (c) 2010 - 2014 Robin Herbots
  5. * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. * Version: 3.1.26
  7. */
  8. (function (factory) {if (typeof define === 'function' && define.amd) {define(["jquery","./jquery.inputmask"], factory);} else {factory(jQuery);}}/*
  9. Input Mask plugin extensions
  10. http://github.com/RobinHerbots/jquery.inputmask
  11. Copyright (c) 2010 - 2014 Robin Herbots
  12. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  13. Version: 0.0.0
  14. Phone extension.
  15. When using this extension make sure you specify the correct url to get the masks
  16. $(selector).inputmask("phone", {
  17. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  18. onKeyValidation: function () { //show some metadata in the console
  19. console.log($(this).inputmask("getmetadata")["cd"]);
  20. }
  21. });
  22. */
  23. (function ($) {
  24. $.extend($.inputmask.defaults.aliases, {
  25. 'phone': {
  26. url: "phone-codes/phone-codes.js",
  27. maskInit: "+pp(pp)pppppppp",
  28. mask: function (opts) {
  29. opts.definitions = {
  30. 'p': {
  31. validator: function () { return false; },
  32. cardinality: 1
  33. },
  34. '#': {
  35. validator: "[0-9]",
  36. cardinality: 1
  37. }
  38. };
  39. var maskList = [];
  40. $.ajax({
  41. url: opts.url,
  42. async: false,
  43. dataType: 'json',
  44. success: function (response) {
  45. maskList = response;
  46. }
  47. });
  48. maskList.splice(0, 0, opts.maskInit);
  49. maskList.sort(function (a, b) { return a.length - b.length; });
  50. return maskList;
  51. },
  52. nojumps: true,
  53. nojumpsThreshold: 1
  54. },
  55. 'phonebe': {
  56. alias: "phone",
  57. url: "phone-codes/phone-be.js",
  58. maskInit: "+32(pp)pppppppp",
  59. nojumpsThreshold: 4
  60. }
  61. });
  62. return $.fn.inputmask;
  63. }));