File "comment-reply.js"
Full Path: /home/ycoalition/public_html/blog/wp-includes/css/comment-reply.js
File size: 4 KB
MIME-type: text/plain
Charset: utf-8
/**
* Handles the addition of the comment form.
*
* @since 2.7.0
* @output wp-includes/js/comment-reply.js
*
* @namespace addComment
*
* @type {Object}
*/
window.addComment = ( function( window ) {
// Avoid scope lookups on commonly used variables.
var document = window.document;
// Settings.
var config = {
commentReplyClass : 'comment-reply-link',
commentReplyTitleId : 'reply-title',
cancelReplyId : 'cancel-comment-reply-link',
commentFormId : 'commentform',
temporaryFormId : 'wp-temp-form-div',
parentIdFieldId : 'comment_parent',
postIdFieldId : 'comment_post_ID'
};
// Cross browser MutationObserver.
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
// Check browser cuts the mustard.
var cutsTheMustard = 'querySelector' in document && 'addEventListener' in window;
/*
* Check browser supports dataset.
* !! sets the variable to true if the property exists.
*/
var supportsDataset = !! document.documentElement.dataset;
// For holding the cancel element.
var cancelElement;
// For holding the comment form element.
var commentFormElement;
// The respond element.
var respondElement;
// The mutation observer.
var observer;
if ( cutsTheMustard && document.readyState !== 'loading' ) {
ready();
} else if ( cutsTheMustard ) {
window.addEventListener( 'DOMContentLoaded', ready, false );
}
/**
* Sets up object variables after the DOM is ready.
*
* @since 5.1.1
*/
function ready() {
// Initialize the events.
init();
// Set up a MutationObserver to check for comments loaded late.
observeChanges();
}
/**
* Add events to links classed .comment-reply-link.
*
* Searches the context for reply links and adds the JavaScript events
* required to move the comment form. To allow for lazy loading of
* comments this method is exposed as window.commentReply.init().
*
* @since 5.1.0
*
* @memberOf addComment
*
* @param {HTMLElement} context The parent DOM element to search for links.
*/
function init( context ) {
if ( ! cutsTheMustard ) {
return;
}
// Get required elements.
cancelElement = getElementById( config.cancelReplyId );
commentFormElement = getElementById( config.commentFormId );
// No cancel element, no replies.
if ( ! cancelElement ) {
return;
}
cancelElement.addEventListener( 'touchstart', cancelEvent );
cancelElement.addEventListener( 'click', cancelEvent );
// Submit the comment form when the user types [Ctrl] or [Cmd] + [Enter].
var submitFormHandler = function( e ) {
if ( ( e.metaKey || e.ctrlKey ) && e.keyCode === 13 && document.activeElement.tagName.toLowerCase() !== 'a' ) {
commentFormElement.removeEventListener( 'keydown', submitFormHandler );
e.preventDefault();
// The submit button ID is 'submit' so we can't call commentFormElement.submit(). Click it instead.
commentFormElement.submit.click();
return false;
}
};
if ( commentFormElement ) {
commentFormElement.addEventListener( 'keydown', submitFormHandler );
}
var links = replyLinks( context );
var element;
for ( var i = 0, l = links.length; i < l; i++ ) {
element = links[i];
element.addEventListener( 'touchstart', clickEvent );
element.addEventListener( 'click', clickEvent );
}
}
/**
* Return all links classed .comment-reply-link.
*
* @since 5.1.0
*
* @param {HTMLElement} context The parent DOM element to search for links.
*
* @return {HTMLCollection|NodeList|Array}
*/
function replyLinks( context ) {
var selectorClass = config.commentReplyClass;
var allReplyLinks;
// childNodes is a handy check to ensure the context is a HTMLElement.
if ( ! context || ! context.childNodes ) {
context = document;
}
if ( document.getElementsByClassName ) {
// Fastest.
allReplyLinks = context.getElementsByClassName( selectorClass );
}
else {
// Fast.
allReplyLinks = context.querySelectorAll( '.' + selectorClass );
}
return allReplyLinks;
}
/*