2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
2015-03-05 23:44:53 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.PhoneInputView = Whisper.View.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
className: 'phone-input',
|
|
|
|
templateName: 'phone-number',
|
|
|
|
initialize: function() {
|
|
|
|
this.$('input.number').intlTelInput();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
change: 'validateNumber',
|
|
|
|
keyup: 'validateNumber',
|
|
|
|
},
|
|
|
|
validateNumber: function() {
|
|
|
|
var input = this.$('input.number');
|
|
|
|
var regionCode = this.$('li.active')
|
|
|
|
.attr('data-country-code')
|
|
|
|
.toUpperCase();
|
|
|
|
var number = input.val();
|
2015-01-14 23:59:40 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
var parsedNumber = libphonenumber.util.parseNumber(number, regionCode);
|
|
|
|
if (parsedNumber.isValidNumber) {
|
|
|
|
this.$('.number-container').removeClass('invalid');
|
|
|
|
this.$('.number-container').addClass('valid');
|
|
|
|
} else {
|
|
|
|
this.$('.number-container').removeClass('valid');
|
|
|
|
}
|
|
|
|
input.trigger('validation');
|
2015-12-09 21:49:15 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
return parsedNumber.e164;
|
|
|
|
},
|
|
|
|
});
|
2015-01-14 23:59:40 +00:00
|
|
|
})();
|