2017-08-24 13:58:44 -04:00
|
|
|
/**
|
|
|
|
* @summary Handles the addition of the comment form.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2013-11-14 23:42:09 -05:00
|
|
|
var addComment = {
|
2017-08-24 13:58:44 -04:00
|
|
|
/**
|
|
|
|
* @summary Retrieves the elements corresponding to the given IDs.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @param {string} commId The comment ID.
|
|
|
|
* @param {string} parentId The parent ID.
|
|
|
|
* @param {string} respondId The respond ID.
|
|
|
|
* @param {string} postId The post ID.
|
|
|
|
* @returns {boolean} Always returns false.
|
|
|
|
*/
|
2015-11-09 19:43:26 -05:00
|
|
|
moveForm: function( commId, parentId, respondId, postId ) {
|
2015-11-18 14:15:28 -05:00
|
|
|
var div, element, style, cssHidden,
|
2015-11-09 19:43:26 -05:00
|
|
|
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];
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
if ( ! comm || ! respond || ! cancel || ! parent || ! commentForm ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
2015-11-09 19:43:26 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
t.respondId = respondId;
|
|
|
|
postId = postId || false;
|
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
if ( ! t.I( 'wp-temp-form-div' ) ) {
|
|
|
|
div = document.createElement( 'div' );
|
2012-08-22 20:04:18 -04:00
|
|
|
div.id = 'wp-temp-form-div';
|
|
|
|
div.style.display = 'none';
|
2015-11-09 19:43:26 -05:00
|
|
|
respond.parentNode.insertBefore( div, respond );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
comm.parentNode.insertBefore( respond, comm.nextSibling );
|
|
|
|
if ( post && postId ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
post.value = postId;
|
2015-11-09 19:43:26 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
parent.value = parentId;
|
|
|
|
cancel.style.display = '';
|
|
|
|
|
2017-08-24 13:58:44 -04:00
|
|
|
/**
|
|
|
|
* @summary Puts back the comment, hides the cancel button and removes the onclick event.
|
|
|
|
*
|
|
|
|
* @returns {boolean} Always returns false.
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
cancel.onclick = function() {
|
2015-11-09 19:43:26 -05:00
|
|
|
var t = addComment,
|
|
|
|
temp = t.I( 'wp-temp-form-div' ),
|
|
|
|
respond = t.I( t.respondId );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
if ( ! temp || ! respond ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
return;
|
2015-11-09 19:43:26 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
t.I( 'comment_parent' ).value = '0';
|
|
|
|
temp.parentNode.insertBefore( respond, temp );
|
|
|
|
temp.parentNode.removeChild( temp );
|
2012-08-22 20:04:18 -04:00
|
|
|
this.style.display = 'none';
|
|
|
|
this.onclick = null;
|
|
|
|
return false;
|
2013-11-14 23:42:09 -05:00
|
|
|
};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-11-18 14:15:28 -05:00
|
|
|
/*
|
2017-08-24 13:58:44 -04:00
|
|
|
* Sets initial focus to the first form focusable element.
|
|
|
|
* Uses try/catch just to avoid errors in IE 7- which return visibility
|
2015-11-18 14:15:28 -05:00
|
|
|
* 'inherit' when the visibility value is inherited from an ancestor.
|
|
|
|
*/
|
2015-11-09 19:43:26 -05:00
|
|
|
try {
|
|
|
|
for ( var i = 0; i < commentForm.elements.length; i++ ) {
|
|
|
|
element = commentForm.elements[i];
|
2015-11-18 14:15:28 -05:00
|
|
|
cssHidden = false;
|
2015-11-09 19:43:26 -05:00
|
|
|
|
2015-11-18 14:15:28 -05:00
|
|
|
// Modern browsers.
|
2015-11-09 19:43:26 -05:00
|
|
|
if ( 'getComputedStyle' in window ) {
|
2015-11-18 14:15:28 -05:00
|
|
|
style = window.getComputedStyle( element );
|
|
|
|
// IE 8.
|
|
|
|
} else if ( document.documentElement.currentStyle ) {
|
|
|
|
style = element.currentStyle;
|
|
|
|
}
|
2015-11-09 19:43:26 -05:00
|
|
|
|
2015-11-18 14:15:28 -05:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
2015-11-09 19:43:26 -05:00
|
|
|
|
2015-11-18 14:15:28 -05:00
|
|
|
// Skip form elements that are hidden or disabled.
|
|
|
|
if ( 'hidden' === element.type || element.disabled || cssHidden ) {
|
|
|
|
continue;
|
2015-11-09 19:43:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
element.focus();
|
|
|
|
// Stop after the first focusable element.
|
|
|
|
break;
|
|
|
|
}
|
2015-11-18 14:15:28 -05:00
|
|
|
|
2015-11-09 19:43:26 -05:00
|
|
|
} catch( er ) {}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2017-08-24 13:58:44 -04:00
|
|
|
/**
|
|
|
|
* @summary Returns the object corresponding to the given ID.
|
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
*
|
|
|
|
* @param {string} id The ID.
|
|
|
|
* @returns {Element} The element belonging to the ID.
|
|
|
|
*/
|
2015-11-09 19:43:26 -05:00
|
|
|
I: function( id ) {
|
|
|
|
return document.getElementById( id );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2013-11-14 23:42:09 -05:00
|
|
|
};
|