Use view.$ shorthand for scoped jquery searches

Wish I'd noticed that one earlier. http://backbonejs.org/#View-dollar
This commit is contained in:
lilia 2015-03-27 18:47:58 -07:00
parent 0373252901
commit 5d4298697c
10 changed files with 48 additions and 46 deletions

View File

@ -22,15 +22,17 @@
extension.windows.getCurrent(function (windowInfo) {
var bg = extension.windows.getBackground();
window.$ = bg.$;
var body = $('body', document)
var conversation = bg.getConversationForWindow(windowInfo.id);
if (conversation) {
window.document.title = conversation.getTitle();
new bg.Whisper.ConversationView({
var view = new bg.Whisper.ConversationView({
model: conversation
}).$el.prependTo($('body', document));
$('input.send-message', document).focus();
});
view.$el.prependTo(body);
view.$('input.send-message').focus();
} else {
$('<div>').text('Error').prependTo($('body', document));
$('<div>').text('Error').prependTo(body);
}
});
}());

View File

@ -32,13 +32,13 @@
this.render();
this.fileInput = new Whisper.FileInputView({
el: this.$el.find('.attachments')
el: this.$('.attachments')
});
this.view = new Whisper.MessageListView({
collection: this.model.messageCollection
});
this.$el.find('.discussion-container').append(this.view.el);
this.$('.discussion-container').append(this.view.el);
this.view.render();
setTimeout(function() {
@ -106,22 +106,22 @@
closeMenu: function(e) {
if (e && !$(e.target).hasClass('hamburger')) {
this.$el.find('.menu-list').hide();
this.$('.menu-list').hide();
}
},
endSession: function() {
this.model.endSession();
this.$el.find('.menu-list').hide();
this.$('.menu-list').hide();
},
leaveGroup: function() {
this.model.leaveGroup();
this.$el.find('.menu-list').hide();
this.$('.menu-list').hide();
},
toggleMenu: function() {
this.$el.find('.menu-list').toggle();
this.$('.menu-list').toggle();
},
newGroupUpdate: function() {
@ -137,12 +137,12 @@
if (confirm("Permanently delete this conversation?")) {
this.model.destroyMessages();
}
this.$el.find('.menu-list').hide();
this.$('.menu-list').hide();
},
sendMessage: function(e) {
e.preventDefault();
var input = this.$el.find('.send input.send-message');
var input = this.$('.send input.send-message');
var message = this.replace_colons(input.val());
var convo = this.model;

View File

@ -25,10 +25,10 @@
tagName: 'span',
className: 'file-input',
initialize: function() {
this.$input = this.$el.find('input[type=file]');
this.$input = this.$('input[type=file]');
this.thumb = new Whisper.AttachmentPreviewView();
this.$el.addClass('file-input');
this.$default = this.$el.find('.default');
this.$default = this.$('.default');
},
events: {
@ -44,7 +44,7 @@
addThumb: function(src) {
this.$default.hide();
this.thumb.src = src;
this.$el.find('.thumbnail').append(this.thumb.render().el);
this.$('.thumbnail').append(this.thumb.render().el);
},
autoScale: function(file) {

View File

@ -65,13 +65,13 @@
this.openConversation.bind(this, null));
this.inbox = new Whisper.ConversationListView({
el : this.$el.find('.conversations'),
el : this.$('.conversations'),
collection : bg.inbox
}).render();
this.inbox.listenTo(bg.inbox, 'sort', this.inbox.render);
new SocketView().render().$el.appendTo(this.$el.find('.socket-status'));
new SocketView().render().$el.appendTo(this.$('.socket-status'));
window.addEventListener('beforeunload', function () {
this.inbox.stopListening();

View File

@ -95,14 +95,14 @@
received_at : moment(this.model.get('received_at')).toString(),
tofrom : this.model.isIncoming() ? 'From' : 'To',
}));
this.view.render().$el.prependTo(this.$el.find('.message-container'));
this.view.render().$el.prependTo(this.$('.message-container'));
if (this.model.isOutgoing()) {
this.conversation.contactCollection.each(function(contact) {
var v = new ContactView({
model: contact,
conflict: this.model.getKeyConflict(contact.id)
}).render().$el.appendTo(this.$el.find('.contacts'));
}).render().$el.appendTo(this.$('.contacts'));
}.bind(this));
} else {
var number = this.model.get('source');
@ -110,7 +110,7 @@
var v = new ContactView({
model: contact,
conflict: this.model.getKeyConflict(number)
}).render().$el.appendTo(this.$el.find('.contacts'));
}).render().$el.appendTo(this.$('.contacts'));
}
}
});

View File

@ -41,7 +41,7 @@
renderControl: function() {
if (this.model.isEndSession() || this.model.isGroupUpdate()) {
this.$el.addClass('control');
this.$el.find('.content').text(this.model.getDescription());
this.$('.content').text(this.model.getDescription());
} else {
this.$el.removeClass('control');
}
@ -62,13 +62,13 @@
twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 });
var content = this.$el.find('.content');
var content = this.$('.content');
content.html(this.autoLink(content.html()));
this.renderDelivered();
this.renderControl();
this.$el.find('.attachments').append(
this.$('.attachments').append(
this.model.get('attachments').map(function(attachment) {
return new Whisper.AttachmentView({
model: attachment
@ -78,7 +78,7 @@
var errors = this.model.get('errors');
if (errors && errors.length) {
this.$el.find('.bubble').prepend(
this.$('.bubble').prepend(
errors.map(function(error) {
return new Whisper.MessageErrorView({
model: error,

View File

@ -22,17 +22,17 @@
template: $('#new-conversation').html(),
initialize: function() {
this.render();
this.$group_update = this.$el.find('.new-group-update-form');
this.$create = this.$el.find('.create');
this.$input = this.$el.find('input.search');
this.$group_update = this.$('.new-group-update-form');
this.$create = this.$('.create');
this.$input = this.$('input.search');
// Group avatar file input
this.avatarInput = new Whisper.FileInputView({
el: this.$el.find('.group-avatar')
el: this.$('.group-avatar')
});
this.recipients_view = new Whisper.RecipientsInputView();
this.$el.find('.scrollable').append(this.recipients_view.el);
this.$('.scrollable').append(this.recipients_view.el);
this.listenTo(this.getRecipients(), 'add', this.updateControls);
this.listenTo(this.getRecipients(), 'remove', this.updateControls);
},
@ -72,7 +72,7 @@
},
create: function() {
var errors = this.recipients_view.$el.find('.error');
var errors = this.recipients_view.$('.error');
if (errors.length) {
// TODO: css animation or error notification
@ -107,7 +107,7 @@
},
createGroup: function() {
var name = this.$el.find('.new-group-update-form .name').val();
var name = this.$('.new-group-update-form .name').val();
if (!name.trim().length) {
return;
}
@ -153,7 +153,7 @@
reset: function() {
this.$create.hide();
this.$el.find('.new-group-update-form .name').val('');
this.$('.new-group-update-form .name').val('');
this.$group_update.hide();
this.recipients_view.reset();
},

View File

@ -24,12 +24,12 @@
initialize: function(options) {
this.render();
this.avatarInput = new Whisper.FileInputView({
el: this.$el.find('.group-avatar')
el: this.$('.group-avatar')
});
this.recipients_view = new Whisper.RecipientsInputView();
this.$el.find('.scrollable').append(this.recipients_view.el);
this.$el.find('.avatar').addClass('default');
this.$('.scrollable').append(this.recipients_view.el);
this.$('.avatar').addClass('default');
},
events: {
'click .back': 'goBack',
@ -47,7 +47,7 @@
send: function() {
return this.avatarInput.getFiles().then(function(avatarFiles) {
this.model.save({
name: this.$el.find('.name').val(),
name: this.$('.name').val(),
avatar: avatarFiles[0],
members: _.union(this.model.get('members'), this.recipients_view.recipients.pluck('id'))
});

View File

@ -23,7 +23,7 @@
template: $('#phone-number').html(),
render: function() {
this.$el.html($(Mustache.render(this.template)));
this.$el.find('input.number').intlTelInput();
this.$('input.number').intlTelInput();
return this;
},
@ -33,18 +33,18 @@
},
validateNumber: function() {
var input = this.$el.find('input.number');
var input = this.$('input.number');
try {
var regionCode = this.$el.find('li.active').attr('data-country-code').toUpperCase();
var regionCode = this.$('li.active').attr('data-country-code').toUpperCase();
var number = input.val();
var parsedNumber = libphonenumber.util.verifyNumber(number, regionCode);
this.$el.find('.number-container').removeClass('invalid');
this.$el.find('.number-container').addClass('valid');
this.$('.number-container').removeClass('invalid');
this.$('.number-container').addClass('valid');
return parsedNumber;
} catch(e) {
this.$el.find('.number-container').removeClass('valid');
this.$('.number-container').removeClass('valid');
} finally {
input.trigger('validation');
}

View File

@ -60,8 +60,8 @@
template: $('#recipients-input').html(),
initialize: function() {
this.render();
this.$input = this.$el.find('input.search');
this.$new_contact = this.$el.find('.new-contact');
this.$input = this.$('input.search');
this.$new_contact = this.$('.new-contact');
// Collection of recipients selected for the new message
this.recipients = new Whisper.ConversationCollection([], {
@ -71,7 +71,7 @@
// View to display the selected recipients
this.recipients_view = new Whisper.RecipientListView({
collection: this.recipients,
el: this.$el.find('.recipients')
el: this.$('.recipients')
});
// Collection of contacts to match user input against
@ -84,7 +84,7 @@
comparator: function(m) { return m.getTitle(); }
})
});
this.$el.find('.contacts').append(this.typeahead_view.el);
this.$('.contacts').append(this.typeahead_view.el);
this.initNewContact();
},