├── README.md ├── acf-intl-tel-input.php ├── assets ├── css │ └── input.css ├── intl-tel-input │ ├── css │ │ ├── demo.css │ │ └── intlTelInput.css │ ├── img │ │ ├── flags.png │ │ └── flags@2x.png │ └── js │ │ ├── intlTelInput.js │ │ ├── intlTelInput.min.js │ │ └── utils.js └── js │ ├── input.js │ └── js.cookie.js ├── fields └── class-jony-acf-field-intl-tel-input-v5.php ├── lang └── README.md └── readme.txt /README.md: -------------------------------------------------------------------------------- 1 | # ACF International Telephone Input Field 2 | 3 | Adds International Telephone Input to ACF. 4 | 5 | Allows separate dial code, drop down, initial country (auto or manual), exclude countries, only countries and preferred countries. 6 | 7 | ## Links 8 | 9 | * International Telephone Input[https://intl-tel-input.com/] by jackocnr[https://github.com/jackocnr] 10 | * Advanced Custom Fields[https://www.advancedcustomfields.com/] by Elliot Condon[https://github.com/elliotcondon] 11 | 12 | ## Compatibility 13 | 14 | This ACF field type is compatible with: 15 | * ACF 5 16 | 17 | ## Installation 18 | 19 | 1. Copy the `acf-intl-tel-input` folder into your `wp-content/plugins` folder 20 | 2. Activate the International Telephone Input plugin via the plugins admin page 21 | 3. Create a new field via ACF and select the International Telephone Input type 22 | 4. Read the description above for usage instructions 23 | 24 | ## Changelog 25 | 26 | ### Version 1.0.0 - Inital Commit -------------------------------------------------------------------------------- /acf-intl-tel-input.php: -------------------------------------------------------------------------------- 1 | settings = array( 45 | 'version' => '1.0.0', 46 | 'url' => plugin_dir_url( __FILE__ ), 47 | 'path' => plugin_dir_path( __FILE__ ) 48 | ); 49 | 50 | 51 | // set text domain 52 | // https://codex.wordpress.org/Function_Reference/load_plugin_textdomain 53 | load_plugin_textdomain( 'acf-intl-tel-input', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' ); 54 | 55 | 56 | // include field 57 | add_action('acf/include_field_types', array($this, 'include_field_types')); // v5 58 | add_action('acf/register_fields', array($this, 'include_field_types')); // v4 59 | 60 | } 61 | 62 | 63 | /* 64 | * include_field_types 65 | * 66 | * This function will include the field type class 67 | * 68 | * @type function 69 | * @date 17/02/2016 70 | * @since 1.0.0 71 | * 72 | * @param $version (int) major ACF version. Defaults to false 73 | * @return n/a 74 | */ 75 | 76 | function include_field_types( $version = false ) { 77 | 78 | // support empty $version 79 | if( !$version ) $version = 5; 80 | 81 | 82 | // include 83 | include_once('fields/class-jony-acf-field-intl-tel-input-v' . $version . '.php'); 84 | 85 | } 86 | 87 | } 88 | 89 | 90 | // initialize 91 | new jony_acf_plugin_intl_tel_input(); 92 | 93 | 94 | // class_exists check 95 | endif; 96 | 97 | ?> -------------------------------------------------------------------------------- /assets/css/input.css: -------------------------------------------------------------------------------- 1 | .acf-input .intl-tel-input{ width:100%; } 2 | .acf-input .intl-tel-input input[type=tel]{ width:100%; padding-top:3px; padding-bottom:3px; line-height:1.4; box-sizing:border-box; margin:0; font-size:14px } -------------------------------------------------------------------------------- /assets/intl-tel-input/css/demo.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | -moz-box-sizing: border-box; } 4 | 5 | body { 6 | margin: 20px; 7 | font-size: 14px; 8 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; 9 | color: #555; } 10 | 11 | .hide { 12 | display: none; } 13 | 14 | pre { 15 | margin: 0 !important; 16 | display: inline-block; } 17 | 18 | .token.operator, 19 | .token.entity, 20 | .token.url, 21 | .language-css .token.string, 22 | .style .token.string, 23 | .token.variable { 24 | background: none; } 25 | 26 | input, button { 27 | height: 35px; 28 | margin: 0; 29 | padding: 6px 12px; 30 | border-radius: 2px; 31 | font-family: inherit; 32 | font-size: 100%; 33 | color: inherit; } 34 | input[disabled], button[disabled] { 35 | background-color: #eee; } 36 | 37 | input, select { 38 | border: 1px solid #CCC; 39 | width: 250px; } 40 | 41 | ::-webkit-input-placeholder { 42 | color: #BBB; } 43 | 44 | ::-moz-placeholder { 45 | /* Firefox 19+ */ 46 | color: #BBB; 47 | opacity: 1; } 48 | 49 | :-ms-input-placeholder { 50 | color: #BBB; } 51 | 52 | button { 53 | color: #FFF; 54 | background-color: #428BCA; 55 | border: 1px solid #357EBD; } 56 | button:hover { 57 | background-color: #3276B1; 58 | border-color: #285E8E; 59 | cursor: pointer; } 60 | 61 | #result { 62 | margin-bottom: 100px; } 63 | -------------------------------------------------------------------------------- /assets/intl-tel-input/css/intlTelInput.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Variables declared here can be overridden by consuming applications, with 3 | * the help of the `!default` flag. 4 | * 5 | * @example 6 | * // overriding $hoverColor 7 | * $hoverColor: rgba(red, 0.05); 8 | * 9 | * // overriding image path 10 | * $flagsImagePath: "images/"; 11 | * 12 | * // import the scss file after the overrides 13 | * @import "bower_component/intl-tel-input/src/css/intlTelInput"; 14 | */ 15 | .intl-tel-input { 16 | position: relative; 17 | display: inline-block; } 18 | .intl-tel-input * { 19 | box-sizing: border-box; 20 | -moz-box-sizing: border-box; } 21 | .intl-tel-input .hide { 22 | display: none; } 23 | .intl-tel-input .v-hide { 24 | visibility: hidden; } 25 | .intl-tel-input input, .intl-tel-input input[type=text], .intl-tel-input input[type=tel] { 26 | position: relative; 27 | z-index: 0; 28 | margin-top: 0 !important; 29 | margin-bottom: 0 !important; 30 | padding-right: 36px; 31 | margin-right: 0; } 32 | .intl-tel-input .flag-container { 33 | position: absolute; 34 | top: 0; 35 | bottom: 0; 36 | right: 0; 37 | padding: 1px; } 38 | .intl-tel-input .selected-flag { 39 | z-index: 1; 40 | position: relative; 41 | width: 36px; 42 | height: 100%; 43 | padding: 0 0 0 8px; } 44 | .intl-tel-input .selected-flag .iti-flag { 45 | position: absolute; 46 | top: 0; 47 | bottom: 0; 48 | margin: auto; } 49 | .intl-tel-input .selected-flag .iti-arrow { 50 | position: absolute; 51 | top: 50%; 52 | margin-top: -2px; 53 | right: 6px; 54 | width: 0; 55 | height: 0; 56 | border-left: 3px solid transparent; 57 | border-right: 3px solid transparent; 58 | border-top: 4px solid #555; } 59 | .intl-tel-input .selected-flag .iti-arrow.up { 60 | border-top: none; 61 | border-bottom: 4px solid #555; } 62 | .intl-tel-input .country-list { 63 | position: absolute; 64 | z-index: 2; 65 | list-style: none; 66 | text-align: left; 67 | padding: 0; 68 | margin: 0 0 0 -1px; 69 | box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.2); 70 | background-color: white; 71 | border: 1px solid #CCC; 72 | white-space: nowrap; 73 | max-height: 200px; 74 | overflow-y: scroll; } 75 | .intl-tel-input .country-list.dropup { 76 | bottom: 100%; 77 | margin-bottom: -1px; } 78 | .intl-tel-input .country-list .flag-box { 79 | display: inline-block; 80 | width: 20px; } 81 | @media (max-width: 500px) { 82 | .intl-tel-input .country-list { 83 | white-space: normal; } } 84 | .intl-tel-input .country-list .divider { 85 | padding-bottom: 5px; 86 | margin-bottom: 5px; 87 | border-bottom: 1px solid #CCC; } 88 | .intl-tel-input .country-list .country { 89 | padding: 5px 10px; } 90 | .intl-tel-input .country-list .country .dial-code { 91 | color: #999; } 92 | .intl-tel-input .country-list .country.highlight { 93 | background-color: rgba(0, 0, 0, 0.05); } 94 | .intl-tel-input .country-list .flag-box, .intl-tel-input .country-list .country-name, .intl-tel-input .country-list .dial-code { 95 | vertical-align: middle; } 96 | .intl-tel-input .country-list .flag-box, .intl-tel-input .country-list .country-name { 97 | margin-right: 6px; } 98 | .intl-tel-input.allow-dropdown input, .intl-tel-input.allow-dropdown input[type=text], .intl-tel-input.allow-dropdown input[type=tel], .intl-tel-input.separate-dial-code input, .intl-tel-input.separate-dial-code input[type=text], .intl-tel-input.separate-dial-code input[type=tel] { 99 | padding-right: 6px; 100 | padding-left: 52px; 101 | margin-left: 0; } 102 | .intl-tel-input.allow-dropdown .flag-container, .intl-tel-input.separate-dial-code .flag-container { 103 | right: auto; 104 | left: 0; } 105 | .intl-tel-input.allow-dropdown .selected-flag, .intl-tel-input.separate-dial-code .selected-flag { 106 | width: 46px; } 107 | .intl-tel-input.allow-dropdown .flag-container:hover { 108 | cursor: pointer; } 109 | .intl-tel-input.allow-dropdown .flag-container:hover .selected-flag { 110 | background-color: rgba(0, 0, 0, 0.05); } 111 | .intl-tel-input.allow-dropdown input[disabled] + .flag-container:hover, .intl-tel-input.allow-dropdown input[readonly] + .flag-container:hover { 112 | cursor: default; } 113 | .intl-tel-input.allow-dropdown input[disabled] + .flag-container:hover .selected-flag, .intl-tel-input.allow-dropdown input[readonly] + .flag-container:hover .selected-flag { 114 | background-color: transparent; } 115 | .intl-tel-input.separate-dial-code .selected-flag { 116 | background-color: rgba(0, 0, 0, 0.05); 117 | display: table; } 118 | .intl-tel-input.separate-dial-code .selected-dial-code { 119 | display: table-cell; 120 | vertical-align: middle; 121 | padding-left: 28px; } 122 | .intl-tel-input.separate-dial-code.iti-sdc-2 input, .intl-tel-input.separate-dial-code.iti-sdc-2 input[type=text], .intl-tel-input.separate-dial-code.iti-sdc-2 input[type=tel] { 123 | padding-left: 66px; } 124 | .intl-tel-input.separate-dial-code.iti-sdc-2 .selected-flag { 125 | width: 60px; } 126 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-2 input, .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-2 input[type=text], .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-2 input[type=tel] { 127 | padding-left: 76px; } 128 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-2 .selected-flag { 129 | width: 70px; } 130 | .intl-tel-input.separate-dial-code.iti-sdc-3 input, .intl-tel-input.separate-dial-code.iti-sdc-3 input[type=text], .intl-tel-input.separate-dial-code.iti-sdc-3 input[type=tel] { 131 | padding-left: 74px; } 132 | .intl-tel-input.separate-dial-code.iti-sdc-3 .selected-flag { 133 | width: 68px; } 134 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-3 input, .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-3 input[type=text], .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-3 input[type=tel] { 135 | padding-left: 84px; } 136 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-3 .selected-flag { 137 | width: 78px; } 138 | .intl-tel-input.separate-dial-code.iti-sdc-4 input, .intl-tel-input.separate-dial-code.iti-sdc-4 input[type=text], .intl-tel-input.separate-dial-code.iti-sdc-4 input[type=tel] { 139 | padding-left: 82px; } 140 | .intl-tel-input.separate-dial-code.iti-sdc-4 .selected-flag { 141 | width: 76px; } 142 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-4 input, .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-4 input[type=text], .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-4 input[type=tel] { 143 | padding-left: 92px; } 144 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-4 .selected-flag { 145 | width: 86px; } 146 | .intl-tel-input.separate-dial-code.iti-sdc-5 input, .intl-tel-input.separate-dial-code.iti-sdc-5 input[type=text], .intl-tel-input.separate-dial-code.iti-sdc-5 input[type=tel] { 147 | padding-left: 90px; } 148 | .intl-tel-input.separate-dial-code.iti-sdc-5 .selected-flag { 149 | width: 84px; } 150 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-5 input, .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-5 input[type=text], .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-5 input[type=tel] { 151 | padding-left: 100px; } 152 | .intl-tel-input.separate-dial-code.allow-dropdown.iti-sdc-5 .selected-flag { 153 | width: 94px; } 154 | .intl-tel-input.iti-container { 155 | position: absolute; 156 | top: -1000px; 157 | left: -1000px; 158 | z-index: 1060; 159 | padding: 1px; } 160 | .intl-tel-input.iti-container:hover { 161 | cursor: pointer; } 162 | 163 | .iti-mobile .intl-tel-input.iti-container { 164 | top: 30px; 165 | bottom: 30px; 166 | left: 30px; 167 | right: 30px; 168 | position: fixed; } 169 | 170 | .iti-mobile .intl-tel-input .country-list { 171 | max-height: 100%; 172 | width: 100%; } 173 | .iti-mobile .intl-tel-input .country-list .country { 174 | padding: 10px 10px; 175 | line-height: 1.5em; } 176 | 177 | .iti-flag { 178 | width: 20px; } 179 | .iti-flag.be { 180 | width: 18px; } 181 | .iti-flag.ch { 182 | width: 15px; } 183 | .iti-flag.mc { 184 | width: 19px; } 185 | .iti-flag.ne { 186 | width: 18px; } 187 | .iti-flag.np { 188 | width: 13px; } 189 | .iti-flag.va { 190 | width: 15px; } 191 | @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { 192 | .iti-flag { 193 | background-size: 5630px 15px; } } 194 | .iti-flag.ac { 195 | height: 10px; 196 | background-position: 0px 0px; } 197 | .iti-flag.ad { 198 | height: 14px; 199 | background-position: -22px 0px; } 200 | .iti-flag.ae { 201 | height: 10px; 202 | background-position: -44px 0px; } 203 | .iti-flag.af { 204 | height: 14px; 205 | background-position: -66px 0px; } 206 | .iti-flag.ag { 207 | height: 14px; 208 | background-position: -88px 0px; } 209 | .iti-flag.ai { 210 | height: 10px; 211 | background-position: -110px 0px; } 212 | .iti-flag.al { 213 | height: 15px; 214 | background-position: -132px 0px; } 215 | .iti-flag.am { 216 | height: 10px; 217 | background-position: -154px 0px; } 218 | .iti-flag.ao { 219 | height: 14px; 220 | background-position: -176px 0px; } 221 | .iti-flag.aq { 222 | height: 14px; 223 | background-position: -198px 0px; } 224 | .iti-flag.ar { 225 | height: 13px; 226 | background-position: -220px 0px; } 227 | .iti-flag.as { 228 | height: 10px; 229 | background-position: -242px 0px; } 230 | .iti-flag.at { 231 | height: 14px; 232 | background-position: -264px 0px; } 233 | .iti-flag.au { 234 | height: 10px; 235 | background-position: -286px 0px; } 236 | .iti-flag.aw { 237 | height: 14px; 238 | background-position: -308px 0px; } 239 | .iti-flag.ax { 240 | height: 13px; 241 | background-position: -330px 0px; } 242 | .iti-flag.az { 243 | height: 10px; 244 | background-position: -352px 0px; } 245 | .iti-flag.ba { 246 | height: 10px; 247 | background-position: -374px 0px; } 248 | .iti-flag.bb { 249 | height: 14px; 250 | background-position: -396px 0px; } 251 | .iti-flag.bd { 252 | height: 12px; 253 | background-position: -418px 0px; } 254 | .iti-flag.be { 255 | height: 15px; 256 | background-position: -440px 0px; } 257 | .iti-flag.bf { 258 | height: 14px; 259 | background-position: -460px 0px; } 260 | .iti-flag.bg { 261 | height: 12px; 262 | background-position: -482px 0px; } 263 | .iti-flag.bh { 264 | height: 12px; 265 | background-position: -504px 0px; } 266 | .iti-flag.bi { 267 | height: 12px; 268 | background-position: -526px 0px; } 269 | .iti-flag.bj { 270 | height: 14px; 271 | background-position: -548px 0px; } 272 | .iti-flag.bl { 273 | height: 14px; 274 | background-position: -570px 0px; } 275 | .iti-flag.bm { 276 | height: 10px; 277 | background-position: -592px 0px; } 278 | .iti-flag.bn { 279 | height: 10px; 280 | background-position: -614px 0px; } 281 | .iti-flag.bo { 282 | height: 14px; 283 | background-position: -636px 0px; } 284 | .iti-flag.bq { 285 | height: 14px; 286 | background-position: -658px 0px; } 287 | .iti-flag.br { 288 | height: 14px; 289 | background-position: -680px 0px; } 290 | .iti-flag.bs { 291 | height: 10px; 292 | background-position: -702px 0px; } 293 | .iti-flag.bt { 294 | height: 14px; 295 | background-position: -724px 0px; } 296 | .iti-flag.bv { 297 | height: 15px; 298 | background-position: -746px 0px; } 299 | .iti-flag.bw { 300 | height: 14px; 301 | background-position: -768px 0px; } 302 | .iti-flag.by { 303 | height: 10px; 304 | background-position: -790px 0px; } 305 | .iti-flag.bz { 306 | height: 14px; 307 | background-position: -812px 0px; } 308 | .iti-flag.ca { 309 | height: 10px; 310 | background-position: -834px 0px; } 311 | .iti-flag.cc { 312 | height: 10px; 313 | background-position: -856px 0px; } 314 | .iti-flag.cd { 315 | height: 15px; 316 | background-position: -878px 0px; } 317 | .iti-flag.cf { 318 | height: 14px; 319 | background-position: -900px 0px; } 320 | .iti-flag.cg { 321 | height: 14px; 322 | background-position: -922px 0px; } 323 | .iti-flag.ch { 324 | height: 15px; 325 | background-position: -944px 0px; } 326 | .iti-flag.ci { 327 | height: 14px; 328 | background-position: -961px 0px; } 329 | .iti-flag.ck { 330 | height: 10px; 331 | background-position: -983px 0px; } 332 | .iti-flag.cl { 333 | height: 14px; 334 | background-position: -1005px 0px; } 335 | .iti-flag.cm { 336 | height: 14px; 337 | background-position: -1027px 0px; } 338 | .iti-flag.cn { 339 | height: 14px; 340 | background-position: -1049px 0px; } 341 | .iti-flag.co { 342 | height: 14px; 343 | background-position: -1071px 0px; } 344 | .iti-flag.cp { 345 | height: 14px; 346 | background-position: -1093px 0px; } 347 | .iti-flag.cr { 348 | height: 12px; 349 | background-position: -1115px 0px; } 350 | .iti-flag.cu { 351 | height: 10px; 352 | background-position: -1137px 0px; } 353 | .iti-flag.cv { 354 | height: 12px; 355 | background-position: -1159px 0px; } 356 | .iti-flag.cw { 357 | height: 14px; 358 | background-position: -1181px 0px; } 359 | .iti-flag.cx { 360 | height: 10px; 361 | background-position: -1203px 0px; } 362 | .iti-flag.cy { 363 | height: 13px; 364 | background-position: -1225px 0px; } 365 | .iti-flag.cz { 366 | height: 14px; 367 | background-position: -1247px 0px; } 368 | .iti-flag.de { 369 | height: 12px; 370 | background-position: -1269px 0px; } 371 | .iti-flag.dg { 372 | height: 10px; 373 | background-position: -1291px 0px; } 374 | .iti-flag.dj { 375 | height: 14px; 376 | background-position: -1313px 0px; } 377 | .iti-flag.dk { 378 | height: 15px; 379 | background-position: -1335px 0px; } 380 | .iti-flag.dm { 381 | height: 10px; 382 | background-position: -1357px 0px; } 383 | .iti-flag.do { 384 | height: 13px; 385 | background-position: -1379px 0px; } 386 | .iti-flag.dz { 387 | height: 14px; 388 | background-position: -1401px 0px; } 389 | .iti-flag.ea { 390 | height: 14px; 391 | background-position: -1423px 0px; } 392 | .iti-flag.ec { 393 | height: 14px; 394 | background-position: -1445px 0px; } 395 | .iti-flag.ee { 396 | height: 13px; 397 | background-position: -1467px 0px; } 398 | .iti-flag.eg { 399 | height: 14px; 400 | background-position: -1489px 0px; } 401 | .iti-flag.eh { 402 | height: 10px; 403 | background-position: -1511px 0px; } 404 | .iti-flag.er { 405 | height: 10px; 406 | background-position: -1533px 0px; } 407 | .iti-flag.es { 408 | height: 14px; 409 | background-position: -1555px 0px; } 410 | .iti-flag.et { 411 | height: 10px; 412 | background-position: -1577px 0px; } 413 | .iti-flag.eu { 414 | height: 14px; 415 | background-position: -1599px 0px; } 416 | .iti-flag.fi { 417 | height: 12px; 418 | background-position: -1621px 0px; } 419 | .iti-flag.fj { 420 | height: 10px; 421 | background-position: -1643px 0px; } 422 | .iti-flag.fk { 423 | height: 10px; 424 | background-position: -1665px 0px; } 425 | .iti-flag.fm { 426 | height: 11px; 427 | background-position: -1687px 0px; } 428 | .iti-flag.fo { 429 | height: 15px; 430 | background-position: -1709px 0px; } 431 | .iti-flag.fr { 432 | height: 14px; 433 | background-position: -1731px 0px; } 434 | .iti-flag.ga { 435 | height: 15px; 436 | background-position: -1753px 0px; } 437 | .iti-flag.gb { 438 | height: 10px; 439 | background-position: -1775px 0px; } 440 | .iti-flag.gd { 441 | height: 12px; 442 | background-position: -1797px 0px; } 443 | .iti-flag.ge { 444 | height: 14px; 445 | background-position: -1819px 0px; } 446 | .iti-flag.gf { 447 | height: 14px; 448 | background-position: -1841px 0px; } 449 | .iti-flag.gg { 450 | height: 14px; 451 | background-position: -1863px 0px; } 452 | .iti-flag.gh { 453 | height: 14px; 454 | background-position: -1885px 0px; } 455 | .iti-flag.gi { 456 | height: 10px; 457 | background-position: -1907px 0px; } 458 | .iti-flag.gl { 459 | height: 14px; 460 | background-position: -1929px 0px; } 461 | .iti-flag.gm { 462 | height: 14px; 463 | background-position: -1951px 0px; } 464 | .iti-flag.gn { 465 | height: 14px; 466 | background-position: -1973px 0px; } 467 | .iti-flag.gp { 468 | height: 14px; 469 | background-position: -1995px 0px; } 470 | .iti-flag.gq { 471 | height: 14px; 472 | background-position: -2017px 0px; } 473 | .iti-flag.gr { 474 | height: 14px; 475 | background-position: -2039px 0px; } 476 | .iti-flag.gs { 477 | height: 10px; 478 | background-position: -2061px 0px; } 479 | .iti-flag.gt { 480 | height: 13px; 481 | background-position: -2083px 0px; } 482 | .iti-flag.gu { 483 | height: 11px; 484 | background-position: -2105px 0px; } 485 | .iti-flag.gw { 486 | height: 10px; 487 | background-position: -2127px 0px; } 488 | .iti-flag.gy { 489 | height: 12px; 490 | background-position: -2149px 0px; } 491 | .iti-flag.hk { 492 | height: 14px; 493 | background-position: -2171px 0px; } 494 | .iti-flag.hm { 495 | height: 10px; 496 | background-position: -2193px 0px; } 497 | .iti-flag.hn { 498 | height: 10px; 499 | background-position: -2215px 0px; } 500 | .iti-flag.hr { 501 | height: 10px; 502 | background-position: -2237px 0px; } 503 | .iti-flag.ht { 504 | height: 12px; 505 | background-position: -2259px 0px; } 506 | .iti-flag.hu { 507 | height: 10px; 508 | background-position: -2281px 0px; } 509 | .iti-flag.ic { 510 | height: 14px; 511 | background-position: -2303px 0px; } 512 | .iti-flag.id { 513 | height: 14px; 514 | background-position: -2325px 0px; } 515 | .iti-flag.ie { 516 | height: 10px; 517 | background-position: -2347px 0px; } 518 | .iti-flag.il { 519 | height: 15px; 520 | background-position: -2369px 0px; } 521 | .iti-flag.im { 522 | height: 10px; 523 | background-position: -2391px 0px; } 524 | .iti-flag.in { 525 | height: 14px; 526 | background-position: -2413px 0px; } 527 | .iti-flag.io { 528 | height: 10px; 529 | background-position: -2435px 0px; } 530 | .iti-flag.iq { 531 | height: 14px; 532 | background-position: -2457px 0px; } 533 | .iti-flag.ir { 534 | height: 12px; 535 | background-position: -2479px 0px; } 536 | .iti-flag.is { 537 | height: 15px; 538 | background-position: -2501px 0px; } 539 | .iti-flag.it { 540 | height: 14px; 541 | background-position: -2523px 0px; } 542 | .iti-flag.je { 543 | height: 12px; 544 | background-position: -2545px 0px; } 545 | .iti-flag.jm { 546 | height: 10px; 547 | background-position: -2567px 0px; } 548 | .iti-flag.jo { 549 | height: 10px; 550 | background-position: -2589px 0px; } 551 | .iti-flag.jp { 552 | height: 14px; 553 | background-position: -2611px 0px; } 554 | .iti-flag.ke { 555 | height: 14px; 556 | background-position: -2633px 0px; } 557 | .iti-flag.kg { 558 | height: 12px; 559 | background-position: -2655px 0px; } 560 | .iti-flag.kh { 561 | height: 13px; 562 | background-position: -2677px 0px; } 563 | .iti-flag.ki { 564 | height: 10px; 565 | background-position: -2699px 0px; } 566 | .iti-flag.km { 567 | height: 12px; 568 | background-position: -2721px 0px; } 569 | .iti-flag.kn { 570 | height: 14px; 571 | background-position: -2743px 0px; } 572 | .iti-flag.kp { 573 | height: 10px; 574 | background-position: -2765px 0px; } 575 | .iti-flag.kr { 576 | height: 14px; 577 | background-position: -2787px 0px; } 578 | .iti-flag.kw { 579 | height: 10px; 580 | background-position: -2809px 0px; } 581 | .iti-flag.ky { 582 | height: 10px; 583 | background-position: -2831px 0px; } 584 | .iti-flag.kz { 585 | height: 10px; 586 | background-position: -2853px 0px; } 587 | .iti-flag.la { 588 | height: 14px; 589 | background-position: -2875px 0px; } 590 | .iti-flag.lb { 591 | height: 14px; 592 | background-position: -2897px 0px; } 593 | .iti-flag.lc { 594 | height: 10px; 595 | background-position: -2919px 0px; } 596 | .iti-flag.li { 597 | height: 12px; 598 | background-position: -2941px 0px; } 599 | .iti-flag.lk { 600 | height: 10px; 601 | background-position: -2963px 0px; } 602 | .iti-flag.lr { 603 | height: 11px; 604 | background-position: -2985px 0px; } 605 | .iti-flag.ls { 606 | height: 14px; 607 | background-position: -3007px 0px; } 608 | .iti-flag.lt { 609 | height: 12px; 610 | background-position: -3029px 0px; } 611 | .iti-flag.lu { 612 | height: 12px; 613 | background-position: -3051px 0px; } 614 | .iti-flag.lv { 615 | height: 10px; 616 | background-position: -3073px 0px; } 617 | .iti-flag.ly { 618 | height: 10px; 619 | background-position: -3095px 0px; } 620 | .iti-flag.ma { 621 | height: 14px; 622 | background-position: -3117px 0px; } 623 | .iti-flag.mc { 624 | height: 15px; 625 | background-position: -3139px 0px; } 626 | .iti-flag.md { 627 | height: 10px; 628 | background-position: -3160px 0px; } 629 | .iti-flag.me { 630 | height: 10px; 631 | background-position: -3182px 0px; } 632 | .iti-flag.mf { 633 | height: 14px; 634 | background-position: -3204px 0px; } 635 | .iti-flag.mg { 636 | height: 14px; 637 | background-position: -3226px 0px; } 638 | .iti-flag.mh { 639 | height: 11px; 640 | background-position: -3248px 0px; } 641 | .iti-flag.mk { 642 | height: 10px; 643 | background-position: -3270px 0px; } 644 | .iti-flag.ml { 645 | height: 14px; 646 | background-position: -3292px 0px; } 647 | .iti-flag.mm { 648 | height: 14px; 649 | background-position: -3314px 0px; } 650 | .iti-flag.mn { 651 | height: 10px; 652 | background-position: -3336px 0px; } 653 | .iti-flag.mo { 654 | height: 14px; 655 | background-position: -3358px 0px; } 656 | .iti-flag.mp { 657 | height: 10px; 658 | background-position: -3380px 0px; } 659 | .iti-flag.mq { 660 | height: 14px; 661 | background-position: -3402px 0px; } 662 | .iti-flag.mr { 663 | height: 14px; 664 | background-position: -3424px 0px; } 665 | .iti-flag.ms { 666 | height: 10px; 667 | background-position: -3446px 0px; } 668 | .iti-flag.mt { 669 | height: 14px; 670 | background-position: -3468px 0px; } 671 | .iti-flag.mu { 672 | height: 14px; 673 | background-position: -3490px 0px; } 674 | .iti-flag.mv { 675 | height: 14px; 676 | background-position: -3512px 0px; } 677 | .iti-flag.mw { 678 | height: 14px; 679 | background-position: -3534px 0px; } 680 | .iti-flag.mx { 681 | height: 12px; 682 | background-position: -3556px 0px; } 683 | .iti-flag.my { 684 | height: 10px; 685 | background-position: -3578px 0px; } 686 | .iti-flag.mz { 687 | height: 14px; 688 | background-position: -3600px 0px; } 689 | .iti-flag.na { 690 | height: 14px; 691 | background-position: -3622px 0px; } 692 | .iti-flag.nc { 693 | height: 10px; 694 | background-position: -3644px 0px; } 695 | .iti-flag.ne { 696 | height: 15px; 697 | background-position: -3666px 0px; } 698 | .iti-flag.nf { 699 | height: 10px; 700 | background-position: -3686px 0px; } 701 | .iti-flag.ng { 702 | height: 10px; 703 | background-position: -3708px 0px; } 704 | .iti-flag.ni { 705 | height: 12px; 706 | background-position: -3730px 0px; } 707 | .iti-flag.nl { 708 | height: 14px; 709 | background-position: -3752px 0px; } 710 | .iti-flag.no { 711 | height: 15px; 712 | background-position: -3774px 0px; } 713 | .iti-flag.np { 714 | height: 15px; 715 | background-position: -3796px 0px; } 716 | .iti-flag.nr { 717 | height: 10px; 718 | background-position: -3811px 0px; } 719 | .iti-flag.nu { 720 | height: 10px; 721 | background-position: -3833px 0px; } 722 | .iti-flag.nz { 723 | height: 10px; 724 | background-position: -3855px 0px; } 725 | .iti-flag.om { 726 | height: 10px; 727 | background-position: -3877px 0px; } 728 | .iti-flag.pa { 729 | height: 14px; 730 | background-position: -3899px 0px; } 731 | .iti-flag.pe { 732 | height: 14px; 733 | background-position: -3921px 0px; } 734 | .iti-flag.pf { 735 | height: 14px; 736 | background-position: -3943px 0px; } 737 | .iti-flag.pg { 738 | height: 15px; 739 | background-position: -3965px 0px; } 740 | .iti-flag.ph { 741 | height: 10px; 742 | background-position: -3987px 0px; } 743 | .iti-flag.pk { 744 | height: 14px; 745 | background-position: -4009px 0px; } 746 | .iti-flag.pl { 747 | height: 13px; 748 | background-position: -4031px 0px; } 749 | .iti-flag.pm { 750 | height: 14px; 751 | background-position: -4053px 0px; } 752 | .iti-flag.pn { 753 | height: 10px; 754 | background-position: -4075px 0px; } 755 | .iti-flag.pr { 756 | height: 14px; 757 | background-position: -4097px 0px; } 758 | .iti-flag.ps { 759 | height: 10px; 760 | background-position: -4119px 0px; } 761 | .iti-flag.pt { 762 | height: 14px; 763 | background-position: -4141px 0px; } 764 | .iti-flag.pw { 765 | height: 13px; 766 | background-position: -4163px 0px; } 767 | .iti-flag.py { 768 | height: 11px; 769 | background-position: -4185px 0px; } 770 | .iti-flag.qa { 771 | height: 8px; 772 | background-position: -4207px 0px; } 773 | .iti-flag.re { 774 | height: 14px; 775 | background-position: -4229px 0px; } 776 | .iti-flag.ro { 777 | height: 14px; 778 | background-position: -4251px 0px; } 779 | .iti-flag.rs { 780 | height: 14px; 781 | background-position: -4273px 0px; } 782 | .iti-flag.ru { 783 | height: 14px; 784 | background-position: -4295px 0px; } 785 | .iti-flag.rw { 786 | height: 14px; 787 | background-position: -4317px 0px; } 788 | .iti-flag.sa { 789 | height: 14px; 790 | background-position: -4339px 0px; } 791 | .iti-flag.sb { 792 | height: 10px; 793 | background-position: -4361px 0px; } 794 | .iti-flag.sc { 795 | height: 10px; 796 | background-position: -4383px 0px; } 797 | .iti-flag.sd { 798 | height: 10px; 799 | background-position: -4405px 0px; } 800 | .iti-flag.se { 801 | height: 13px; 802 | background-position: -4427px 0px; } 803 | .iti-flag.sg { 804 | height: 14px; 805 | background-position: -4449px 0px; } 806 | .iti-flag.sh { 807 | height: 10px; 808 | background-position: -4471px 0px; } 809 | .iti-flag.si { 810 | height: 10px; 811 | background-position: -4493px 0px; } 812 | .iti-flag.sj { 813 | height: 15px; 814 | background-position: -4515px 0px; } 815 | .iti-flag.sk { 816 | height: 14px; 817 | background-position: -4537px 0px; } 818 | .iti-flag.sl { 819 | height: 14px; 820 | background-position: -4559px 0px; } 821 | .iti-flag.sm { 822 | height: 15px; 823 | background-position: -4581px 0px; } 824 | .iti-flag.sn { 825 | height: 14px; 826 | background-position: -4603px 0px; } 827 | .iti-flag.so { 828 | height: 14px; 829 | background-position: -4625px 0px; } 830 | .iti-flag.sr { 831 | height: 14px; 832 | background-position: -4647px 0px; } 833 | .iti-flag.ss { 834 | height: 10px; 835 | background-position: -4669px 0px; } 836 | .iti-flag.st { 837 | height: 10px; 838 | background-position: -4691px 0px; } 839 | .iti-flag.sv { 840 | height: 12px; 841 | background-position: -4713px 0px; } 842 | .iti-flag.sx { 843 | height: 14px; 844 | background-position: -4735px 0px; } 845 | .iti-flag.sy { 846 | height: 14px; 847 | background-position: -4757px 0px; } 848 | .iti-flag.sz { 849 | height: 14px; 850 | background-position: -4779px 0px; } 851 | .iti-flag.ta { 852 | height: 10px; 853 | background-position: -4801px 0px; } 854 | .iti-flag.tc { 855 | height: 10px; 856 | background-position: -4823px 0px; } 857 | .iti-flag.td { 858 | height: 14px; 859 | background-position: -4845px 0px; } 860 | .iti-flag.tf { 861 | height: 14px; 862 | background-position: -4867px 0px; } 863 | .iti-flag.tg { 864 | height: 13px; 865 | background-position: -4889px 0px; } 866 | .iti-flag.th { 867 | height: 14px; 868 | background-position: -4911px 0px; } 869 | .iti-flag.tj { 870 | height: 10px; 871 | background-position: -4933px 0px; } 872 | .iti-flag.tk { 873 | height: 10px; 874 | background-position: -4955px 0px; } 875 | .iti-flag.tl { 876 | height: 10px; 877 | background-position: -4977px 0px; } 878 | .iti-flag.tm { 879 | height: 14px; 880 | background-position: -4999px 0px; } 881 | .iti-flag.tn { 882 | height: 14px; 883 | background-position: -5021px 0px; } 884 | .iti-flag.to { 885 | height: 10px; 886 | background-position: -5043px 0px; } 887 | .iti-flag.tr { 888 | height: 14px; 889 | background-position: -5065px 0px; } 890 | .iti-flag.tt { 891 | height: 12px; 892 | background-position: -5087px 0px; } 893 | .iti-flag.tv { 894 | height: 10px; 895 | background-position: -5109px 0px; } 896 | .iti-flag.tw { 897 | height: 14px; 898 | background-position: -5131px 0px; } 899 | .iti-flag.tz { 900 | height: 14px; 901 | background-position: -5153px 0px; } 902 | .iti-flag.ua { 903 | height: 14px; 904 | background-position: -5175px 0px; } 905 | .iti-flag.ug { 906 | height: 14px; 907 | background-position: -5197px 0px; } 908 | .iti-flag.um { 909 | height: 11px; 910 | background-position: -5219px 0px; } 911 | .iti-flag.us { 912 | height: 11px; 913 | background-position: -5241px 0px; } 914 | .iti-flag.uy { 915 | height: 14px; 916 | background-position: -5263px 0px; } 917 | .iti-flag.uz { 918 | height: 10px; 919 | background-position: -5285px 0px; } 920 | .iti-flag.va { 921 | height: 15px; 922 | background-position: -5307px 0px; } 923 | .iti-flag.vc { 924 | height: 14px; 925 | background-position: -5324px 0px; } 926 | .iti-flag.ve { 927 | height: 14px; 928 | background-position: -5346px 0px; } 929 | .iti-flag.vg { 930 | height: 10px; 931 | background-position: -5368px 0px; } 932 | .iti-flag.vi { 933 | height: 14px; 934 | background-position: -5390px 0px; } 935 | .iti-flag.vn { 936 | height: 14px; 937 | background-position: -5412px 0px; } 938 | .iti-flag.vu { 939 | height: 12px; 940 | background-position: -5434px 0px; } 941 | .iti-flag.wf { 942 | height: 14px; 943 | background-position: -5456px 0px; } 944 | .iti-flag.ws { 945 | height: 10px; 946 | background-position: -5478px 0px; } 947 | .iti-flag.xk { 948 | height: 15px; 949 | background-position: -5500px 0px; } 950 | .iti-flag.ye { 951 | height: 14px; 952 | background-position: -5522px 0px; } 953 | .iti-flag.yt { 954 | height: 14px; 955 | background-position: -5544px 0px; } 956 | .iti-flag.za { 957 | height: 14px; 958 | background-position: -5566px 0px; } 959 | .iti-flag.zm { 960 | height: 14px; 961 | background-position: -5588px 0px; } 962 | .iti-flag.zw { 963 | height: 10px; 964 | background-position: -5610px 0px; } 965 | 966 | .iti-flag { 967 | width: 20px; 968 | height: 15px; 969 | box-shadow: 0px 0px 1px 0px #888; 970 | background-image: url("../img/flags.png"); 971 | background-repeat: no-repeat; 972 | background-color: #DBDBDB; 973 | background-position: 20px 0; } 974 | @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { 975 | .iti-flag { 976 | background-image: url("../img/flags@2x.png"); } } 977 | 978 | .iti-flag.np { 979 | background-color: transparent; } 980 | -------------------------------------------------------------------------------- /assets/intl-tel-input/img/flags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonyhayama/acf-intl-tel-input/e06d2c12270015d24ba4f409da4ac5788eeeac46/assets/intl-tel-input/img/flags.png -------------------------------------------------------------------------------- /assets/intl-tel-input/img/flags@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonyhayama/acf-intl-tel-input/e06d2c12270015d24ba4f409da4ac5788eeeac46/assets/intl-tel-input/img/flags@2x.png -------------------------------------------------------------------------------- /assets/intl-tel-input/js/intlTelInput.js: -------------------------------------------------------------------------------- 1 | /* 2 | * International Telephone Input v12.1.0 3 | * https://github.com/jackocnr/intl-tel-input.git 4 | * Licensed under the MIT license 5 | */ 6 | 7 | // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js 8 | (function(factory) { 9 | if (typeof define === "function" && define.amd) { 10 | define([ "jquery" ], function($) { 11 | factory($, window, document); 12 | }); 13 | } else if (typeof module === "object" && module.exports) { 14 | module.exports = factory(require("jquery"), window, document); 15 | } else { 16 | factory(jQuery, window, document); 17 | } 18 | })(function($, window, document, undefined) { 19 | "use strict"; 20 | // these vars persist through all instances of the plugin 21 | var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling 22 | defaults = { 23 | // whether or not to allow the dropdown 24 | allowDropdown: true, 25 | // if there is just a dial code in the input: remove it on blur, and re-add it on focus 26 | autoHideDialCode: true, 27 | // add a placeholder in the input with an example number for the selected country 28 | autoPlaceholder: "polite", 29 | // modify the auto placeholder 30 | customPlaceholder: null, 31 | // append menu to a specific element 32 | dropdownContainer: "", 33 | // don't display these countries 34 | excludeCountries: [], 35 | // format the input value during initialisation and on setNumber 36 | formatOnDisplay: true, 37 | // geoIp lookup function 38 | geoIpLookup: null, 39 | // inject a hidden input with this name, and on submit, populate it with the result of getNumber 40 | hiddenInput: "", 41 | // initial country 42 | initialCountry: "", 43 | // don't insert international dial codes 44 | nationalMode: true, 45 | // display only these countries 46 | onlyCountries: [], 47 | // number type to use for placeholders 48 | placeholderNumberType: "MOBILE", 49 | // the countries at the top of the list. defaults to united states and united kingdom 50 | preferredCountries: [ "us", "gb" ], 51 | // display the country dial code next to the selected flag so it's not part of the typed number 52 | separateDialCode: false, 53 | // specify the path to the libphonenumber script to enable validation/formatting 54 | utilsScript: "" 55 | }, keys = { 56 | UP: 38, 57 | DOWN: 40, 58 | ENTER: 13, 59 | ESC: 27, 60 | PLUS: 43, 61 | A: 65, 62 | Z: 90, 63 | SPACE: 32, 64 | TAB: 9 65 | }, // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes 66 | regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ]; 67 | // keep track of if the window.load event has fired as impossible to check after the fact 68 | $(window).on("load", function() { 69 | // UPDATE: use a public static field so we can fudge it in the tests 70 | $.fn[pluginName].windowLoaded = true; 71 | }); 72 | function Plugin(element, options) { 73 | this.telInput = $(element); 74 | this.options = $.extend({}, defaults, options); 75 | // event namespace 76 | this.ns = "." + pluginName + id++; 77 | // Chrome, FF, Safari, IE9+ 78 | this.isGoodBrowser = Boolean(element.setSelectionRange); 79 | this.hadInitialPlaceholder = Boolean($(element).attr("placeholder")); 80 | } 81 | Plugin.prototype = { 82 | _init: function() { 83 | // if in nationalMode, disable options relating to dial codes 84 | if (this.options.nationalMode) { 85 | this.options.autoHideDialCode = false; 86 | } 87 | // if separateDialCode then doesn't make sense to A) insert dial code into input (autoHideDialCode), and B) display national numbers (because we're displaying the country dial code next to them) 88 | if (this.options.separateDialCode) { 89 | this.options.autoHideDialCode = this.options.nationalMode = false; 90 | } 91 | // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions 92 | // Note: for some reason jasmine breaks if you put this in the main Plugin function with the rest of these declarations 93 | // Note: to target Android Mobiles (and not Tablets), we must find "Android" and "Mobile" 94 | this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 95 | if (this.isMobile) { 96 | // trigger the mobile dropdown css 97 | $("body").addClass("iti-mobile"); 98 | // on mobile, we want a full screen dropdown, so we must append it to the body 99 | if (!this.options.dropdownContainer) { 100 | this.options.dropdownContainer = "body"; 101 | } 102 | } 103 | // we return these deferred objects from the _init() call so they can be watched, and then we resolve them when each specific request returns 104 | // Note: again, jasmine breaks when I put these in the Plugin function 105 | this.autoCountryDeferred = new $.Deferred(); 106 | this.utilsScriptDeferred = new $.Deferred(); 107 | // in various situations there could be no country selected initially, but we need to be able to assume this variable exists 108 | this.selectedCountryData = {}; 109 | // process all the data: onlyCountries, excludeCountries, preferredCountries etc 110 | this._processCountryData(); 111 | // generate the markup 112 | this._generateMarkup(); 113 | // set the initial state of the input value and the selected flag 114 | this._setInitialState(); 115 | // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click 116 | this._initListeners(); 117 | // utils script, and auto country 118 | this._initRequests(); 119 | // return the deferreds 120 | return [ this.autoCountryDeferred, this.utilsScriptDeferred ]; 121 | }, 122 | /******************** 123 | * PRIVATE METHODS 124 | ********************/ 125 | // prepare all of the country data, including onlyCountries, excludeCountries and preferredCountries options 126 | _processCountryData: function() { 127 | // process onlyCountries or excludeCountries array if present 128 | this._processAllCountries(); 129 | // process the countryCodes map 130 | this._processCountryCodes(); 131 | // process the preferredCountries 132 | this._processPreferredCountries(); 133 | }, 134 | // add a country code to this.countryCodes 135 | _addCountryCode: function(iso2, dialCode, priority) { 136 | if (!(dialCode in this.countryCodes)) { 137 | this.countryCodes[dialCode] = []; 138 | } 139 | var index = priority || 0; 140 | this.countryCodes[dialCode][index] = iso2; 141 | }, 142 | // process onlyCountries or excludeCountries array if present 143 | _processAllCountries: function() { 144 | if (this.options.onlyCountries.length) { 145 | var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) { 146 | return country.toLowerCase(); 147 | }); 148 | this.countries = allCountries.filter(function(country) { 149 | return lowerCaseOnlyCountries.indexOf(country.iso2) > -1; 150 | }); 151 | } else if (this.options.excludeCountries.length) { 152 | var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) { 153 | return country.toLowerCase(); 154 | }); 155 | this.countries = allCountries.filter(function(country) { 156 | return lowerCaseExcludeCountries.indexOf(country.iso2) === -1; 157 | }); 158 | } else { 159 | this.countries = allCountries; 160 | } 161 | }, 162 | // process the countryCodes map 163 | _processCountryCodes: function() { 164 | this.countryCodes = {}; 165 | for (var i = 0; i < this.countries.length; i++) { 166 | var c = this.countries[i]; 167 | this._addCountryCode(c.iso2, c.dialCode, c.priority); 168 | // area codes 169 | if (c.areaCodes) { 170 | for (var j = 0; j < c.areaCodes.length; j++) { 171 | // full dial code is country code + dial code 172 | this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]); 173 | } 174 | } 175 | } 176 | }, 177 | // process preferred countries - iterate through the preferences, fetching the country data for each one 178 | _processPreferredCountries: function() { 179 | this.preferredCountries = []; 180 | for (var i = 0; i < this.options.preferredCountries.length; i++) { 181 | var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true); 182 | if (countryData) { 183 | this.preferredCountries.push(countryData); 184 | } 185 | } 186 | }, 187 | // generate all of the markup for the plugin: the selected flag overlay, and the dropdown 188 | _generateMarkup: function() { 189 | // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can easily put the plugin in an inconsistent state e.g. the wrong flag selected for the autocompleted number, which on submit could mean the wrong number is saved (esp in nationalMode) 190 | this.telInput.attr("autocomplete", "off"); 191 | // containers (mostly for positioning) 192 | var parentClass = "intl-tel-input"; 193 | if (this.options.allowDropdown) { 194 | parentClass += " allow-dropdown"; 195 | } 196 | if (this.options.separateDialCode) { 197 | parentClass += " separate-dial-code"; 198 | } 199 | this.telInput.wrap($("
", { 200 | "class": parentClass 201 | })); 202 | this.flagsContainer = $("
", { 203 | "class": "flag-container" 204 | }).insertBefore(this.telInput); 205 | // currently selected flag (displayed to left of input) 206 | var selectedFlag = $("
", { 207 | "class": "selected-flag" 208 | }); 209 | selectedFlag.appendTo(this.flagsContainer); 210 | this.selectedFlagInner = $("
", { 211 | "class": "iti-flag" 212 | }).appendTo(selectedFlag); 213 | if (this.options.separateDialCode) { 214 | this.selectedDialCode = $("
", { 215 | "class": "selected-dial-code" 216 | }).appendTo(selectedFlag); 217 | } 218 | if (this.options.allowDropdown) { 219 | // make element focusable and tab naviagable 220 | selectedFlag.attr("tabindex", "0"); 221 | // CSS triangle 222 | $("
", { 223 | "class": "iti-arrow" 224 | }).appendTo(selectedFlag); 225 | // country dropdown: preferred countries, then divider, then all countries 226 | this.countryList = $("
    ", { 227 | "class": "country-list hide" 228 | }); 229 | if (this.preferredCountries.length) { 230 | this._appendListItems(this.preferredCountries, "preferred"); 231 | $("
  • ", { 232 | "class": "divider" 233 | }).appendTo(this.countryList); 234 | } 235 | this._appendListItems(this.countries, ""); 236 | // this is useful in lots of places 237 | this.countryListItems = this.countryList.children(".country"); 238 | // create dropdownContainer markup 239 | if (this.options.dropdownContainer) { 240 | this.dropdown = $("
    ", { 241 | "class": "intl-tel-input iti-container" 242 | }).append(this.countryList); 243 | } else { 244 | this.countryList.appendTo(this.flagsContainer); 245 | } 246 | } else { 247 | // a little hack so we don't break anything 248 | this.countryListItems = $(); 249 | } 250 | if (this.options.hiddenInput) { 251 | this.hiddenInput = $("", { 252 | type: "hidden", 253 | name: this.options.hiddenInput 254 | }).insertBefore(this.telInput); 255 | } 256 | }, 257 | // add a country
  • to the countryList
      container 258 | _appendListItems: function(countries, className) { 259 | // we create so many DOM elements, it is faster to build a temp string 260 | // and then add everything to the DOM in one go at the end 261 | var tmp = ""; 262 | // for each country 263 | for (var i = 0; i < countries.length; i++) { 264 | var c = countries[i]; 265 | // open the list item 266 | tmp += "
    • "; 267 | // add the flag 268 | tmp += "
      "; 269 | // and the country name and dial code 270 | tmp += "" + c.name + ""; 271 | tmp += "+" + c.dialCode + ""; 272 | // close the list item 273 | tmp += "
    • "; 274 | } 275 | this.countryList.append(tmp); 276 | }, 277 | // set the initial state of the input value and the selected flag by: 278 | // 1. extracting a dial code from the given number 279 | // 2. using explicit initialCountry 280 | // 3. picking the first preferred country 281 | // 4. picking the first country 282 | _setInitialState: function() { 283 | var val = this.telInput.val(); 284 | // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the flag, else fall back to the default country 285 | // UPDATE: actually we do want to set the flag for a regionlessNanp in one situation: if we're in nationalMode and there's no initialCountry - otherwise we lose the +1 and we're left with an invalid number 286 | if (this._getDialCode(val) && (!this._isRegionlessNanp(val) || this.options.nationalMode && !this.options.initialCountry)) { 287 | this._updateFlagFromNumber(val); 288 | } else if (this.options.initialCountry !== "auto") { 289 | // see if we should select a flag 290 | if (this.options.initialCountry) { 291 | this._setFlag(this.options.initialCountry.toLowerCase()); 292 | } else { 293 | // no dial code and no initialCountry, so default to first in list 294 | this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2; 295 | if (!val) { 296 | this._setFlag(this.defaultCountry); 297 | } 298 | } 299 | // if empty and no nationalMode and no autoHideDialCode then insert the default dial code 300 | if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) { 301 | this.telInput.val("+" + this.selectedCountryData.dialCode); 302 | } 303 | } 304 | // NOTE: if initialCountry is set to auto, that will be handled separately 305 | // format 306 | if (val) { 307 | // this wont be run after _updateDialCode as that's only called if no val 308 | this._updateValFromNumber(val); 309 | } 310 | }, 311 | // initialise the main event listeners: input keyup, and click selected flag 312 | _initListeners: function() { 313 | this._initKeyListeners(); 314 | if (this.options.autoHideDialCode) { 315 | this._initFocusListeners(); 316 | } 317 | if (this.options.allowDropdown) { 318 | this._initDropdownListeners(); 319 | } 320 | if (this.hiddenInput) { 321 | this._initHiddenInputListener(); 322 | } 323 | }, 324 | // update hidden input on form submit 325 | _initHiddenInputListener: function() { 326 | var that = this; 327 | var form = this.telInput.closest("form"); 328 | if (form.length) { 329 | form.submit(function() { 330 | that.hiddenInput.val(that.getNumber()); 331 | }); 332 | } 333 | }, 334 | // initialise the dropdown listeners 335 | _initDropdownListeners: function() { 336 | var that = this; 337 | // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again 338 | var label = this.telInput.closest("label"); 339 | if (label.length) { 340 | label.on("click" + this.ns, function(e) { 341 | // if the dropdown is closed, then focus the input, else ignore the click 342 | if (that.countryList.hasClass("hide")) { 343 | that.telInput.focus(); 344 | } else { 345 | e.preventDefault(); 346 | } 347 | }); 348 | } 349 | // toggle country dropdown on click 350 | var selectedFlag = this.selectedFlagInner.parent(); 351 | selectedFlag.on("click" + this.ns, function(e) { 352 | // only intercept this event if we're opening the dropdown 353 | // else let it bubble up to the top ("click-off-to-close" listener) 354 | // we cannot just stopPropagation as it may be needed to close another instance 355 | if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) { 356 | that._showDropdown(); 357 | } 358 | }); 359 | // open dropdown list if currently focused 360 | this.flagsContainer.on("keydown" + that.ns, function(e) { 361 | var isDropdownHidden = that.countryList.hasClass("hide"); 362 | if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) { 363 | // prevent form from being submitted if "ENTER" was pressed 364 | e.preventDefault(); 365 | // prevent event from being handled again by document 366 | e.stopPropagation(); 367 | that._showDropdown(); 368 | } 369 | // allow navigation from dropdown to input on TAB 370 | if (e.which == keys.TAB) { 371 | that._closeDropdown(); 372 | } 373 | }); 374 | }, 375 | // init many requests: utils script / geo ip lookup 376 | _initRequests: function() { 377 | var that = this; 378 | // if the user has specified the path to the utils script, fetch it on window.load, else resolve 379 | if (this.options.utilsScript) { 380 | // if the plugin is being initialised after the window.load event has already been fired 381 | if ($.fn[pluginName].windowLoaded) { 382 | $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred); 383 | } else { 384 | // wait until the load event so we don't block any other requests e.g. the flags image 385 | $(window).on("load", function() { 386 | $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred); 387 | }); 388 | } 389 | } else { 390 | this.utilsScriptDeferred.resolve(); 391 | } 392 | if (this.options.initialCountry === "auto") { 393 | this._loadAutoCountry(); 394 | } else { 395 | this.autoCountryDeferred.resolve(); 396 | } 397 | }, 398 | // perform the geo ip lookup 399 | _loadAutoCountry: function() { 400 | var that = this; 401 | // 3 options: 402 | // 1) already loaded (we're done) 403 | // 2) not already started loading (start) 404 | // 3) already started loading (do nothing - just wait for loading callback to fire) 405 | if ($.fn[pluginName].autoCountry) { 406 | this.handleAutoCountry(); 407 | } else if (!$.fn[pluginName].startedLoadingAutoCountry) { 408 | // don't do this twice! 409 | $.fn[pluginName].startedLoadingAutoCountry = true; 410 | if (typeof this.options.geoIpLookup === "function") { 411 | this.options.geoIpLookup(function(countryCode) { 412 | $.fn[pluginName].autoCountry = countryCode.toLowerCase(); 413 | // tell all instances the auto country is ready 414 | // TODO: this should just be the current instances 415 | // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight away (e.g. if they have already done the geo ip lookup somewhere else). Using setTimeout means that the current thread of execution will finish before executing this, which allows the plugin to finish initialising. 416 | setTimeout(function() { 417 | $(".intl-tel-input input").intlTelInput("handleAutoCountry"); 418 | }); 419 | }); 420 | } 421 | } 422 | }, 423 | // initialize any key listeners 424 | _initKeyListeners: function() { 425 | var that = this; 426 | // update flag on keyup 427 | // (keep this listener separate otherwise the setTimeout breaks all the tests) 428 | this.telInput.on("keyup" + this.ns, function() { 429 | if (that._updateFlagFromNumber(that.telInput.val())) { 430 | that._triggerCountryChange(); 431 | } 432 | }); 433 | // update flag on cut/paste events (now supported in all major browsers) 434 | this.telInput.on("cut" + this.ns + " paste" + this.ns, function() { 435 | // hack because "paste" event is fired before input is updated 436 | setTimeout(function() { 437 | if (that._updateFlagFromNumber(that.telInput.val())) { 438 | that._triggerCountryChange(); 439 | } 440 | }); 441 | }); 442 | }, 443 | // adhere to the input's maxlength attr 444 | _cap: function(number) { 445 | var max = this.telInput.attr("maxlength"); 446 | return max && number.length > max ? number.substr(0, max) : number; 447 | }, 448 | // listen for mousedown, focus and blur 449 | _initFocusListeners: function() { 450 | var that = this; 451 | // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click 452 | this.telInput.on("mousedown" + this.ns, function(e) { 453 | if (!that.telInput.is(":focus") && !that.telInput.val()) { 454 | e.preventDefault(); 455 | // but this also cancels the focus, so we must trigger that manually 456 | that.telInput.focus(); 457 | } 458 | }); 459 | // on focus: if empty, insert the dial code for the currently selected flag 460 | this.telInput.on("focus" + this.ns, function(e) { 461 | if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) { 462 | // insert the dial code 463 | that.telInput.val("+" + that.selectedCountryData.dialCode); 464 | // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one 465 | that.telInput.one("keypress.plus" + that.ns, function(e) { 466 | if (e.which == keys.PLUS) { 467 | that.telInput.val(""); 468 | } 469 | }); 470 | // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that 471 | setTimeout(function() { 472 | var input = that.telInput[0]; 473 | if (that.isGoodBrowser) { 474 | var len = that.telInput.val().length; 475 | input.setSelectionRange(len, len); 476 | } 477 | }); 478 | } 479 | }); 480 | // on blur or form submit: if just a dial code then remove it 481 | var form = this.telInput.prop("form"); 482 | if (form) { 483 | $(form).on("submit" + this.ns, function() { 484 | that._removeEmptyDialCode(); 485 | }); 486 | } 487 | this.telInput.on("blur" + this.ns, function() { 488 | that._removeEmptyDialCode(); 489 | }); 490 | }, 491 | _removeEmptyDialCode: function() { 492 | var value = this.telInput.val(), startsPlus = value.charAt(0) == "+"; 493 | if (startsPlus) { 494 | var numeric = this._getNumeric(value); 495 | // if just a plus, or if just a dial code 496 | if (!numeric || this.selectedCountryData.dialCode == numeric) { 497 | this.telInput.val(""); 498 | } 499 | } 500 | // remove the keypress listener we added on focus 501 | this.telInput.off("keypress.plus" + this.ns); 502 | }, 503 | // extract the numeric digits from the given string 504 | _getNumeric: function(s) { 505 | return s.replace(/\D/g, ""); 506 | }, 507 | // show the dropdown 508 | _showDropdown: function() { 509 | this._setDropdownPosition(); 510 | // update highlighting and scroll to active list item 511 | var activeListItem = this.countryList.children(".active"); 512 | if (activeListItem.length) { 513 | this._highlightListItem(activeListItem); 514 | this._scrollTo(activeListItem); 515 | } 516 | // bind all the dropdown-related listeners: mouseover, click, click-off, keydown 517 | this._bindDropdownListeners(); 518 | // update the arrow 519 | this.selectedFlagInner.children(".iti-arrow").addClass("up"); 520 | this.telInput.trigger("open:countrydropdown"); 521 | }, 522 | // decide where to position dropdown (depends on position within viewport, and scroll) 523 | _setDropdownPosition: function() { 524 | var that = this; 525 | if (this.options.dropdownContainer) { 526 | this.dropdown.appendTo(this.options.dropdownContainer); 527 | } 528 | // show the menu and grab the dropdown height 529 | this.dropdownHeight = this.countryList.removeClass("hide").outerHeight(); 530 | if (!this.isMobile) { 531 | var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom) 532 | dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop; 533 | // by default, the dropdown will be below the input. If we want to position it above the input, we add the dropup class. 534 | this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove); 535 | // if dropdownContainer is enabled, calculate postion 536 | if (this.options.dropdownContainer) { 537 | // by default the dropdown will be directly over the input because it's not in the flow. If we want to position it below, we need to add some extra top value. 538 | var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHeight(); 539 | // calculate placement 540 | this.dropdown.css({ 541 | top: inputTop + extraTop, 542 | left: pos.left 543 | }); 544 | // close menu on window scroll 545 | $(window).on("scroll" + this.ns, function() { 546 | that._closeDropdown(); 547 | }); 548 | } 549 | } 550 | }, 551 | // we only bind dropdown listeners when the dropdown is open 552 | _bindDropdownListeners: function() { 553 | var that = this; 554 | // when mouse over a list item, just highlight that one 555 | // we add the class "highlight", so if they hit "enter" we know which one to select 556 | this.countryList.on("mouseover" + this.ns, ".country", function(e) { 557 | that._highlightListItem($(this)); 558 | }); 559 | // listen for country selection 560 | this.countryList.on("click" + this.ns, ".country", function(e) { 561 | that._selectListItem($(this)); 562 | }); 563 | // click off to close 564 | // (except when this initial opening click is bubbling up) 565 | // we cannot just stopPropagation as it may be needed to close another instance 566 | var isOpening = true; 567 | $("html").on("click" + this.ns, function(e) { 568 | if (!isOpening) { 569 | that._closeDropdown(); 570 | } 571 | isOpening = false; 572 | }); 573 | // listen for up/down scrolling, enter to select, or letters to jump to country name. 574 | // use keydown as keypress doesn't fire for non-char keys and we want to catch if they 575 | // just hit down and hold it to scroll down (no keyup event). 576 | // listen on the document because that's where key events are triggered if no input has focus 577 | var query = "", queryTimer = null; 578 | $(document).on("keydown" + this.ns, function(e) { 579 | // prevent down key from scrolling the whole page, 580 | // and enter key from submitting a form etc 581 | e.preventDefault(); 582 | if (e.which == keys.UP || e.which == keys.DOWN) { 583 | // up and down to navigate 584 | that._handleUpDownKey(e.which); 585 | } else if (e.which == keys.ENTER) { 586 | // enter to select 587 | that._handleEnterKey(); 588 | } else if (e.which == keys.ESC) { 589 | // esc to close 590 | that._closeDropdown(); 591 | } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) { 592 | // upper case letters (note: keyup/keydown only return upper case letters) 593 | // jump to countries that start with the query string 594 | if (queryTimer) { 595 | clearTimeout(queryTimer); 596 | } 597 | query += String.fromCharCode(e.which); 598 | that._searchForCountry(query); 599 | // if the timer hits 1 second, reset the query 600 | queryTimer = setTimeout(function() { 601 | query = ""; 602 | }, 1e3); 603 | } 604 | }); 605 | }, 606 | // highlight the next/prev item in the list (and ensure it is visible) 607 | _handleUpDownKey: function(key) { 608 | var current = this.countryList.children(".highlight").first(); 609 | var next = key == keys.UP ? current.prev() : current.next(); 610 | if (next.length) { 611 | // skip the divider 612 | if (next.hasClass("divider")) { 613 | next = key == keys.UP ? next.prev() : next.next(); 614 | } 615 | this._highlightListItem(next); 616 | this._scrollTo(next); 617 | } 618 | }, 619 | // select the currently highlighted item 620 | _handleEnterKey: function() { 621 | var currentCountry = this.countryList.children(".highlight").first(); 622 | if (currentCountry.length) { 623 | this._selectListItem(currentCountry); 624 | } 625 | }, 626 | // find the first list item whose name starts with the query string 627 | _searchForCountry: function(query) { 628 | for (var i = 0; i < this.countries.length; i++) { 629 | if (this._startsWith(this.countries[i].name, query)) { 630 | var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred"); 631 | // update highlighting and scroll 632 | this._highlightListItem(listItem); 633 | this._scrollTo(listItem, true); 634 | break; 635 | } 636 | } 637 | }, 638 | // check if (uppercase) string a starts with string b 639 | _startsWith: function(a, b) { 640 | return a.substr(0, b.length).toUpperCase() == b; 641 | }, 642 | // update the input's value to the given val (format first if possible) 643 | // NOTE: this is called from _setInitialState, handleUtils and setNumber 644 | _updateValFromNumber: function(number) { 645 | if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) { 646 | var format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL; 647 | number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format); 648 | } 649 | number = this._beforeSetNumber(number); 650 | this.telInput.val(number); 651 | }, 652 | // check if need to select a new flag based on the given number 653 | // Note: called from _setInitialState, keyup handler, setNumber 654 | _updateFlagFromNumber: function(number) { 655 | // if we're in nationalMode and we already have US/Canada selected, make sure the number starts with a +1 so _getDialCode will be able to extract the area code 656 | // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag from the number), that means we're initialising the plugin with a number that already has a dial code, so fine to ignore this bit 657 | if (number && this.options.nationalMode && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") { 658 | if (number.charAt(0) != "1") { 659 | number = "1" + number; 660 | } 661 | number = "+" + number; 662 | } 663 | // try and extract valid dial code from input 664 | var dialCode = this._getDialCode(number), countryCode = null, numeric = this._getNumeric(number); 665 | if (dialCode) { 666 | // check if one of the matching countries is already selected 667 | var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = $.inArray(this.selectedCountryData.iso2, countryCodes) > -1, // check if the given number contains a NANP area code i.e. the only dialCode that could be extracted was +1 (instead of say +1204) and the actual number's length is >=4 668 | isNanpAreaCode = dialCode == "+1" && numeric.length >= 4, nanpSelected = this.selectedCountryData.dialCode == "1"; 669 | // only update the flag if: 670 | // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp) 671 | // AND 672 | // B) either a matching country is not already selected OR the number contains a NANP area code (ensure the flag is set to the first matching country) 673 | if (!(nanpSelected && this._isRegionlessNanp(numeric)) && (!alreadySelected || isNanpAreaCode)) { 674 | // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index 675 | for (var j = 0; j < countryCodes.length; j++) { 676 | if (countryCodes[j]) { 677 | countryCode = countryCodes[j]; 678 | break; 679 | } 680 | } 681 | } 682 | } else if (number.charAt(0) == "+" && numeric.length) { 683 | // invalid dial code, so empty 684 | // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars 685 | countryCode = ""; 686 | } else if (!number || number == "+") { 687 | // empty, or just a plus, so default 688 | countryCode = this.defaultCountry; 689 | } 690 | if (countryCode !== null) { 691 | return this._setFlag(countryCode); 692 | } 693 | return false; 694 | }, 695 | // check if the given number is a regionless NANP number (expects the number to contain an international dial code) 696 | _isRegionlessNanp: function(number) { 697 | var numeric = this._getNumeric(number); 698 | if (numeric.charAt(0) == "1") { 699 | var areaCode = numeric.substr(1, 3); 700 | return $.inArray(areaCode, regionlessNanpNumbers) > -1; 701 | } 702 | return false; 703 | }, 704 | // remove highlighting from other list items and highlight the given item 705 | _highlightListItem: function(listItem) { 706 | this.countryListItems.removeClass("highlight"); 707 | listItem.addClass("highlight"); 708 | }, 709 | // find the country data for the given country code 710 | // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array 711 | _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) { 712 | var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries; 713 | for (var i = 0; i < countryList.length; i++) { 714 | if (countryList[i].iso2 == countryCode) { 715 | return countryList[i]; 716 | } 717 | } 718 | if (allowFail) { 719 | return null; 720 | } else { 721 | throw new Error("No country data for '" + countryCode + "'"); 722 | } 723 | }, 724 | // select the given flag, update the placeholder and the active list item 725 | // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry 726 | _setFlag: function(countryCode) { 727 | var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; 728 | // do this first as it will throw an error and stop if countryCode is invalid 729 | this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {}; 730 | // update the defaultCountry - we only need the iso2 from now on, so just store that 731 | if (this.selectedCountryData.iso2) { 732 | this.defaultCountry = this.selectedCountryData.iso2; 733 | } 734 | this.selectedFlagInner.attr("class", "iti-flag " + countryCode); 735 | // update the selected country's title attribute 736 | var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown"; 737 | this.selectedFlagInner.parent().attr("title", title); 738 | if (this.options.separateDialCode) { 739 | var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent(); 740 | if (prevCountry.dialCode) { 741 | parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1)); 742 | } 743 | if (dialCode) { 744 | parent.addClass("iti-sdc-" + dialCode.length); 745 | } 746 | this.selectedDialCode.text(dialCode); 747 | } 748 | // and the input's placeholder 749 | this._updatePlaceholder(); 750 | // update the active list item 751 | this.countryListItems.removeClass("active"); 752 | if (countryCode) { 753 | this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active"); 754 | } 755 | // return if the flag has changed or not 756 | return prevCountry.iso2 !== countryCode; 757 | }, 758 | // update the input placeholder to an example number from the currently selected country 759 | _updatePlaceholder: function() { 760 | var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && (this.options.autoPlaceholder === true || this.options.autoPlaceholder === "polite"); 761 | if (window.intlTelInputUtils && shouldSetPlaceholder) { 762 | var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : ""; 763 | placeholder = this._beforeSetNumber(placeholder); 764 | if (typeof this.options.customPlaceholder === "function") { 765 | placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData); 766 | } 767 | this.telInput.attr("placeholder", placeholder); 768 | } 769 | }, 770 | // called when the user selects a list item from the dropdown 771 | _selectListItem: function(listItem) { 772 | // update selected flag and active list item 773 | var flagChanged = this._setFlag(listItem.attr("data-country-code")); 774 | this._closeDropdown(); 775 | this._updateDialCode(listItem.attr("data-dial-code"), true); 776 | // focus the input 777 | this.telInput.focus(); 778 | // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto inserting dial code), who try to put the cursor at the beginning the first time 779 | if (this.isGoodBrowser) { 780 | var len = this.telInput.val().length; 781 | this.telInput[0].setSelectionRange(len, len); 782 | } 783 | if (flagChanged) { 784 | this._triggerCountryChange(); 785 | } 786 | }, 787 | // close the dropdown and unbind any listeners 788 | _closeDropdown: function() { 789 | this.countryList.addClass("hide"); 790 | // update the arrow 791 | this.selectedFlagInner.children(".iti-arrow").removeClass("up"); 792 | // unbind key events 793 | $(document).off(this.ns); 794 | // unbind click-off-to-close 795 | $("html").off(this.ns); 796 | // unbind hover and click listeners 797 | this.countryList.off(this.ns); 798 | // remove menu from container 799 | if (this.options.dropdownContainer) { 800 | if (!this.isMobile) { 801 | $(window).off("scroll" + this.ns); 802 | } 803 | this.dropdown.detach(); 804 | } 805 | this.telInput.trigger("close:countrydropdown"); 806 | }, 807 | // check if an element is visible within it's container, else scroll until it is 808 | _scrollTo: function(element, middle) { 809 | var container = this.countryList, containerHeight = container.height(), containerTop = container.offset().top, containerBottom = containerTop + containerHeight, elementHeight = element.outerHeight(), elementTop = element.offset().top, elementBottom = elementTop + elementHeight, newScrollTop = elementTop - containerTop + container.scrollTop(), middleOffset = containerHeight / 2 - elementHeight / 2; 810 | if (elementTop < containerTop) { 811 | // scroll up 812 | if (middle) { 813 | newScrollTop -= middleOffset; 814 | } 815 | container.scrollTop(newScrollTop); 816 | } else if (elementBottom > containerBottom) { 817 | // scroll down 818 | if (middle) { 819 | newScrollTop += middleOffset; 820 | } 821 | var heightDifference = containerHeight - elementHeight; 822 | container.scrollTop(newScrollTop - heightDifference); 823 | } 824 | }, 825 | // replace any existing dial code with the new one 826 | // Note: called from _selectListItem and setCountry 827 | _updateDialCode: function(newDialCode, hasSelectedListItem) { 828 | var inputVal = this.telInput.val(), newNumber; 829 | // save having to pass this every time 830 | newDialCode = "+" + newDialCode; 831 | if (inputVal.charAt(0) == "+") { 832 | // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not) 833 | var prevDialCode = this._getDialCode(inputVal); 834 | if (prevDialCode) { 835 | // current number contains a valid dial code, so replace it 836 | newNumber = inputVal.replace(prevDialCode, newDialCode); 837 | } else { 838 | // current number contains an invalid dial code, so ditch it 839 | // (no way to determine where the invalid dial code ends and the rest of the number begins) 840 | newNumber = newDialCode; 841 | } 842 | } else if (this.options.nationalMode || this.options.separateDialCode) { 843 | // don't do anything 844 | return; 845 | } else { 846 | // nationalMode is disabled 847 | if (inputVal) { 848 | // there is an existing value with no dial code: prefix the new dial code 849 | newNumber = newDialCode + inputVal; 850 | } else if (hasSelectedListItem || !this.options.autoHideDialCode) { 851 | // no existing value and either they've just selected a list item, or autoHideDialCode is disabled: insert new dial code 852 | newNumber = newDialCode; 853 | } else { 854 | return; 855 | } 856 | } 857 | this.telInput.val(newNumber); 858 | }, 859 | // try and extract a valid international dial code from a full telephone number 860 | // Note: returns the raw string inc plus character and any whitespace/dots etc 861 | _getDialCode: function(number) { 862 | var dialCode = ""; 863 | // only interested in international numbers (starting with a plus) 864 | if (number.charAt(0) == "+") { 865 | var numericChars = ""; 866 | // iterate over chars 867 | for (var i = 0; i < number.length; i++) { 868 | var c = number.charAt(i); 869 | // if char is number 870 | if ($.isNumeric(c)) { 871 | numericChars += c; 872 | // if current numericChars make a valid dial code 873 | if (this.countryCodes[numericChars]) { 874 | // store the actual raw string (useful for matching later) 875 | dialCode = number.substr(0, i + 1); 876 | } 877 | // longest dial code is 4 chars 878 | if (numericChars.length == 4) { 879 | break; 880 | } 881 | } 882 | } 883 | } 884 | return dialCode; 885 | }, 886 | // get the input val, adding the dial code if separateDialCode is enabled 887 | _getFullNumber: function() { 888 | var val = $.trim(this.telInput.val()), dialCode = this.selectedCountryData.dialCode, prefix, numericVal = this._getNumeric(val), // normalized means ensure starts with a 1, so we can match against the full dial code 889 | normalizedVal = numericVal.charAt(0) == "1" ? numericVal : "1" + numericVal; 890 | if (this.options.separateDialCode) { 891 | prefix = "+" + dialCode; 892 | } else if (val.charAt(0) != "+" && val.charAt(0) != "1" && dialCode && dialCode.charAt(0) == "1" && dialCode.length == 4 && dialCode != normalizedVal.substr(0, 4)) { 893 | // if the user has entered a national NANP number, then ensure it includes the full dial code / area code 894 | prefix = dialCode.substr(1); 895 | } else { 896 | prefix = ""; 897 | } 898 | return prefix + val; 899 | }, 900 | // remove the dial code if separateDialCode is enabled 901 | _beforeSetNumber: function(number) { 902 | if (this.options.separateDialCode) { 903 | var dialCode = this._getDialCode(number); 904 | if (dialCode) { 905 | // US dialCode is "+1", which is what we want 906 | // CA dialCode is "+1 123", which is wrong - should be "+1" (as it has multiple area codes) 907 | // AS dialCode is "+1 684", which is what we want 908 | // Solution: if the country has area codes, then revert to just the dial code 909 | if (this.selectedCountryData.areaCodes !== null) { 910 | dialCode = "+" + this.selectedCountryData.dialCode; 911 | } 912 | // a lot of numbers will have a space separating the dial code and the main number, and some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get rid of it 913 | // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc 914 | var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length; 915 | number = number.substr(start); 916 | } 917 | } 918 | return this._cap(number); 919 | }, 920 | // trigger the 'countrychange' event 921 | _triggerCountryChange: function() { 922 | this.telInput.trigger("countrychange", this.selectedCountryData); 923 | }, 924 | /************************** 925 | * SECRET PUBLIC METHODS 926 | **************************/ 927 | // this is called when the geoip call returns 928 | handleAutoCountry: function() { 929 | if (this.options.initialCountry === "auto") { 930 | // we must set this even if there is an initial val in the input: in case the initial val is invalid and they delete it - they should see their auto country 931 | this.defaultCountry = $.fn[pluginName].autoCountry; 932 | // if there's no initial value in the input, then update the flag 933 | if (!this.telInput.val()) { 934 | this.setCountry(this.defaultCountry); 935 | } 936 | this.autoCountryDeferred.resolve(); 937 | } 938 | }, 939 | // this is called when the utils request completes 940 | handleUtils: function() { 941 | // if the request was successful 942 | if (window.intlTelInputUtils) { 943 | // if there's an initial value in the input, then format it 944 | if (this.telInput.val()) { 945 | this._updateValFromNumber(this.telInput.val()); 946 | } 947 | this._updatePlaceholder(); 948 | } 949 | this.utilsScriptDeferred.resolve(); 950 | }, 951 | /******************** 952 | * PUBLIC METHODS 953 | ********************/ 954 | // remove plugin 955 | destroy: function() { 956 | if (this.allowDropdown) { 957 | // make sure the dropdown is closed (and unbind listeners) 958 | this._closeDropdown(); 959 | // click event to open dropdown 960 | this.selectedFlagInner.parent().off(this.ns); 961 | // label click hack 962 | this.telInput.closest("label").off(this.ns); 963 | } 964 | // unbind submit event handler on form 965 | if (this.options.autoHideDialCode) { 966 | var form = this.telInput.prop("form"); 967 | if (form) { 968 | $(form).off(this.ns); 969 | } 970 | } 971 | // unbind all events: key events, and focus/blur events if autoHideDialCode=true 972 | this.telInput.off(this.ns); 973 | // remove markup (but leave the original input) 974 | var container = this.telInput.parent(); 975 | container.before(this.telInput).remove(); 976 | }, 977 | // get the extension from the current number 978 | getExtension: function() { 979 | if (window.intlTelInputUtils) { 980 | return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2); 981 | } 982 | return ""; 983 | }, 984 | // format the number to the given format 985 | getNumber: function(format) { 986 | if (window.intlTelInputUtils) { 987 | return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format); 988 | } 989 | return ""; 990 | }, 991 | // get the type of the entered number e.g. landline/mobile 992 | getNumberType: function() { 993 | if (window.intlTelInputUtils) { 994 | return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2); 995 | } 996 | return -99; 997 | }, 998 | // get the country data for the currently selected flag 999 | getSelectedCountryData: function() { 1000 | return this.selectedCountryData; 1001 | }, 1002 | // get the validation error 1003 | getValidationError: function() { 1004 | if (window.intlTelInputUtils) { 1005 | return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2); 1006 | } 1007 | return -99; 1008 | }, 1009 | // validate the input val - assumes the global function isValidNumber (from utilsScript) 1010 | isValidNumber: function() { 1011 | var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : ""; 1012 | return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null; 1013 | }, 1014 | // update the selected flag, and update the input val accordingly 1015 | setCountry: function(countryCode) { 1016 | countryCode = countryCode.toLowerCase(); 1017 | // check if already selected 1018 | if (!this.selectedFlagInner.hasClass(countryCode)) { 1019 | this._setFlag(countryCode); 1020 | this._updateDialCode(this.selectedCountryData.dialCode, false); 1021 | this._triggerCountryChange(); 1022 | } 1023 | }, 1024 | // set the input value and update the flag 1025 | setNumber: function(number) { 1026 | // we must update the flag first, which updates this.selectedCountryData, which is used for formatting the number before displaying it 1027 | var flagChanged = this._updateFlagFromNumber(number); 1028 | this._updateValFromNumber(number); 1029 | if (flagChanged) { 1030 | this._triggerCountryChange(); 1031 | } 1032 | }, 1033 | // set the placeholder number typ 1034 | setPlaceholderNumberType: function(type) { 1035 | this.options.placeholderNumberType = type; 1036 | this._updatePlaceholder(); 1037 | } 1038 | }; 1039 | // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate 1040 | // (adapted to allow public functions) 1041 | $.fn[pluginName] = function(options) { 1042 | var args = arguments; 1043 | // Is the first parameter an object (options), or was omitted, 1044 | // instantiate a new instance of the plugin. 1045 | if (options === undefined || typeof options === "object") { 1046 | // collect all of the deferred objects for all instances created with this selector 1047 | var deferreds = []; 1048 | this.each(function() { 1049 | if (!$.data(this, "plugin_" + pluginName)) { 1050 | var instance = new Plugin(this, options); 1051 | var instanceDeferreds = instance._init(); 1052 | // we now have 2 deffereds: 1 for auto country, 1 for utils script 1053 | deferreds.push(instanceDeferreds[0]); 1054 | deferreds.push(instanceDeferreds[1]); 1055 | $.data(this, "plugin_" + pluginName, instance); 1056 | } 1057 | }); 1058 | // return the promise from the "master" deferred object that tracks all the others 1059 | return $.when.apply(null, deferreds); 1060 | } else if (typeof options === "string" && options[0] !== "_") { 1061 | // If the first parameter is a string and it doesn't start 1062 | // with an underscore or "contains" the `init`-function, 1063 | // treat this as a call to a public method. 1064 | // Cache the method call to make it possible to return a value 1065 | var returns; 1066 | this.each(function() { 1067 | var instance = $.data(this, "plugin_" + pluginName); 1068 | // Tests that there's already a plugin-instance 1069 | // and checks that the requested public method exists 1070 | if (instance instanceof Plugin && typeof instance[options] === "function") { 1071 | // Call the method of our plugin instance, 1072 | // and pass it the supplied arguments. 1073 | returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 1074 | } 1075 | // Allow instances to be destroyed via the 'destroy' method 1076 | if (options === "destroy") { 1077 | $.data(this, "plugin_" + pluginName, null); 1078 | } 1079 | }); 1080 | // If the earlier cached method gives a value back return the value, 1081 | // otherwise return this to preserve chainability. 1082 | return returns !== undefined ? returns : this; 1083 | } 1084 | }; 1085 | /******************** 1086 | * STATIC METHODS 1087 | ********************/ 1088 | // get the country data object 1089 | $.fn[pluginName].getCountryData = function() { 1090 | return allCountries; 1091 | }; 1092 | // load the utils script 1093 | $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) { 1094 | if (!$.fn[pluginName].loadedUtilsScript) { 1095 | // don't do this twice! (dont just check if window.intlTelInputUtils exists as if init plugin multiple times in quick succession, it may not have finished loading yet) 1096 | $.fn[pluginName].loadedUtilsScript = true; 1097 | // dont use $.getScript as it prevents caching 1098 | $.ajax({ 1099 | type: "GET", 1100 | url: path, 1101 | complete: function() { 1102 | // tell all instances that the utils request is complete 1103 | $(".intl-tel-input input").intlTelInput("handleUtils"); 1104 | }, 1105 | dataType: "script", 1106 | cache: true 1107 | }); 1108 | } else if (utilsScriptDeferred) { 1109 | utilsScriptDeferred.resolve(); 1110 | } 1111 | }; 1112 | // default options 1113 | $.fn[pluginName].defaults = defaults; 1114 | // version 1115 | $.fn[pluginName].version = "12.1.0"; 1116 | // Array of country objects for the flag dropdown. 1117 | // Here is the criteria for the plugin to support a given country/territory 1118 | // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 1119 | // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes 1120 | // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png 1121 | // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml 1122 | // Each country array has the following information: 1123 | // [ 1124 | // Country name, 1125 | // iso2 code, 1126 | // International dial code, 1127 | // Order (if >1 country with same dial code), 1128 | // Area codes 1129 | // ] 1130 | var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1684" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1264" ], [ "Antigua and Barbuda", "ag", "1268" ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1242" ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1246" ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1441" ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1284" ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1 ], [ "Cayman Islands", "ky", "1345" ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2 ], [ "Cocos (Keeling) Islands", "cc", "61", 1 ], [ "Colombia", "co", "57" ], [ "Comoros (‫جزر القمر‬‎)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1767" ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (‫مصر‬‎)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1 ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (‫ایران‬‎)", "ir", "98" ], [ "Iraq (‫العراق‬‎)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2 ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3 ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1 ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait (‫الكويت‬‎)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (‫لبنان‬‎)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (‫ليبيا‬‎)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "Macedonia (FYROM) (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (‫موريتانيا‬‎)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1 ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1664" ], [ "Morocco (‫المغرب‬‎)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1670" ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (‫عُمان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫المملكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1 ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1 ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1 ] ]; 1131 | // loop over all of the countries above 1132 | for (var i = 0; i < allCountries.length; i++) { 1133 | var c = allCountries[i]; 1134 | allCountries[i] = { 1135 | name: c[0], 1136 | iso2: c[1], 1137 | dialCode: c[2], 1138 | priority: c[3] || 0, 1139 | areaCodes: c[4] || null 1140 | }; 1141 | } 1142 | }); -------------------------------------------------------------------------------- /assets/intl-tel-input/js/intlTelInput.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * International Telephone Input v12.1.0 3 | * https://github.com/jackocnr/intl-tel-input.git 4 | * Licensed under the MIT license 5 | */ 6 | 7 | !function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b,window,document)}):"object"==typeof module&&module.exports?module.exports=a(require("jquery"),window,document):a(jQuery,window,document)}(function(a,b,c,d){"use strict";function e(b,c){this.a=a(b),this.b=a.extend({},h,c),this.ns="."+f+g++,this.d=Boolean(b.setSelectionRange),this.e=Boolean(a(b).attr("placeholder"))}var f="intlTelInput",g=1,h={allowDropdown:!0,autoHideDialCode:!0,autoPlaceholder:"polite",customPlaceholder:null,dropdownContainer:"",excludeCountries:[],formatOnDisplay:!0,geoIpLookup:null,hiddenInput:"",initialCountry:"",nationalMode:!0,onlyCountries:[],placeholderNumberType:"MOBILE",preferredCountries:["us","gb"],separateDialCode:!1,utilsScript:""},i={b:38,c:40,d:13,e:27,f:43,A:65,Z:90,j:32,k:9},j=["800","822","833","844","855","866","877","880","881","882","883","884","885","886","887","888","889"];a(b).on("load",function(){a.fn[f].windowLoaded=!0}),e.prototype={_a:function(){return this.b.nationalMode&&(this.b.autoHideDialCode=!1),this.b.separateDialCode&&(this.b.autoHideDialCode=this.b.nationalMode=!1),this.g=/Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),this.g&&(a("body").addClass("iti-mobile"),this.b.dropdownContainer||(this.b.dropdownContainer="body")),this.h=new a.Deferred,this.i=new a.Deferred,this.s={},this._b(),this._f(),this._h(),this._i(),this._i2(),[this.h,this.i]},_b:function(){this._d(),this._d2(),this._e()},_c:function(a,b,c){b in this.q||(this.q[b]=[]);var d=c||0;this.q[b][d]=a},_d:function(){if(this.b.onlyCountries.length){var a=this.b.onlyCountries.map(function(a){return a.toLowerCase()});this.p=k.filter(function(b){return a.indexOf(b.iso2)>-1})}else if(this.b.excludeCountries.length){var b=this.b.excludeCountries.map(function(a){return a.toLowerCase()});this.p=k.filter(function(a){return-1===b.indexOf(a.iso2)})}else this.p=k},_d2:function(){this.q={};for(var a=0;a",{"class":b})),this.k=a("
      ",{"class":"flag-container"}).insertBefore(this.a);var c=a("
      ",{"class":"selected-flag"});c.appendTo(this.k),this.l=a("
      ",{"class":"iti-flag"}).appendTo(c),this.b.separateDialCode&&(this.t=a("
      ",{"class":"selected-dial-code"}).appendTo(c)),this.b.allowDropdown?(c.attr("tabindex","0"),a("
      ",{"class":"iti-arrow"}).appendTo(c),this.m=a("
        ",{"class":"country-list hide"}),this.preferredCountries.length&&(this._g(this.preferredCountries,"preferred"),a("
      • ",{"class":"divider"}).appendTo(this.m)),this._g(this.p,""),this.o=this.m.children(".country"),this.b.dropdownContainer?this.dropdown=a("
        ",{"class":"intl-tel-input iti-container"}).append(this.m):this.m.appendTo(this.k)):this.o=a(),this.b.hiddenInput&&(this.hiddenInput=a("",{type:"hidden",name:this.b.hiddenInput}).insertBefore(this.a))},_g:function(a,b){for(var c="",d=0;d",c+="
        ",c+=""+e.name+"",c+="+"+e.dialCode+"",c+="
      • "}this.m.append(c)},_h:function(){var a=this.a.val();this._af(a)&&(!this._isRegionlessNanp(a)||this.b.nationalMode&&!this.b.initialCountry)?this._v(a):"auto"!==this.b.initialCountry&&(this.b.initialCountry?this._z(this.b.initialCountry.toLowerCase()):(this.j=this.preferredCountries.length?this.preferredCountries[0].iso2:this.p[0].iso2,a||this._z(this.j)),a||this.b.nationalMode||this.b.autoHideDialCode||this.b.separateDialCode||this.a.val("+"+this.s.dialCode)),a&&this._u(a)},_i:function(){this._j(),this.b.autoHideDialCode&&this._l(),this.b.allowDropdown&&this._i1(),this.hiddenInput&&this._initHiddenInputListener()},_initHiddenInputListener:function(){var a=this,b=this.a.closest("form");b.length&&b.submit(function(){a.hiddenInput.val(a.getNumber())})},_i1:function(){var a=this,b=this.a.closest("label");b.length&&b.on("click"+this.ns,function(b){a.m.hasClass("hide")?a.a.focus():b.preventDefault()}),this.l.parent().on("click"+this.ns,function(b){!a.m.hasClass("hide")||a.a.prop("disabled")||a.a.prop("readonly")||a._n()}),this.k.on("keydown"+a.ns,function(b){!a.m.hasClass("hide")||b.which!=i.b&&b.which!=i.c&&b.which!=i.j&&b.which!=i.d||(b.preventDefault(),b.stopPropagation(),a._n()),b.which==i.k&&a._ac()})},_i2:function(){var c=this;this.b.utilsScript?a.fn[f].windowLoaded?a.fn[f].loadUtils(this.b.utilsScript,this.i):a(b).on("load",function(){a.fn[f].loadUtils(c.b.utilsScript,c.i)}):this.i.resolve(),"auto"===this.b.initialCountry?this._i3():this.h.resolve()},_i3:function(){a.fn[f].autoCountry?this.handleAutoCountry():a.fn[f].startedLoadingAutoCountry||(a.fn[f].startedLoadingAutoCountry=!0,"function"==typeof this.b.geoIpLookup&&this.b.geoIpLookup(function(b){a.fn[f].autoCountry=b.toLowerCase(),setTimeout(function(){a(".intl-tel-input input").intlTelInput("handleAutoCountry")})}))},_j:function(){var a=this;this.a.on("keyup"+this.ns,function(){a._v(a.a.val())&&a._triggerCountryChange()}),this.a.on("cut"+this.ns+" paste"+this.ns,function(){setTimeout(function(){a._v(a.a.val())&&a._triggerCountryChange()})})},_j2:function(a){var b=this.a.attr("maxlength");return b&&a.length>b?a.substr(0,b):a},_l:function(){var b=this;this.a.on("mousedown"+this.ns,function(a){b.a.is(":focus")||b.a.val()||(a.preventDefault(),b.a.focus())}),this.a.on("focus"+this.ns,function(a){b.a.val()||b.a.prop("readonly")||!b.s.dialCode||(b.a.val("+"+b.s.dialCode),b.a.one("keypress.plus"+b.ns,function(a){a.which==i.f&&b.a.val("")}),setTimeout(function(){var a=b.a[0];if(b.d){var c=b.a.val().length;a.setSelectionRange(c,c)}}))});var c=this.a.prop("form");c&&a(c).on("submit"+this.ns,function(){b._removeEmptyDialCode()}),this.a.on("blur"+this.ns,function(){b._removeEmptyDialCode()})},_removeEmptyDialCode:function(){var a=this.a.val();if("+"==a.charAt(0)){var b=this._m(a);b&&this.s.dialCode!=b||this.a.val("")}this.a.off("keypress.plus"+this.ns)},_m:function(a){return a.replace(/\D/g,"")},_n:function(){this._o();var a=this.m.children(".active");a.length&&(this._x(a),this._ad(a)),this._p(),this.l.children(".iti-arrow").addClass("up"),this.a.trigger("open:countrydropdown")},_o:function(){var c=this;if(this.b.dropdownContainer&&this.dropdown.appendTo(this.b.dropdownContainer),this.n=this.m.removeClass("hide").outerHeight(),!this.g){var d=this.a.offset(),e=d.top,f=a(b).scrollTop(),g=e+this.a.outerHeight()+this.nf;if(this.m.toggleClass("dropup",!g&&h),this.b.dropdownContainer){var i=!g&&h?0:this.a.innerHeight();this.dropdown.css({top:e+i,left:d.left}),a(b).on("scroll"+this.ns,function(){c._ac()})}}},_p:function(){var b=this;this.m.on("mouseover"+this.ns,".country",function(c){b._x(a(this))}),this.m.on("click"+this.ns,".country",function(c){b._ab(a(this))});var d=!0;a("html").on("click"+this.ns,function(a){d||b._ac(),d=!1});var e="",f=null;a(c).on("keydown"+this.ns,function(a){a.preventDefault(),a.which==i.b||a.which==i.c?b._q(a.which):a.which==i.d?b._r():a.which==i.e?b._ac():(a.which>=i.A&&a.which<=i.Z||a.which==i.j)&&(f&&clearTimeout(f),e+=String.fromCharCode(a.which),b._s(e),f=setTimeout(function(){e=""},1e3))})},_q:function(a){var b=this.m.children(".highlight").first(),c=a==i.b?b.prev():b.next();c.length&&(c.hasClass("divider")&&(c=a==i.b?c.prev():c.next()),this._x(c),this._ad(c))},_r:function(){var a=this.m.children(".highlight").first();a.length&&this._ab(a)},_s:function(a){for(var b=0;b-1,h="+1"==c&&e.length>=4;if((!("1"==this.s.dialCode)||!this._isRegionlessNanp(e))&&(!g||h))for(var i=0;i-1}return!1},_x:function(a){this.o.removeClass("highlight"),a.addClass("highlight")},_y:function(a,b,c){for(var d=b?k:this.p,e=0;ef){b&&(j+=k);var l=d-g;c.scrollTop(j-l)}},_ae:function(a,b){var c,d=this.a.val();if(a="+"+a,"+"==d.charAt(0)){var e=this._af(d);c=e?d.replace(e,a):a}else{if(this.b.nationalMode||this.b.separateDialCode)return;if(d)c=a+d;else{if(!b&&this.b.autoHideDialCode)return;c=a}}this.a.val(c)},_af:function(b){var c="";if("+"==b.charAt(0))for(var d="",e=0;e 1) { 49 | attributes = extend({ 50 | path: '/' 51 | }, api.defaults, attributes); 52 | 53 | if (typeof attributes.expires === 'number') { 54 | var expires = new Date(); 55 | expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); 56 | attributes.expires = expires; 57 | } 58 | 59 | // We're using "expires" because "max-age" is not supported by IE 60 | attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; 61 | 62 | try { 63 | result = JSON.stringify(value); 64 | if (/^[\{\[]/.test(result)) { 65 | value = result; 66 | } 67 | } catch (e) {} 68 | 69 | if (!converter.write) { 70 | value = encodeURIComponent(String(value)) 71 | .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); 72 | } else { 73 | value = converter.write(value, key); 74 | } 75 | 76 | key = encodeURIComponent(String(key)); 77 | key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); 78 | key = key.replace(/[\(\)]/g, escape); 79 | 80 | var stringifiedAttributes = ''; 81 | 82 | for (var attributeName in attributes) { 83 | if (!attributes[attributeName]) { 84 | continue; 85 | } 86 | stringifiedAttributes += '; ' + attributeName; 87 | if (attributes[attributeName] === true) { 88 | continue; 89 | } 90 | stringifiedAttributes += '=' + attributes[attributeName]; 91 | } 92 | return (document.cookie = key + '=' + value + stringifiedAttributes); 93 | } 94 | 95 | // Read 96 | 97 | if (!key) { 98 | result = {}; 99 | } 100 | 101 | // To prevent the for loop in the first place assign an empty array 102 | // in case there are no cookies at all. Also prevents odd result when 103 | // calling "get()" 104 | var cookies = document.cookie ? document.cookie.split('; ') : []; 105 | var rdecode = /(%[0-9A-Z]{2})+/g; 106 | var i = 0; 107 | 108 | for (; i < cookies.length; i++) { 109 | var parts = cookies[i].split('='); 110 | var cookie = parts.slice(1).join('='); 111 | 112 | if (!this.json && cookie.charAt(0) === '"') { 113 | cookie = cookie.slice(1, -1); 114 | } 115 | 116 | try { 117 | var name = parts[0].replace(rdecode, decodeURIComponent); 118 | cookie = converter.read ? 119 | converter.read(cookie, name) : converter(cookie, name) || 120 | cookie.replace(rdecode, decodeURIComponent); 121 | 122 | if (this.json) { 123 | try { 124 | cookie = JSON.parse(cookie); 125 | } catch (e) {} 126 | } 127 | 128 | if (key === name) { 129 | result = cookie; 130 | break; 131 | } 132 | 133 | if (!key) { 134 | result[name] = cookie; 135 | } 136 | } catch (e) {} 137 | } 138 | 139 | return result; 140 | } 141 | 142 | api.set = api; 143 | api.get = function (key) { 144 | return api.call(api, key); 145 | }; 146 | api.getJSON = function () { 147 | return api.apply({ 148 | json: true 149 | }, [].slice.call(arguments)); 150 | }; 151 | api.defaults = {}; 152 | 153 | api.remove = function (key, attributes) { 154 | api(key, '', extend(attributes, { 155 | expires: -1 156 | })); 157 | }; 158 | 159 | api.withConverter = init; 160 | 161 | return api; 162 | } 163 | 164 | return init(function () {}); 165 | })); 166 | -------------------------------------------------------------------------------- /fields/class-jony-acf-field-intl-tel-input-v5.php: -------------------------------------------------------------------------------- 1 | name = 'intl_tel_input'; 34 | 35 | 36 | /* 37 | * label (string) Multiple words, can include spaces, visible when selecting a field type 38 | */ 39 | 40 | $this->label = __('International Telephone Input', 'acf-intl-tel-input'); 41 | 42 | 43 | /* 44 | * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME 45 | */ 46 | 47 | $this->category = 'jquery'; 48 | 49 | 50 | /* 51 | * defaults (array) Array of default settings which are merged into the field object. These are used later in settings 52 | */ 53 | 54 | $this->defaults = array( 55 | 'separateDialCode' => false, 56 | 'allowDropdown' => true, 57 | 'excludeCountries' => '', 58 | 'onlyCountries' => '', 59 | 'preferredCountries' => '', 60 | 'initialCountry' => 'auto' 61 | ); 62 | 63 | 64 | /* 65 | * l10n (array) Array of strings that are used in JavaScript. This allows JS strings to be translated in PHP and loaded via: 66 | * var message = acf._e('intl_tel_input', 'error'); 67 | */ 68 | 69 | $this->l10n = array( 70 | 'error' => __('Error! Please enter a higher value', 'acf-intl-tel-input'), 71 | ); 72 | 73 | 74 | /* 75 | * settings (array) Store plugin settings (url, path, version) as a reference for later use with assets 76 | */ 77 | 78 | $this->settings = $settings; 79 | 80 | 81 | // do not delete! 82 | parent::__construct(); 83 | 84 | } 85 | 86 | 87 | /* 88 | * render_field_settings() 89 | * 90 | * Create extra settings for your field. These are visible when editing a field 91 | * 92 | * @type action 93 | * @since 3.6 94 | * @date 23/01/13 95 | * 96 | * @param $field (array) the $field being edited 97 | * @return n/a 98 | */ 99 | 100 | function render_field_settings( $field ) { 101 | 102 | /* 103 | * acf_render_field_setting 104 | * 105 | * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. 106 | * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. 107 | * 108 | * More than one setting can be added by copy/paste the above code. 109 | * Please note that you must also have a matching $defaults value for the field name (font_size) 110 | */ 111 | 112 | // $this->defaults = array( 113 | // 'nationalMode' => true, 114 | // 'separateDialCode' => false, 115 | // 'allowDropdown' => true, 116 | // 'excludeCountries' => '', 117 | // 'onlyCountries' => '', 118 | // 'preferredCountries' => '', 119 | // 'initialCountry' => 'auto' 120 | // ); 121 | 122 | acf_render_field_setting( $field, array( 123 | 'label' => __( 'Separate Dial Code', 'acf-intl-tel-input'), 124 | 'instructions' => '', 125 | 'type' => 'true_false', 126 | 'name' => 'separateDialCode', 127 | 'ui' => 1 128 | ) ); 129 | 130 | acf_render_field_setting( $field, array( 131 | 'label' => __( 'Allow Drop Down', 'acf-intl-tel-input'), 132 | 'instructions' => '', 133 | 'type' => 'true_false', 134 | 'name' => 'allowDropdown', 135 | 'ui' => 1 136 | ) ); 137 | $countryCodeLink = 'ISO 3166-1 alpha-2'; 138 | acf_render_field_setting( $field, array( 139 | 'label' => __( 'Initial Country','acf-intl-tel-input' ), 140 | 'instructions' => sprintf( __( 'Use "auto" to display user country (geo location based) or enter a country code (%s)', 'acf-intl-tel-input' ), $countryCodeLink ), 141 | 'type' => 'text', 142 | 'name' => 'initialCountry', 143 | )); 144 | 145 | acf_render_field_setting( $field, array( 146 | 'label' => __('Exclude Countries','acf-intl-tel-input'), 147 | 'instructions' => sprintf( __( 'Comma separated list of country codes (%s)', 'acf-intl-tel-input' ), $countryCodeLink ), 148 | 'type' => 'textarea', 149 | 'name' => 'excludeCountries', 150 | 'rows' => 2 151 | )); 152 | 153 | acf_render_field_setting( $field, array( 154 | 'label' => __('Only Countries','acf-intl-tel-input'), 155 | 'instructions' => sprintf( __( 'Comma separated list of country codes (%s)', 'acf-intl-tel-input' ), $countryCodeLink ), 156 | 'type' => 'textarea', 157 | 'name' => 'onlyCountries', 158 | 'rows' => 2 159 | )); 160 | 161 | acf_render_field_setting( $field, array( 162 | 'label' => __('Preferred Countries','acf-intl-tel-input'), 163 | 'instructions' => sprintf( __( 'Comma separated list of country codes (%s)', 'acf-intl-tel-input' ), $countryCodeLink ), 164 | 'type' => 'textarea', 165 | 'name' => 'preferredCountries', 166 | 'rows' => 2 167 | )); 168 | 169 | } 170 | 171 | 172 | 173 | /* 174 | * render_field() 175 | * 176 | * Create the HTML interface for your field 177 | * 178 | * @param $field (array) the $field being rendered 179 | * 180 | * @type action 181 | * @since 3.6 182 | * @date 23/01/13 183 | * 184 | * @param $field (array) the $field being edited 185 | * @return n/a 186 | */ 187 | 188 | function render_field( $field ) { 189 | $attr[] = 'data-hiddenInput="' . esc_attr($field['name']) . '"'; 190 | foreach( $this->defaults as $key => $value ){ 191 | $value = $field[$key]; 192 | switch( $key ){ 193 | case 'preferredCountries': 194 | case 'excludeCountries': 195 | case 'onlyCountries': 196 | $value = str_replace(' ', '', $value ); 197 | $value = str_replace(' ', '', apply_filters( "jony-acf-intl-tel-input/render_field/$key", $value, $field ) ); 198 | break; 199 | } 200 | $attr[] = 'data-' . $key .'="' . $value . '"'; 201 | } 202 | $attr = implode( ' ', $attr ); 203 | 204 | ?> >settings['url']; 228 | $version = $this->settings['version']; 229 | $intlTelInputVersion = '12.1.0'; 230 | $jsCookieVersion = '2.2.0'; 231 | 232 | 233 | // register & include JS 234 | wp_register_script('intl-tel-input', "{$url}assets/intl-tel-input/js/intlTelInput.min.js", array('jquery'), $intlTelInputVersion, true); 235 | wp_register_script('intl-tel-input-util', "{$url}assets/intl-tel-input/js/utils.js", array('jquery'), $intlTelInputVersion, true); 236 | wp_register_script('js-cookie', "{$url}assets/js/js.cookie.js", array(), $jsCookieVersion, true); 237 | wp_register_script('acf-intl-tel-input', "{$url}assets/js/input.js", array('acf-input', 'jquery', 'intl-tel-input', 'intl-tel-input-util', 'js-cookie'), $version, true); 238 | wp_localize_script('acf-intl-tel-input', 'acf_intl_tel_input_obj', array( 239 | 'COOKIEPATH' => COOKIEPATH, 240 | 'COOKIE_DOMAIN' => COOKIE_DOMAIN, 241 | ) ); 242 | wp_enqueue_script('acf-intl-tel-input'); 243 | 244 | 245 | // register & include CSS 246 | wp_register_style('intl-tel-input', "{$url}assets/intl-tel-input/css/intlTelInput.css", array(), $intlTelInputVersion); 247 | wp_register_style('acf-intl-tel-input', "{$url}assets/css/input.css", array('acf-input', 'intl-tel-input'), $version); 248 | wp_enqueue_style('acf-intl-tel-input'); 249 | 250 | } 251 | 252 | 253 | 254 | 255 | /* 256 | * input_admin_head() 257 | * 258 | * This action is called in the admin_head action on the edit screen where your field is created. 259 | * Use this action to add CSS and JavaScript to assist your render_field() action. 260 | * 261 | * @type action (admin_head) 262 | * @since 3.6 263 | * @date 23/01/13 264 | * 265 | * @param n/a 266 | * @return n/a 267 | */ 268 | 269 | /* 270 | 271 | function input_admin_head() { 272 | 273 | 274 | 275 | } 276 | 277 | */ 278 | 279 | 280 | /* 281 | * input_form_data() 282 | * 283 | * This function is called once on the 'input' page between the head and footer 284 | * There are 2 situations where ACF did not load during the 'acf/input_admin_enqueue_scripts' and 285 | * 'acf/input_admin_head' actions because ACF did not know it was going to be used. These situations are 286 | * seen on comments / user edit forms on the front end. This function will always be called, and includes 287 | * $args that related to the current screen such as $args['post_id'] 288 | * 289 | * @type function 290 | * @date 6/03/2014 291 | * @since 5.0.0 292 | * 293 | * @param $args (array) 294 | * @return n/a 295 | */ 296 | 297 | /* 298 | 299 | function input_form_data( $args ) { 300 | 301 | 302 | 303 | } 304 | 305 | */ 306 | 307 | 308 | /* 309 | * input_admin_footer() 310 | * 311 | * This action is called in the admin_footer action on the edit screen where your field is created. 312 | * Use this action to add CSS and JavaScript to assist your render_field() action. 313 | * 314 | * @type action (admin_footer) 315 | * @since 3.6 316 | * @date 23/01/13 317 | * 318 | * @param n/a 319 | * @return n/a 320 | */ 321 | 322 | /* 323 | 324 | function input_admin_footer() { 325 | 326 | 327 | 328 | } 329 | 330 | */ 331 | 332 | 333 | /* 334 | * field_group_admin_enqueue_scripts() 335 | * 336 | * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited. 337 | * Use this action to add CSS + JavaScript to assist your render_field_options() action. 338 | * 339 | * @type action (admin_enqueue_scripts) 340 | * @since 3.6 341 | * @date 23/01/13 342 | * 343 | * @param n/a 344 | * @return n/a 345 | */ 346 | 347 | /* 348 | 349 | function field_group_admin_enqueue_scripts() { 350 | 351 | } 352 | 353 | */ 354 | 355 | 356 | /* 357 | * field_group_admin_head() 358 | * 359 | * This action is called in the admin_head action on the edit screen where your field is edited. 360 | * Use this action to add CSS and JavaScript to assist your render_field_options() action. 361 | * 362 | * @type action (admin_head) 363 | * @since 3.6 364 | * @date 23/01/13 365 | * 366 | * @param n/a 367 | * @return n/a 368 | */ 369 | 370 | /* 371 | 372 | function field_group_admin_head() { 373 | 374 | } 375 | 376 | */ 377 | 378 | 379 | /* 380 | * load_value() 381 | * 382 | * This filter is applied to the $value after it is loaded from the db 383 | * 384 | * @type filter 385 | * @since 3.6 386 | * @date 23/01/13 387 | * 388 | * @param $value (mixed) the value found in the database 389 | * @param $post_id (mixed) the $post_id from which the value was loaded 390 | * @param $field (array) the field array holding all the field options 391 | * @return $value 392 | */ 393 | 394 | /* 395 | 396 | function load_value( $value, $post_id, $field ) { 397 | 398 | return $value; 399 | 400 | } 401 | 402 | */ 403 | 404 | 405 | /* 406 | * update_value() 407 | * 408 | * This filter is applied to the $value before it is saved in the db 409 | * 410 | * @type filter 411 | * @since 3.6 412 | * @date 23/01/13 413 | * 414 | * @param $value (mixed) the value found in the database 415 | * @param $post_id (mixed) the $post_id from which the value was loaded 416 | * @param $field (array) the field array holding all the field options 417 | * @return $value 418 | */ 419 | 420 | /* 421 | 422 | function update_value( $value, $post_id, $field ) { 423 | 424 | return $value; 425 | 426 | } 427 | 428 | */ 429 | 430 | 431 | /* 432 | * format_value() 433 | * 434 | * This filter is appied to the $value after it is loaded from the db and before it is returned to the template 435 | * 436 | * @type filter 437 | * @since 3.6 438 | * @date 23/01/13 439 | * 440 | * @param $value (mixed) the value which was loaded from the database 441 | * @param $post_id (mixed) the $post_id from which the value was loaded 442 | * @param $field (array) the field array holding all the field options 443 | * 444 | * @return $value (mixed) the modified value 445 | */ 446 | 447 | /* 448 | 449 | function format_value( $value, $post_id, $field ) { 450 | 451 | // bail early if no value 452 | if( empty($value) ) { 453 | 454 | return $value; 455 | 456 | } 457 | 458 | 459 | // apply setting 460 | if( $field['font_size'] > 12 ) { 461 | 462 | // format the value 463 | // $value = 'something'; 464 | 465 | } 466 | 467 | 468 | // return 469 | return $value; 470 | } 471 | 472 | */ 473 | 474 | 475 | /* 476 | * validate_value() 477 | * 478 | * This filter is used to perform validation on the value prior to saving. 479 | * All values are validated regardless of the field's required setting. This allows you to validate and return 480 | * messages to the user if the value is not correct 481 | * 482 | * @type filter 483 | * @date 11/02/2014 484 | * @since 5.0.0 485 | * 486 | * @param $valid (boolean) validation status based on the value and the field's required setting 487 | * @param $value (mixed) the $_POST value 488 | * @param $field (array) the field array holding all the field options 489 | * @param $input (string) the corresponding input name for $_POST value 490 | * @return $valid 491 | */ 492 | 493 | /* 494 | 495 | function validate_value( $valid, $value, $field, $input ){ 496 | 497 | // Basic usage 498 | if( $value < $field['custom_minimum_setting'] ) 499 | { 500 | $valid = false; 501 | } 502 | 503 | 504 | // Advanced usage 505 | if( $value < $field['custom_minimum_setting'] ) 506 | { 507 | $valid = __('The value is too little!','acf-intl-tel-input'), 508 | } 509 | 510 | 511 | // return 512 | return $valid; 513 | 514 | } 515 | 516 | */ 517 | 518 | 519 | /* 520 | * delete_value() 521 | * 522 | * This action is fired after a value has been deleted from the db. 523 | * Please note that saving a blank value is treated as an update, not a delete 524 | * 525 | * @type action 526 | * @date 6/03/2014 527 | * @since 5.0.0 528 | * 529 | * @param $post_id (mixed) the $post_id from which the value was deleted 530 | * @param $key (string) the $meta_key which the value was deleted 531 | * @return n/a 532 | */ 533 | 534 | /* 535 | 536 | function delete_value( $post_id, $key ) { 537 | 538 | 539 | 540 | } 541 | 542 | */ 543 | 544 | 545 | /* 546 | * load_field() 547 | * 548 | * This filter is applied to the $field after it is loaded from the database 549 | * 550 | * @type filter 551 | * @date 23/01/2013 552 | * @since 3.6.0 553 | * 554 | * @param $field (array) the field array holding all the field options 555 | * @return $field 556 | */ 557 | 558 | /* 559 | 560 | function load_field( $field ) { 561 | 562 | return $field; 563 | 564 | } 565 | 566 | */ 567 | 568 | 569 | /* 570 | * update_field() 571 | * 572 | * This filter is applied to the $field before it is saved to the database 573 | * 574 | * @type filter 575 | * @date 23/01/2013 576 | * @since 3.6.0 577 | * 578 | * @param $field (array) the field array holding all the field options 579 | * @return $field 580 | */ 581 | 582 | /* 583 | 584 | function update_field( $field ) { 585 | 586 | return $field; 587 | 588 | } 589 | 590 | */ 591 | 592 | 593 | /* 594 | * delete_field() 595 | * 596 | * This action is fired after a field is deleted from the database 597 | * 598 | * @type action 599 | * @date 11/02/2014 600 | * @since 5.0.0 601 | * 602 | * @param $field (array) the field array holding all the field options 603 | * @return n/a 604 | */ 605 | 606 | /* 607 | 608 | function delete_field( $field ) { 609 | 610 | 611 | 612 | } 613 | 614 | */ 615 | 616 | 617 | } 618 | 619 | 620 | // initialize 621 | new jony_acf_field_intl_tel_input( $this->settings ); 622 | 623 | 624 | // class_exists check 625 | endif; 626 | 627 | ?> 628 | -------------------------------------------------------------------------------- /lang/README.md: -------------------------------------------------------------------------------- 1 | # Translations directory 2 | 3 | Use this directory to store .po and .mo files. 4 | 5 | This directory can be removed if not used. 6 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Advanced Custom Fields: International Telephone Input Field === 2 | Contributors: Jony Hayama 3 | Tags: acf, acf-pro, intl-tel-input 4 | Requires at least: 3.6.0 5 | Tested up to: 4.9.0 6 | Stable tag: trunk 7 | License: GPLv2 or later 8 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 | 10 | Adds International Telephone Input to ACF. 11 | 12 | == Description == 13 | 14 | Adds International Telephone Input to ACF. 15 | 16 | Allows separate dial code, drop down, initial country (auto or manual), exclude countries, only countries and preferred countries. 17 | 18 | = Links = 19 | * International Telephone Input[https://intl-tel-input.com/] by jackocnr[https://github.com/jackocnr] 20 | * Advanced Custom Fields[https://www.advancedcustomfields.com/] by Elliot Condon[https://github.com/elliotcondon] 21 | 22 | = Compatibility = 23 | 24 | This ACF field type is compatible with: 25 | * ACF 5 26 | 27 | == Installation == 28 | 29 | 1. Copy the `acf-intl-tel-input` folder into your `wp-content/plugins` folder 30 | 2. Activate the International Telephone Input plugin via the plugins admin page 31 | 3. Create a new field via ACF and select the International Telephone Input type 32 | 4. Read the description above for usage instructions 33 | 34 | == Changelog == 35 | 36 | = 1.0.0 = 37 | * Initial Release. --------------------------------------------------------------------------------