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; }; function coauthors_delete( elem ) { var $coauthor_row = jQuery(elem).closest('.coauthor-row'); $coauthor_row.remove(); 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 coauthor * @param int Author ID * @param string 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.login); } /* * Add coauthor * @param string Author Name * @param object The autosuggest input box * @param boolean Initial set up or not? */ // function coauthors_add_coauthor(authorID, authorName, co, init, count){ 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 author entry if(count == 0) { var coName = (count == 0) ? 'coauthors-main' : ''; // Add new author to '); $co.attr({ 'class': 'coauthor-suggest' , 'name': inputName }) .appendTo($coauthors_div) /* .autocomplete(coauthors_all, { matchContains: true , scroll: false , formatItem: function(row) { return row[2] + ' ' + row[0] + ' | ' + row[1] } , formatResult: function(row) { return row[1]; } }) */ .suggest(coAuthorsPlus_ajax_suggest_link, { onSelect: coauthors_autosuggest_select }) .keydown(coauthors_autosuggest_keydown) ; if(authorName) $co.attr( 'value', unescape( authorName ) ); else $co.attr( 'value', coAuthorsPlusStrings.search_box_text ) .focus( function(){ $co.val( '' ) } ) .blur( function(){ $co.val( coAuthorsPlusStrings.search_box_text ) } ) ; return $co; } // Callback for when a user selects an author function coauthors_autosuggest_select() { $this = jQuery(this); var vals = this.value.split("|"); var author = {} author.id = jQuery.trim(vals[0]); author.login = jQuery.trim(vals[1]); author.name = jQuery.trim(vals[2]); author.email = jQuery.trim(vals[3]); if(author.id=="New") { //alert('Eventually, this will allow you to add a new author right from here. But it\'s not ready yet. *sigh*'); coauthors_new_author_display(name); } else { //coauthors_add_coauthor(login, name, co); coauthors_add_coauthor(author, $this); } } // Prevent the enter key from triggering a submit function coauthors_autosuggest_keydown(e) { if(e.keyCode == 13) {return false;} } /* * Blur handler for autosuggest input box * @param event */ function coauthors_stop_editing(event) { var co = jQuery(this); var tag = jQuery(co.next()); co.attr('value',tag.text()); co.hide(); tag.show(); // editing = false; } /* * Creates the text tag for an author * @param string Name of the author */ function coauthors_create_author_tag(author) { var $tag = jQuery('') .html(unescape(author.name)) .attr('title', coAuthorsPlusStrings.input_box_title) .addClass('coauthor-tag') // Add Click event to edit .click(coauthors_edit_onclick); return $tag; } function coauthors_create_author_gravatar(author, size) { var gravatar_link = get_gravatar_link(author.email, size); var $gravatar = jQuery('') .attr('alt', author.name) .attr('src', gravatar_link) .addClass('coauthor-gravatar') ; return $gravatar; } // MD5 (Message-Digest Algorithm) by WebToolkit -- needed for gravatars // http://www.webtoolkit.info/javascript-md5.html function MD5(s){function L(k,d){return(k<>>(32-d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)}function q(d,F,k){return(d&k)|(F&(~k))}function p(d,F,k){return(d^F^k)}function n(d,F,k){return(F^(d|(~k)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(G){var Z;var F=G.length;var x=F+8;var k=(x-(x%64))/64;var I=(k+1)*16;var aa=Array(I-1);var d=0;var H=0;while(H>>29;return aa}function B(x){var k="",F="",G,d;for(d=0;d<=3;d++){G=(x>>>(d*8))&255;F="0"+G.toString(16);k=k+F.substr(F.length-2,2)}return k}function J(k){k=k.replace(/\r\n/g,"\n");var d="";for(var F=0;F127)&&(x<2048)){d+=String.fromCharCode((x>>6)|192);d+=String.fromCharCode((x&63)|128)}else{d+=String.fromCharCode((x>>12)|224);d+=String.fromCharCode(((x>>6)&63)|128);d+=String.fromCharCode((x&63)|128)}}}return d}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;P') .attr({ 'type': 'hidden', 'id': 'coauthors_hidden_input', 'name': 'coauthors[]', 'value': unescape(author.login) }) ; return input; } /* * Creates display for adding new author * @param string Name of the author */ /* function coauthors_new_author_create_display ( ) { var author_window = jQuery('
') .appendTo(jQuery('body')) .attr('id','new-author-window') .addClass('wrap') .append( jQuery('
') .addClass('icon32') .attr('id','icon-users') ) .append( jQuery('

') .text('Add new author') .attr('id', 'add-new-user') ) .append( jQuery('
') .attr('id', 'createauthor-ajax-response') ) ; var author_form = jQuery('
') .appendTo(author_window) .attr({ id: 'createauthor', name: 'createauthor', method: 'post', action: '' }) ; var create_text_field = function( name, id, label) { var field = jQuery('') .attr({ type:'text', name: name, id: id, }) var label = jQuery('') .attr('for',name) .text(label) //return {field, label}; }; create_field('user_login', 'user_login', 'User Name'); create_field('first_name', 'first_name', 'First Name'); //last_name //email //pass1 //email password checkbox //role } */ // Add the controls to add co-authors var $coauthors_div = jQuery('#coauthors-edit'); if( $coauthors_div.length ) { // Create the co-authors table var table = jQuery('
') .attr('id', 'coauthors-list') ; $coauthors_div.append(table); } var $post_coauthor_logins = jQuery('input[name="coauthors[]"]'); var $post_coauthor_names = jQuery('input[name="coauthorsinput[]"]'); var $post_coauthor_emails = jQuery('input[name="coauthorsemails[]"]'); post_coauthors = []; for(var i = 0; i < $post_coauthor_logins.length; i++) { post_coauthors.push({ login: $post_coauthor_logins[i].value, name: $post_coauthor_names[i].value, email: $post_coauthor_emails[i].value, }); } // Select authors already added to the post var addedAlready = []; //jQuery('#the-list tr').each(function(){ var count = 0; jQuery.each(post_coauthors, function() { coauthors_add_coauthor(this, undefined, true, count ); count++; }); // Create new author-suggest and append it to a new row var newCO = coauthors_create_autosuggest('', false); coauthors_add_to_table(newCO); $coauthors_loading = jQuery('#ajax-loading').clone().attr('id', 'coauthors-loading'); move_loading(newCO); // Remove the read-only coauthors so we don't get craziness jQuery('#coauthors-readonly').remove(); function show_loading() { $coauthors_loading.css('visibility', 'visible'); } function hide_loading() { $coauthors_loading.css('visibility', 'hidden'); } function move_loading($input) { $coauthors_loading.insertAfter($input); } // Show laoding cursor for autocomplete ajax requests jQuery(document).ajaxSend(function(e, xhr, settings) { if( settings.url.indexOf(coAuthorsPlus_ajax_suggest_link) != -1 ) { show_loading(); } }); // Hide laoding cursor when autocomplete ajax requests are finished jQuery(document).ajaxComplete(function(e, xhr, settings) { if( settings.url.indexOf(coAuthorsPlus_ajax_suggest_link) != -1 ) hide_loading(); }); }); if( typeof(console) === 'undefined' ) { var console = {} console.log = console.error = function() {}; } .