Restyled country dropdown

Added jquery plugin that allows for flags and country codes to be
displayed in a user-friendly way, on top of the existing phone view
This commit is contained in:
Emily Chao 2015-01-15 11:11:45 -10:00 committed by lilia
parent 5d3020b9ed
commit e74cba8a92
11 changed files with 2043 additions and 54 deletions

File diff suppressed because one or more lines are too long

View file

@ -17,36 +17,6 @@ var Whisper = Whisper || {};
(function () {
'use strict';
var MessageRecipientInputView = Backbone.View.extend({
events: {
'change': 'verifyNumber',
'focus' : 'removeError'
},
removeError: function() {
this.$el.removeClass('error');
},
verifyNumber: function() {
try {
var val = this.$el.val();
if (val[0] === '+') {
// assume that the country code is specified
var number = libphonenumber.util.verifyNumber(val);
} else {
// assume that the country code should match our own
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
var myRegionCode = libphonenumber.util.getRegionCodeForNumber(me);
var number = libphonenumber.util.verifyNumber(val, myRegionCode);
}
this.removeError();
return number;
} catch(ex) {
this.$el.addClass('error');
console.log(ex);
}
}
});
Whisper.NewConversationView = Backbone.View.extend({
className: 'conversation',
@ -56,7 +26,7 @@ var Whisper = Whisper || {};
this.$el.html($(Mustache.render(this.template)));
this.input = new Whisper.PhoneInputView({el: this.$el.find('div.phone-number-input')});
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
this.$el.find('#phone-number-input').append(this.input.render().el);
this.$el.find('div.phone-number-input').append(this.input.render().el);
},
events: {

View file

@ -28,15 +28,7 @@ var Whisper = Whisper || {};
render: function() {
this.$el.html($(Mustache.render(this.template)));
var regionCodes = [];
var countryNames = [];
$.each(libphonenumber.util.getAllRegionCodes(), function(regionCode, countryName) {
regionCodes.push(regionCode);
countryNames.push(countryName);
});
for (var i = 0; i < regionCodes.length; i++) {
this.$el.find('.regionCode').append($('<option>', { value: regionCodes[i], text: countryNames[i]}));
}
this.$el.find('input.number').intlTelInput();
return this;
},
@ -47,12 +39,11 @@ var Whisper = Whisper || {};
validateNumber: function() {
try {
var regionCode = this.$el.find('.regionCode').val();
var regionCode = this.$el.find('li.active').attr('data-country-code').toUpperCase();
var number = this.$el.find('input.number').val();
var parsedNumber = libphonenumber.util.verifyNumber(number, regionCode);
this.$el.find('.regionCode').val(libphonenumber.util.getRegionCodeForNumber(parsedNumber));
this.$el.find('.number-container').removeClass('invalid');
this.$el.find('.number-container').addClass('valid');
return parsedNumber;