jQuery( document ).ready(function () {
/*
* Click handler for the delete button
* @param event
*/
var coauthors_delete_onclick = function( e ) {
if ( confirm( coAuthorsPlusStrings.confirm_delete ) ) {
return coauthors_delete( this );
}
return false;
};
var $coauthors_loading = jQuery("");
function coauthors_delete( elem ) {
var $coauthor_row = jQuery( elem ).closest( '.coauthor-row' );
$coauthor_row.remove();
// Hide the delete button when there's only one Co-Author
if ( jQuery( '#coauthors-list .coauthor-row .coauthor-tag' ).length <= 1 )
jQuery( '#coauthors-list .coauthor-row .coauthors-author-options' ).addClass( 'hidden' );
return true;
}
var coauthors_edit_onclick = function( event ) {
var $tag = jQuery( this );
var $co = $tag.prev();
$tag.hide();
$co.show()
.focus()
;
$co.previousAuthor = $tag.text();
}
/*
* Save co-author
* @param int Co-Author ID
* @param string Co-Author Name
* @param object The autosuggest input box
*/
function coauthors_save_coauthor( author, co ) {
// get sibling and update
co.siblings( '.coauthor-tag' )
.html( author.name )
.append( coauthors_create_author_gravatar( author ) )
.show()
;
// Update the value of the hidden input
co.siblings( 'input[name="coauthors[]"]' ).val( author.nicename );
}
/*
* Add co-author
* @param string Co-Author Name
* @param object The autosuggest input box
* @param boolean Initial set up or not?
*/
function coauthors_add_coauthor( author, co, init, count ){
// Check if editing
if ( co && co.siblings( '.coauthor-tag' ).length ) {
coauthors_save_coauthor( author, co );
} else {
// Not editing, so we create a new co-author entry
if ( count == 0 ) {
var coName = ( count == 0 ) ? 'coauthors-main' : '';
// Add new co-author to