Making WordPress.org

Changeset 7762


Ignore:
Timestamp:
10/23/2018 05:04:37 PM (6 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Improve JS by only searching for comments once.

Props keesiemeijer.
Fixes #3882.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/user-notes-feedback.js

    r7754 r7762  
    77    var wpAdminBar     = 0;
    88    var options        = wporg_note_feedback;
     9    var comments       = $( '.comment' );
    910    var feedbackToggle = $( '<a role="button" class="feedback-toggle" href="#">' + options.show + '</a>' );
    1011    var commentID      = window.location.hash;
     
    2829
    2930    // Loop through feedback notes
    30     $( '.comment' ).each( function() {
     31    comments.each( function() {
    3132        var feedbackLinks = $( this ).find( '.feedback-links' );
    3233        var childComments = $( this ).find( 'ul.children' );
     
    8687        // Set wpAdminBar
    8788        wpAdminBar = $('#wpadminbar').length ? 32 : 0;
    88         var childComments = $( '.comment' ).find( 'ul.children' );
     89        var childComments = comments.find( 'ul.children' );
    8990
    9091        if ( ! ( commentID.length && childComments.length ) ) {
     
    9293        }
    9394
    94         var comment = childComments.find( commentID + '.depth-2' ).first();
    95         if ( ! comment.length ) {
     95        var childComment = childComments.find( commentID + '.depth-2' ).first();
     96        if ( ! childComment.length ) {
    9697            return;
    9798        }
    9899        // Child comment exists.
    99100
    100         var parent = comment.closest( '.comment.depth-1' );
     101        var parent = childComment.closest( '.comment.depth-1' );
    101102        if ( parent.find( '.feedback' ).hasClass( 'hide-if-js' ) ) {
    102103            // Show child comments.
     
    105106
    106107        // Scroll to child comment and adjust for admin bar
    107         var pos = comment.offset();
     108        var pos = childComment.offset();
    108109        $( 'html,body' ).animate( {
    109110            scrollTop: pos.top - wpAdminBar
     
    113114
    114115    // Click event for Show/Hide feedback toggle link.
    115     $( document ).on( 'click', '.feedback-toggle', function( e ) {
     116    comments.on( 'click', '.feedback-toggle', function( e ) {
    116117        e.preventDefault();
    117118
     
    161162
    162163    // Show editor when the add feedback link is clicked.
    163     $( document ).on( 'click', '.feedback-add', function( e ) {
     164    comments.on( 'click', '.feedback-add', function( e ) {
    164165        e.preventDefault();
    165166
Note: See TracChangeset for help on using the changeset viewer.