/** * WordPress jQuery-Ajax-Comments v1.29 by Willin Kan. * URI: http://willin.heliohost.org/?p=1271 */ var i = 0, got = -1, len = document.getElementsByTagName('script').length; while ( i <= len && got == -1){ var js_url = document.getElementsByTagName('script')[i].src, got = js_url.indexOf('comments-ajax.js'); i++ ; } var edit_mode = '0', // 再編輯模式 ( '1'=開; '0'=不開 ) ajax_php_url = js_url.replace('-ajax.js','-ajax.php'), wp_url = js_url.substr(0, js_url.indexOf('wp-content')), pic_sb = wp_url + '/wp-admin/images/wpspin_light.gif', // 提交 icon pic_no = wp_url + '/wp-admin/images/no.png', // 錯誤 icon //pic_ys = wp_url + '/wp-admin/images/yes.png', // 成功 icon txt1 = '', txt2 = '', //txt3 = '" style="margin-left:40px; background:url(' + pic_ys + ') no-repeat left; padding-left:20px;">提交成功', edt1 = '" style="margin-left:60px;">(刷新页面之前可以 再编辑)', cancel_edit = '点击这里取消编辑', edit, num = 1, comm_array=[]; comm_array.push(''); jQuery(document).ready(function($) { //$comments = $('#comments'); // 評論數的 ID $cancel = $('#cancel-comment-reply-link'); cancel_text = $cancel.text(); $submit = $('#commentform #submit'); $submit.attr('disabled', false); $('#comment').after( txt1 + txt2 ); $('#loading').hide(); $('#error').hide(); $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body'); /** submit */ $('#commentform').submit(function() { $('#loading').slideDown(); $submit.attr('disabled', true).fadeTo('slow', 0.5); if ( edit ) $('#comment').after(''); /** Ajax */ $.ajax( { url: ajax_php_url, data: $(this).serialize(), type: $(this).attr('method'), error: function(request) { $('#loading').slideUp(); $('#error').slideDown().html(' ' + request.responseText); setTimeout(function() {$submit.attr('disabled', false).fadeTo('slow', 1); $('#error').slideUp();}, 3000); }, success: function(data) { $('#loading').hide(); comm_array.push($('#comment').val()); $('textarea').each(function() {this.value = ''}); var t = addComment, cancel = t.I('cancel-comment-reply-link'), temp = t.I('wp-temp-form-div'), respond = t.I(t.respondId), post = t.I('comment_post_ID').value, parent = t.I('comment_parent').value; // comments //if ( ! edit && $comments.length ) { //n = parseInt($comments.text().match(/\d+/)); //$comments.text($comments.text().replace( n, n + 1 )); //} // show comment new_htm = '" id="new_comm_' + num + '">') : ('\n