PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website tin tức PHP/discuznews/static/image/admincp/cloud/qqgroup.js

https://gitlab.com/phamngsinh/baitaplon_sinhvien
JavaScript | 403 lines | 361 code | 42 blank | 0 comment | 85 complexity | 9e1a66de00f5a876011843a2b529c7ab MD5 | raw file
  1. var j = jQuery.noConflict();
  2. if (typeof disallowfloat == 'undefined' || disallowfloat === null) {
  3. var disallowfloat = '';
  4. }
  5. var currentNormalEditDisplay = 0;
  6. j(document).ready(function() {
  7. ajaxGetSearchResultThreads();
  8. j('#previewForm').submit(function() {
  9. return previewFormSubmit();
  10. });
  11. });
  12. function previewFormSubmit() {
  13. saveAllThread();
  14. if (!selectedTopicId) {
  15. alert('请推送头条信息');
  16. return false;
  17. }
  18. if (selectedNormalIds.length < 1) {
  19. alert('请至少推送一条信息到列表区域');
  20. return false;
  21. }
  22. var i = 1;
  23. for (var k = 1; k <= 5; k++) {
  24. var input_displayorder = j('#normal_thread_' + k).find('.preview_displayorder');
  25. if (input_displayorder.size()) {
  26. input_displayorder.val(i);
  27. i++;
  28. }
  29. }
  30. return true;
  31. }
  32. function initSelect() {
  33. var initTopicObj = j('#search_result .qqqun_op .qqqun_op_topon');
  34. initTopicObj.addClass('qqqun_op_top');
  35. initTopicObj.removeClass('qqqun_op_topon');
  36. var initNormalObj = j('#search_result .qqqun_op .qqqun_op_liston');
  37. initNormalObj.addClass('qqqun_op_list');
  38. initNormalObj.removeClass('qqqun_op_liston');
  39. selectedTopicId = parseInt(selectedTopicId);
  40. if (selectedTopicId) {
  41. j('#thread_addtop_' + selectedTopicId).addClass('qqqun_op_topon');
  42. j('#thread_addtop_' + selectedTopicId).removeClass('qqqun_op_top');
  43. }
  44. j.each(selectedNormalIds, function(k, v) {
  45. v = parseInt(v);
  46. if (v) {
  47. j('#thread_addlist_' + v).addClass('qqqun_op_liston');
  48. j('#thread_addlist_' + v).removeClass('qqqun_op_list');
  49. }
  50. });
  51. }
  52. function ajaxChangeSearch() {
  53. j('#srchtid').val('');
  54. ajaxGetSearchResultThreads();
  55. }
  56. function ajaxGetSearchResultThreads() {
  57. j('#search_result').html('<tr><td colspan="3">加载中...</td></tr>');
  58. qqgroupajaxpost('search_form', 'search_result', 'search_result', null, null, function() {initSelect(); return false});
  59. return false;
  60. }
  61. function ajaxGetPageResultThreads(page, mpurl) {
  62. j('#search_result').html('<tr><td colspan="3">加载中...</td></tr>');
  63. if (typeof page == 'undefined' || page === null) {
  64. page = 1;
  65. }
  66. if (typeof mpurl == 'undefined' || !mpurl) {
  67. return false;
  68. }
  69. ajaxget(mpurl + '&page=' + page, 'search_result', null, null, null, function() {initSelect();} );
  70. }
  71. function addMiniportalTop(tid) {
  72. tid = parseInt(tid);
  73. if (j.inArray(tid, selectedNormalIds) > -1) {
  74. removeNormalThreadByTid(tid);
  75. }
  76. addMiniportalTopId(tid);
  77. initSelect();
  78. ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread&tid=' + tid, 'topicDiv', null, null, null, function() { clickTopicEditor(); });
  79. }
  80. function addMiniportalTopId(tid) {
  81. selectedTopicId = tid;
  82. }
  83. function showPreviewEditor(topic, hideall) {
  84. if (hideall) {
  85. j('.qqqun_list .qqqun_editor').hide();
  86. j('.qqqun_list .qqqun_xl li').removeClass('current');
  87. j('.qqqun_list').removeClass('qqqun_list_editor');
  88. j('.qqqun_top .qqqun_editor').hide();
  89. j('.qqqun_top').removeClass('qqqun_top_editor');
  90. } else {
  91. if (topic) {
  92. j('.qqqun_list .qqqun_editor').hide();
  93. j('.qqqun_list .qqqun_xl li').removeClass('current');
  94. j('.qqqun_list').removeClass('qqqun_list_editor');
  95. j('.qqqun_top .qqqun_editor').show();
  96. j('.qqqun_top').addClass('qqqun_top_editor');
  97. } else {
  98. j('.qqqun_list .qqqun_editor').show();
  99. j('.qqqun_list').addClass('qqqun_list_editor');
  100. j('.qqqun_list .qqqun_xl li').removeClass('current');
  101. j('.qqqun_top .qqqun_editor').hide();
  102. j('.qqqun_top').removeClass('qqqun_top_editor');
  103. }
  104. }
  105. }
  106. function clickTopicEditor(topicFocus) {
  107. if (typeof topicFocus == 'undefined') {
  108. var topicFocus = 'title';
  109. }
  110. showPreviewEditor(true, false);
  111. if (topicFocus == 'title') {
  112. j('#topic-editor-input-title').addClass('pt_focus');
  113. j('#topic-editor-input-title').focus();
  114. } else if (topicFocus == 'content') {
  115. j('#topic-editor-textarea-content').addClass('pt_focus');
  116. j('#topic-editor-textarea-content').focus();
  117. }
  118. currentNormalEditDisplay = 0;
  119. }
  120. function blurTopic(obj) {
  121. var thisobj = j(obj);
  122. thisobj.removeClass('pt_focus');
  123. }
  124. function clickNormalEditor(obj) {
  125. var thisobj = j(obj);
  126. showPreviewEditor(false, false);
  127. thisobj.addClass('pt_focus');
  128. thisobj.focus();
  129. currentNormalEditDisplay = parseInt(thisobj.parent().attr('displayorder'));
  130. }
  131. function blurNormalTextarea(obj) {
  132. var thisobj = j(obj);
  133. liObj = thisobj.parent();
  134. var displayorder = parseInt(liObj.attr('displayorder'));
  135. if (displayorder == currentNormalEditDisplay) {
  136. liObj.addClass('current');
  137. }
  138. j('.qqqun_list .qqqun_xl textarea').removeClass('pt_focus');
  139. }
  140. function addMiniportalList(tid) {
  141. tid = parseInt(tid);
  142. if (j.inArray(tid, selectedNormalIds) > -1) {
  143. return false;
  144. }
  145. if (selectedNormalIds.length >= 5) {
  146. alert('推送帖子已达到5条,请在右侧取消一些再重试。');
  147. return false;
  148. }
  149. if (tid == selectedTopicId) {
  150. selectedTopicId = 0;
  151. ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread&tid=0', 'topicDiv');
  152. }
  153. addMiniportalListId(tid);
  154. initSelect();
  155. var insertPos = 'normal_thread_' + selectedNormalIds.length;
  156. ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getNormalThread&tid=' + tid, insertPos, null, null, null, function() { clickNormalEditor(j('#' + insertPos).find('textarea')); });
  157. }
  158. function addMiniportalListId(tid) {
  159. selectedNormalIds.push(tid);
  160. }
  161. function editNormalThread() {
  162. var threadLi = j('#normal_thread_' + currentNormalEditDisplay);
  163. clickNormalEditor(threadLi.find('textarea'));
  164. }
  165. function saveAllThread() {
  166. showPreviewEditor(false, true);
  167. currentNormalEditDisplay = 0;
  168. }
  169. function moveNormalThread(up) {
  170. var displayorder = currentNormalEditDisplay;
  171. var threadLi = j('#normal_thread_' + displayorder);
  172. if (!threadLi.attr('id') || !displayorder) {
  173. return false;
  174. }
  175. var newDisplayorder = 0;
  176. if (up) {
  177. newDisplayorder = displayorder - 1;
  178. } else {
  179. newDisplayorder = displayorder + 1;
  180. }
  181. if (newDisplayorder < 1 || newDisplayorder > 5) {
  182. return false;
  183. }
  184. var newLiId = 'normal_thread_' + newDisplayorder;
  185. var newThreadLi = j('#' + newLiId);
  186. if (!newThreadLi.find('textarea').size()) {
  187. return false;
  188. }
  189. var tmpHtml = newThreadLi.html();
  190. newThreadLi.html(threadLi.html());
  191. threadLi.html(tmpHtml);
  192. newThreadLi.addClass('current');
  193. threadLi.removeClass('current');
  194. currentNormalEditDisplay = newDisplayorder;
  195. }
  196. function removeTopicThread(tid) {
  197. tid = parseInt(tid);
  198. selectedTopicId = 0;
  199. initSelect();
  200. ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread', 'topicDiv', null, null, null, function() { showPreviewEditor(false, true)});
  201. }
  202. function removeNormalThread() {
  203. var displayorder = currentNormalEditDisplay;
  204. var removeTid = parseInt(j('#normal_thread_' + displayorder).find('.normal_thread_tid').val());
  205. return removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, true);
  206. }
  207. function removeNormalThreadByTid(tid) {
  208. tid = parseInt(tid);
  209. var threadInput = j('.qqqun_list .qqqun_xl .normal_thread_tid[value="' + tid + '"]');
  210. if (threadInput.size()) {
  211. var displayorder = threadInput.parent().attr('displayorder');
  212. var removeTid = tid;
  213. return removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, false);
  214. }
  215. }
  216. function removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, inNormalEditor) {
  217. displayorder = parseInt(displayorder);
  218. removeTid = parseInt(removeTid);
  219. var threadLi = j('#normal_thread_' + displayorder);
  220. if (!threadLi.attr('id') || !displayorder) {
  221. return false;
  222. }
  223. threadLi.removeClass('current');
  224. var index = j.inArray(removeTid, selectedNormalIds);
  225. if (index != -1) {
  226. selectedNormalIds.splice(index, 1);
  227. }
  228. initSelect();
  229. if (typeof inNormalEditor == 'udefined') {
  230. var inNormalEditor = false;
  231. }
  232. threadLi.slideUp(100, function() { removeNormalThreadRecall(displayorder, inNormalEditor)});
  233. }
  234. function removeNormalThreadRecall(displayorder, inNormalEditor) {
  235. for (var i = displayorder; i <= 5; i++) {
  236. var currentDisplayorder = i;
  237. var nextDisplayorder = i + 1;
  238. var currentLiId = 'normal_thread_' + currentDisplayorder;
  239. var currentThreadLi = j('#' + currentLiId);
  240. var nextLiId = 'normal_thread_' + nextDisplayorder;
  241. var nextThreadLi = j('#' + nextLiId);
  242. if (nextThreadLi.find('textarea').size()) {
  243. currentThreadLi.html(nextThreadLi.html());
  244. currentThreadLi.show();
  245. } else {
  246. currentThreadLi.html('');
  247. currentThreadLi.hide();
  248. break;
  249. }
  250. }
  251. var threadLi = j('#normal_thread_' + displayorder);
  252. var prevDisplayorder = displayorder - 1;
  253. if (threadLi.find('textarea').size()) {
  254. if (inNormalEditor) {
  255. threadLi.addClass('current');
  256. }
  257. currentNormalEditDisplay = displayorder;
  258. } else if (prevDisplayorder) {
  259. var prevThreadLi = j('#normal_thread_' + prevDisplayorder);
  260. if (inNormalEditor) {
  261. prevThreadLi.addClass('current');
  262. }
  263. currentNormalEditDisplay = prevDisplayorder;
  264. } else {
  265. var firstThreadLi = j('#normal_thread_1');
  266. if (inNormalEditor) {
  267. saveAllThread();
  268. }
  269. firstThreadLi.html('<div class="tips">点击左侧 <img src="static/image/admincp/cloud/qun_op_list.png" align="absmiddle" /> 将信息推送到列表</div>');
  270. firstThreadLi.show();
  271. }
  272. }
  273. function ajaxUploadQQGroupImage() {
  274. j('#uploadImageResult').parent().show();
  275. j('#uploadImageResult').text('图片上传中,请稍后...');
  276. qqgroupajaxpost('uploadImage', 'uploadImageResult', 'uploadImageResult', null, null, 'uploadRecall()');
  277. }
  278. function uploadRecall() {
  279. if(j('#uploadImageResult').find('#upload_msg_success').size()) {
  280. j('#uploadImageResult').parent().show();
  281. var debug_rand = Math.random();
  282. var imagePath = j('#uploadImageResult #upload_msg_imgpath').text();
  283. var imageUrl = j('#uploadImageResult #upload_msg_imgurl').text();
  284. j('#topic_image_value').val(imagePath);
  285. j('#topic_editor_thumb').attr('src', imageUrl + '?' + debug_rand);
  286. j('#topic_preview_thumb').attr('src', imageUrl + '?' + debug_rand);
  287. setTimeout(function() {hideWindow('uploadImgWin');}, 2000);
  288. }
  289. }
  290. function qqgroupajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
  291. var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
  292. var showidclass = !showidclass ? '' : showidclass;
  293. var ajaxframeid = 'ajaxframe';
  294. var ajaxframe = $(ajaxframeid);
  295. var formtarget = $(formid).target;
  296. var handleResult = function() {
  297. var s = '';
  298. var evaled = false;
  299. showloading('none');
  300. ajaxResponse = j('#' + ajaxframeid).contents().text();
  301. var regex = /<\!\[CDATA\[(.*)\]\]>/;
  302. var regexed = regex.exec(ajaxResponse);
  303. if (regexed && regexed[1]) {
  304. s = regexed[1];
  305. } else {
  306. s = ajaxResponse;
  307. }
  308. if (!s) {
  309. s = '内部错误,无法显示此内容';
  310. }
  311. if(s != '' && s.indexOf('ajaxerror') != -1) {
  312. evalscript(s);
  313. evaled = true;
  314. }
  315. if(showidclass) {
  316. if(showidclass != 'onerror') {
  317. j(showid).addClass(showidclass);
  318. } else {
  319. showError(s);
  320. ajaxerror = true;
  321. }
  322. }
  323. if(submitbtn) {
  324. j(submitbtn).attr('disabled', false);
  325. }
  326. if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  327. ajaxinnerhtml($(showid), s);
  328. }
  329. ajaxerror = null;
  330. j('#' + formid).attr('target', formtarget);
  331. if(typeof recall == 'function') {
  332. recall();
  333. } else {
  334. eval(recall);
  335. }
  336. if(!evaled) evalscript(s);
  337. ajaxframe.loading = 0;
  338. j(ajaxframe.parentNode).remove();
  339. };
  340. if(!ajaxframe) {
  341. var div = j('<div>');
  342. div.css('display', 'none');
  343. div.html('<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '" loading="1">');
  344. j('#append_parent').append(div);
  345. ajaxframe = $(ajaxframeid);
  346. } else if(ajaxframe.loading) {
  347. return false;
  348. }
  349. _attachEvent(ajaxframe, 'load', handleResult);
  350. showloading();
  351. j('#' + formid).attr('target', ajaxframeid);
  352. var action = j('#' + formid).attr('action');
  353. action = hostconvert(action);
  354. j('#' + formid).attr('action', action.replace(/\&inajax\=1/g, '')+'&inajax=1');
  355. $(formid).submit();
  356. if(submitbtn) {
  357. j(submitbtn).attr('disabled', true);
  358. }
  359. doane();
  360. return false;
  361. }