/* * Author: Addo */ jQuery(function() { replyComment(); changInfo(); ajaxComment(); }); function replyComment() { jQuery('a.reply').click(function() { var id = jQuery(this).parents('li.comment').attr('id').split('-')[2]; var authorId = 'author-' + id; var commentId = 'comment-' + id; var commentBoxId = jQuery('#comment').attr('id'); reply(authorId, commentId, commentBoxId); }); jQuery('li.comment').hover(function() { if (jQuery(this).find('#respond').length == 0) { jQuery(this).find('a.reply').slideDown('normal'); } }, function() { jQuery(this).find('a.reply').slideUp('fast'); }); } function changInfo() { jQuery('a#change_info').click(function() { if (jQuery(this).text() == 'change') { jQuery(this).text('close'); jQuery('#author_info').slideDown('fast'); } else { jQuery(this).text('change'); jQuery('#author_info').slideUp('fast'); } }); } function reply(authorId, commentId, commentBoxId) { var author = jQuery('#' + authorId).text(); var linkStr = '@' + author.replace(/\t|\r|\n/g, '') + ': '; appendStr(linkStr, commentBoxId); } function appendStr(linkStr, commentBoxId) { var $commentBox = jQuery('#' + commentBoxId); if ($commentBox.val().indexOf(linkStr) > -1) { alert('You have already replyed this person!'); return; } if ($commentBox.val().replace(/\t|\s|\r|\n/g, '').length == 0) { $commentBox.val(linkStr + '\n'); } else { $commentBox.val($commentBox.val().replace(/[\n]*$/g, '') + '\n\n' + linkStr + '\n'); } $commentBox[0].focus(); } function ajaxComment() { jQuery('#commentform').submit(function() { postData(); return false; }); } function postData() { var url = jQuery('#commentform').attr('action'); var data = jQuery('#commentform').serialize(); // ajax before var before = function() { jQuery('#submit').attr('disabled', 'true'); jQuery('#ajaxerror').slideUp('normal'); jQuery('#commentform') .append('
') .append(''); jQuery('#overlay').css( { display : 'none', position : 'absolute', top : 0, left : 0, width : '100%', height : '100%', opacity : 0.6, zIndex : 1000 }).fadeIn('normal'); }; // ajax success var success = function(data, textStatus) { if (!/') + 3, message .indexOf('
'))); jQuery('#ajaxerror').slideDown('normal'); jQuery('#submit').removeAttr('disabled'); }; // ajax complete var complete = function(request, status) { jQuery('#overlay').fadeOut(500, function() { jQuery(this).remove(); }); }; // process ajax jQuery.ajax( { url : url, type : 'POST', data : data, beforeSend : before, success : success, error : error, complete : complete }); }