Comments: in comment_form()
when replying to a comment ensure to set focus on the first focusable form element, regardless of what that form element is.
Props azaozz. See #29974. git-svn-id: https://develop.svn.wordpress.org/trunk@35593 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a21b20c3f6
commit
62c7da8710
@ -1,47 +1,92 @@
|
|||||||
var addComment = {
|
var addComment = {
|
||||||
moveForm : function(commId, parentId, respondId, postId) {
|
moveForm: function( commId, parentId, respondId, postId ) {
|
||||||
var t = this, div, comm = t.I(commId), respond = t.I(respondId), cancel = t.I('cancel-comment-reply-link'), parent = t.I('comment_parent'), post = t.I('comment_post_ID');
|
var div, element, node, style, cssHidden,
|
||||||
|
t = this,
|
||||||
|
comm = t.I( commId ),
|
||||||
|
respond = t.I( respondId ),
|
||||||
|
cancel = t.I( 'cancel-comment-reply-link' ),
|
||||||
|
parent = t.I( 'comment_parent' ),
|
||||||
|
post = t.I( 'comment_post_ID' ),
|
||||||
|
commentForm = respond.getElementsByTagName( 'form' )[0];
|
||||||
|
|
||||||
if ( ! comm || ! respond || ! cancel || ! parent )
|
if ( ! comm || ! respond || ! cancel || ! parent || ! commentForm ) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
t.respondId = respondId;
|
t.respondId = respondId;
|
||||||
postId = postId || false;
|
postId = postId || false;
|
||||||
|
|
||||||
if ( ! t.I('wp-temp-form-div') ) {
|
if ( ! t.I( 'wp-temp-form-div' ) ) {
|
||||||
div = document.createElement('div');
|
div = document.createElement( 'div' );
|
||||||
div.id = 'wp-temp-form-div';
|
div.id = 'wp-temp-form-div';
|
||||||
div.style.display = 'none';
|
div.style.display = 'none';
|
||||||
respond.parentNode.insertBefore(div, respond);
|
respond.parentNode.insertBefore( div, respond );
|
||||||
}
|
}
|
||||||
|
|
||||||
comm.parentNode.insertBefore(respond, comm.nextSibling);
|
comm.parentNode.insertBefore( respond, comm.nextSibling );
|
||||||
if ( post && postId )
|
if ( post && postId ) {
|
||||||
post.value = postId;
|
post.value = postId;
|
||||||
|
}
|
||||||
parent.value = parentId;
|
parent.value = parentId;
|
||||||
cancel.style.display = '';
|
cancel.style.display = '';
|
||||||
|
|
||||||
cancel.onclick = function() {
|
cancel.onclick = function() {
|
||||||
var t = addComment, temp = t.I('wp-temp-form-div'), respond = t.I(t.respondId);
|
var t = addComment,
|
||||||
|
temp = t.I( 'wp-temp-form-div' ),
|
||||||
|
respond = t.I( t.respondId );
|
||||||
|
|
||||||
if ( ! temp || ! respond )
|
if ( ! temp || ! respond ) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
t.I('comment_parent').value = '0';
|
t.I( 'comment_parent' ).value = '0';
|
||||||
temp.parentNode.insertBefore(respond, temp);
|
temp.parentNode.insertBefore( respond, temp );
|
||||||
temp.parentNode.removeChild(temp);
|
temp.parentNode.removeChild( temp );
|
||||||
this.style.display = 'none';
|
this.style.display = 'none';
|
||||||
this.onclick = null;
|
this.onclick = null;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
try { t.I('comment').focus(); }
|
// Set initial focus to the first form focusable element.
|
||||||
catch(e) {}
|
try {
|
||||||
|
for ( var i = 0; i < commentForm.elements.length; 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;
|
||||||
|
|
||||||
|
while( node.parentNode ) {
|
||||||
|
style = window.getComputedStyle( node );
|
||||||
|
|
||||||
|
if ( style.display === 'none' || style.visibility === 'hidden' ) {
|
||||||
|
cssHidden = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( cssHidden ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
element.focus();
|
||||||
|
// Stop after the first focusable element.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch( er ) {}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
I : function(e) {
|
I: function( id ) {
|
||||||
return document.getElementById(e);
|
return document.getElementById( id );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user