Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16825 efrain 1
var input,
2
  iti,
3
  totalCountries = 243,
4
  totalDialCodes = 228,
5
  defaultPreferredCountries = 2;
6
 
7
var intlSetup = function(utilsScript) {
8
  // by default put us in desktop mode
9
  window.innerWidth = 1024;
10
 
11
  // this should only run the first time
12
  if (!window.intlTelInputUtilsBackup) {
13
    window.intlTelInputUtilsBackup = window.intlTelInputUtils;
14
  }
15
  if (utilsScript) {
16
    window.intlTelInputUtils = window.intlTelInputUtilsBackup;
17
  } else {
18
    window.intlTelInputUtils = null;
19
  }
20
};
21
 
22
var intlTeardown = function() {
23
  $("script.iti-load-utils").remove();
24
  window.intlTelInputGlobals.startedLoadingUtilsScript = false;
25
  window.intlTelInputGlobals.documentReady = () => false;
26
  window.intlTelInputGlobals.autoCountry = null;
27
  window.intlTelInputGlobals.startedLoadingAutoCountry = false;
28
  // just make sure before we change the ref
29
  if (!window.intlTelInputUtilsBackup) {
30
    window.intlTelInputUtilsBackup = window.intlTelInputUtils;
31
  }
32
  window.intlTelInputUtils = null;
33
  if (iti) iti.destroy();
34
  if (input) input.remove();
35
  input = iti = null;
36
};
37
 
38
var waitForUtilsRequest = function(done) {
39
  // this wait is needed while jasmine actually does the request to load utils.js
40
  setTimeout(done, 100);
41
};
42
 
43
var getInputVal = function(i) {
44
  i = i || input;
45
  return i.val();
46
};
47
 
48
var getParentElement = function(i) {
49
  i = i || input;
50
  return i.parent();
51
};
52
 
53
var getListElement = function(i) {
54
  i = i || input;
55
  return i.parent().find(".iti__country-list");
56
};
57
 
58
var getListLength = function(i) {
59
  i = i || input;
60
  return getListElement(i).find("li.iti__country").length;
61
};
62
 
63
var getActiveListItem = function(i) {
64
  i = i || input;
65
  return getListElement(i).find("li.iti__active");
66
};
67
 
68
var getPreferredCountriesLength = function(i) {
69
  i = i || input;
70
  return getListElement(i).find("li.iti__preferred").length;
71
};
72
 
73
var getSelectedFlagContainer = function(i) {
74
  i = i || input;
75
  return i.parent().find(".iti__selected-flag");
76
};
77
 
78
var getSelectedFlagElement = function(i) {
79
  i = i || input;
80
  return getSelectedFlagContainer(i).find(".iti__flag");
81
};
82
 
83
var getSelectedDialCodeElement = function(i) {
84
  i = i || input;
85
  return getSelectedFlagContainer(i).find(".iti__selected-dial-code");
86
};
87
 
88
var getFlagsContainerElement = function(i) {
89
  i = i || input;
90
  return i.parent().find(".iti__flag-container");
91
};
92
 
93
var selectFlag = function(countryCode, i) {
94
  i = i || input;
95
  getSelectedFlagContainer(i)[0].click();
96
  getListElement(i).find("li[data-country-code='" + countryCode + "']")[0].click();
97
};
98
 
99
var openCountryDropDown = function() {
100
  getSelectedFlagContainer()[0].click();
101
};
102
 
103
var putCursorAtEnd = function() {
104
  var len = input.val().length;
105
  selectInputChars(len, len);
106
};
107
 
108
var selectInputChars = function(start, end) {
109
  input[0].setSelectionRange(start, end);
110
};
111
 
112
// use this for focus/blur (instead of using .focus() and .blur() directly, which cause problems in IE11)
113
var triggerInputEvent = function(type) {
114
  var e = new CustomEvent(type);
115
  input[0].dispatchEvent(e);
116
}
117
 
118
var triggerKey = function(el, type, key) {
119
  var e = new CustomEvent(type);
120
  e.key = key;
121
  el.dispatchEvent(e);
122
};
123
 
124
// trigger keydown, then keypress, then add the key, then keyup
125
var triggerKeyOnInput = function(key) {
126
  triggerKey(input[0], 'keydown', key);
127
  triggerKey(input[0], 'keypress', key);
128
  var val = input.val();
129
  input.val(val + key);
130
  triggerKey(input[0], 'keyup', key);
131
};
132
 
133
var triggerKeyOnBody = function(key) {
134
  triggerKey(document, 'keydown', key);
135
  triggerKey(document, 'keypress', key);
136
  triggerKey(document, 'keyup', key);
137
};
138
 
139
var triggerKeyOnFlagsContainerElement = function(key) {
140
  triggerKey(getFlagsContainerElement()[0], 'keydown', key);
141
};