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-03-05 23:25:49 +00:00
|
|
|
template: $('#phone-number').html(),
|
2015-01-14 23:59:40 +00:00
|
|
|
render: function() {
|
|
|
|
this.$el.html($(Mustache.render(this.template)));
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('input.number').intlTelInput();
|
2015-01-14 23:59:40 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'change': 'validateNumber',
|
|
|
|
'keyup': 'validateNumber'
|
|
|
|
},
|
|
|
|
|
|
|
|
validateNumber: function() {
|
2015-03-28 01:47:58 +00:00
|
|
|
var input = this.$('input.number');
|
2015-01-14 23:59:40 +00:00
|
|
|
try {
|
2015-03-28 01:47:58 +00:00
|
|
|
var regionCode = this.$('li.active').attr('data-country-code').toUpperCase();
|
2015-01-18 08:51:32 +00:00
|
|
|
var number = input.val();
|
2015-01-14 23:59:40 +00:00
|
|
|
|
|
|
|
var parsedNumber = libphonenumber.util.verifyNumber(number, regionCode);
|
|
|
|
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.number-container').removeClass('invalid');
|
|
|
|
this.$('.number-container').addClass('valid');
|
2015-01-14 23:59:40 +00:00
|
|
|
return parsedNumber;
|
|
|
|
} catch(e) {
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.number-container').removeClass('valid');
|
2015-01-18 08:51:32 +00:00
|
|
|
} finally {
|
|
|
|
input.trigger('validation');
|
2015-01-14 23:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|