2015-01-15 00:59:40 +01:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
(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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|