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

Props afercia.
Fixes #29974.

Built from https://develop.svn.wordpress.org/trunk@35675


git-svn-id: http://core.svn.wordpress.org/trunk@35639 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-11-18 19:15:28 +00:00
parent 838592c1ba
commit f1d0763785
3 changed files with 28 additions and 24 deletions

View File

@ -1,6 +1,6 @@
var addComment = {
moveForm: function( commId, parentId, respondId, postId ) {
var div, element, node, style, cssHidden,
var div, element, style, cssHidden,
t = this,
comm = t.I( commId ),
respond = t.I( respondId ),
@ -47,40 +47,44 @@ var addComment = {
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 {
for ( var i = 0; i < commentForm.elements.length; i++ ) {
element = commentForm.elements[i];
cssHidden = false;
// Skip form elements that are hidden or disabled.
if ( 'hidden' === element.type || element.hasAttribute( 'disabled' ) ) {
continue;
// Modern browsers.
if ( 'getComputedStyle' in window ) {
style = window.getComputedStyle( element );
// IE 8.
} else if ( document.documentElement.currentStyle ) {
style = element.currentStyle;
}
if ( 'getComputedStyle' in window ) {
node = element;
cssHidden = false;
/*
* 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;
}
while( node.parentNode ) {
style = window.getComputedStyle( node );
if ( style.display === 'none' || style.visibility === 'hidden' ) {
cssHidden = true;
break;
}
node = node.parentNode;
}
if ( cssHidden ) {
continue;
}
// Skip form elements that are hidden or disabled.
if ( 'hidden' === element.type || element.disabled || cssHidden ) {
continue;
}
element.focus();
// Stop after the first focusable element.
break;
}
} catch( er ) {}
return false;

View File

@ -1 +1 @@
var addComment={moveForm:function(a,b,c,d){var e,f,g,h,i,j=this,k=j.I(a),l=j.I(c),m=j.I("cancel-comment-reply-link"),n=j.I("comment_parent"),o=j.I("comment_post_ID"),p=l.getElementsByTagName("form")[0];if(k&&l&&m&&n&&p){j.respondId=c,d=d||!1,j.I("wp-temp-form-div")||(e=document.createElement("div"),e.id="wp-temp-form-div",e.style.display="none",l.parentNode.insertBefore(e,l)),k.parentNode.insertBefore(l,k.nextSibling),o&&d&&(o.value=d),n.value=b,m.style.display="",m.onclick=function(){var a=addComment,b=a.I("wp-temp-form-div"),c=a.I(a.respondId);if(b&&c)return a.I("comment_parent").value="0",b.parentNode.insertBefore(c,b),b.parentNode.removeChild(b),this.style.display="none",this.onclick=null,!1};try{for(var q=0;q<p.elements.length;q++)if(f=p.elements[q],"hidden"!==f.type&&!f.hasAttribute("disabled")){if("getComputedStyle"in window){for(g=f,i=!1;g.parentNode;){if(h=window.getComputedStyle(g),"none"===h.display||"hidden"===h.visibility){i=!0;break}g=g.parentNode}if(i)continue}f.focus();break}}catch(r){}return!1}},I:function(a){return document.getElementById(a)}};
var addComment={moveForm:function(a,b,c,d){var e,f,g,h,i=this,j=i.I(a),k=i.I(c),l=i.I("cancel-comment-reply-link"),m=i.I("comment_parent"),n=i.I("comment_post_ID"),o=k.getElementsByTagName("form")[0];if(j&&k&&l&&m&&o){i.respondId=c,d=d||!1,i.I("wp-temp-form-div")||(e=document.createElement("div"),e.id="wp-temp-form-div",e.style.display="none",k.parentNode.insertBefore(e,k)),j.parentNode.insertBefore(k,j.nextSibling),n&&d&&(n.value=d),m.value=b,l.style.display="",l.onclick=function(){var a=addComment,b=a.I("wp-temp-form-div"),c=a.I(a.respondId);if(b&&c)return a.I("comment_parent").value="0",b.parentNode.insertBefore(c,b),b.parentNode.removeChild(b),this.style.display="none",this.onclick=null,!1};try{for(var p=0;p<o.elements.length;p++)if(f=o.elements[p],h=!1,"getComputedStyle"in window?g=window.getComputedStyle(f):document.documentElement.currentStyle&&(g=f.currentStyle),(f.offsetWidth<=0&&f.offsetHeight<=0||"hidden"===g.visibility)&&(h=!0),"hidden"!==f.type&&!f.disabled&&!h){f.focus();break}}catch(q){}return!1}},I:function(a){return document.getElementById(a)}};

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-beta4-35674';
$wp_version = '4.4-beta4-35675';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.