Browse Source

replace .parents() method with .closest() — need only first ancestor

master
Simon Grim 9 years ago
parent
commit
d5bbe2c6f1
  1. 32
      js/interface_common.js
  2. 4
      js/mobile_abstract.js
  3. 12
      js/twister_directmsg.js

32
js/interface_common.js

@ -479,7 +479,7 @@ function reTwistPopup(event, post, textArea) {
} }
if (typeof post === 'undefined') if (typeof post === 'undefined')
post = $.evalJSON($(event.target).parents('.post-data').attr('data-userpost')); post = $.evalJSON($(event.target).closest('.post-data').attr('data-userpost'));
var modal = openModal({ var modal = openModal({
classBase: '.prompt-wrapper', classBase: '.prompt-wrapper',
@ -495,7 +495,7 @@ function reTwistPopup(event, post, textArea) {
modal.content.find('.switch-mode') modal.content.find('.switch-mode')
.text(polyglot.t('Switch to Reply')) .text(polyglot.t('Switch to Reply'))
.on('click', (function(event) {replyInitPopup(event, post, .on('click', (function(event) {replyInitPopup(event, post,
$(event.target).parents('form').find('textarea').detach());}).bind(post)) $(event.target).closest('form').find('textarea').detach());}).bind(post))
; ;
var replyArea = modal.content.find('.post-area .post-area-new'); var replyArea = modal.content.find('.post-area .post-area-new');
@ -533,7 +533,7 @@ function replyInitPopup(e, post, textArea) {
modal.content.find('.switch-mode') modal.content.find('.switch-mode')
.text(polyglot.t('Switch to Retransmit')) .text(polyglot.t('Switch to Retransmit'))
.on('click', (function(event) {reTwistPopup(event, post, .on('click', (function(event) {reTwistPopup(event, post,
$(event.target).parents('form').find('textarea').detach())}).bind(post)) $(event.target).closest('form').find('textarea').detach())}).bind(post))
; ;
var replyArea = modal.content.find('.post-area .post-area-new').addClass('open'); var replyArea = modal.content.find('.post-area .post-area-new').addClass('open');
@ -661,7 +661,7 @@ function postReplyClick(e) {
if (!post.hasClass('original')) if (!post.hasClass('original'))
replyInitPopup(e, $.evalJSON(post.find('.post-data').attr('data-userpost'))); replyInitPopup(e, $.evalJSON(post.find('.post-data').attr('data-userpost')));
else { else {
if (!post.parents('.post.open').length) if (!post.closest('.post.open').length)
postExpandFunction(e, post); postExpandFunction(e, post);
composeNewPost(e, post.find('.post-area-new')); composeNewPost(e, post.find('.post-area-new'));
} }
@ -743,12 +743,12 @@ var usePostSpliting = false;
function replyTextInput(event) { function replyTextInput(event) {
var textArea = $(event.target); var textArea = $(event.target);
var textAreaForm = textArea.parents('form'); var textAreaForm = textArea.closest('form');
if (textAreaForm.length) { if (textAreaForm.length) {
if ($.Options.unicodeConversion.val !== 'disable') if ($.Options.unicodeConversion.val !== 'disable')
textArea.val(convert2Unicodes(textArea.val(), textArea)); textArea.val(convert2Unicodes(textArea.val(), textArea));
if (usePostSpliting && !textArea.parents('.directMessages').length) { if (usePostSpliting && !textArea.closest('.directMessages').length) {
var caretPos = textArea.caret(); var caretPos = textArea.caret();
var reply_to = textArea.attr('data-reply-to'); var reply_to = textArea.attr('data-reply-to');
var tas = textAreaForm.find('textarea'); var tas = textAreaForm.find('textarea');
@ -875,12 +875,12 @@ function replyTextUpdateRemaining(ta) {
ta = ta.target; ta = ta.target;
if (ta === document.activeElement) { if (ta === document.activeElement) {
var textArea = $(ta); var textArea = $(ta);
var textAreaForm = textArea.parents('form'); var textAreaForm = textArea.closest('form');
if (textAreaForm.length) { if (textAreaForm.length) {
var remainingCount = textAreaForm.find('.post-area-remaining'); var remainingCount = textAreaForm.find('.post-area-remaining');
var c = replyTextCountRemaining(ta); var c = replyTextCountRemaining(ta);
if (usePostSpliting && !textArea.parents('.directMessages').length && splitedPostsCount > 1) if (usePostSpliting && !textArea.closest('.directMessages').length && splitedPostsCount > 1)
remainingCount.text((textAreaForm.find('textarea').index(ta) + 1).toString() remainingCount.text((textAreaForm.find('textarea').index(ta) + 1).toString()
+ '/' + splitedPostsCount.toString() + ': ' + c.toString()); + '/' + splitedPostsCount.toString() + ': ' + c.toString());
else else
@ -913,8 +913,8 @@ function replyTextCountRemaining(ta) {
var textArea = $(ta); var textArea = $(ta);
var c; var c;
if (usePostSpliting && !textArea.parents('.directMessages').length && splitedPostsCount > 1) { if (usePostSpliting && !textArea.closest('.directMessages').length && splitedPostsCount > 1) {
c = 140 - ta.value.length - (textArea.parents('form').find('textarea').index(ta) + 1).toString().length - splitedPostsCount.toString().length - 4; c = 140 - ta.value.length - (textArea.closest('form').find('textarea').index(ta) + 1).toString().length - splitedPostsCount.toString().length - 4;
var reply_to = textArea.attr('data-reply-to'); var reply_to = textArea.attr('data-reply-to');
if (typeof reply_to !== 'undefined' && if (typeof reply_to !== 'undefined' &&
!checkPostForMentions(ta.value, reply_to, 140 -c -reply_to.length)) !checkPostForMentions(ta.value, reply_to, 140 -c -reply_to.length))
@ -931,7 +931,7 @@ function replyTextKeySend(event) {
$('.dropdown-menu').css('display') === 'none') $('.dropdown-menu').css('display') === 'none')
|| ((event.metaKey || event.ctrlKey) && $.Options.keysSend.val === 'ctrlenter')) { || ((event.metaKey || event.ctrlKey) && $.Options.keysSend.val === 'ctrlenter')) {
var textArea = $(event.target); var textArea = $(event.target);
var textAreaForm = textArea.parents('form'); var textAreaForm = textArea.closest('form');
var buttonSend = textAreaForm.find('.post-submit'); var buttonSend = textAreaForm.find('.post-submit');
if (!buttonSend.length) if (!buttonSend.length)
buttonSend = textAreaForm.find('.dm-submit'); buttonSend = textAreaForm.find('.dm-submit');
@ -1413,11 +1413,11 @@ function postSubmit(e, oldLastPostId) {
return; return;
} }
if (btnPostSubmit.parents('.prompt-wrapper').length) if (btnPostSubmit.closest('.prompt-wrapper').length)
closePrompt(); closePrompt();
else { else {
textArea.val('').attr('placeholder', polyglot.t('Your message was sent!')); textArea.val('').attr('placeholder', polyglot.t('Your message was sent!'));
var tweetForm = btnPostSubmit.parents('form'); var tweetForm = btnPostSubmit.closest('form');
var remainingCount = tweetForm.find('.post-area-remaining'); var remainingCount = tweetForm.find('.post-area-remaining');
remainingCount.text(140); remainingCount.text(140);
@ -1639,7 +1639,7 @@ function elemFitNextIntoParentHeight(elem) {
function inputEnterActivator(event) { function inputEnterActivator(event) {
var elemEvent = $(event.target); var elemEvent = $(event.target);
elemEvent.parents(event.data.parentSelector).find(event.data.enterSelector) elemEvent.closest(event.data.parentSelector).find(event.data.enterSelector)
.attr('disabled', elemEvent.val().trim() === ''); .attr('disabled', elemEvent.val().trim() === '');
} }
@ -1652,7 +1652,7 @@ function setTextcompleteOnEventTarget(event) {
function setTextcompleteOnElement(elem, req) { function setTextcompleteOnElement(elem, req) {
elem = $(elem); elem = $(elem);
elem.textcomplete(req, { elem.textcomplete(req, {
appendTo: (elem.parents('.dashboard').length) ? elem.parent() : $('body'), appendTo: (elem.closest('.dashboard').length) ? elem.parent() : $('body'),
listPosition: setTextcompleteDropdownListPos listPosition: setTextcompleteDropdownListPos
}); });
} }
@ -1666,7 +1666,7 @@ function unsetTextcompleteOnEventTarget(event) {
function setTextcompleteDropdownListPos(position) { function setTextcompleteDropdownListPos(position) {
position = this._applyPlacement(position); position = this._applyPlacement(position);
if (this.option.appendTo.parents('.dashboard').length > 0) { if (this.option.appendTo.closest('.dashboard').length > 0) {
position.position = 'fixed'; position.position = 'fixed';
position.top = (parseFloat(position.top) - window.pageYOffset).toString() + 'px'; position.top = (parseFloat(position.top) - window.pageYOffset).toString() + 'px';
} else } else

4
js/mobile_abstract.js

@ -47,7 +47,7 @@ var MAL = function()
$dmChatList.listview('refresh'); $dmChatList.listview('refresh');
$.mobile.silentScroll( $(".dm-form").offset().top ); $.mobile.silentScroll( $(".dm-form").offset().top );
} else { } else {
var modalContent = dmConvo.parents(".modal-content"); var modalContent = dmConvo.closest(".modal-content");
modalContent.scrollTop(modalContent[0].scrollHeight); modalContent.scrollTop(modalContent[0].scrollHeight);
} }
} }
@ -498,7 +498,7 @@ var MAL = function()
if ($.hasOwnProperty('mobile')) { if ($.hasOwnProperty('mobile')) {
return postLi.siblings().length; return postLi.siblings().length;
} else { } else {
return postLi.parents('.module.post.original.open').find('.post.related').length; return postLi.closest('.module.post.original.open').find('.post.related').length;
} }
}; };
} }

12
js/twister_directmsg.js

@ -270,7 +270,7 @@ function openGroupMessagesNewGroupModal() {
; ;
modal.content.find('.create').on('click', function (event) { modal.content.find('.create').on('click', function (event) {
var elemEvent = $(event.target); var elemEvent = $(event.target);
var elemForm = elemEvent.parents('.module') var elemForm = elemEvent.closest('.module');
var peersToInvite = elemForm.find('.invite').val().toLowerCase().match(/@\w+/g); var peersToInvite = elemForm.find('.invite').val().toLowerCase().match(/@\w+/g);
if (peersToInvite) if (peersToInvite)
@ -307,9 +307,9 @@ function openGroupMessagesJoinGroupModal() {
.attr('data-screen-name', groupChatAliases[i]) .attr('data-screen-name', groupChatAliases[i])
.on('click', function (event) { .on('click', function (event) {
var elemEvent = $(event.target); var elemEvent = $(event.target);
elemEvent.parents('.module').find('.join') elemEvent.closest('.module').find('.join')
.attr('disabled', .attr('disabled',
!elemEvent.parents('.groups-list').find('input:checked').length); !elemEvent.closest('.groups-list').find('input:checked').length);
}) })
; ;
item.find('.twister-user-name') item.find('.twister-user-name')
@ -325,7 +325,7 @@ function openGroupMessagesJoinGroupModal() {
modal.content.find('.join').on('click', function (event) { modal.content.find('.join').on('click', function (event) {
var elemEvent = $(event.target); var elemEvent = $(event.target);
var groups = elemEvent.parents('.module').find('.groups-list input:checked'); var groups = elemEvent.closest('.module').find('.groups-list input:checked');
for (var i = 0; i < groups.length; i++) for (var i = 0; i < groups.length; i++)
groupMsgInviteToGroup(groups[i].getAttribute('data-screen-name'), [defaultScreenName]); groupMsgInviteToGroup(groups[i].getAttribute('data-screen-name'), [defaultScreenName]);
@ -335,7 +335,7 @@ function openGroupMessagesJoinGroupModal() {
modal.content.find('.secret-key-import, .username-import').on('input', importSecretKeypress); modal.content.find('.secret-key-import, .username-import').on('input', importSecretKeypress);
modal.content.find('.import-secret-key').on('click', function (event) { modal.content.find('.import-secret-key').on('click', function (event) {
var elemModule = $(event.target).parents('.module'); var elemModule = $(event.target).closest('.module');
var groupAlias = elemModule.find('.username-import').val().toLowerCase(); var groupAlias = elemModule.find('.username-import').val().toLowerCase();
var secretKey = elemModule.find('.secret-key-import').val(); var secretKey = elemModule.find('.secret-key-import').val();
@ -490,7 +490,7 @@ function initInterfaceDirectMsg() {
peersToInvite); peersToInvite);
elemInput.val(''); elemInput.val('');
elemEvent.parents('.invite-form').toggle(); elemEvent.closest('.invite-form').toggle();
// TODO reload group members list // TODO reload group members list
}); });

Loading…
Cancel
Save