/* FILE ARCHIVED ON 6:08:43 Sep 8, 2008 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 21:12:01 May 27, 2015. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ //Overwrite thickbox variables tb_pathToImage = "/wp_includes/js/thickbox/loadingAnimation.gif"; tb_closeImage = "/wp_includes/js/thickbox/tb_close.png"; jQuery(document).ready(function(){ AjaxEditComments.init(); }); var AjaxEditComments = function() { var $j = jQuery; var timers = new Array(); //keeps track of timers var timerObjs = new Array(); //keeps track of timer data objects var PluginUrl = "/wp_content/plugins/wp_ajax_edit_comments/index.html"; var CommentAuthorName = "editAuthor"; var CommentClassName = "editComment"; //Initializes the edit links function initialize_links() { //Leave the style in for Safari $j(".edit-comment-admin-links").attr("style", "display: block"); $j(".edit-comment-user-link").attr("style", "display: block"); /* For Crappy IE */ $j(".edit-comment-admin-links").show(); $j(".edit-comment-user-link").show(); get_time_left(); } //Finds an area (if applicable) and displays the time left to comment function get_time_left() { $j("." + 'ajax-edit-time-left').each(function() { data = pre_process($j(this).prev()); data.data = $j.extend({ action: 'gettimeleft', cid: data.cid,pid:data.pid, _ajax_nonce: data.nonce },''); data.action = 'gettimeleft'; data.success = function(r) { var res = wpAjax.parseAjaxResponse(r, data.response,data.element); jQuery.each( res.responses, function() { if (this.what == "error" || this.what == "success") { return; } if (this.what == "minutes") { minutes = parseInt(this.data); } if (this.what == "seconds") { seconds = parseInt(this.data); } }); cid = data.cid; element = $j("#ajax-edit-time-left-" + data.cid); data.timer = $j.extend({minutes: minutes, seconds: seconds, cid: data.cid, element: element},''); timerObjs[data.cid] = data; timers[data.cid] = setTimeout(function() {get_time_left_timer(data.timer) }, 1000); } $j.ajax(data); return; }) } //Updates the UI with the correct time left to edit //Parameters - timer (obj with timer data) function get_time_left_timer(timer) { clearTimeout(timers[timer.cid]); seconds = timer.seconds - 1; minutes = timer.minutes; element = timer.element; //Check to see if the time has run out if (minutes = 1) { if (minutes >= 2) { text = minutes + " minutes"; } else { text = minutes + " minute"; } if (seconds > 0) { text += " and "; } } if (seconds > 0) { if (seconds >= 2) { text += seconds + " seconds"; } else { text += seconds + " second"; } } //Output the timer to the user try { //This try statement is for the iFrame //Iframe code from: http://xkr.us/articles/dom/iframe-document/ if (document.getElementById('TB_iframeContent') != undefined) { var oIframe = document.getElementById('TB_iframeContent'); var oDoc = (oIframe.contentWindow || oIframe.contentDocument); if (oDoc.document) oDoc = oDoc.document; $j("#timer" + timer.cid, oDoc).html(" (" + text + ")"); } } catch(err) { } $j("#ajax-edit-time-left-" + timer.cid).html(" (" + text + ")"); timer.minutes = minutes; timer.seconds = seconds; timerObjs[timer.cid] = timer; timers[timer.cid] = setTimeout(function() { get_time_left_timer(timer) }, 1000); } //Returns a data object for ajax calls function pre_process(element) { var s = {}; s.element = element.attr("id"); s.response = 'ajax-response'; var url = wpAjax.unserialize(element.attr('href')); s.nonce = url._wpnonce; s.cid = url.c; s.pid = url.p; s.action = url.action; s.type = "POST"; s.url = PluginUrl + "/php/AjaxEditComments.html"; s.data = $j.extend({ action: s.action, cid: s.cid,pid:s.pid, _ajax_nonce: s.nonce },''); s.global = false; s.timeout = 30000; return s; } function Moderate(data) { data.success = function(r) { if (r == 1) { //Yay, comment is unapproved - Show visual var li = $j("#" + "comment-" + data.cid); if (li.is("li") || li.is("div") ) { li.addClass("ajax-unapprove"); li.slideUp(1000, function() { li.remove(); }); } return; } //Unapproval wasn't a success, display error alert(r); } if (confirm("Mark for Moderation?")) { $j.ajax(data); } } function Approve(data) { data.success = function(r) { if (r == 1) { //Yay, comment is approved - Show visual var li = $j("#" + "comment-" + data.cid); if (li.is("li") || li.is("div") ) { li.addClass("ajax-approve"); li.slideUp(1000, function() { li.remove(); }); } return; } //Approval wasn't a success, display error alert(r); } if (confirm("Approve Comment?")) { $j.ajax(data); } } function Spam(data) { data.success = function(r) { if (r == 1) { //Yay, comment was marked as spam. Try to show a visual var li = $j("#" + "comment-" + data.cid); if (li.is("li") || li.is("div") ) { li.addClass("ajax-delete"); li.slideUp(1000, function() { li.remove(); }); } return; } //Spamation wasn't a success, display error alert(r); } if (confirm("Mark as Spam?")) { $j.ajax(data); } } function Delete(data) { data.success = function(r) { if (r == 1) { //Yay, comment was deleted. Try to show a visual var li = $j("#" + "comment-" + data.cid); if (li.is("li") || li.is("div") ) { li.addClass("ajax-delete"); li.slideUp(1000, function() { li.remove(); }); } return; } //Deletion wasn't a success, display error alert(r); } if (confirm("Delete this comment?")) { $j.ajax(data); } } return { init : function() { initialize_links(); }, update_comment: function(id, content) { $j("#" + id).html(content); }, update_author: function(id, author, url) { if ( url == '' || 'http://' == url ) { if (author == '') { $j("#" + id).html('Anonymous'); return; } $j("#" + id).html(author); } else if (author == '') { $j("#" + id).html('Anonymous'); } else { $j("#" + id).html("" + author + ""); } }, edit: function(obj) { obj = $j(obj); var data = pre_process(obj); //For the Thickbox obj.addClass("thickbox"); var t = obj.attr("title")|| obj.attr("name") || null; var a = obj.attr("href") || obj.attr("alt"); var g = obj.attr("rel") || false; if (!window.tb_show) { jQuery.tb_show(t,a,g); //NextGen Compatibility } else { tb_show(t,a,g); } obj.blur(); }, approve: function(obj) { var data = pre_process($j(obj)); Approve(data); }, spam: function(obj) { var data = pre_process($j(obj)); Spam(data); }, moderate: function(obj) { var data = pre_process($j(obj)); Moderate(data); }, delete_comment: function(obj) { var data = pre_process($j(obj)); Delete(data); } }; }();