jQuery(document).ready(function(){ AjaxEditComments.init(); }); var AjaxEditComments = function() { var $j = jQuery; var timers = new Array(); var PluginUrl = "http://sorin-tudor.ro/wp-content/plugins/wp-ajax-edit-comments"; var CommentAuthorName = "editAuthor"; var CommentClassName = "editComment"; var EditCommentAuthorName = "editableAuthor"; //not edible author :) var EditCommentClassName = "editableComment"; var TextAuthorClassName = "textAuthor"; var TextCommentClassName = "textComment"; //Scans the spans and divs for a specific class and sets events to make them editable function MakeEdit() { StopEdit(); //Make the Author portions editable $j('.' + CommentAuthorName).bind("mouseover",function() {ShowAsEditable($j(this));}); $j('.' + CommentAuthorName).bind("mouseout",function() {ShowAsUnEditable($j(this));}); $j('.' + CommentAuthorName).bind("click",function() {Edit($j(this)); return false;}); //Make the comment portions editable $j('.' + CommentClassName).bind("mouseover",function() {ShowAsEditable($j(this));}); $j('.' + CommentClassName).bind("mouseout",function() {ShowAsUnEditable($j(this));}); $j('.' + CommentClassName).bind("click",function() {Edit($j(this)); return false;}); //Remove the extra classes $j('.' + CommentClassName).removeClass("post"); $j('.' + CommentClassName).removeClass("admin"); $j('.' + CommentAuthorName).removeClass("post"); $j('.' + CommentAuthorName).removeClass("admin"); GetEditText(); AddAdminLinks(); } //Disable all the edit events function StopEdit() { $j('.' + CommentAuthorName).unbind(); $j('.' + CommentClassName).unbind(); $j("." + 'ajax-admin-edit-links').unbind(); } //Adds in the admin links and sets up the events function AddAdminLinks() { $j("." + 'ajax-admin-edit-links').each(function() { // Adds Edit | Delete | Spam functionality var id = $j(this).attr("id"); var element = $j(this); var option = id.match(/([a-zA-Z]+)/i)[1]; var id = GetId(id); if (option == "edit") { element.bind("click", function() { Edit($j("#" + CommentClassName + id));Edit($j("#" + CommentAuthorName + id)); return false; }); } else if (option == "delete") { element.bind("click", function() { if (confirm("Delete this comment?")) { DeleteSpamComment(option, id);} return false;}) } else if (option == "spam") { element.bind("click", function() { if (confirm("Mark this comment as Spam?")) { DeleteSpamComment(option, id); } return false;}) } }); $j("." + 'ajax-akismet-links').each(function() { //Adds Akismet functionality var id = $j(this).attr("id"); var element = $j(this); var option = id.match(/([a-zA-Z]+)/i)[1]; var id = GetId(id); if (option == "unspam") { element.bind("click", function() { DeleteSpamComment(option, id); return false;}) } }); $j("." + "ajax-admin-edit-paragraph").show(); } //Deletes or Marks a comment as spam //Option = "delete" or "spam"| id is the comment ID function DeleteSpamComment(option, id) { $j.ajax({ type: "post", url: PluginUrl + '/php-includes/AjaxEditComments.php', timeout: 30000, global: false, data: { CommentOption: option, CommentId: id, _wpnonce:"6a25a616786bca2c17f0dab60bdf58f8"}, success: function(msg) { DeleteSpamCommentComplete(msg, id); }, error: function(msg) { DeleteSpamCommentFailure(msg, id); } }) } //Outputs the edit text function GetEditText() { //Output edit text $j("." + "ajax-edit").html('Verifica daca textul este corect.'); GetTimeLeft(); } //Finds the time left for editing comments function GetTimeLeft() { $j("." + "ajax-edit").each(function() { var text = $j(this).attr("id"); var element = $j(this); $j.ajax({ type: "post", url: PluginUrl + '/php-includes/AjaxEditComments.php', timeout: 30000, global: false, data: {LoadTimeId: $j(this).attr("id"), _wpnonce:"65bc30d83fca4984c425b6a5636c30fe"}, success: function(msg) { LoadTimeComplete(msg, text, element); } }) }); } //Allows the comment and author areas to be editable //obj - The object that triggered the event function Edit(obj) { if (obj.is("span")) { //Create a new span element to replace the author span if ($j('body').find('#' + TextAuthorClassName + obj.attr("id")).is("span")) { return; } //Return if the span has already been created var newSpan = '([^<]*)<\/a>/i)[1]; } var authorInputBox = ' '; var authorButtons = ' or '; newSpan = newSpan + authorInputBox + authorButtons + ""; //Hide the old span obj.hide(); obj.before(newSpan); //Setup save and cancel button events var saveButton = $j("#" + obj.attr("id") + "_saveAuthor"); var cancelButton = $j("#" + obj.attr("id") + "_cancelAuthor"); saveButton.click(function() { AuthorSave($j(this), obj, $j("#" + TextAuthorClassName + obj.attr("id"))); }); cancelButton.click(function() { EditCancel($j(this), obj, $j("#" + TextAuthorClassName + obj.attr("id"))); }); //Setup the events for the input boxes $j("#" + obj.attr("id") + '_URL').keypress(function() { EnableSave(saveButton) }); $j("#" + obj.attr("id") + '_author').keypress(function() { EnableSave(saveButton) }); } else if (obj.is("div")) { if ($j('body').find('#' + TextCommentClassName + obj.attr("id")).is("div")) { return; } //Return if the textarea has already been created var newDiv = '