Comments: after [35593], extend support to IE8 and improve checking for elements hidden with CSS
Props afercia. Fixes #29974. git-svn-id: https://develop.svn.wordpress.org/trunk@35675 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0e5625e4fa
commit
2499be55d6
@ -1,6 +1,6 @@
|
|||||||
var addComment = {
|
var addComment = {
|
||||||
moveForm: function( commId, parentId, respondId, postId ) {
|
moveForm: function( commId, parentId, respondId, postId ) {
|
||||||
var div, element, node, style, cssHidden,
|
var div, element, style, cssHidden,
|
||||||
t = this,
|
t = this,
|
||||||
comm = t.I( commId ),
|
comm = t.I( commId ),
|
||||||
respond = t.I( respondId ),
|
respond = t.I( respondId ),
|
||||||
@ -47,40 +47,44 @@ var addComment = {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set initial focus to the first form focusable element.
|
/*
|
||||||
|
* Set initial focus to the first form focusable element.
|
||||||
|
* Try/catch used just to avoid errors in IE 7- which return visibility
|
||||||
|
* 'inherit' when the visibility value is inherited from an ancestor.
|
||||||
|
*/
|
||||||
try {
|
try {
|
||||||
for ( var i = 0; i < commentForm.elements.length; i++ ) {
|
for ( var i = 0; i < commentForm.elements.length; i++ ) {
|
||||||
element = commentForm.elements[i];
|
element = commentForm.elements[i];
|
||||||
|
|
||||||
// Skip form elements that are hidden or disabled.
|
|
||||||
if ( 'hidden' === element.type || element.hasAttribute( 'disabled' ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( 'getComputedStyle' in window ) {
|
|
||||||
node = element;
|
|
||||||
cssHidden = false;
|
cssHidden = false;
|
||||||
|
|
||||||
while( node.parentNode ) {
|
// Modern browsers.
|
||||||
style = window.getComputedStyle( node );
|
if ( 'getComputedStyle' in window ) {
|
||||||
|
style = window.getComputedStyle( element );
|
||||||
|
// IE 8.
|
||||||
|
} else if ( document.documentElement.currentStyle ) {
|
||||||
|
style = element.currentStyle;
|
||||||
|
}
|
||||||
|
|
||||||
if ( style.display === 'none' || style.visibility === 'hidden' ) {
|
/*
|
||||||
|
* For display none, do the same thing jQuery does. For visibility,
|
||||||
|
* check the element computed style since browsers are already doing
|
||||||
|
* the job for us. In fact, the visibility computed style is the actual
|
||||||
|
* computed value and already takes into account the element ancestors.
|
||||||
|
*/
|
||||||
|
if ( ( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden' ) {
|
||||||
cssHidden = true;
|
cssHidden = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node = node.parentNode;
|
// Skip form elements that are hidden or disabled.
|
||||||
}
|
if ( 'hidden' === element.type || element.disabled || cssHidden ) {
|
||||||
|
|
||||||
if ( cssHidden ) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
element.focus();
|
element.focus();
|
||||||
// Stop after the first focusable element.
|
// Stop after the first focusable element.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch( er ) {}
|
} catch( er ) {}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user