]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
JS performance: speeding up initialization by consolidating event handlers for reply...
authorBrion Vibber <brion@pobox.com>
Fri, 11 Mar 2011 23:03:15 +0000 (15:03 -0800)
committerBrion Vibber <brion@pobox.com>
Fri, 11 Mar 2011 23:03:15 +0000 (15:03 -0800)
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!

js/util.js

index a244f1ecfbb1004de6e62d8be991fa846dd0aff6..d0d23d464d606f5c7004aefb0b2c5e22872ec811 100644 (file)
@@ -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;
-            });
         },
 
         /**