forked from GNUsocial/gnu-social
JS performance: speeding up initialization by consolidating event handlers for reply buttons
Saved about 60ms on my test system during page setup by using a single global 'live' click handler for reply links. No longer need to seek out and attach event handlers on every notice, yay!
This commit is contained in:
parent
4e2a0e2fd0
commit
10e5cb482e
31
js/util.js
31
js/util.js
@ -423,7 +423,6 @@ var SN = { // StatusNet
|
|||||||
.css({display:'none'})
|
.css({display:'none'})
|
||||||
.fadeIn(2500);
|
.fadeIn(2500);
|
||||||
SN.U.NoticeWithAttachment($('#'+notice.id));
|
SN.U.NoticeWithAttachment($('#'+notice.id));
|
||||||
SN.U.NoticeReplyTo($('#'+notice.id));
|
|
||||||
SN.U.switchInputFormTab("placeholder");
|
SN.U.switchInputFormTab("placeholder");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -516,34 +515,22 @@ var SN = { // StatusNet
|
|||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
NoticeReply: function() {
|
NoticeReply: function() {
|
||||||
if ($('#content .notice_reply').length > 0) {
|
$('#content .notice_reply').live('click', function(e) {
|
||||||
$('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup function -- DOES NOT trigger actions immediately.
|
|
||||||
*
|
|
||||||
* Sets up event handlers on the given notice's reply button to
|
|
||||||
* tweak the new-notice form with needed variables and focus it
|
|
||||||
* when pushed.
|
|
||||||
*
|
|
||||||
* (This replaces the default reply button behavior to submit
|
|
||||||
* directly to a form which comes back with a specialized page
|
|
||||||
* with the form data prefilled.)
|
|
||||||
*
|
|
||||||
* @param {jQuery} notice: jQuery object containing one or more notices
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
NoticeReplyTo: function(notice) {
|
|
||||||
notice.find('.notice_reply').live('click', function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
var notice = $(this).closest('li.notice');
|
||||||
var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
|
var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid');
|
||||||
SN.U.NoticeInlineReplyTrigger(notice, '@' + nickname.text());
|
SN.U.NoticeInlineReplyTrigger(notice, '@' + nickname.text());
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub -- kept for compat with plugins for now.
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
NoticeReplyTo: function(notice) {
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open up a notice's inline reply box.
|
* Open up a notice's inline reply box.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user