2015-09-07 23:53:43 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-15 00:59:40 +01:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
2015-03-06 00:44:53 +01:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
2015-03-06 00:25:49 +01:00
|
|
|
Whisper.PhoneInputView = Whisper.View.extend({
|
2015-01-15 00:59:40 +01:00
|
|
|
tagName: 'div',
|
|
|
|
className: 'phone-input',
|
2015-03-06 00:25:49 +01:00
|
|
|
template: $('#phone-number').html(),
|
2015-01-15 00:59:40 +01:00
|
|
|
render: function() {
|
|
|
|
this.$el.html($(Mustache.render(this.template)));
|
2015-03-28 02:47:58 +01:00
|
|
|
this.$('input.number').intlTelInput();
|
2015-01-15 00:59:40 +01:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'change': 'validateNumber',
|
|
|
|
'keyup': 'validateNumber'
|
|
|
|
},
|
|
|
|
|
|
|
|
validateNumber: function() {
|
2015-03-28 02:47:58 +01:00
|
|
|
var input = this.$('input.number');
|
2015-01-15 00:59:40 +01:00
|
|
|
try {
|
2015-03-28 02:47:58 +01:00
|
|
|
var regionCode = this.$('li.active').attr('data-country-code').toUpperCase();
|
2015-01-18 09:51:32 +01:00
|
|
|
var number = input.val();
|
2015-01-15 00:59:40 +01:00
|
|
|
|
|
|
|
var parsedNumber = libphonenumber.util.verifyNumber(number, regionCode);
|
|
|
|
|
2015-03-28 02:47:58 +01:00
|
|
|
this.$('.number-container').removeClass('invalid');
|
|
|
|
this.$('.number-container').addClass('valid');
|
2015-01-15 00:59:40 +01:00
|
|
|
return parsedNumber;
|
|
|
|
} catch(e) {
|
2015-03-28 02:47:58 +01:00
|
|
|
this.$('.number-container').removeClass('valid');
|
2015-01-18 09:51:32 +01:00
|
|
|
} finally {
|
|
|
|
input.trigger('validation');
|
2015-01-15 00:59:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|