WordPress.org

Make WordPress Core

Changeset 35675


Ignore:
Timestamp:
11/18/2015 07:14:50 PM (5 years ago)
Author:
wonderboymusic
Message:

Comments: after [35593], extend support to IE8 and improve checking for elements hidden with CSS

Props afercia.
Fixes #29974.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/comment-reply.js

    r35593 r35675  
    11var addComment = {
    22    moveForm: function( commId, parentId, respondId, postId ) {
    3         var div, element, node, style, cssHidden,
     3        var div, element, style, cssHidden,
    44            t           = this,
    55            comm        = t.I( commId ),
     
    4848        };
    4949
    50         // Set initial focus to the first form focusable element.
     50        /*
     51         * Set initial focus to the first form focusable element.
     52         * Try/catch used just to avoid errors in IE 7- which return visibility
     53         * 'inherit' when the visibility value is inherited from an ancestor.
     54         */
    5155        try {
    5256            for ( var i = 0; i < commentForm.elements.length; i++ ) {
    5357                element = commentForm.elements[i];
     58                cssHidden = false;
     59
     60                // Modern browsers.
     61                if ( 'getComputedStyle' in window ) {
     62                    style = window.getComputedStyle( element );
     63                // IE 8.
     64                } else if ( document.documentElement.currentStyle ) {
     65                    style = element.currentStyle;
     66                }
     67
     68                /*
     69                 * For display none, do the same thing jQuery does. For visibility,
     70                 * check the element computed style since browsers are already doing
     71                 * the job for us. In fact, the visibility computed style is the actual
     72                 * computed value and already takes into account the element ancestors.
     73                 */
     74                if ( ( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden' ) {
     75                    cssHidden = true;
     76                }
    5477
    5578                // Skip form elements that are hidden or disabled.
    56                 if ( 'hidden' === element.type || element.hasAttribute( 'disabled' ) ) {
     79                if ( 'hidden' === element.type || element.disabled || cssHidden ) {
    5780                    continue;
    58                 }
    59 
    60                 if ( 'getComputedStyle' in window ) {
    61                     node = element;
    62                     cssHidden = false;
    63 
    64                     while( node.parentNode ) {
    65                         style = window.getComputedStyle( node );
    66 
    67                         if ( style.display === 'none' || style.visibility === 'hidden' ) {
    68                             cssHidden = true;
    69                             break;
    70                         }
    71 
    72                         node = node.parentNode;
    73                     }
    74 
    75                     if ( cssHidden ) {
    76                         continue;
    77                     }
    7881                }
    7982
     
    8285                break;
    8386            }
     87
    8488        } catch( er ) {}
    8589
Note: See TracChangeset for help on using the changeset viewer.