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/>.
|
|
|
|
*/
|
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
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-01-15 22:11:45 +01:00
|
|
|
this.$el.find('input.number').intlTelInput();
|
2015-01-15 00:59:40 +01:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'change': 'validateNumber',
|
|
|
|
'keyup': 'validateNumber'
|
|
|
|
},
|
|
|
|
|
|
|
|
validateNumber: function() {
|
2015-01-18 09:51:32 +01:00
|
|
|
var input = this.$el.find('input.number');
|
2015-01-15 00:59:40 +01:00
|
|
|
try {
|
2015-01-15 22:11:45 +01:00
|
|
|
var regionCode = this.$el.find('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);
|
|
|
|
|
|
|
|
this.$el.find('.number-container').removeClass('invalid');
|
|
|
|
this.$el.find('.number-container').addClass('valid');
|
|
|
|
return parsedNumber;
|
|
|
|
} catch(e) {
|
|
|
|
this.$el.find('.number-container').removeClass('valid');
|
2015-01-18 09:51:32 +01:00
|
|
|
} finally {
|
|
|
|
input.trigger('validation');
|
2015-01-15 00:59:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|