var id_AtD_plugin = {}; id_AtD_plugin.add_button = function() { id_add_plugin_button('javascript:id_AtD_plugin.check_writing(0)', 'javascript:id_AtD_plugin.check_writing(1)', 'http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif', 'Proofread Comment w/ After the Deadline', 'AtD', 'Check Spelling'); }; id_AtD_plugin.restore_edit_comment = function(button_selector, field_id) { AtD.remove(field_id); var style = jQuery('#' + field_id).attr('style'); jQuery('#' + field_id).replaceWith(''); jQuery('#' + field_id).attr('style', style); jQuery(button_selector).text('Check Spelling'); }; id_AtD_plugin.check_writing = function(field) { /* Choose your destiny: the main comment box or the reply comment box */ var field_id, button_selector; if (field == 0) { field_id = 'IDCommentNewThreadText'; button_selector = '#idc-plugin-buttons-new-thread > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span'; } else { field_id = 'txtComment'; button_selector = '#idc-plugin-buttons-reply > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span'; } /* restore or spellcheck the field... it all depends on the text of the AtD button associated with the form */ if (jQuery(button_selector).text() == 'Edit Comment') { id_AtD_plugin.restore_edit_comment(button_selector, field_id); } else { jQuery(button_selector).text('Edit Comment'); var style = jQuery('#' + field_id).attr('style'); jQuery('#' + field_id).replaceWith('
' + jQuery('#' + field_id).val() + '
'); jQuery('#' + field_id).attr('style', style); AtD.checkCrossAJAX(field_id, { success : function(errorCount) { if (errorCount == 0) { alert("No writing errors were found"); } id_AtD_plugin.restore_edit_comment(button_selector, field_id); }, error : function(reason) { alert("There was an error communicating with the spell checking service.\n\n" + reason); } }); } }; id_AtD_plugin.fix_form = function(text) { /* this is a hack that exists to remove the AtD markup and turn the preview DIV back into a textarea if the user hits submit while in the middle of spellchecking. */ if (text != undefined) { return text; } else if (jQuery('#idc-plugin-buttons-reply > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span').text() == 'Edit Comment') { id_AtD_plugin.restore_edit_comment('#idc-plugin-buttons-reply > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span', 'txtComment'); setTimeout(function() { jQuery('#IDCommentNewThreadText').css({ color: 'black' }); /* this is on purpose, the main one gets set to grey for reasons unknown to me. */ jQuery('#txtComment').css({ color: 'black' }); }, 501); return jQuery('#txtComment').val(); } else if (jQuery('#idc-plugin-buttons-new-thread > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span').text() == 'Edit Comment') { id_AtD_plugin.restore_edit_comment('#idc-plugin-buttons-new-thread > li > a > img[src="http://static.afterthedeadline.com/atd_jquery/images/atdbuttontr.gif"] + span', 'IDCommentNewThreadText'); setTimeout(function() { jQuery('#IDCommentNewThreadText').css({ color: 'black' }); }, 501); return jQuery('#IDCommentNewThreadText').val(); } else { return ""; } }; id_AtD_plugin.init_plugin = function() { var atd_api = ['atd_jquery/css/atd.css', 'atd_jquery/scripts/jquery.atd.js', 'atd_jquery/scripts/csshttprequest.js', 'atd_id/id.css']; /* load some helpful JS and CSS for AtD/ID */ for (var i = 0; i < atd_api.length; i++) { if (atd_api[i].substr(atd_api[i].length - 4) == '.css') { s = document.createElement('link') s.rel = 'stylesheet'; s.type = 'text/css'; s.media = 'screen'; s.href = 'http://static.afterthedeadline.com/' + atd_api[i]; document.getElementsByTagName('head')[0].appendChild(s); } else if (atd_api[i].substr(atd_api[i].length - 3) == '.js') { s = document.createElement('script') s.src = 'http://static.afterthedeadline.com/' + atd_api[i]; document.getElementsByTagName('head')[0].appendChild(s); } } /* load jQuery if it isn't already loaded */ if (typeof jQuery == 'undefined') { s = document.createElement('script'); s.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'; document.getElementsByTagName('head')[0].appendChild(s); } }; id_add_filter('pre_comment_text', id_AtD_plugin.fix_form, 0); id_add_action('idcomments_func_load', id_AtD_plugin.init_plugin); id_add_action('idcomments_func_load', id_AtD_plugin.add_button);