From: Brion Vibber Date: Fri, 11 Mar 2011 23:03:15 +0000 (-0800) Subject: JS performance: speeding up initialization by consolidating event handlers for reply... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10e5cb482e8eefdc3dcbe5aa1983df336524c02d;p=quix0rs-gnu-social.git 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! --- diff --git a/js/util.js b/js/util.js index a244f1ecfb..d0d23d464d 100644 --- a/js/util.js +++ b/js/util.js @@ -423,7 +423,6 @@ var SN = { // StatusNet .css({display:'none'}) .fadeIn(2500); SN.U.NoticeWithAttachment($('#'+notice.id)); - SN.U.NoticeReplyTo($('#'+notice.id)); SN.U.switchInputFormTab("placeholder"); } } else { @@ -516,32 +515,20 @@ var SN = { // StatusNet * @access private */ NoticeReply: function() { - if ($('#content .notice_reply').length > 0) { - $('#content .notice').each(function() { SN.U.NoticeReplyTo($(this)); }); - } + $('#content .notice_reply').live('click', function(e) { + e.preventDefault(); + var notice = $(this).closest('li.notice'); + var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); + SN.U.NoticeInlineReplyTrigger(notice, '@' + nickname.text()); + return false; + }); }, /** - * 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 + * Stub -- kept for compat with plugins for now. * @access private */ NoticeReplyTo: function(notice) { - notice.find('.notice_reply').live('click', function(e) { - e.preventDefault(); - var nickname = ($('.author .nickname', notice).length > 0) ? $($('.author .nickname', notice)[0]) : $('.author .nickname.uid'); - SN.U.NoticeInlineReplyTrigger(notice, '@' + nickname.text()); - return false; - }); }, /**