2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-14 23:59:40 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
2015-03-05 23:44:53 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-03-05 23:25:49 +00:00
|
|
|
Whisper.PhoneInputView = Whisper.View.extend({
|
2015-01-14 23:59:40 +00:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'phone-input',
|
2015-12-08 23:01:29 +00:00
|
|
|
templateName: 'phone-number',
|
2017-04-19 17:34:19 +00:00
|
|
|
initialize: function() {
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('input.number').intlTelInput();
|
2015-01-14 23:59:40 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'change': 'validateNumber',
|
|
|
|
'keyup': 'validateNumber'
|
|
|
|
},
|
|
|
|
validateNumber: function() {
|
2015-03-28 01:47:58 +00:00
|
|
|
var input = this.$('input.number');
|
2015-12-05 01:38:41 +00:00
|
|
|
var regionCode = this.$('li.active').attr('data-country-code').toUpperCase();
|
|
|
|
var number = input.val();
|
2015-01-14 23:59:40 +00:00
|
|
|
|
2015-12-05 01:38:41 +00:00
|
|
|
var parsedNumber = libphonenumber.util.parseNumber(number, regionCode);
|
|
|
|
if (parsedNumber.isValidNumber) {
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.number-container').removeClass('invalid');
|
|
|
|
this.$('.number-container').addClass('valid');
|
2015-12-05 01:38:41 +00:00
|
|
|
} else {
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.number-container').removeClass('valid');
|
2015-01-14 23:59:40 +00:00
|
|
|
}
|
2015-12-05 01:38:41 +00:00
|
|
|
input.trigger('validation');
|
2015-12-09 21:49:15 +00:00
|
|
|
|
|
|
|
return parsedNumber.e164;
|
2015-01-14 23:59:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|