PageSourceSearch

https://www.iowen.cn/wp-content/themes/ioswallow/js/comments-ajax.js?ver=3.25

js iowen.cn collected 2026-10-02 03:19:35 UTC 10,886 bytes, 314 lines download raw bytes

1function ajaxComt(){
2	var edit_mode = '0', // 再編輯模式 ( '1'=開; '0'=不開 )
3		ajax_php_url = Theme.comment, // ××××××对应位置改为ajax php的路径,若js在主题js文件夹下,那么加 ../ 
4		 
5		comment = 'comment', // ××× textarea 的id 不带#
6		commentlist = 'commentwrap',  // ××× 评论列表ul或ol的class,不带点 
7
8		txt1 = '<div id="loading" class="text-info"><span class="comload"></span></div>',
9		txt2 = '<div id="error">#</div>',
10		txt3 = '"><div class="text-success"> <span class="sub-yes"></span>',
11		txt4 = '<div id="textloading">#</div>',
12		edt1 = ' 刷新页面之前您可以<a rel="nofollow" class="comment-reply-link" href="#edit" onclick=\'return addComment.moveForm("',
13		edt2 = ')\'>再次编辑评论</a></div>',
14		cancel_edit = '取消编辑',
15		edit, num = 1, comm_array=[]; comm_array.push('');
16		$comments = $('#comments-list-title'); // 评论计数的id
17		$cancel = $('#cancel-comment-reply-link'); 
18		cancel_text = $cancel.text();
19		$submit = $('#commentform #submit'); // ×××××××××××××××××××××××××××××× 提交按钮的id或class
20		$submit.attr('disabled', false);
21		$('#'+comment).after( txt1 + txt2 + txt4);  // ×××××××××××××××××××××××××××××××××× 这是评论表单textarea的id或class
22		$('#loading').hide(); 
23		$('#error').hide();
24		$('#textloading').hide();
25		$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
26	
27	/** 评论提交 */
28	$('#commentform').submit(function() { // ×××××××××× form表单的id
29		$('#loading').slideDown();
30		$submit.attr('disabled', true).fadeTo('slow', 0.5);
31		if ( edit ) $('#'+comment).after('<input type="text" name="edit_id" id="edit_id" value="' + edit + '" style="display:none;" />'); //×××××××× 在textarea标签之后插入
32	
33		/** 评论Ajax核心 */
34		$.ajax( {
35			url: ajax_php_url, // 这是ajax.php的路径
36			data: $(this).serialize()+ "&action=ajax_comment_post",//iowen
37			type: $(this).attr('method'),
38			error: function(request) {
39				$('#loading').slideUp();
40				$('#error').slideDown().html('<span class="sub-no"></span>' +request.responseText);
41				setTimeout(function() {$submit.attr('disabled', false).fadeTo('slow', 1); $('#error').slideUp();}, 3000);
42				},
43			success: function (data) {
44				$('#loading').hide();
45				comm_array.push($('#' + comment).val()); // ×××××××××××××××××××× 这个c-textarea为textarea的id
46				$('textarea').each(function () { this.value = '' });
47				var t = addComment,
48					cancel = GI('cancel-comment-reply-link'),
49					temp = GI('wp-temp-form-div'),
50					respond = GI(t.respondId),
51					post = GI('comment_post_ID').value,
52					parent = GI('comment_parent').value;
53				//location.reload(true);
54				//$(".entry-content").html(data);//要刷新的div
55				// 增加评论数
56				if (!edit && $comments.length) {
57					n = parseInt($comments.text().match(/\d+/)); // 正则匹配文本内容中的数字
58					$comments.html($comments.html().replace(n, n + 1));
59				}
60				// 评论显示
61				new_htm = '" id="new_comm_' + num + '"></';
62				new_htm = (parent == '0') ? ('\n<ol class="' + commentlist + '" ' + new_htm + 'ol>') : ('\n<ul class="children' + new_htm + 'ul>');// ×××××××评论列表的class
63				ok_htm = '\n<div class="ajax-notice" id="success_' + num + txt3;
64				if (edit_mode == '1') {
65					div_ = (document.body.innerHTML.indexOf('div-comment-') == -1) ? '' : ((document.body.innerHTML.indexOf('li-comment-') == -1) ? 'div-' : '');
66					ok_htm = ok_htm.concat(edt1, div_, 'comment-', parent, '", "', parent, '", "respond", "', post, '", ', num, edt2);
67				} else {
68					ok_htm += '评论成功';
69				}
70				ok_htm += '</span><span></span>\n';
71
72				new_htm = $(new_htm);
73				$('#respond').before(new_htm);
74	
75				$('#new_comm_' + num).append(data);
76				$('#new_comm_' + num + ' li').append(ok_htm);
77				$body.animate({ scrollTop: $('#new_comm_' + num).offset().top - 200 }, 900);
78				countdown(); num++; edit = ''; $('*').remove('#edit_id');
79				cancel.style.display = 'none';
80				cancel.onclick = null;
81				GI('comment_parent').value = '0';
82
83				if (new_htm.find('pre').length && $('link#enlighterjs').length) {
84					new_htm.find('pre').enlight({
85						linenumbers: !0,
86						indent: 2,
87						textOverflow: 'scroll',
88						theme: 'enlighter', 
89						title: Theme.pre_c,
90					});
91				} else {
92					highlightJs();
93				}
94
95				if (temp && respond) {
96					temp.parentNode.insertBefore(respond, temp);
97					temp.parentNode.removeChild(temp)
98				}
99			}
100		}); // end Ajax
101	  return false;
102	}); // end submit
103	
104	/** 移动回复表单 */
105	addComment = {
106		moveForm : function(commId, parentId, respondId, postId, num) {
107			//reply(commId); // 回复添加@
108			var t = this,
109				div,
110				comm = GI(commId),
111				respond = GI(respondId),
112				cancel = GI('cancel-comment-reply-link'),
113				parent = GI('comment_parent'),
114				post = GI('comment_post_ID');
115			if ( edit ) exit_prev_edit();
116			num ? (
117				GI(comment).value = comm_array[num],// ××××××××××××××××××××这个为textarea的id
118				edit = GI('new_comm_' + num).innerHTML.match(/(comment-)(\d+)/)[2],
119				$new_sucs = $('#success_' + num ), $new_sucs.hide(),
120				$new_comm = $('#new_comm_' + num ), $new_comm.hide(),
121				$cancel.text(cancel_edit)
122			) : $cancel.text(cancel_text);
123	
124			t.respondId = respondId;
125			postId = postId || false;
126	
127			if ( !GI('wp-temp-form-div') ) {
128				div = document.createElement('div');
129				div.id = 'wp-temp-form-div';
130				div.style.display = 'none';
131				respond.parentNode.insertBefore(div, respond);
132			}
133	
134			!comm ? ( 
135				temp = GI('wp-temp-form-div'),
136				GI('comment_parent').value = '0',
137				temp.parentNode.insertBefore(respond, temp),
138				temp.parentNode.removeChild(temp)
139			) : comm.parentNode.insertBefore(respond, comm.nextSibling);
140			$body.animate( { scrollTop: $('#respond').offset().top - 180 }, 400);
141			if ( post && postId ) post.value = postId;
142			parent.value = parentId;
143			cancel.style.display = '';
144			// 取消按钮动作
145			cancel.onclick = function() {
146				if ( edit ) exit_prev_edit();
147				var t = addComment, temp = GI('wp-temp-form-div'), respond = GI(t.respondId);
148	
149				GI('comment_parent').value = '0';
150				if ( temp && respond ) {
151					temp.parentNode.insertBefore(respond, temp);
152					temp.parentNode.removeChild(temp);
153				}
154				this.style.display = 'none';
155				this.onclick = null;
156				$('textarea').val(''); // 清空textarea区
157				return false;
158			};
159	
160			try { GI('comment').focus(); }
161			catch(e) {}
162	
163			return false;
164		}
165	} // end addComment
166	
167	function GI(e) {
168		return document.getElementById(e);
169	}
170	function exit_prev_edit() {
171			$new_comm.show(); $new_sucs.show();
172			$('textarea').each(function() {this.value = ''});
173			edit = '';
174	}
175	
176	/** 重编辑等待时间 防止快速提交 */
177	var wait = 8, submit_val = $submit.val();
178	function countdown() {
179		if ( wait > 0 ) {
180			$submit.val(wait); wait--; setTimeout(countdown, 1000);
181		} else {
182			$submit.val(submit_val).attr('disabled', false).fadeTo('slow', 1);
183			wait = 8;
184	  }
185	}
186}
187
188// end Ajax评论
189(function ($) {
190	$(document).ready(function () {
191		ajaxComt();
192		$("#io_emojis").hover(function () {
193			$("#emojis_link").toggle(150);
194		});
195	});
196	$(document).on('click', '#io-img-url-btn', function () {
197		var src = $('#io-img-url').val();
198		if (!src) {
199			return iPopupTips(0, "请输入图片地址");
200		}
201		val = "[img]" + src + "[/img]\n";
202		insertContent(val);
203		$('#io-img-modal').modal('hide');
204	});
205	$(document).on('click', '#io-add-code-btn', function () {
206		var src = $('#io-code-text').val();
207		if (!src) {
208			return iPopupTips(0, "请输入代码");
209		}
210		val = "[code]\n" + src + "\n[/code]\n";
211		insertContent(val);
212		$('#io-code-modal').modal('hide');
213	});
214	$(document).on('click', '.add-smily', function () {
215		var tag = $(this).data('smilies');
216		grin(tag);
217	});
218	
219	$(document).on('change', "#io-img-up-input", function (e) {
220		var files = this.files || e.dataTransfer.files;
221		var ing_key = 'uploading';
222		
223		if (!files[0] || $(this).data(ing_key)){
224			return false;
225		} 
226		var file = files[0];
227		//文件大小判断
228		var size_max = Theme.up_img_max || 1024;
229		if (file.size > size_max * 1024 ) {
230			return iPopupTips(0,"文件大小超过" + size_max + "KB");
231		}
232
233		$('#io-img-modal').modal('hide');
234		$('#loading').slideDown();
235		//执行上传
236		uploadImg(file, $(this), function (n) {
237			if (n.src) {
238				val = "[img]" + n.src + "[/img]\n";
239				$('#loading').hide();
240				insertContent(val);
241			}
242		});
243	});
244})(jQuery);
245	
246function insertContent(val, fun) {
247    var textarea = $("#comment");
248    var _val = textarea.val();
249    textarea.val(_val + val).focus().click();
250    $.isFunction(fun) && fun(_this, val);
251}
252
253//上传图片
254function uploadImg(file, _input, success_fun) {
255	var formData = new FormData();
256	var ing_key = 'uploading';
257	formData.append('file', file, file.name);
258	formData.append('action', 'edit_file_upload');
259	formData.append('_wpnonce', Theme.upload_nonce);
260	//showAlert({"status":0,"msg":"正在上传请稍候..."});
261	_input.data(ing_key, true);
262	$.ajax({
263		type: 'POST',
264		url: Theme.ajaxurl,
265		data: formData,
266		processData: false,
267		contentType: false,
268		dataType: 'json',
269		error: function (n) {
270			var _msg = "操作失败 " + n.status + ' ' + n.statusText + ',请刷新页面后重试';
271			if (n.responseText && n.responseText.indexOf("致命错误") > -1) {
272				_msg = '网站遇到致命错误,请检查插件冲突或通过错误日志排除错误';
273			}
274			iPopupTips(0,_msg);
275			_input.data(ing_key, false);
276		},
277		success: function (n) {
278			$.isFunction(success_fun) && success_fun(n, _input);
279			_input.data(ing_key, false);
280		}
281	})
282}
283
284function grin(tag) {
285	var myField;
286	tag = ' ' + tag + ' ';
287	if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
288		myField = document.getElementById('comment');
289	} else {
290		return false;
291	}
292	if (document.selection) {
293		myField.focus();
294		sel = document.selection.createRange();
295		sel.text = tag;
296		myField.focus();
297	}
298	else if (myField.selectionStart || myField.selectionStart == '0') {
299		var startPos = myField.selectionStart;
300		var endPos = myField.selectionEnd;
301		var cursorPos = endPos;
302		myField.value = myField.value.substring(0, startPos)
303					  + tag
304					  + myField.value.substring(endPos, myField.value.length);
305		cursorPos += tag.length;
306		myField.focus();
307		myField.selectionStart = cursorPos;
308		myField.selectionEnd = cursorPos;
309	}
310	else {
311		myField.value += tag;
312		myField.focus();
313	}
314}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.