PageSourceSearch

https://elasticsearch.cn/static/js/aws.js?v=20151125

js elasticsearch.cn collected 2026-10-03 19:17:35 UTC 70,874 bytes, 2,838 lines download raw bytes

1var AWS =
2{
3	//全局loading
4	loading: function (type)
5	{
6		if (!$('#aw-loading').length)
7		{
8			$('#aw-ajax-box').append(AW_TEMPLATE.loadingBox);
9		}
10
11		if (type == 'show')
12		{
13			if ($('#aw-loading').css('display') == 'block')
14			{
15				return false;
16			}
17
18			$('#aw-loading').fadeIn();
19
20			AWS.G.loading_timer = setInterval(function ()
21			{
22				AWS.G.loading_bg_count -= 1;
23
24				$('#aw-loading-box').css('background-position', '0px ' + AWS.G.loading_bg_count * 40 + 'px');
25
26				if (AWS.G.loading_bg_count == 1)
27				{
28					AWS.G.loading_bg_count = 12;
29				}
30			}, 100);
31		}
32		else
33		{
34			$('#aw-loading').fadeOut();
35
36			clearInterval(AWS.G.loading_timer);
37		}
38	},
39
40	loading_mini: function (selector, type)
41	{
42		if (!selector.find('#aw-loading-mini-box').length)
43		{
44			selector.append(AW_TEMPLATE.loadingMiniBox);
45		}
46
47		if (type == 'show')
48		{
49			selector.find('#aw-loading-mini-box').fadeIn();
50
51			AWS.G.loading_timer = setInterval(function ()
52			{
53				AWS.G.loading_mini_bg_count -= 1;
54
55				$('#aw-loading-mini-box').css('background-position', '0px ' + AWS.G.loading_mini_bg_count * 16 + 'px');
56
57				if (AWS.G.loading_mini_bg_count == 1)
58				{
59					AWS.G.loading_mini_bg_count = 9;
60				}
61			}, 100);
62		}
63		else
64		{
65			selector.find('#aw-loading-mini-box').fadeOut();
66
67			clearInterval(AWS.G.loading_timer);
68		}
69	},
70
71	ajax_request: function(url, params)
72	{
73		AWS.loading('show');
74
75		if (params)
76		{
77			$.post(url, params + '&_post_type=ajax', function (result)
78			{
79				_callback(result);
80			}, 'json').error(function (error)
81			{
82				_error(error);
83			});
84		}
85		else
86		{
87			$.get(url, function (result)
88			{
89				_callback(result);
90			}, 'json').error(function (error)
91			{
92				_error(error);
93			});
94		}
95
96		function _callback (result)
97		{
98			AWS.loading('hide');
99
100			if (!result)
101			{
102				return false;
103			}
104
105			if (result.err)
106			{
107				AWS.alert(result.err);
108			}
109			else if (result.rsm && result.rsm.url)
110			{
111				window.location = decodeURIComponent(result.rsm.url);
112			}
113			else if (result.errno == 1)
114			{
115				window.location.reload();
116			}
117		}
118
119		function _error (error)
120		{
121			AWS.loading('hide');
122
123			if ($.trim(error.responseText) != '')
124			{
125				alert(_t('发生错误, 返回的信息:') + ' ' + error.responseText);
126			}
127		}
128
129		return false;
130	},
131
132	ajax_post: function(formEl, processer, type) // 表单对象,用 jQuery 获取,回调函数名
133	{
134		// 若有编辑器的话就更新编辑器内容再提交
135		if (typeof CKEDITOR != 'undefined')
136		{
137			for ( instance in CKEDITOR.instances ) {
138				CKEDITOR.instances[instance].updateElement();
139			}
140		}
141
142		if (typeof (processer) != 'function')
143		{
144			var processer = AWS.ajax_processer;
145
146			AWS.loading('show');
147		}
148
149		if (!type)
150		{
151			var type = 'default';
152		}
153		else if (type == 'reply_question')
154		{
155			AWS.loading('show');
156
157			$('.btn-reply').addClass('disabled');
158
159			// 删除草稿绑定事件
160			if (EDITOR != undefined)
161			{
162				EDITOR.removeListener('blur', EDITOR_CALLBACK);
163			}
164		}
165
166		var custom_data = {
167			_post_type: 'ajax'
168		};
169
170		formEl.ajaxSubmit(
171		{
172			dataType: 'json',
173			data: custom_data,
174			success: function (result)
175			{
176				processer(type, result);
177			},
178			error: function (error)
179			{
180				console.log(error);
181				if ($.trim(error.responseText) != '')
182				{
183					AWS.loading('hide');
184
185					alert(_t('发生错误, 返回的信息:') + ' ' + error.responseText);
186				}
187				else if (error.status == 0)
188				{
189					AWS.loading('hide');
190
191					alert(_t('网络链接异常'));
192				}
193				else if (error.status == 500)
194				{
195					AWS.loading('hide');
196
197					alert(_t('内部服务器错误'));
198				}
199			}
200		});
201	},
202
203	// ajax提交callback
204	ajax_processer: function (type, result)
205	{
206		AWS.loading('hide');
207
208		if (typeof (result.errno) == 'undefined')
209		{
210			AWS.alert(result);
211		}
212		else if (result.errno != 1)
213		{
214			switch (type)
215			{
216				case 'default':
217				case 'comments_form':
218				case 'reply':
219				case 'reply_question':
220					AWS.alert(result.err);
221
222					$('.aw-comment-box-btn .btn-success, .btn-reply').removeClass('disabled');
223				break;
224
225				case 'ajax_post_alert':
226				case 'ajax_post_modal':
227				case 'error_message':
228					if (!$('.error_message').length)
229					{
230						alert(result.err);
231					}
232					else if ($('.error_message em').length)
233					{
234						$('.error_message em').html(result.err);
235					}
236					else
237					{
238						 $('.error_message').html(result.err);
239					}
240
241					if ($('.error_message').css('display') != 'none')
242					{
243						AWS.shake($('.error_message'));
244					}
245					else
246					{
247						$('.error_message').fadeIn();
248					}
249
250					if ($('#captcha').length)
251					{
252						$('#captcha').click();
253					}
254				break;
255			}
256		}
257		else
258		{
259			if (type == 'comments_form')
260			{
261				AWS.reload_comments_list(result.rsm.item_id, result.rsm.item_id, result.rsm.type_name);
262				$('#aw-comment-box-' + result.rsm.type_name + '-' + result.rsm.item_id + ' form textarea').val('');
263				$('.aw-comment-box-btn .btn-success').removeClass('disabled');
264			}
265
266			if (result.rsm && result.rsm.url)
267			{
268				// 判断返回url跟当前url是否相同
269				if (window.location.href == result.rsm.url)
270				{
271					window.location.reload();
272				}
273				else
274				{
275					window.location = decodeURIComponent(result.rsm.url);
276				}
277			}
278			else
279			{
280				switch (type)
281				{
282					case 'default':
283					case 'ajax_post_alert':
284					case 'error_message':
285						window.location.reload();
286					break;
287
288					case 'ajax_post_modal':
289						$('#aw-ajax-box div.modal').modal('hide');
290					break;
291
292					// 问题回复
293					case 'reply_question':
294						AWS.loading('hide');
295
296						if (result.rsm.ajax_html)
297						{
298							$('.aw-feed-list').append(result.rsm.ajax_html);
299
300							$('.aw-comment-box-btn .btn-success, .btn-reply').removeClass('disabled');
301
302							$.scrollTo($('#' + $(result.rsm.ajax_html).attr('id')), 600, {queue:true});
303
304							// 问题
305							$('.question_answer_form').detach();
306
307							if ($('.aw-replay-box.question').length)
308							{
309								if (USER_ANSWERED)
310								{
311									$('.aw-replay-box').append('<p align="center">一个问题只能回复一次, 你可以在发言后 ' + ANSWER_EDIT_TIME + ' 分钟内编辑回复过的内容</p>');
312								}
313							}
314						}
315						else if(result.rsm.url)
316						{
317							window.location = decodeURIComponent(result.rsm.url);
318						}
319						else
320						{
321							window.location.reload();
322						}
323					break;
324					// 文章回复
325					case 'reply':
326						AWS.loading('hide');
327
328						if (result.rsm.ajax_html)
329						{
330							$('.aw-feed-list').append(result.rsm.ajax_html);
331
332							$('.aw-comment-box-btn .btn-success, .btn-reply').removeClass('disabled');
333
334							$.scrollTo($('#' + $(result.rsm.ajax_html).attr('id')), 600, {queue:true});
335
336							// 文章
337							$('#comment_editor').val('');
338						}
339						else if(result.rsm.url)
340						{
341							window.location = decodeURIComponent(result.rsm.url);
342						}
343						else
344						{
345							window.location.reload();
346						}
347					break;
348				}
349			}
350		}
351	},
352
353	// 加载更多
354	load_list_view: function(url, selector, container, start_page, callback)
355	{
356		if (!selector.attr('id'))
357		{
358			return false;
359		}
360
361		if (!start_page)
362		{
363			start_page = 0
364		}
365
366		// 把页数绑定在元素上面
367		if (selector.attr('data-page') == undefined)
368		{
369			selector.attr('data-page', start_page);
370		}
371		else
372		{
373			selector.attr('data-page', parseInt(selector.attr('data-page')) + 1);
374		}
375
376		selector.bind('click', function ()
377		{
378			var _this = this;
379
380			$(this).addClass('loading');
381
382			$.get(url + '__page-' + $(_this).attr('data-page'), function (result)
383			{
384				$(_this).removeClass('loading');
385
386				if ($.trim(result) != '')
387				{
388					if ($(_this).attr('data-page') == start_page && $(_this).attr('auto-load') != 'false')
389					{
390						container.html(result);
391					}
392					else
393					{
394						container.append(result);
395					}
396
397					// 页数增加1
398					$(_this).attr('data-page', parseInt($(_this).attr('data-page')) + 1);
399				}
400				else
401				{
402					//没有内容
403					if ($(_this).attr('data-page') == start_page && $(_this).attr('auto-load') != 'false')
404					{
405						container.html('<p style="padding: 15px 0" align="center">' + _t('没有内容') + '</p>');
406					}
407
408					$(_this).addClass('disabled').unbind('click').bind('click', function () { return false; });
409
410					$(_this).find('span').html(_t('没有更多了'));
411				}
412
413				if (callback != null)
414				{
415					callback();
416				}
417			});
418
419			return false;
420		});
421
422		// 自动加载
423		if (selector.attr('auto-load') != 'false')
424		{
425			selector.click();
426		}
427	},
428
429	// 重新加载评论列表
430	reload_comments_list: function(item_id, element_id, type_name)
431	{
432		$('#aw-comment-box-' + type_name + '-' + element_id + ' .aw-comment-list').html('<p align="center" class="aw-padding10"><i class="aw-loading"></i></p>');
433
434		$.get(G_BASE_URL + '/question/ajax/get_' + type_name + '_comments/' + type_name + '_id-' + item_id, function (data)
435		{
436			$('#aw-comment-box-' + type_name + '-' + element_id + ' .aw-comment-list').html(data);
437		});
438	},
439
440	// 警告弹窗
441	alert: function (text)
442	{
443		if ($('.alert-box').length)
444		{
445			$('.alert-box').remove();
446		}
447
448		$('#aw-ajax-box').append(Hogan.compile(AW_TEMPLATE.alertBox).render(
449		{
450			message: text
451		}));
452
453		$(".alert-box").modal('show');
454	},
455
456	/**
457	 *	公共弹窗
458	 *	publish     : 发起
459	 *	redirect    : 问题重定向
460	 *	imageBox    : 插入图片
461	 *	videoBox    : 插入视频
462	 *  linkbox     : 插入链接
463	 *	commentEdit : 评论编辑
464	 *  favorite    : 评论添加收藏
465	 *	inbox       : 私信
466	 *  report      : 举报问题
467	 */
468	dialog: function (type, data, callback)
469	{
470		switch (type)
471		{
472			case 'alertImg':
473				var template = Hogan.compile(AW_TEMPLATE.alertImg).render(
474				{
475					'hide': data.hide,
476					'url': data.url,
477					'message': data.message
478				});
479			break;
480
481			case 'publish':
482				var template = Hogan.compile(AW_TEMPLATE.publishBox).render(
483				{
484					'category_id': data.category_id,
485					'ask_user_id': data.ask_user_id
486				});
487			break;
488
489			case 'redirect':
490				var template = Hogan.compile(AW_TEMPLATE.questionRedirect).render(
491				{
492					'data_id': data
493				});
494			break;
495
496			case 'commentEdit':
497				var template = Hogan.compile(AW_TEMPLATE.editCommentBox).render(
498				{
499					'answer_id': data.answer_id,
500					'attach_access_key': data.attach_access_key
501				});
502			break;
503
504			case 'favorite':
505				var template = Hogan.compile(AW_TEMPLATE.favoriteBox).render(
506				{
507					 'item_id': data.item_id,
508					 'item_type': data.item_type
509				});
510			break;
511
512			case 'inbox':
513				var template = Hogan.compile(AW_TEMPLATE.inbox).render(
514				{
515					'recipient': data
516				});
517			break;
518
519			case 'report':
520				var template = Hogan.compile(AW_TEMPLATE.reportBox).render(
521				{
522					'item_type': data.item_type,
523					'item_id': data.item_id
524				});
525			break;
526
527			case 'topicEditHistory':
528				var template = AW_TEMPLATE.ajaxData.replace('{{title}}', _t('编辑记录')).replace('{{data}}', data);
529			break;
530
531			case 'ajaxData':
532				var template = AW_TEMPLATE.ajaxData.replace('{{title}}', data.title).replace('{{data}}', '<div id="aw_dialog_ajax_data"></div>');
533			break;
534
535			case 'imagePreview':
536				var template = AW_TEMPLATE.ajaxData.replace('{{title}}', data.title).replace('{{data}}', '<p align="center"><img src="' + data.image + '" alt="" style="max-width:520px" /></p>');
537			break;
538
539			case 'confirm':
540				var template = Hogan.compile(AW_TEMPLATE.confirmBox).render(
541				{
542					'message': data.message
543				});
544			break;
545
546			case 'recommend':
547				var template = Hogan.compile(AW_TEMPLATE.recommend).render();
548			break;
549
550			// modify by wecenter 活动模块
551			case 'projectEventForm':
552				var template = Hogan.compile(AW_TEMPLATE.projectEventForm).render(
553				{
554					'project_id': data.project_id,
555					'contact_name': data.contact_name,
556					'contact_tel': data.contact_tel,
557					'contact_email': data.contact_email
558				});
559			break;
560
561			case 'projectStockForm':
562				var template = Hogan.compile(AW_TEMPLATE.projectStockForm).render(
563				{
564					'project_id': data.project_id,
565					'contact_name': data.contact_name,
566					'contact_tel': data.contact_tel,
567					'contact_email': data.contact_email
568				});
569			break;
570
571			case 'activityBox':
572				var template = Hogan.compile(AW_TEMPLATE.activityBox).render(
573				{
574					'contact_name': data.contact_name,
575					'contact_tel': data.contact_tel,
576					'contact_qq': data.contact_qq
577				});
578
579			break;
580		}
581
582		if (template)
583		{
584			if ($('.alert-box').length)
585			{
586				$('.alert-box').remove();
587			}
588
589			$('#aw-ajax-box').html(template).show();
590
591			switch (type)
592			{
593				case 'redirect' :
594					AWS.Dropdown.bind_dropdown_list($('.aw-question-redirect-box #question-input'), 'redirect');
595				break;
596
597				case 'inbox' :
598					AWS.Dropdown.bind_dropdown_list($('.aw-inbox #invite-input'), 'inbox');
599					//私信用户下拉点击事件
600					$(document).on('click','.aw-inbox .aw-dropdown-list li a',function() {
601						$('.alert-box #quick_publish input.form-control').val($(this).text());
602						$(this).parents('.aw-dropdown').hide();
603					});
604				break;
605
606				case 'publish':
607					AWS.Dropdown.bind_dropdown_list($('.aw-publish-box #quick_publish_question_content'), 'publish');
608					AWS.Dropdown.bind_dropdown_list($('.aw-publish-box #aw_edit_topic_title'), 'topic');
609					if (parseInt(data.category_enable) == 1)
610					{
611						$.get(G_BASE_URL + '/publish/ajax/fetch_question_category/', function (result)
612						{
613							AWS.Dropdown.set_dropdown_list('.aw-publish-box .dropdown', eval(result), data.category_id);
614
615							$('.aw-publish-title .dropdown li a').click(function ()
616							{
617								$('.aw-publish-box #quick_publish_category_id').val($(this).attr('data-value'));
618								$('.aw-publish-box #aw-topic-tags-select').html($(this).text());
619							});
620						});
621					}
622					else
623					{
624						$('.aw-publish-box .aw-publish-title').hide();
625					}
626
627					if (data.ask_user_id != '' && data.ask_user_id != undefined)
628					{
629						$('.aw-publish-box .modal-title').html('向 ' + data.ask_user_name + ' 提问');
630					}
631
632					if ($('#aw-search-query').val() && $('#aw-search-query').val() != $('#aw-search-query').attr('placeholder'))
633					{
634						$('#quick_publish_question_content').val($('#aw-search-query').val());
635					}
636
637					AWS.Init.init_topic_edit_box('#quick_publish .aw-edit-topic');
638
639					$('#quick_publish .aw-edit-topic').click();
640
641					$('#quick_publish .close-edit').hide();
642
643					if (data.topic_title)
644					{
645						$('#quick_publish .aw-edit-topic').parents('.aw-topic-bar').prepend('<span class="topic-tag"><a class="text">' + data.topic_title + '</a><a class="close" onclick="$(this).parents(\'.topic-tag\').detach();"><i class="icon icon-delete"></i></a><input type="hidden" value="' + data.topic_title + '" name="topics[]" /></span>')
646					}
647
648					if (typeof(G_QUICK_PUBLISH_HUMAN_VALID) != 'undefined')
649					{
650						$('#quick_publish_captcha').show();
651						$('#captcha').click();
652					}
653				break;
654
655				case 'favorite':
656					$.get(G_BASE_URL + '/favorite/ajax/get_favorite_tags/', function (result)
657					{
658						var html = ''
659
660						$.each(result, function (i, e)
661						{
662							html += '<li><a data-value="' + e['title'] + '"><span class="title">' + e['title'] + '</span></a><i class="icon icon-followed"></i></li>';
663						});
664
665						$('.aw-favorite-tag-list ul').append(html);
666
667						$.post(G_BASE_URL + '/favorite/ajax/get_item_tags/', {
668							'item_id' : $('#favorite_form input[name="item_id"]').val(),
669							'item_type' : $('#favorite_form input[name="item_type"]').val()
670						}, function (result)
671						{
672							if (result != null)
673							{
674								$.each(result, function (i, e)
675								{
676									var index = i;
677
678									$.each($('.aw-favorite-tag-list ul li .title'), function (i, e)
679									{
680										if ($(this).text() == result[index])
681										{
682											$(this).parents('li').addClass('active');
683										}
684									});
685								});
686							}
687						}, 'json');
688
689						$(document).on('click', '.aw-favorite-tag-list ul li a', function()
690						{
691							var _this = this,
692								addClassFlag = true, url = G_BASE_URL + '/favorite/ajax/update_favorite_tag/';
693
694							if ($(this).parents('li').hasClass('active'))
695							{
696								url = G_BASE_URL + '/favorite/ajax/remove_favorite_tag/';
697
698								addClassFlag = false;
699							}
700
701							$.post(url,
702							{
703								'item_id' : $('#favorite_form input[name="item_id"]').val(),
704								'item_type' : $('#favorite_form input[name="item_type"]').val(),
705								'tags' : $(_this).attr('data-value')
706							}, function (result)
707							{
708								if (result.errno == 1)
709								{
710									if (addClassFlag)
711									{
712										$(_this).parents('li').addClass('active');
713									}
714									else
715									{
716										$(_this).parents('li').removeClass('active');
717									}
718								}
719							}, 'json');
720						});
721
722					}, 'json');
723				break;
724
725				case 'report':
726					$('.aw-report-box select option').click(function ()
727					{
728						$('.aw-report-box textarea').text($(this).attr('value'));
729					});
730				break;
731
732				case 'commentEdit':
733					$.get(G_BASE_URL + '/question/ajax/fetch_answer_data/' + data.answer_id, function (result)
734					{
735						$('#editor_reply').html(result.answer_content.replace('&amp;', '&'));
736
737						var editor = CKEDITOR.replace( 'editor_reply' );
738
739						if (UPLOAD_ENABLE == 'Y')
740						{
741							var fileupload = new FileUpload('file', '.aw-edit-comment-box .aw-upload-box .btn', '.aw-edit-comment-box .aw-upload-box .upload-container', G_BASE_URL + '/publish/ajax/attach_upload/id-answer__attach_access_key-' + ATTACH_ACCESS_KEY, {'insertTextarea': '.aw-edit-comment-box #editor_reply', 'editor' : editor});
742
743							$.post(G_BASE_URL + '/publish/ajax/answer_attach_edit_list/', 'answer_id=' + data.answer_id, function (data) {
744								if (data['err']) {
745									return false;
746								} else {
747									$.each(data['rsm']['attachs'], function (i, v) {
748										fileupload.setFileList(v);
749									});
750								}
751							}, 'json');
752						}
753						else
754						{
755							$('.aw-edit-comment-box .aw-file-upload-box').hide();
756						}
757					}, 'json');
758				break;
759
760				case 'ajaxData':
761					$.get(data.url, function (result) {
762						$('#aw_dialog_ajax_data').html(result);
763					});
764				break;
765
766				case 'confirm':
767					$('.aw-confirm-box .yes').click(function()
768					{
769						if (callback)
770						{
771							callback();
772						}
773
774						$(".alert-box").modal('hide');
775
776						return false;
777					});
778				break;
779
780				case 'recommend':
781					$.get(G_BASE_URL + '/help/ajax/list/', function (result)
782					{
783						if (result && result != 0)
784						{
785							var html = '';
786
787							$.each(result, function (i, e)
788							{
789								html += '<li class="aw-border-radius-5"><img class="aw-border-radius-5" src="' + e.icon + '"><a data-id="' + e.id + '" class="aw-hide-txt">' + e.title + '</a><i class="icon icon-followed"></i></li>'
790							});
791
792							$('.aw-recommend-box ul').append(html);
793
794							$.each($('.aw-recommend-box ul li'), function (i, e)
795							{
796								if (data.focus_id == $(this).find('a').attr('data-id'))
797								{
798									$(this).addClass('active');
799								}
800							});
801
802							$(document).on('click', '.aw-recommend-box ul li a', function()
803							{
804								var _this = $(this), url = G_BASE_URL + '/help/ajax/add_data/', removeClass = false;
805
806								if ($(this).parents('li').hasClass('active'))
807								{
808									url =  G_BASE_URL + '/help/ajax/remove_data/';
809
810									removeClass = true;
811								}
812
813								$.post(url,
814								{
815									'item_id' : data.item_id,
816									'id' : _this.attr('data-id'),
817									'title' : _this.text(),
818									'type' : data.type
819								}, function (result)
820								{
821									if (result.errno == 1)
822									{
823										if (removeClass)
824										{
825											_this.parents('li').removeClass('active');
826										}
827										else
828										{
829											$('.aw-recommend-box ul li').removeClass('active');
830
831											_this.parents('li').addClass('active');
832										}
833									}
834								}, 'json');
835							});
836						}
837						else
838						{
839							$('.error_message').html(_t('请先去后台创建好章节'));
840
841							if ($('.error_message').css('display') != 'none')
842							{
843								AWS.shake($('.error_message'));
844							}
845							else
846							{
847								$('.error_message').fadeIn();
848							}
849						}
850					}, 'json');
851				break;
852			}
853
854			$(".alert-box").modal('show');
855		}
856	},
857
858	// 兼容placeholder
859	check_placeholder: function(selector)
860	{
861		$.each(selector, function()
862		{
863			if (typeof ($(this).attr("placeholder")) != "undefined")
864			{
865				$(this).attr('data-placeholder', 'true');
866
867				if ($(this).val() == '')
868				{
869					$(this).addClass('aw-placeholder').val($(this).attr("placeholder"));
870				}
871
872				$(this).focus(function () {
873					if ($(this).val() == $(this).attr('placeholder'))
874					{
875						$(this).removeClass('aw-placeholder').val('');
876					}
877				});
878
879				$(this).blur(function () {
880					if ($(this).val() == '')
881					{
882						$(this).addClass('aw-placeholder').val($(this).attr('placeholder'));
883					}
884				});
885			}
886		});
887	},
888
889	// 回复背景高亮
890	hightlight: function(selector, class_name)
891	{
892		if (selector.hasClass(class_name))
893		{
894			return true;
895		}
896
897		var hightlight_timer_front = setInterval(function ()
898		{
899			selector.addClass(class_name);
900		}, 500);
901
902		var hightlight_timer_background = setInterval(function ()
903		{
904			selector.removeClass(class_name);
905		}, 600);
906
907		setTimeout(function ()
908		{
909			clearInterval(hightlight_timer_front);
910			clearInterval(hightlight_timer_background);
911
912			selector.addClass(class_name);
913		}, 1200);
914
915		setTimeout(function ()
916		{
917			selector.removeClass(class_name);
918		}, 6000);
919	},
920
921	nl2br: function(str)
922	{
923		return str.replace(new RegExp("\r\n|\n\r|\r|\n", "g"), "<br />");
924	},
925
926	content_switcher: function(hide_el, show_el)
927	{
928		hide_el.hide();
929		show_el.fadeIn();
930	},
931
932	htmlspecialchars: function(text)
933	{
934		return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
935	},
936
937	/*
938	 * 用户头像提示box效果
939	 *  @params
940	 *  type : user/topic
941	 *	nTop    : 焦点到浏览器上边距
942	 *	nRight  : 焦点到浏览器右边距
943	 *	nBottom : 焦点到浏览器下边距
944	 *	left    : 焦点距离文档左偏移量
945	 *	top     : 焦点距离文档上偏移量
946	 **
947	 */
948	show_card_box: function(selector, type, time) //selector -> .aw-user-name/.topic-tag
949	{
950		if (!time)
951		{
952			var time = 300;
953		}
954
955		$(document).on('mouseover', selector, function ()
956		{
957			clearTimeout(AWS.G.card_box_hide_timer);
958			var _this = $(this);
959			AWS.G.card_box_show_timer = setTimeout(function ()
960			{
961				//判断用户id or 话题id 是否存在
962				if (_this.attr('data-id'))
963				{
964					 switch (type)
965					{
966						case 'user' :
967							//检查是否有缓存
968							if (AWS.G.cashUserData.length == 0)
969							{
970								_getdata('user', '/people/ajax/user_info/uid-');
971							}
972							else
973							{
974								var flag = 0;
975								//遍历缓存中是否含有此id的数据
976								_checkcash('user');
977								if (flag == 0)
978								{
979									_getdata('user', '/people/ajax/user_info/uid-');
980								}
981							}
982						break;
983
984						case 'topic' :
985							//检查是否有缓存
986							if (AWS.G.cashTopicData.length == 0)
987							{
988								_getdata('topic', '/topic/ajax/topic_info/topic_id-');
989							}
990							else
991							{
992								var flag = 0;
993								//遍历缓存中是否含有此id的数据
994								_checkcash('topic');
995								if (flag == 0)
996								{
997									_getdata('topic', '/topic/ajax/topic_info/topic_id-');
998								}
999							}
1000						break;
1001					}
1002				}
1003
1004				//获取数据
1005				function _getdata(type, url)
1006				{
1007					if (type == 'user')
1008					{
1009						$.get(G_BASE_URL + url + _this.attr('data-id'), function(result)
1010						{
1011							var focus = result.focus, verified = result.verified, focusTxt;
1012
1013							if (focus == 1)
1014							{
1015								focus = 'active';
1016								focusTxt = '取消关注';
1017							}
1018							else
1019							{
1020								focus = '';
1021								focusTxt = '关注';
1022							}
1023
1024							if(result.verified == 'enterprise')
1025							{
1026								verified_enterprise = 'icon-v i-ve';
1027								verified_title = '企业认证';
1028							}
1029							else if(result.verified == 'personal')
1030							{
1031								verified_enterprise = 'icon-v';
1032								verified_title = '个人认证';
1033							}
1034							else
1035							{
1036								verified_enterprise = verified_title = '';
1037							}
1038
1039							//动态插入盒子
1040							$('#aw-ajax-box').html(Hogan.compile(AW_TEMPLATE.userCard).render(
1041							{
1042								'verified_enterprise' : verified_enterprise,
1043								'verified_title' : verified_title,
1044								'uid': result.uid,
1045								'avatar_file': result.avatar_file,
1046								'user_name': result.user_name,
1047								'reputation': result.reputation,
1048								'agree_count': result.agree_count,
1049								'signature': result.signature,
1050								'url' : result.url,
1051								'category_enable' : result.category_enable,
1052								'focus': focus,
1053								'focusTxt': focusTxt,
1054								'ask_name': "'" + result.user_name + "'",
1055								'fansCount': result.fans_count
1056							}));
1057
1058							//判断是否为游客or自己
1059							if (G_USER_ID == '' || G_USER_ID == result.uid || result.uid < 0)
1060							{
1061								$('#aw-card-tips .mod-footer').hide();
1062							}
1063							_init();
1064							//缓存
1065							AWS.G.cashUserData.push($('#aw-ajax-box').html());
1066						}, 'json');
1067					}
1068					if (type == 'topic')
1069					{
1070						$.get(G_BASE_URL + url + _this.attr('data-id'), function(result)
1071						{
1072							var focus = result.focus,
1073								focusTxt;
1074								if (focus == false)
1075								{
1076									focus = '';
1077									focusTxt = _t('关注');
1078								}
1079								else
1080								{
1081									focus = 'active';
1082									focusTxt = _t('取消关注');
1083								}
1084								//动态插入盒子
1085								$('#aw-ajax-box').html(Hogan.compile(AW_TEMPLATE.topicCard).render(
1086								{
1087									'topic_id': result.topic_id,
1088									'topic_pic': result.topic_pic,
1089									'topic_title': result.topic_title,
1090									'topic_description': result.topic_description,
1091									'discuss_count': result.discuss_count,
1092									'focus_count': result.focus_count,
1093									'focus': focus,
1094									'focusTxt': focusTxt,
1095									'url' : result.url,
1096									'fansCount': result.fans_count
1097								}));
1098								//判断是否为游客
1099								if (G_USER_ID == '')
1100								{
1101									$('#aw-card-tips .mod-footer .follow').hide();
1102								}
1103								_init();
1104								//缓存
1105								AWS.G.cashTopicData.push($('#aw-ajax-box').html());
1106						}, 'json');
1107					}
1108				}
1109
1110				//检测缓存
1111				function _checkcash(type)
1112				{
1113					if (type == 'user')
1114					{
1115						$.each(AWS.G.cashUserData, function (i, a)
1116						{
1117							if (a.match('data-id="' + _this.attr('data-id') + '"'))
1118							{
1119								$('#aw-ajax-box').html(a);
1120								$('#aw-card-tips').removeAttr('style');
1121								_init();
1122								flag = 1;
1123							}
1124						});
1125					}
1126					if (type == 'topic')
1127					{
1128
1129						$.each(AWS.G.cashTopicData, function (i, a)
1130						{
1131							if (a.match('data-id="' + _this.attr('data-id') + '"'))
1132							{
1133								$('#aw-ajax-box').html(a);
1134								$('#aw-card-tips').removeAttr('style');
1135								_init();
1136								flag = 1;
1137							}
1138						});
1139					}
1140				}
1141
1142				//初始化
1143				function _init()
1144				{
1145					var left = _this.offset().left,
1146						top = _this.offset().top + _this.height() + 5,
1147						nTop = _this.offset().top - $(window).scrollTop();
1148
1149					//判断下边距离不足情况
1150					if (nTop + $('#aw-card-tips').innerHeight() > $(window).height())
1151					{
1152						top = _this.offset().top - ($('#aw-card-tips').innerHeight()) - 10;
1153					}
1154
1155					//判断右边距离不足情况
1156					if (left + $('#aw-card-tips').innerWidth() > $(window).width())
1157					{
1158						left = _this.offset().left - $('#aw-card-tips').innerWidth() + _this.innerWidth();
1159					}
1160
1161					$('#aw-card-tips').css(
1162					{
1163						left: left,
1164						top: top
1165					}).fadeIn();
1166				}
1167			}, time);
1168		});
1169
1170		$(document).on('mouseout', selector, function ()
1171		{
1172			clearTimeout(AWS.G.card_box_show_timer);
1173			AWS.G.card_box_hide_timer = setTimeout(function ()
1174			{
1175				$('#aw-card-tips').fadeOut();
1176			}, 600);
1177		});
1178	},
1179
1180	// @人功能
1181	at_user_lists: function(selector, limit) {
1182		$(selector).keyup(function (e) {
1183			var _this = $(this),
1184				flag = _getCursorPosition($(this)[0]).start;
1185			if ($(this).val().charAt(flag - 1) == '@')
1186			{
1187				_init();
1188				$('#aw-ajax-box .content_cursor').html($(this).val().substring(0, flag));
1189			} else
1190			{
1191				var lis = $('.aw-invite-dropdown li');
1192				switch (e.which)
1193				{
1194					case 38:
1195						var _index;
1196						if (!lis.hasClass('active'))
1197						{
1198							lis.eq(lis.length - 1).addClass('active');
1199						}
1200						else
1201						{
1202							$.each(lis, function (i, e)
1203							{
1204								if ($(this).hasClass('active'))
1205								{
1206									$(this).removeClass('active');
1207									if ($(this).index() == 0)
1208									{
1209										_index = lis.length - 1;
1210									}
1211									else
1212									{
1213										_index = $(this).index() - 1;
1214									}
1215								}
1216							});
1217							lis.eq(_index).addClass('active');
1218						}
1219						break;
1220					case 40:
1221						var _index;
1222						if (!lis.hasClass('active'))
1223						{
1224							lis.eq(0).addClass('active');
1225						}
1226						else
1227						{
1228							$.each(lis, function (i, e)
1229							{
1230								if ($(this).hasClass('active'))
1231								{
1232									$(this).removeClass('active');
1233									if ($(this).index() == lis.length - 1)
1234									{
1235										_index = 0;
1236									}
1237									else
1238									{
1239										_index = $(this).index() + 1;
1240									}
1241								}
1242							});
1243							lis.eq(_index).addClass('active');
1244						}
1245						break;
1246					case 13:
1247						$.each($('.aw-invite-dropdown li'), function (i, e)
1248						{
1249							if ($(this).hasClass('active'))
1250							{
1251								$(this).click();
1252							}
1253						});
1254						break;
1255					default:
1256						if ($('.aw-invite-dropdown')[0])
1257						{
1258							var ti = 0;
1259							for (var i = flag; i > 0; i--)
1260							{
1261								if ($(this).val().charAt(i) == "@")
1262								{
1263									ti = i;
1264									break;
1265								}
1266							}
1267							$.get(G_BASE_URL + '/search/ajax/search/?type=users&q=' + encodeURIComponent($(this).val().substring(flag, ti).replace('@', '')) + '&limit=' + limit, function (result)
1268							{
1269								if ($('.aw-invite-dropdown')[0])
1270								{
1271									if (result.length != 0)
1272									{
1273										var html = '';
1274
1275										$('.aw-invite-dropdown').html('');
1276
1277										$.each(result, function (i, a)
1278										{
1279											html += '<li><img src="' + a.detail.avatar_file + '"/><a>' + a.name + '</a></li>'
1280										});
1281
1282										$('.aw-invite-dropdown').append(html);
1283
1284										_display();
1285
1286										$('.aw-invite-dropdown li').click(function ()
1287										{
1288											_this.val(_this.val().substring(0, ti) + '@' + $(this).find('a').html() + " ").focus();
1289											$('.aw-invite-dropdown').detach();
1290										});
1291									}
1292									else
1293									{
1294										$('.aw-invite-dropdown').hide();
1295									}
1296								}
1297								if (_this.val().length == 0)
1298								{
1299									$('.aw-invite-dropdown').hide();
1300								}
1301							}, 'json');
1302						}
1303				}
1304			}
1305		});
1306
1307		$(selector).keydown(function (e) {
1308			var key = e.which;
1309			if ($('.aw-invite-dropdown').is(':visible')) {
1310				if (key == 38 || key == 40 || key == 13) {
1311					return false;
1312				}
1313			}
1314		});
1315
1316		//初始化插入定位符
1317		function _init() {
1318			if (!$('.content_cursor')[0]) {
1319				$('#aw-ajax-box').append('<span class="content_cursor"></span>');
1320			}
1321			$('#aw-ajax-box').find('.content_cursor').css({
1322				'left': parseInt($(selector).offset().left + parseInt($(selector).css('padding-left')) + 2),
1323				'top': parseInt($(selector).offset().top + parseInt($(selector).css('padding-left')))
1324			});
1325			if (!$('.aw-invite-dropdown')[0])
1326			{
1327				$('#aw-ajax-box').append('<ul class="aw-invite-dropdown"></ul>');
1328			}
1329		};
1330
1331		//初始化列表和三角型
1332		function _display() {
1333			$('.aw-invite-dropdown').css({
1334				'left': $('.content_cursor').offset().left + $('.content_cursor').innerWidth(),
1335				'top': $('.content_cursor').offset().top + 24
1336			}).show();
1337		};
1338
1339		//获取当前textarea光标位置
1340		function _getCursorPosition(textarea)
1341		{
1342			var rangeData = {
1343				text: "",
1344				start: 0,
1345				end: 0
1346			};
1347
1348			textarea.focus();
1349
1350			if (textarea.setSelectionRange) { // W3C
1351				rangeData.start = textarea.selectionStart;
1352				rangeData.end = textarea.selectionEnd;
1353				rangeData.text = (rangeData.start != rangeData.end) ? textarea.value.substring(rangeData.start, rangeData.end) : "";
1354			} else if (document.selection) { // IE
1355				var i,
1356					oS = document.selection.createRange(),
1357					// Don't: oR = textarea.createTextRange()
1358					oR = document.body.createTextRange();
1359				oR.moveToElementText(textarea);
1360
1361				rangeData.text = oS.text;
1362				rangeData.bookmark = oS.getBookmark();
1363
1364				// object.moveStart(sUnit [, iCount])
1365				// Return Value: Integer that returns the number of units moved.
1366				for (i = 0; oR.compareEndPoints('StartToStart', oS) < 0 && oS.moveStart("character", -1) !== 0; i++) {
1367					// Why? You can alert(textarea.value.length)
1368					if (textarea.value.charAt(i) == '\n') {
1369						i++;
1370					}
1371				}
1372				rangeData.start = i;
1373				rangeData.end = rangeData.text.length + rangeData.start;
1374			}
1375
1376			return rangeData;
1377		};
1378	},
1379
1380	// 错误提示效果
1381	shake: function(selector)
1382	{
1383		var length = 6;
1384		selector.css('position', 'relative');
1385		for (var i = 1; i <= length; i++)
1386		{
1387			if (i % 2 == 0)
1388			{
1389				if (i == length)
1390				{
1391					selector.animate({ 'left': 0 }, 50);
1392				}
1393				else
1394				{
1395					selector.animate({ 'left': 10 }, 50);
1396				}
1397			}
1398			else
1399			{
1400				selector.animate({ 'left': -10 }, 50);
1401			}
1402		}
1403	}
1404}
1405
1406// 全局变量
1407AWS.G =
1408{
1409	cashUserData: [],
1410	cashTopicData: [],
1411	card_box_hide_timer: '',
1412	card_box_show_timer: '',
1413	dropdown_list_xhr: '',
1414	loading_timer: '',
1415	loading_bg_count: 12,
1416	loading_mini_bg_count: 9,
1417	notification_timer: ''
1418}
1419
1420AWS.User =
1421{
1422	// 关注
1423	follow: function(selector, type, data_id)
1424	{
1425		if (selector.html())
1426		{
1427			if (selector.hasClass('active'))
1428			{
1429				selector.find('span').html(_t('关注'));
1430
1431				selector.find('b').html(parseInt(selector.find('b').html()) - 1);
1432			}
1433			else
1434			{
1435				selector.find('span').html(_t('取消关注'));
1436
1437				selector.find('b').html(parseInt(selector.find('b').html()) + 1);
1438			}
1439		}
1440		else
1441		{
1442			if (selector.hasClass('active'))
1443			{
1444				selector.attr('data-original-title', _t('关注'));
1445			}
1446			else
1447			{
1448				selector.attr('data-original-title', _t('取消关注'));
1449			}
1450		}
1451
1452		selector.addClass('disabled');
1453
1454		switch (type)
1455		{
1456			case 'question':
1457				var url = '/question/ajax/focus/';
1458
1459				var data = {
1460					'question_id': data_id
1461				};
1462
1463				break;
1464
1465			case 'topic':
1466				var url = '/topic/ajax/focus_topic/';
1467
1468				var data = {
1469					'topic_id': data_id
1470				};
1471
1472				break;
1473
1474			case 'user':
1475				var url = '/follow/ajax/follow_people/';
1476
1477				var data = {
1478					'uid': data_id
1479				};
1480
1481				break;
1482		}
1483
1484		$.post(G_BASE_URL + url, data, function (result)
1485		{
1486			if (result.errno == 1)
1487			{
1488				if (result.rsm.type == 'add')
1489				{
1490					selector.addClass('active');
1491				}
1492				else
1493				{
1494					selector.removeClass('active');
1495				}
1496			}
1497			else
1498			{
1499				if (result.err)
1500				{
1501					AWS.alert(result.err);
1502				}
1503
1504				if (result.rsm.url)
1505				{
1506					window.location = decodeURIComponent(result.rsm.url);
1507				}
1508			}
1509
1510			selector.removeClass('disabled');
1511
1512		}, 'json');
1513	},
1514
1515	share_out: function(options)
1516	{
1517		var url = options.url || window.location.href, pic = '';
1518
1519		if (options.title)
1520		{
1521			var title = options.title + ' - ' + G_SITE_NAME;
1522		}
1523		else
1524		{
1525			var title = $('title').text();
1526		}
1527
1528		shareURL = 'http://s.jiathis.com/?webid=' + options.webid + '&url=' + url + '&title=' + title +'';
1529
1530		if (options.content)
1531		{
1532			if ($(options.content).find('img').length)
1533			{
1534				shareURL = shareURL + '&pic=' + $(options.content).find('img').eq(0).attr('src');
1535			}
1536		}
1537
1538		window.open(shareURL);
1539	},
1540
1541	// 删除草稿
1542	delete_draft: function(item_id, type)
1543	{
1544		if (type == 'clean')
1545		{
1546			$.post(G_BASE_URL + '/account/ajax/delete_draft/', 'type=' + type, function (result)
1547			{
1548				if (result.errno != 1)
1549				{
1550					AWS.alert(result.err);
1551				}
1552			}, 'json');
1553		}
1554		else
1555		{
1556			$.post(G_BASE_URL + '/account/ajax/delete_draft/', 'item_id=' + item_id + '&type=' + type, function (result)
1557			{
1558				if (result.errno != 1)
1559				{
1560					AWS.alert(result.err);
1561				}
1562			}, 'json');
1563		}
1564	},
1565
1566	// 赞成投票
1567	agree_vote: function(selector, user_name, answer_id)
1568	{
1569		$.post(G_BASE_URL + '/question/ajax/answer_vote/', 'answer_id=' + answer_id + '&value=1');
1570
1571		// 判断是否投票过
1572		if ($(selector).parents('.aw-item').find('.aw-agree-by').text().match(user_name))
1573		{
1574			$.each($(selector).parents('.aw-item').find('.aw-user-name'), function (i, e)
1575			{
1576				if ($(e).html() == user_name)
1577				{
1578					if ($(e).prev())
1579					{
1580						$(e).prev().remove();
1581					}
1582					else
1583					{
1584						$(e).next().remove();
1585					}
1586
1587					$(e).remove();
1588				}
1589			});
1590
1591			$(selector).removeClass('active');
1592
1593			if (parseInt($(selector).parents('.operate').find('.count').html()) != 0)
1594			{
1595				$(selector).parents('.operate').find('.count').html(parseInt($(selector).parents('.operate').find('.count').html()) - 1);
1596			}
1597
1598			if ($(selector).parents('.aw-item').find('.aw-agree-by a').length == 0)
1599			{
1600				$(selector).parents('.aw-item').find('.aw-agree-by').hide();
1601			}
1602		}
1603		else
1604		{
1605			// 判断是否第一个投票
1606			if ($(selector).parents('.aw-item').find('.aw-agree-by .aw-user-name').length == 0)
1607			{
1608				$(selector).parents('.aw-item').find('.aw-agree-by').append('<a class="aw-user-name">' + user_name + '</a>');
1609			}
1610			else
1611			{
1612				$(selector).parents('.aw-item').find('.aw-agree-by').append('<em>、</em><a class="aw-user-name">' + user_name + '</a>');
1613			}
1614
1615			$(selector).parents('.operate').find('.count').html(parseInt($(selector).parents('.operate').find('.count').html()) + 1);
1616
1617			$(selector).parents('.aw-item').find('.aw-agree-by').show();
1618
1619			$(selector).parents('.operate').find('a.active').removeClass('active');
1620
1621			$(selector).addClass('active');
1622		}
1623	},
1624
1625	// 反对投票
1626	disagree_vote: function(selector, user_name, answer_id)
1627	{
1628		$.post(G_BASE_URL + '/question/ajax/answer_vote/', 'answer_id=' + answer_id + '&value=-1', function (result) {});
1629
1630		if ($(selector).hasClass('active'))
1631		{
1632			$(selector).removeClass('active');
1633		}
1634		else
1635		{
1636			// 判断是否有赞同过
1637			if ($(selector).parents('.operate').find('.agree').hasClass('active'))
1638			{
1639				// 删除赞同操作
1640				$.each($(selector).parents('.aw-item').find('.aw-user-name'), function (i, e)
1641				{
1642					if ($(e).html() == user_name)
1643					{
1644						if ($(e).prev())
1645						{
1646							$(e).prev().remove();
1647						}
1648						else
1649						{
1650							$(e).next().remove();
1651						}
1652
1653						$(e).remove();
1654					}
1655				});
1656
1657				// 判断赞同来自内是否有人
1658				if ($(selector).parents('.aw-item').find('.aw-agree-by a').length == 0)
1659				{
1660					$(selector).parents('.aw-item').find('.aw-agree-by').hide();
1661				}
1662
1663				$(selector).parents('.operate').find('.count').html(parseInt($(selector).parents('.operate').find('.count').html()) - 1);
1664
1665				$(selector).parents('.operate').find('.agree').removeClass('active');
1666
1667				$(selector).addClass('active');
1668			}
1669			else
1670			{
1671				$(selector).addClass('active');
1672			}
1673		}
1674	},
1675
1676	// 问题不感兴趣
1677	question_uninterested: function(selector, question_id)
1678	{
1679		selector.fadeOut();
1680
1681		$.post(G_BASE_URL + '/question/ajax/uninterested/', 'question_id=' + question_id, function (result)
1682		{
1683			if (result.errno != '1')
1684			{
1685				AWS.alert(result.err);
1686			}
1687		}, 'json');
1688	},
1689
1690	// 回复折叠
1691	answer_force_fold: function(selector, answer_id)
1692	{
1693		$.post(G_BASE_URL + '/question/ajax/answer_force_fold/', 'answer_id=' + answer_id, function (result) {
1694			if (result.errno != 1)
1695			{
1696				AWS.alert(result.err);
1697			}
1698			else if (result.errno == 1)
1699			{
1700				if (result.rsm.action == 'fold')
1701				{
1702					selector.html(selector.html().replace(_t('折叠'), _t('撤消折叠')));
1703				}
1704				else
1705				{
1706					selector.html(selector.html().replace(_t('撤消折叠'), _t('折叠')));
1707				}
1708			}
1709		}, 'json');
1710	},
1711
1712	// 删除别人邀请我回复的问题
1713	question_invite_delete: function(selector, question_invite_id)
1714	{
1715		$.post(G_BASE_URL + '/question/ajax/question_invite_delete/', 'question_invite_id=' + question_invite_id, function (result)
1716		{
1717			if (result.errno == 1)
1718			{
1719				selector.fadeOut();
1720			}
1721			else
1722			{
1723				AWS.alert(result.rsm.err);
1724			}
1725		}, 'json');
1726	},
1727
1728	// 邀请用户回答问题
1729	invite_user: function(selector, img)
1730	{
1731		$.post(G_BASE_URL + '/question/ajax/save_invite/',
1732		{
1733			'question_id': QUESTION_ID,
1734			'uid': selector.attr('data-id')
1735		}, function (result)
1736		{
1737			if (result.errno != -1)
1738			{
1739				if (selector.parents('.aw-invite-box').find('.invite-list a').length == 0)
1740				{
1741					selector.parents('.aw-invite-box').find('.invite-list').show();
1742				}
1743				selector.parents('.aw-invite-box').find('.invite-list').append(' <a class="text-color-999 invite-list-user" data-toggle="tooltip" data-placement="bottom" data-original-title="'+ selector.attr('data-value') +'"><img src='+ img +' /></a>');
1744				selector.addClass('active').attr('onclick','AWS.User.disinvite_user($(this))').text('取消邀请');
1745				selector.parents('.aw-question-detail').find('.aw-invite-replay .badge').text(parseInt(selector.parents('.aw-question-detail').find('.aw-invite-replay .badge').text()) + 1);
1746			}
1747			else if (result.errno == -1)
1748			{
1749				AWS.alert(result.err);
1750			}
1751		}, 'json');
1752	},
1753
1754	// 取消邀请用户回答问题
1755	disinvite_user: function(selector)
1756	{
1757		$.get(G_BASE_URL + '/question/ajax/cancel_question_invite/question_id-' + QUESTION_ID + "__recipients_uid-" + selector.attr('data-id'), function (result)
1758		{
1759			if (result.errno != -1)
1760			{
1761				$.each($('.aw-question-detail .invite-list a'), function (i, e)
1762				{
1763					if ($(this).attr('data-original-title') == selector.parents('.main').find('.aw-user-name').text())
1764					{
1765						$(this).detach();
1766					}
1767				});
1768				selector.removeClass('active').attr('onclick','AWS.User.invite_user($(this),$(this).parents(\'li\').find(\'img\').attr(\'src\'))').text('邀请');
1769				selector.parents('.aw-question-detail').find('.aw-invite-replay .badge').text(parseInt(selector.parents('.aw-question-detail').find('.aw-invite-replay .badge').text()) - 1);
1770				if (selector.parents('.aw-invite-box').find('.invite-list').children().length == 0)
1771				{
1772					selector.parents('.aw-invite-box').find('.invite-list').hide();
1773				}
1774			}
1775		});
1776	},
1777
1778	// 问题感谢
1779	question_thanks: function(selector, question_id)
1780	{
1781		$.post(G_BASE_URL + '/question/ajax/question_thanks/', 'question_id=' + question_id, function (result)
1782		{
1783			if (result.errno != 1)
1784			{
1785				AWS.alert(result.err);
1786			}
1787			else if (result.rsm.action == 'add')
1788			{
1789				selector.html(selector.html().replace(_t('感谢'), _t('已感谢')));
1790				selector.removeAttr('onclick');
1791			}
1792			else
1793			{
1794				selector.html(selector.html().replace(_t('已感谢'), _t('感谢')));
1795			}
1796		}, 'json');
1797	},
1798
1799	// 感谢评论回复者
1800	answer_user_rate: function(selector, type, answer_id)
1801	{
1802		$.post(G_BASE_URL + '/question/ajax/question_answer_rate/', 'type=' + type + '&answer_id=' + answer_id, function (result)
1803		{
1804			if (result.errno != 1)
1805			{
1806				AWS.alert(result.err);
1807			}
1808			else if (result.errno == 1)
1809			{
1810				switch (type)
1811				{
1812				case 'thanks':
1813					if (result.rsm.action == 'add')
1814					{
1815						selector.html(selector.html().replace(_t('感谢'), _t('已感谢')));
1816						selector.removeAttr('onclick');
1817					}
1818					else
1819					{
1820						selector.html(selector.html().replace(_t('已感谢'), _t('感谢')));
1821					}
1822					break;
1823
1824				case 'uninterested':
1825					if (result.rsm.action == 'add')
1826					{
1827						selector.html(selector.html().replace(_t('没有帮助'), _t('撤消没有帮助')));
1828					}
1829					else
1830					{
1831						selector.html(selector.html().replace(_t('撤消没有帮助'), _t('没有帮助')));
1832					}
1833					break;
1834				}
1835			}
1836		}, 'json');
1837	},
1838
1839	// 提交评论
1840	save_comment: function(selector)
1841	{
1842		selector.addClass('disabled');
1843
1844		AWS.ajax_post(selector.parents('form'), AWS.ajax_processer, 'comments_form');
1845	},
1846
1847	// 删除评论
1848	remove_comment: function(selector, type, comment_id)
1849	{
1850		$.get(G_BASE_URL + '/question/ajax/remove_comment/type-' + type + '__comment_id-' + comment_id);
1851
1852		selector.parents('.aw-comment-box li').fadeOut();
1853	},
1854
1855	// 文章赞同
1856	article_vote: function(selector, article_id, rating)
1857	{
1858		AWS.loading('show');
1859
1860		if (selector.hasClass('active'))
1861		{
1862			var rating = 0;
1863		}
1864
1865		$.post(G_BASE_URL + '/article/ajax/article_vote/', 'type=article&item_id=' + article_id + '&rating=' + rating, function (result) {
1866
1867			AWS.loading('hide');
1868
1869			if (result.errno != 1)
1870			{
1871				AWS.alert(result.err);
1872			}
1873			else
1874			{
1875				if (rating == 0)
1876				{
1877					selector.removeClass('active').find('b').html(parseInt(selector.find('b').html()) - 1);
1878				}
1879				else if (rating == -1)
1880				{
1881					if (selector.parents('.aw-article-vote').find('.agree').hasClass('active'))
1882					{
1883						selector.parents('.aw-article-vote').find('b').html(parseInt(selector.parents('.aw-article-vote').find('b').html()) - 1);
1884						selector.parents('.aw-article-vote').find('a').removeClass('active');
1885					}
1886
1887					selector.addClass('active');
1888				}
1889				else
1890				{
1891					selector.parents('.aw-article-vote').find('a').removeClass('active');
1892					selector.addClass('active').find('b').html(parseInt(selector.find('b').html()) + 1);
1893				}
1894			}
1895		}, 'json');
1896	},
1897
1898	// 文章评论赞同
1899	article_comment_vote: function(selector, comment_id, rating)
1900	{
1901		AWS.loading('show');
1902
1903		if (selector.hasClass('active'))
1904		{
1905			var rating = 0;
1906		}
1907
1908		$.post(G_BASE_URL + '/article/ajax/article_vote/', 'type=comment&item_id=' + comment_id + '&rating=' + rating, function (result)
1909		{
1910			AWS.loading('hide');
1911
1912			if (result.errno != 1)
1913			{
1914				AWS.alert(result.err);
1915			}
1916			else
1917			{
1918				if (rating == 0)
1919				{
1920					selector.html(selector.html().replace(_t('我已赞'), _t('赞'))).removeClass('active');
1921				}
1922				else
1923				{
1924					selector.html(selector.html().replace(_t('赞'), _t('我已赞'))).addClass('active');
1925				}
1926			}
1927		}, 'json');
1928	},
1929
1930	// 创建收藏标签
1931	add_favorite_tag: function()
1932	{
1933		$.post(G_BASE_URL + '/favorite/ajax/update_favorite_tag/', {
1934			'item_id' : $('#favorite_form input[name="item_id"]').val(),
1935			'item_type' : $('#favorite_form input[name="item_type"]').val(),
1936			'tags' : $('#favorite_form .add-input').val()
1937		}, function (result)
1938		{
1939			if (result.errno == 1)
1940			{
1941				$('.aw-favorite-box .aw-favorite-tag-list').show();
1942				$('.aw-favorite-box .aw-favorite-tag-add').hide();
1943
1944				$('.aw-favorite-tag-list ul').prepend('<li class="active"><a data-value="' + $('#favorite_form .add-input').val() + '"><span class="title">' + $('#favorite_form .add-input').val() + '</span></a><i class="icon icon-followed"></i></li>');
1945			}
1946		}, 'json');
1947	}
1948}
1949
1950AWS.Dropdown =
1951{
1952	// 下拉菜单功能绑定
1953	bind_dropdown_list: function(selector, type)
1954	{
1955		if (type == 'search')
1956		{
1957			$(selector).focus(function()
1958			{
1959				$(selector).parent().find('.aw-dropdown').show();
1960			});
1961		}
1962		$(selector).keyup(function(e)
1963		{
1964			if (type == 'search')
1965			{
1966				$(selector).parent().find('.search').show().children('a').text($(selector).val());
1967			}
1968			if ($(selector).val().length >= 1)
1969			{
1970				if (e.which != 38 && e.which != 40 && e.which != 188 && e.which != 13)
1971				{
1972					AWS.Dropdown.get_dropdown_list($(this), type, $(selector).val());
1973				}
1974			}
1975			else
1976			{
1977			   $(selector).parent().find('.aw-dropdown').hide();
1978			}
1979
1980			if (type == 'topic')
1981			{
1982				// 逗号或回车提交
1983				if (e.which == 188)
1984				{
1985					if ($('.aw-edit-topic-box #aw_edit_topic_title').val() != ',')
1986					{
1987						$('.aw-edit-topic-box #aw_edit_topic_title').val( $('.aw-edit-topic-box #aw_edit_topic_title').val().substring(0,$('.aw-edit-topic-box #aw_edit_topic_title').val().length-1));
1988						$('.aw-edit-topic-box .aw-dropdown').hide();
1989						$('.aw-edit-topic-box .add').click();
1990					}
1991					return false;
1992				}
1993
1994				// 回车提交
1995				if (e.which == 13)
1996				{
1997					$('.aw-edit-topic-box .aw-dropdown').hide();
1998					$('.aw-edit-topic-box .add').click();
1999					return false;
2000				}
2001
2002				var lis = $(selector).parent().find('.aw-dropdown-list li');
2003
2004				//键盘往下
2005				if (e.which == 40 && lis.is(':visible'))
2006				{
2007					var _index;
2008					if (!lis.hasClass('active'))
2009					{
2010						lis.eq(0).addClass('active');
2011					}
2012					else
2013					{
2014						$.each(lis, function (i, e)
2015						{
2016							if ($(this).hasClass('active'))
2017							{
2018								$(this).removeClass('active');
2019								if ($(this).index() == lis.length - 1)
2020								{
2021									_index = 0;
2022								}
2023								else
2024								{
2025									_index = $(this).index() + 1;
2026								}
2027							}
2028						});
2029						lis.eq(_index).addClass('active');
2030						$(selector).val(lis.eq(_index).text());
2031					}
2032				}
2033
2034				//键盘往上
2035				if (e.which == 38 && lis.is(':visible'))
2036				{
2037					var _index;
2038					if (!lis.hasClass('active'))
2039					{
2040						lis.eq(lis.length - 1).addClass('active');
2041					}
2042					else
2043					{
2044						$.each(lis, function (i, e)
2045						{
2046							if ($(this).hasClass('active'))
2047							{
2048								$(this).removeClass('active');
2049								if ($(this).index() == 0)
2050								{
2051									_index = lis.length - 1;
2052								}
2053								else
2054								{
2055									_index = $(this).index() - 1;
2056								}
2057							}
2058						});
2059						lis.eq(_index).addClass('active');
2060						$(selector).val(lis.eq(_index).text());
2061					}
2062
2063				}
2064			}
2065		});
2066
2067		$(selector).blur(function()
2068		{
2069			$(selector).parent().find('.aw-dropdown').delay(500).fadeOut(300);
2070		});
2071	},
2072
2073	// 插入下拉菜单
2074	set_dropdown_list: function(selector, data, selected)
2075	{
2076		$(selector).append(Hogan.compile(AW_TEMPLATE.dropdownList).render(
2077		{
2078			'items': data
2079		}));
2080
2081		$(selector + ' .aw-dropdown-list li a').click(function ()
2082		{
2083			$('#aw-topic-tags-select').html($(this).text());
2084		});
2085
2086		if (selected)
2087		{
2088			$(selector + " .dropdown-menu li a[data-value='" + selected + "']").click();
2089		}
2090	},
2091
2092	/* 下拉菜单数据获取 */
2093	/*
2094	*    type : search, publish, redirect, invite, inbox, topic_question, topic
2095	*/
2096	get_dropdown_list: function(selector, type, data)
2097	{
2098		if (AWS.G.dropdown_list_xhr != '')
2099		{
2100			AWS.G.dropdown_list_xhr.abort(); // 中止上一次ajax请求
2101		}
2102		var url;
2103		switch (type)
2104		{
2105			case 'search' :
2106				url = G_BASE_URL + '/search/ajax/search/?q=' + encodeURIComponent(data) + '&limit=5';
2107			break;
2108
2109			case 'publish' :
2110				url = G_BASE_URL + '/search/ajax/search/?type=questions&q=' + encodeURIComponent(data) + '&limit=5';
2111			break;
2112
2113			case 'redirect' :
2114				url = G_BASE_URL + '/search/ajax/search/?q=' + encodeURIComponent(data) + '&type=questions&limit=30&is_question_id=1';
2115			break;
2116
2117			case 'invite' :
2118			case 'inbox' :
2119				url = G_BASE_URL + '/search/ajax/search/?type=users&q=' + encodeURIComponent(data) + '&limit=10';
2120			break;
2121
2122			case 'topic_question' :
2123				url = G_BASE_URL + '/search/ajax/search/?type=questions,articles&q=' + encodeURIComponent(data) + '&topic_ids=' + CONTENTS_RELATED_TOPIC_IDS + '&limit=50';
2124			break;
2125
2126			case 'topic' :
2127				url = G_BASE_URL + '/search/ajax/search/?type=topics&q=' + encodeURIComponent(data) + '&limit=10';
2128			break;
2129
2130			case 'questions' :
2131				url = G_BASE_URL + '/search/ajax/search/?type=questions&q=' + encodeURIComponent(data) + '&limit=10';
2132			break;
2133
2134			case 'articles' :
2135				url = G_BASE_URL + '/search/ajax/search/?type=articles&q=' + encodeURIComponent(data) + '&limit=10';
2136			break;
2137
2138		}
2139
2140		AWS.G.dropdown_list_xhr = $.get(url, function (result)
2141		{
2142			if (result.length != 0 && AWS.G.dropdown_list_xhr != undefined)
2143			{
2144				$(selector).parent().find('.aw-dropdown-list').html(''); // 清空内容
2145				switch (type)
2146				{
2147					case 'search' :
2148						$.each(result, function (i, a)
2149						{
2150							switch (a.type)
2151							{
2152								case 'questions':
2153									if (a.detail.best_answer > 0)
2154									{
2155										var active = 'active';
2156									}
2157									else
2158									{
2159										var active = ''
2160									}
2161
2162									$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.searchDropdownListQuestions).render(
2163									{
2164										'url': a.url,
2165										'active': active,
2166										'content': a.name,
2167										'discuss_count': a.detail.answer_count
2168									}));
2169								break;
2170
2171								case 'articles':
2172									$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.searchDropdownListArticles).render(
2173									{
2174										'url': a.url,
2175										'content': a.name,
2176										'comments': a.detail.comments
2177									}));
2178								break;
2179
2180								case 'topics':
2181									$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.searchDropdownListTopics).render(
2182									{
2183										'url': a.url,
2184										'name': a.name,
2185										'discuss_count': a.detail.discuss_count,
2186										'topic_id': a.detail.topic_id
2187									}));
2188								break;
2189
2190								case 'users':
2191									if (a.detail.signature == '')
2192									{
2193										var signature = _t('暂无介绍');
2194									}
2195									else
2196									{
2197										var signature = a.detail.signature;
2198									}
2199
2200									$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.searchDropdownListUsers).render(
2201									{
2202										'url': a.url,
2203										'img': a.detail.avatar_file,
2204										'name': a.name,
2205										'intro': signature
2206									}));
2207								break;
2208							}
2209						});
2210					break;
2211
2212					case 'publish' :
2213					case 'topic_question' :
2214						$.each(result, function (i, a)
2215						{
2216							$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.questionDropdownList).render(
2217							{
2218								'url': a.url,
2219								'name': a.name
2220							}));
2221						});
2222						break;
2223
2224					case 'topic' :
2225						$.each(result, function (i, a)
2226						{
2227							$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.editTopicDorpdownList).render(
2228							{
2229								'name': a['name']
2230							}));
2231						});
2232						break;
2233
2234					case 'redirect' :
2235						$.each(result, function (i, a)
2236						{
2237							$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.questionRedirectList).render(
2238							{
2239								'url': "'" + G_BASE_URL + "/question/ajax/redirect/', 'item_id=" + $(selector).attr('data-id') + "&target_id=" + a['search_id'] + "'",
2240								'name': a['name']
2241							}));
2242						});
2243						break;
2244
2245					case 'questions' :
2246					case 'articles' :
2247						$.each(result, function (i, a)
2248						{
2249							$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.questionDropdownList).render(
2250							{
2251								'url': '#',
2252								'name': a['name']
2253							}));
2254						});
2255						break;
2256
2257						$(selector).parent().find('.aw-dropdown-list li').click(function()
2258						{
2259							$('.aw-question-list').append('<li data-id="'+$(this).attr('data-id')+'"><div class="col-sm-9">' + $(this).html() + '</div> <div class="col-sm-3"><a class="btn btn-danger btn-xs">删除</a></div></li>');
2260
2261							$('.aw-question-list li').find("a").attr('href',function(){
2262								return $(this).attr("_href")
2263
2264							});
2265
2266							if ($('.question_ids').val() == '')
2267							{
2268								$('.question_ids').val($(this).attr('data-id') + ',');
2269							}
2270							else
2271							{
2272								$('.question_ids').val($('.question_ids').val() + $(this).attr('data-id') + ',');
2273							}
2274							$(".alert-box").modal('hide');
2275						});
2276
2277						break;
2278
2279					case 'inbox' :
2280					case 'invite' :
2281						$.each(result, function (i, a)
2282						{
2283							$(selector).parent().find('.aw-dropdown-list').append(Hogan.compile(AW_TEMPLATE.inviteDropdownList).render(
2284							{
2285								'uid': a.uid,
2286								'name': a.name,
2287								'img': a.detail.avatar_file
2288							}));
2289						});
2290						break;
2291
2292				}
2293				if (type == 'publish')
2294				{
2295					$(selector).parent().find('.aw-publish-suggest-question, .aw-publish-suggest-question .aw-dropdown-list').show();
2296				}
2297				else
2298				{
2299					$(selector).parent().find('.aw-dropdown, .aw-dropdown-list').show().children().show();
2300					$(selector).parent().find('.title').hide();
2301					// 关键词高亮
2302					$(selector).parent().find('.aw-dropdown-list li.question a').highText(data, 'b', 'active');
2303				}
2304			}else
2305			{
2306				$(selector).parent().find('.aw-dropdown').show().end().find('.title').html(_t('没有找到相关结果')).show();
2307				$(selector).parent().find('.aw-dropdown-list, .aw-publish-suggest-question').hide();
2308			}
2309		}, 'json');
2310
2311	}
2312}
2313
2314AWS.Message =
2315{
2316	// 检测通知
2317	check_notifications: function()
2318	{
2319		// 检测登录状态
2320		if (G_USER_ID == 0)
2321		{
2322			clearInterval(AWS.G.notification_timer);
2323			return false;
2324		}
2325
2326		$.get(G_BASE_URL + '/home/ajax/notifications/', function (result)
2327		{
2328			$('#inbox_unread').html(Number(result.rsm.inbox_num));
2329
2330			var last_unread_notification = G_UNREAD_NOTIFICATION;
2331
2332			G_UNREAD_NOTIFICATION = Number(result.rsm.notifications_num);
2333
2334			if (G_UNREAD_NOTIFICATION > 0)
2335			{
2336				if (G_UNREAD_NOTIFICATION != last_unread_notification)
2337				{
2338					// 加载消息列表
2339					AWS.Message.load_notification_list();
2340
2341					// 给导航label添加未读消息数量
2342					$('#notifications_unread').html(G_UNREAD_NOTIFICATION);
2343				}
2344
2345				document.title = '(' + (Number(result.rsm.notifications_num) + Number(result.rsm.inbox_num)) + ') ' + document_title;
2346
2347				$('#notifications_unread').show();
2348			}
2349			else
2350			{
2351				if ($('#header_notification_list').length)
2352				{
2353					$("#header_notification_list").html('<p class="aw-padding10" align="center">' + _t('没有未读通知') + '</p>');
2354				}
2355
2356				if ($("#index_notification").length)
2357				{
2358					$("#index_notification").fadeOut();
2359				}
2360
2361				document.title = document_title;
2362
2363				$('#notifications_unread').hide();
2364			}
2365
2366			// 私信
2367			if (Number(result.rsm.inbox_num) > 0)
2368			{
2369				$('#inbox_unread').show();
2370			}
2371			else
2372			{
2373				$('#inbox_unread').hide();
2374			}
2375
2376		}, 'json');
2377	},
2378
2379	// 阅读通知
2380	read_notification: function(selector, notification_id , reload)
2381	{
2382		if (notification_id)
2383		{
2384			selector.remove();
2385
2386			var url = G_BASE_URL + '/notifications/ajax/read_notification/notification_id-' + notification_id;
2387		}
2388		else
2389		{
2390			if ($("#index_notification").length)
2391			{
2392				$("#index_notification").fadeOut();
2393			}
2394
2395			var url = G_BASE_URL + '/notifications/ajax/read_notification/';
2396		}
2397
2398		$.get(url, function (result)
2399		{
2400			AWS.Message.check_notifications();
2401
2402			if (reload)
2403			{
2404				window.location.reload();
2405			}
2406		});
2407	},
2408
2409	// 重新加载通知列表
2410	load_notification_list: function()
2411	{
2412		if ($("#index_notification").length)
2413		{
2414			// 给首页通知box内label添加未读消息数量
2415			$("#index_notification").fadeIn().find('[name=notification_unread_num]').html(G_UNREAD_NOTIFICATION);
2416
2417			$('#index_notification ul#notification_list').html('<p align="center" style="padding: 15px 0"><img src="' + G_STATIC_URL + '/common/loading_b.gif"/></p>');
2418
2419			$.get(G_BASE_URL + '/notifications/ajax/list/flag-0__page-0', function (result)
2420			{
2421				$('#index_notification ul#notification_list').html(result);
2422
2423				AWS.Message.notification_show(5);
2424			});
2425		}
2426
2427		if ($("#header_notification_list").length)
2428		{
2429			$.get(G_BASE_URL + '/notifications/ajax/list/flag-0__limit-5__template-header_list', function (result)
2430			{
2431				if (result.length)
2432				{
2433					$("#header_notification_list").html(result);
2434				}
2435				else
2436				{
2437					$("#header_notification_list").html('<p class="aw-padding10" align="center">' + _t('没有未读通知') + '</p>');
2438				}
2439			});
2440		}
2441	},
2442
2443	// 控制通知数量
2444	notification_show: function(length)
2445	{
2446		if ($('#index_notification').length > 0)
2447		{
2448			if ($('#index_notification ul#notification_list li').length == 0)
2449			{
2450				$('#index_notification').fadeOut();
2451			}
2452			else
2453			{
2454				$('#index_notification ul#notification_list li').each(function (i, e)
2455				{
2456					if (i < length)
2457					{
2458						$(e).show();
2459					}
2460					else
2461					{
2462						$(e).hide();
2463					}
2464				});
2465			}
2466		}
2467	}
2468}
2469
2470AWS.Init =
2471{
2472	// 初始化问题评论框
2473	init_comment_box: function(selector)
2474	{
2475		$(document).on('click', selector, function ()
2476		{
2477			$(this).parents('.aw-question-detail').find('.aw-invite-box, .aw-question-related-box').hide();
2478			if (typeof COMMENT_UNFOLD != 'undefined')
2479			{
2480				if (COMMENT_UNFOLD == 'all' && $(this).attr('data-comment-count') == 0 && $(this).attr('data-first-click') == 'hide')
2481				{
2482					$(this).removeAttr('data-first-click');
2483					return false;
2484				}
2485			}
2486
2487			if (!$(this).attr('data-type') || !$(this).attr('data-id'))
2488			{
2489				return true;
2490			}
2491
2492			var comment_box_id = '#aw-comment-box-' + $(this).attr('data-type') + '-' +  $(this).attr('data-id');
2493
2494			if ($(comment_box_id).length)
2495			{
2496				if ($(comment_box_id).css('display') == 'none')
2497				{
2498					$(this).addClass('active');
2499
2500					$(comment_box_id).fadeIn();
2501				}
2502				else
2503				{
2504					$(this).removeClass('active');
2505					$(comment_box_id).fadeOut();
2506				}
2507			}
2508			else
2509			{
2510				// 动态插入commentBox
2511				switch ($(this).attr('data-type'))
2512				{
2513					case 'question':
2514						var comment_form_action = G_BASE_URL + '/question/ajax/save_question_comment/question_id-' + $(this).attr('data-id');
2515						var comment_data_url = G_BASE_URL + '/question/ajax/get_question_comments/question_id-' + $(this).attr('data-id');
2516						break;
2517
2518					case 'answer':
2519						var comment_form_action = G_BASE_URL + '/question/ajax/save_answer_comment/answer_id-' + $(this).attr('data-id');
2520						var comment_data_url = G_BASE_URL + '/question/ajax/get_answer_comments/answer_id-' + $(this).attr('data-id');
2521						break;
2522				}
2523
2524				if (G_USER_ID)
2525				{
2526					$(this).parents('.aw-item').find('.mod-footer').append(Hogan.compile(AW_TEMPLATE.commentBox).render(
2527					{
2528						'comment_form_id': comment_box_id.replace('#', ''),
2529						'comment_form_action': comment_form_action
2530					}));
2531
2532					$(comment_box_id).find('.aw-comment-txt').bind(
2533					{
2534						focus: function ()
2535						{
2536							$(comment_box_id).find('.aw-comment-box-btn').show();
2537						},
2538
2539						blur: function ()
2540						{
2541							if ($(this).val() == '')
2542							{
2543								$(comment_box_id).find('.aw-comment-box-btn').hide();
2544							}
2545						}
2546					});
2547
2548					$(comment_box_id).find('.close-comment-box').click(function ()
2549					{
2550						$(comment_box_id).fadeOut();
2551						$(comment_box_id).find('.aw-comment-txt').css('height', $(this).css('line-height'));
2552					});
2553				}
2554				else
2555				{
2556					$(this).parents('.aw-item').find('.mod-footer').append(Hogan.compile(AW_TEMPLATE.commentBoxClose).render(
2557					{
2558						'comment_form_id': comment_box_id.replace('#', ''),
2559						'comment_form_action': comment_form_action
2560					}));
2561				}
2562
2563				// 判断是否有评论数据
2564				$.get(comment_data_url, function (result)
2565				{
2566					if ($.trim(result) == '')
2567					{
2568						result = '<div align="center" class="aw-padding10">' + _t('暂无评论') + '</div>';
2569					}
2570
2571					$(comment_box_id).find('.aw-comment-list').html(result);
2572				});
2573
2574				// textarae自动增高
2575				$(comment_box_id).find('.aw-comment-txt').autosize();
2576
2577				$(this).addClass('active');
2578
2579				AWS.at_user_lists(comment_box_id + ' .aw-comment-txt', 5);
2580			}
2581
2582			AWS.at_user_lists($(this).parents('.aw-item').find('.aw-comment-txt'));
2583		});
2584	},
2585
2586	// 初始化文章评论框
2587	init_article_comment_box: function(selector)
2588	{
2589		$(document).on('click', selector, function ()
2590		{
2591			var _editor_box = $(this).parents('.aw-item').find('.aw-article-replay-box');
2592			if (_editor_box.length)
2593			{
2594				if (_editor_box.css('display') == 'block')
2595				{
2596				   _editor_box.fadeOut();
2597				}
2598				else
2599				{
2600					_editor_box.fadeIn();
2601				}
2602			}
2603			else
2604			{
2605				$(this).parents('.mod-footer').append(Hogan.compile(AW_TEMPLATE.articleCommentBox).render(
2606				{
2607					'at_uid' : $(this).attr('data-id'),
2608					'article_id' : $('.aw-topic-bar').attr('data-id')
2609				}));
2610			}
2611		});
2612	},
2613
2614	// 初始化话题编辑box
2615	init_topic_edit_box: function(selector) //selector -> .aw-edit-topic
2616	{
2617		$(selector).click(function ()
2618		{
2619			var _topic_editor = $(this).parents('.aw-topic-bar'),
2620				data_id = _topic_editor.attr('data-id'),
2621				data_type = _topic_editor.attr('data-type');
2622
2623			if (!_topic_editor.hasClass('active'))
2624			{
2625				_topic_editor.addClass('active');
2626
2627				if (!_topic_editor.find('.topic-tag .close').length)
2628				{
2629					_topic_editor.find('.topic-tag').append('<a class="close"><i class="icon icon-delete"></i></a>');
2630				}
2631			}
2632			else
2633			{
2634				_topic_editor.addClass('active');
2635			}
2636
2637			// 判断插入编辑box
2638			if (_topic_editor.find('.aw-edit-topic-box').length == 0)
2639			{
2640				_topic_editor.append(AW_TEMPLATE.editTopicBox);
2641
2642				// 给编辑box添加按钮添加事件
2643				_topic_editor.find('.add').click(function ()
2644				{
2645					if (_topic_editor.find('#aw_edit_topic_title').val() != '')
2646					{
2647						switch (data_type)
2648						{
2649							case 'publish':
2650								_topic_editor.find('.tag-bar').prepend('<span class="topic-tag"><a class="text">' + _topic_editor.find('#aw_edit_topic_title').val() + '</a><a class="close" onclick="$(this).parents(\'.topic-tag\').remove();"><i class="icon icon-delete"></i></a><input type="hidden" value="' + _topic_editor.find('#aw_edit_topic_title').val() + '" name="topics[]" /></span>').hide().fadeIn();
2651
2652								_topic_editor.find('#aw_edit_topic_title').val('');
2653							break;
2654
2655							case 'question':
2656								$.post(G_BASE_URL + '/topic/ajax/save_topic_relation/', 'type=question&item_id=' + data_id + '&topic_title=' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()), function (result)
2657								{
2658									if (result.errno != 1)
2659									{
2660										AWS.alert(result.err);
2661
2662										return false;
2663									}
2664
2665									_topic_editor.find('.tag-bar').prepend('<span class="topic-tag" data-id="' + result.rsm.topic_id + '"><a href="' + G_BASE_URL + '/topic/' + result.rsm.topic_id + '" class="text">' + _topic_editor.find('#aw_edit_topic_title').val() + '</a><a class="close"><i class="icon icon-delete"></i></a></span>').hide().fadeIn();
2666
2667									_topic_editor.find('#aw_edit_topic_title').val('');
2668								}, 'json');
2669							break;
2670
2671							case 'article':
2672								$.post(G_BASE_URL + '/topic/ajax/save_topic_relation/', 'type=article&item_id=' + data_id + '&topic_title=' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()), function (result)
2673								{
2674									if (result.errno != 1)
2675									{
2676										AWS.alert(result.err);
2677
2678										return false;
2679									}
2680
2681									_topic_editor.find('.tag-bar').prepend('<span class="topic-tag" data-id="' + result.rsm.topic_id + '"><a href="' + G_BASE_URL + '/topic/' + result.rsm.topic_id + '" class="text">' + _topic_editor.find('#aw_edit_topic_title').val() + '</a><a class="close"><i class="icon icon-delete"></i></a></span>').hide().fadeIn();
2682
2683									_topic_editor.find('#aw_edit_topic_title').val('');
2684								}, 'json');
2685							break;
2686
2687
2688							case 'topic':
2689								$.post(G_BASE_URL + '/topic/ajax/save_related_topic/topic_id-' + data_id, 'topic_title=' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()), function (result)
2690								{
2691									if (result.errno != 1)
2692									{
2693										AWS.alert(result.err);
2694
2695										return false;
2696									}
2697
2698									_topic_editor.find('.tag-bar').prepend('<span class="topic-tag"><a href="' + G_BASE_URL + '/favorite/tag-' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()) + '" class="text">' + _topic_editor.find('#aw_edit_topic_title').val() + '</a><a class="close"><i class="icon icon-delete"></i></a></span>').hide().fadeIn();
2699
2700									_topic_editor.find('#aw_edit_topic_title').val('');
2701								}, 'json');
2702							break;
2703
2704							case 'favorite':
2705								$.post(G_BASE_URL + '/favorite/ajax/update_favorite_tag/', 'item_id=' + data_id + '&item_type=' + _topic_editor.attr('data-item-type') + '&tags=' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()), function (result)
2706								{
2707									if (result.errno != 1)
2708									{
2709										AWS.alert(result.err);
2710
2711										return false;
2712									}
2713
2714									_topic_editor.find('.tag-bar').prepend('<span class="topic-tag"><a href="' + G_BASE_URL + '/favorite/tag-' + encodeURIComponent(_topic_editor.find('#aw_edit_topic_title').val()) + '" class="text">' + _topic_editor.find('#aw_edit_topic_title').val() + '</a><a class="close"><i class="icon icon-delete"></i></a></span>').hide().fadeIn();
2715
2716									_topic_editor.find('#aw_edit_topic_title').val('');
2717								}, 'json');
2718							break;
2719						}
2720					}
2721				});
2722
2723				// 给编辑box取消按钮添加事件
2724				_topic_editor.find('.close-edit').click(function ()
2725				{
2726					_topic_editor.removeClass('active');
2727					_topic_editor.find('.aw-edit-topic-box').hide();
2728					_topic_editor.find('.aw-edit-topic').show();
2729				});
2730
2731				AWS.Dropdown.bind_dropdown_list($(this).parents('.aw-topic-bar').find('#aw_edit_topic_title'),'topic');
2732			}
2733
2734			$(this).parents('.aw-topic-bar').find('.aw-edit-topic-box').fadeIn();
2735
2736			// 是否允许创建新话题
2737			if (!G_CAN_CREATE_TOPIC)
2738			{
2739				$(this).parents('.aw-topic-bar').find('.add').hide();
2740			}
2741
2742			$(this).hide();
2743		});
2744	}
2745}
2746
2747function _t(string, replace)
2748{
2749	if (typeof (aws_lang) != 'undefined')
2750	{
2751		if (typeof (aws_lang[string]) != 'undefined')
2752		{
2753			string = aws_lang[string];
2754		}
2755	}
2756
2757	if (replace)
2758	{
2759		string = string.replace('%s', replace);
2760	}
2761
2762	return string;
2763};
2764
2765// jQuery扩展
2766(function ($)
2767{
2768	$.fn.extend(
2769	{
2770		insertAtCaret: function (textFeildValue)
2771		{
2772			var textObj = $(this).get(0);
2773			if (document.all && textObj.createTextRange && textObj.caretPos)
2774			{
2775				var caretPos = textObj.caretPos;
2776				caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ?
2777					textFeildValue + '' : textFeildValue;
2778			}
2779			else if (textObj.setSelectionRange)
2780			{
2781				var rangeStart = textObj.selectionStart,
2782					rangeEnd = textObj.selectionEnd,
2783					tempStr1 = textObj.value.substring(0, rangeStart),
2784					tempStr2 = textObj.value.substring(rangeEnd);
2785				textObj.value = tempStr1 + textFeildValue + tempStr2;
2786				textObj.focus();
2787				var len = textFeildValue.length;
2788				textObj.setSelectionRange(rangeStart + len, rangeStart + len);
2789				textObj.blur();
2790			}
2791			else
2792			{
2793				textObj.value += textFeildValue;
2794			}
2795		},
2796
2797		highText: function (searchWords, htmlTag, tagClass)
2798		{
2799			return this.each(function ()
2800			{
2801				$(this).html(function high(replaced, search, htmlTag, tagClass)
2802				{
2803					var pattarn = search.replace(/\b(\w+)\b/g, "($1)").replace(/\s+/g, "|");
2804
2805					return replaced.replace(new RegExp(pattarn, "ig"), function (keyword)
2806					{
2807						return $("<" + htmlTag + " class=" + tagClass + ">" + keyword + "</" + htmlTag + ">").outerHTML();
2808					});
2809				}($(this).text(), searchWords, htmlTag, tagClass));
2810			});
2811		},
2812
2813		outerHTML: function (s)
2814		{
2815			return (s) ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
2816		}
2817	});
2818
2819	$.extend(
2820	{
2821		// 滚动到指定位置
2822		scrollTo : function (type, duration, options)
2823		{
2824			if (typeof type == 'object')
2825			{
2826				var type = $(type).offset().top
2827			}
2828
2829			$('html, body').animate({
2830				scrollTop: type
2831			}, {
2832				duration: duration,
2833				queue: options.queue
2834			});
2835		}
2836	})
2837
2838})(jQuery);

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.