Blame view

vendor/bower-asset/jquery.inputmask/js/jquery.inputmask.phone.extensions.js 2.18 KB
b2a15e0c   Dmitryi   роли и права поль...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  /*
  Input Mask plugin extensions
  http://github.com/RobinHerbots/jquery.inputmask
  Copyright (c) 2010 -  Robin Herbots
  Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  Version: 0.0.0-dev
  
  Phone extension.
  When using this extension make sure you specify the correct url to get the masks
  
   $(selector).inputmask("phone", {
                  url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json", 
                  onKeyValidation: function () { //show some metadata in the console
                      console.log($(this).inputmask("getmetadata")["cd"]);
                  } 
    });
  
  
  */
  (function ($) {
      $.extend($.inputmask.defaults.aliases, {
          'phone': {
              url: "phone-codes/phone-codes.js",
              countrycode: "",
              mask: function (opts) {
                  opts.definitions['#'] = opts.definitions['9'];
                  var maskList = [];
                  $.ajax({
                      url: opts.url,
                      async: false,
                      dataType: 'json',
                      success: function (response) {
                          maskList = response;
                      },
                      error: function (xhr, ajaxOptions, thrownError) {
                          alert(thrownError + " - " + opts.url);
                      }
                  });
  
                  maskList = maskList.sort(function (a, b) {
                      return (a["mask"] || a) < (b["mask"] || b) ? -1 : 1;
                  });
  
                  return maskList;
              },
              keepStatic: false,
              nojumps: true,
              nojumpsThreshold: 1,
              onBeforeMask: function (value, opts) {
                  var processedValue = value.replace(/^0/g, "");
                  if (processedValue.indexOf(opts.countrycode) > 1 || processedValue.indexOf(opts.countrycode) == -1) {
                      processedValue = "+" + opts.countrycode + processedValue;
                  }
  
                  return processedValue;
              }
          },
          'phonebe': {
              alias: "phone",
              url: "phone-codes/phone-be.js",
              countrycode: "32",
              nojumpsThreshold: 4
          }
      });
      return $.fn.inputmask;
  })(jQuery);