forum_post.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: forum_post.js 33695 2013-08-03 04:39:22Z nemohou $
  5. */
  6. var forum_post_inited = true;
  7. var postSubmited = false;
  8. var AID = {0:1,1:1};
  9. var UPLOADSTATUS = -1;
  10. var UPLOADFAILED = UPLOADCOMPLETE = AUTOPOST = 0;
  11. var CURRENTATTACH = '0';
  12. var FAILEDATTACHS = '';
  13. var UPLOADWINRECALL = null;
  14. var imgexts = typeof imgexts == 'undefined' ? 'jpg, jpeg, gif, png, bmp' : imgexts;
  15. var ATTACHORIMAGE = '0';
  16. var STATUSMSG = {
  17. '-1' : '内部服务器错误',
  18. '0' : '上传成功',
  19. '1' : '不支持此类扩展名',
  20. '2' : '服务器限制无法上传那么大的附件',
  21. '3' : '用户组限制无法上传那么大的附件',
  22. '4' : '不支持此类扩展名',
  23. '5' : '文件类型限制无法上传那么大的附件',
  24. '6' : '今日您已无法上传更多的附件',
  25. '7' : '请选择图片文件(' + imgexts + ')',
  26. '8' : '附件文件无法保存',
  27. '9' : '没有合法的文件被上传',
  28. '10' : '非法操作',
  29. '11' : '今日您已无法上传那么大的附件'
  30. };
  31. EXTRAFUNC['validator'] = [];
  32. function checkFocus() {
  33. var obj = wysiwyg ? editwin : textobj;
  34. if(!obj.hasfocus) {
  35. obj.focus();
  36. }
  37. }
  38. function ctlent(event) {
  39. if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83) && $('postsubmit')) {
  40. if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit', 'editsubmit']) && !validate($('postform'))) {
  41. doane(event);
  42. return;
  43. }
  44. postSubmited = true;
  45. $('postsubmit').disabled = true;
  46. $('postform').submit();
  47. }
  48. if(event.keyCode == 9) {
  49. doane(event);
  50. }
  51. }
  52. function checklength(theform) {
  53. var message = wysiwyg ? html2bbcode(getEditorContents()) : theform.message.value;
  54. if(!theform.parseurloff.checked) {
  55. message = parseurl(message);
  56. }
  57. showDialog('当前长度: ' + mb_strlen(message) + ' 字节,' + (postmaxchars != 0 ? '系统限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字节。' : ''), 'notice', '字数检查');
  58. }
  59. if(!tradepost) {
  60. var tradepost = 0;
  61. }
  62. function validate(theform) {
  63. var message = wysiwyg ? html2bbcode(getEditorContents()) : theform.message.value;
  64. if(!theform.parseurloff.checked) {
  65. message = parseurl(message);
  66. }
  67. if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {
  68. showError('抱歉,您尚未输入标题或内容');
  69. return false;
  70. } else if(mb_strlen(theform.subject.value) > 80) {
  71. showError('您的标题超过 80 个字符的限制');
  72. return false;
  73. }
  74. if(in_array($('postsubmit').name, ['topicsubmit', 'editsubmit'])) {
  75. if(theform.typeid && (theform.typeid.options && theform.typeid.options[theform.typeid.selectedIndex].value == 0) && typerequired) {
  76. showError('请选择主题对应的分类');
  77. return false;
  78. }
  79. if(theform.sortid && (theform.sortid.options && theform.sortid.options[theform.sortid.selectedIndex].value == 0) && sortrequired) {
  80. showError('请选择主题对应的分类信息');
  81. return false;
  82. }
  83. }
  84. for(i in EXTRAFUNC['validator']) {
  85. try {
  86. eval('var v = ' + EXTRAFUNC['validator'][i] + '()');
  87. if(!v) {
  88. return false;
  89. }
  90. } catch(e) {}
  91. }
  92. if(!disablepostctrl && !sortid && !special && ((postminchars != 0 && mb_strlen(message) < postminchars) || (postmaxchars != 0 && mb_strlen(message) > postmaxchars))) {
  93. showError('您的帖子长度不符合要求。\n\n当前长度: ' + mb_strlen(message) + ' 字节\n系统限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字节');
  94. return false;
  95. }
  96. if(UPLOADSTATUS == 0) {
  97. if(!confirm('您有等待上传的附件,确认不上传这些附件吗?')) {
  98. return false;
  99. }
  100. } else if(UPLOADSTATUS == 1) {
  101. showDialog('您有正在上传的附件,请稍候,上传完成后帖子将会自动发表...', 'notice');
  102. AUTOPOST = 1;
  103. return false;
  104. }
  105. if(isfirstpost && $('adddynamic') != null && $('adddynamic').checked && $('postsave') != null && isNaN(parseInt($('postsave').value)) && ($('readperm') != null && $('readperm').value || $('price') != null && $('price').value)) {
  106. if(confirm('由于您设置了阅读权限或出售帖,您确认还转播给您的听众看吗?') == false) {
  107. return false;
  108. }
  109. }
  110. theform.message.value = message;
  111. if($('postsubmit').name == 'editsubmit') {
  112. checkpostrule_post(theform);
  113. return false;
  114. } else if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit'])) {
  115. if(seccodecheck || secqaacheck) {
  116. var chk = 1, chkv = '';
  117. if(secqaacheck) {
  118. chkv = $('checksecqaaverify_' + theform.secqaahash.value).innerHTML;
  119. if(chkv.indexOf('loading') != -1) {
  120. setTimeout(function () { validate(theform); }, 100);
  121. chk = 0;
  122. } else if(chkv.indexOf('check_right') == -1) {
  123. showError('验证问答错误,请重新填写');
  124. chk = 0;
  125. }
  126. }
  127. if(seccodecheck) {
  128. chkv = $('checkseccodeverify_' + theform.seccodehash.value).innerHTML;
  129. if(chkv.indexOf('loading') !== -1) {
  130. setTimeout(function () { validate(theform); }, 100);
  131. chk = 0;
  132. } else if(chkv.indexOf('check_right') === -1) {
  133. showError('验证码错误,请重新填写');
  134. chk = 0;
  135. }
  136. }
  137. if(chk) {
  138. checkpostrule_post(theform);
  139. }
  140. } else {
  141. checkpostrule_post(theform);
  142. }
  143. return false;
  144. }
  145. }
  146. function checkpostrule_post(theform) {
  147. if(!seccodecheck && !secqaacheck && !theform.sechash) {
  148. var x = new Ajax();
  149. x.get('forum.php?mod=ajax&action=checkpostrule&ac=' + postaction + '&inajax=yes', function(s) {
  150. if(s) {
  151. ajaxinnerhtml($('seccheck'), s);
  152. evalscript(s);
  153. seccodecheck = true;
  154. } else {
  155. postsubmit(theform);
  156. }
  157. });
  158. } else {
  159. postsubmit(theform);
  160. }
  161. }
  162. function postsubmit(theform) {
  163. if($(editorid + '_attachlist')) {
  164. $('postbox').appendChild($(editorid + '_attachlist'));
  165. $(editorid + '_attachlist').style.display = 'none';
  166. }
  167. if($(editorid + '_imgattachlist')) {
  168. $('postbox').appendChild($(editorid + '_imgattachlist'));
  169. $(editorid + '_imgattachlist').style.display = 'none';
  170. }
  171. hideMenu();
  172. theform.replysubmit ? theform.replysubmit.disabled = true : (theform.editsubmit ? theform.editsubmit.disabled = true : theform.topicsubmit.disabled = true);
  173. theform.submit();
  174. }
  175. function relatekw(subject, message) {
  176. if(isUndefined(subject) || subject == -1) {
  177. subject = $('subject').value;
  178. subject = subject.replace(/<\/?[^>]+>|\[\/?.+?\]|"/ig, "");
  179. subject = subject.replace(/\s{2,}/ig, ' ');
  180. }
  181. if(isUndefined(message) || message == -1) {
  182. message = getEditorContents();
  183. message = message.replace(/<\/?[^>]+>|\[\/?.+?\]|"/ig, "");
  184. message = message.replace(/\s{2,}/ig, ' ');
  185. }
  186. subject = (BROWSER.ie && document.charset == 'utf-8' ? encodeURIComponent(subject) : subject);
  187. message = (BROWSER.ie && document.charset == 'utf-8' ? encodeURIComponent(message) : message);
  188. message = message.replace(/&/ig, '', message).substr(0, 500);
  189. ajaxget('forum.php?mod=relatekw&subjectenc=' + subject + '&messageenc=' + message, 'tagselect');
  190. }
  191. function switchicon(iconid, obj) {
  192. $('iconid').value = iconid;
  193. $('icon_img').src = obj.src;
  194. hideMenu();
  195. }
  196. function clearContent() {
  197. if(wysiwyg) {
  198. editdoc.body.innerHTML = BROWSER.firefox ? '<br />' : '';
  199. } else {
  200. textobj.value = '';
  201. }
  202. }
  203. function uploadNextAttach() {
  204. var str = $('attachframe').contentWindow.document.body.innerHTML;
  205. if(str == '') return;
  206. var arr = str.split('|');
  207. var att = CURRENTATTACH.split('|');
  208. var sizelimit = '';
  209. if(arr[4] == 'ban') {
  210. sizelimit = '(附件类型被禁止)';
  211. } else if(arr[4] == 'perday') {
  212. sizelimit = '(不能超过 ' + arr[5] + ' 字节)';
  213. } else if(arr[4] > 0) {
  214. sizelimit = '(不能超过 ' + arr[4] + ' 字节)';
  215. }
  216. uploadAttach(parseInt(att[0]), arr[0] == 'DISCUZUPLOAD' ? parseInt(arr[1]) : -1, att[1], sizelimit);
  217. }
  218. function uploadAttach(curId, statusid, prefix, sizelimit) {
  219. prefix = isUndefined(prefix) ? '' : prefix;
  220. var nextId = 0;
  221. for(var i = 0; i < AID[prefix ? 1 : 0] - 1; i++) {
  222. if($(prefix + 'attachform_' + i)) {
  223. nextId = i;
  224. if(curId == 0) {
  225. break;
  226. } else {
  227. if(i > curId) {
  228. break;
  229. }
  230. }
  231. }
  232. }
  233. if(nextId == 0) {
  234. return;
  235. }
  236. CURRENTATTACH = nextId + '|' + prefix;
  237. if(curId > 0) {
  238. if(statusid == 0) {
  239. UPLOADCOMPLETE++;
  240. } else {
  241. FAILEDATTACHS += '<br />' + mb_cutstr($(prefix + 'attachnew_' + curId).value.substr($(prefix + 'attachnew_' + curId).value.replace(/\\/g, '/').lastIndexOf('/') + 1), 25) + ': ' + STATUSMSG[statusid] + sizelimit;
  242. UPLOADFAILED++;
  243. }
  244. $(prefix + 'cpdel_' + curId).innerHTML = '<img src="' + IMGDIR + '/check_' + (statusid == 0 ? 'right' : 'error') + '.gif" alt="' + STATUSMSG[statusid] + '" />';
  245. if(nextId == curId || in_array(statusid, [6, 8])) {
  246. if(prefix == 'img') {
  247. updateImageList();
  248. } else {
  249. updateAttachList();
  250. }
  251. if(UPLOADFAILED > 0) {
  252. showDialog('附件上传完成!成功 ' + UPLOADCOMPLETE + ' 个,失败 ' + UPLOADFAILED + ' 个:' + FAILEDATTACHS);
  253. FAILEDATTACHS = '';
  254. }
  255. UPLOADSTATUS = 2;
  256. for(var i = 0; i < AID[prefix ? 1 : 0] - 1; i++) {
  257. if($(prefix + 'attachform_' + i)) {
  258. reAddAttach(prefix, i)
  259. }
  260. }
  261. $(prefix + 'uploadbtn').style.display = '';
  262. $(prefix + 'uploading').style.display = 'none';
  263. if(AUTOPOST) {
  264. hideMenu();
  265. validate($('postform'));
  266. } else if(UPLOADFAILED == 0 && (prefix == 'img' || prefix == '')) {
  267. showDialog('附件上传完成!', 'right', null, null, 0, null, null, null, null, 3);
  268. }
  269. UPLOADFAILED = UPLOADCOMPLETE = 0;
  270. CURRENTATTACH = '0';
  271. FAILEDATTACHS = '';
  272. return;
  273. }
  274. } else {
  275. $(prefix + 'uploadbtn').style.display = 'none';
  276. $(prefix + 'uploading').style.display = '';
  277. }
  278. $(prefix + 'cpdel_' + nextId).innerHTML = '<img src="' + IMGDIR + '/loading.gif" alt="上传中..." />';
  279. UPLOADSTATUS = 1;
  280. $(prefix + 'attachform_' + nextId).submit();
  281. }
  282. function addAttach(prefix) {
  283. var id = AID[prefix ? 1 : 0];
  284. var tags, newnode, i;
  285. prefix = isUndefined(prefix) ? '' : prefix;
  286. newnode = $(prefix + 'attachbtnhidden').firstChild.cloneNode(true);
  287. tags = newnode.getElementsByTagName('input');
  288. for(i = 0;i < tags.length;i++) {
  289. if(tags[i].name == 'Filedata') {
  290. tags[i].id = prefix + 'attachnew_' + id;
  291. tags[i].onchange = function() {insertAttach(prefix, id);};
  292. tags[i].unselectable = 'on';
  293. } else if(tags[i].name == 'attachid') {
  294. tags[i].value = id;
  295. }
  296. }
  297. tags = newnode.getElementsByTagName('form');
  298. tags[0].name = tags[0].id = prefix + 'attachform_' + id;
  299. $(prefix + 'attachbtn').appendChild(newnode);
  300. newnode = $(prefix + 'attachbodyhidden').firstChild.cloneNode(true);
  301. tags = newnode.getElementsByTagName('input');
  302. for(i = 0;i < tags.length;i++) {
  303. if(tags[i].name == prefix + 'localid[]') {
  304. tags[i].value = id;
  305. }
  306. }
  307. tags = newnode.getElementsByTagName('span');
  308. for(i = 0;i < tags.length;i++) {
  309. if(tags[i].id == prefix + 'localfile[]') {
  310. tags[i].id = prefix + 'localfile_' + id;
  311. } else if(tags[i].id == prefix + 'cpdel[]') {
  312. tags[i].id = prefix + 'cpdel_' + id;
  313. } else if(tags[i].id == prefix + 'localno[]') {
  314. tags[i].id = prefix + 'localno_' + id;
  315. } else if(tags[i].id == prefix + 'deschidden[]') {
  316. tags[i].id = prefix + 'deschidden_' + id;
  317. }
  318. }
  319. AID[prefix ? 1 : 0]++;
  320. newnode.style.display = 'none';
  321. $(prefix + 'attachbody').appendChild(newnode);
  322. }
  323. function insertAttach(prefix, id) {
  324. var path = $(prefix + 'attachnew_' + id).value;
  325. var extpos = path.lastIndexOf('.');
  326. var ext = extpos == -1 ? '' : path.substr(extpos + 1, path.length).toLowerCase();
  327. var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
  328. var localfile = $(prefix + 'attachnew_' + id).value.substr($(prefix + 'attachnew_' + id).value.replace(/\\/g, '/').lastIndexOf('/') + 1);
  329. var filename = mb_cutstr(localfile, 30);
  330. if(path == '') {
  331. return;
  332. }
  333. if(extensions != '' && (re.exec(extensions) == null || ext == '')) {
  334. reAddAttach(prefix, id);
  335. showError('对不起,不支持上传此类扩展名的附件。');
  336. return;
  337. }
  338. if(prefix == 'img' && imgexts.indexOf(ext) == -1) {
  339. reAddAttach(prefix, id);
  340. showError('请选择图片文件(' + imgexts + ')');
  341. return;
  342. }
  343. $(prefix + 'cpdel_' + id).innerHTML = '<a href="javascript:;" class="d" onclick="reAddAttach(\'' + prefix + '\', ' + id + ')">删除</a>';
  344. $(prefix + 'localfile_' + id).innerHTML = '<span>' + filename + '</span>';
  345. $(prefix + 'attachnew_' + id).style.display = 'none';
  346. $(prefix + 'deschidden_' + id).style.display = '';
  347. $(prefix + 'deschidden_' + id).title = localfile;
  348. $(prefix + 'localno_' + id).parentNode.parentNode.style.display = '';
  349. addAttach(prefix);
  350. UPLOADSTATUS = 0;
  351. }
  352. function reAddAttach(prefix, id) {
  353. $(prefix + 'attachbody').removeChild($(prefix + 'localno_' + id).parentNode.parentNode);
  354. $(prefix + 'attachbtn').removeChild($(prefix + 'attachnew_' + id).parentNode.parentNode);
  355. $(prefix + 'attachbody').innerHTML == '' && addAttach(prefix);
  356. $('localimgpreview_' + id) ? document.body.removeChild($('localimgpreview_' + id)) : null;
  357. }
  358. function delAttach(id, type) {
  359. var ids = {};
  360. if(typeof id == 'number') {
  361. ids[id] = id;
  362. } else {
  363. ids = id;
  364. }
  365. for(id in ids) {
  366. if($('attach_' + id)) {
  367. $('attach_' + id).style.display = 'none';
  368. ATTACHNUM['attach' + (type ? 'un' : '') + 'used']--;
  369. updateattachnum('attach');
  370. }
  371. }
  372. appendAttachDel(ids);
  373. }
  374. function delImgAttach(id, type) {
  375. var ids = {};
  376. if(typeof id == 'number') {
  377. ids[id] = id;
  378. } else {
  379. ids = id;
  380. }
  381. for(id in ids) {
  382. if($('image_td_' + id)) {
  383. $('image_td_' + id).className = 'imgdeleted';
  384. $('image_' + id).onclick = null;
  385. $('image_desc_' + id).disabled = true;
  386. ATTACHNUM['image' + (type ? 'un' : '') + 'used']--;
  387. updateattachnum('image');
  388. }
  389. }
  390. appendAttachDel(ids);
  391. }
  392. function appendAttachDel(ids) {
  393. if(!ids) {
  394. return;
  395. }
  396. var aids = '';
  397. for(id in ids) {
  398. aids += '&aids[]=' + id;
  399. }
  400. var x = new Ajax();
  401. x.get('forum.php?mod=ajax&action=deleteattach&inajax=yes&tid=' + (typeof tid == 'undefined' ? 0 : tid) + '&pid=' + (typeof pid == 'undefined' ? 0 : pid) + aids + ($('modthreadkey') ? '&modthreadkey=' + $('modthreadkey').value : ''), function() {});
  402. if($('delattachop')) {
  403. $('delattachop').value = 1;
  404. }
  405. }
  406. function updateAttach(aid) {
  407. objupdate = $('attachupdate'+aid);
  408. obj = $('attach' + aid);
  409. if(!objupdate.innerHTML) {
  410. obj.style.display = 'none';
  411. objupdate.innerHTML = '<input type="file" name="attachupdate[paid' + aid + ']"><a href="javascript:;" onclick="updateAttach(' + aid + ')">取消</a>';
  412. } else {
  413. obj.style.display = '';
  414. objupdate.innerHTML = '';
  415. }
  416. }
  417. function updateattachnum(type) {
  418. ATTACHNUM[type + 'used'] = ATTACHNUM[type + 'used'] >= 0 ? ATTACHNUM[type + 'used'] : 0;
  419. ATTACHNUM[type + 'unused'] = ATTACHNUM[type + 'unused'] >= 0 ? ATTACHNUM[type + 'unused'] : 0;
  420. var num = ATTACHNUM[type + 'used'] + ATTACHNUM[type + 'unused'];
  421. if(num) {
  422. if($(editorid + '_' + type)) {
  423. $(editorid + '_' + type).title = '包含 ' + num + (type == 'image' ? ' 个图片附件' : ' 个附件');
  424. }
  425. if($(editorid + '_' + type + 'n')) {
  426. $(editorid + '_' + type + 'n').style.display = '';
  427. }
  428. ATTACHORIMAGE = 1;
  429. } else {
  430. if($(editorid + '_' + type)) {
  431. $(editorid + '_' + type).title = type == 'image' ? '图片' : '附件';
  432. }
  433. if($(editorid + '_' + type + 'n')) {
  434. $(editorid + '_' + type + 'n').style.display = 'none';
  435. }
  436. }
  437. }
  438. function swfHandler(action, type) {
  439. if(action == 2) {
  440. if(type == 'image') {
  441. updateImageList();
  442. } else {
  443. updateAttachList();
  444. }
  445. }
  446. }
  447. function updateAttachList(action, aids) {
  448. ajaxget('forum.php?mod=ajax&action=attachlist' + (!action ? '&posttime=' + $('posttime').value : (!aids ? '' : '&aids=' + aids)) + (!fid ? '' : '&fid=' + fid), 'attachlist');
  449. switchAttachbutton('attachlist');$('attach_tblheader').style.display = $('attach_notice').style.display = '';
  450. }
  451. function updateImageList(action, aids) {
  452. ajaxget('forum.php?mod=ajax&action=imagelist' + (!action ? '&pid=' + pid + '&posttime=' + $('posttime').value : (!aids ? '' : '&aids=' + aids)) + (!fid ? '' : '&fid=' + fid), 'imgattachlist');
  453. switchImagebutton('imgattachlist');$('imgattach_notice').style.display = '';
  454. }
  455. function updateDownImageList(msg) {
  456. hideMenu('fwin_dialog', 'dialog');
  457. if(msg == '') {
  458. showError('抱歉,暂无远程附件');
  459. } else {
  460. ajaxget('forum.php?mod=ajax&action=imagelist&pid=' + pid + '&posttime=' + $('posttime').value + (!fid ? '' : '&fid=' + fid), 'imgattachlist', null, null, null, function(){if(wysiwyg) {editdoc.body.innerHTML = msg;switchEditor(0);switchEditor(1)} else {textobj.value = msg;}});
  461. switchImagebutton('imgattachlist');$('imgattach_notice').style.display = '';
  462. showDialog('远程附件下载完成!', 'right', null, null, 0, null, null, null, null, 3);
  463. }
  464. }
  465. function switchButton(btn, type) {
  466. var btnpre = editorid + '_btn_';
  467. if(!$(btnpre + btn) || !$(editorid + '_' + btn)) {
  468. return;
  469. }
  470. var tabs = $(editorid + '_' + type + '_ctrl').getElementsByTagName('LI');
  471. $(btnpre + btn).style.display = '';
  472. $(editorid + '_' + btn).style.display = '';
  473. $(btnpre + btn).className = 'current';
  474. var btni = '';
  475. for(i = 0;i < tabs.length;i++) {
  476. if(tabs[i].id.indexOf(btnpre) !== -1) {
  477. btni = tabs[i].id.substr(btnpre.length);
  478. }
  479. if(btni != btn) {
  480. if(!$(editorid + '_' + btni) || !$(editorid + '_btn_' + btni)) {
  481. continue;
  482. }
  483. $(editorid + '_' + btni).style.display = 'none';
  484. $(editorid + '_btn_' + btni).className = '';
  485. }
  486. }
  487. }
  488. function uploadWindowstart() {
  489. $('uploadwindowing').style.visibility = 'visible';
  490. }
  491. function uploadWindowload() {
  492. $('uploadwindowing').style.visibility = 'hidden';
  493. var str = $('uploadattachframe').contentWindow.document.body.innerHTML;
  494. if(str == '') return;
  495. var arr = str.split('|');
  496. if(arr[0] == 'DISCUZUPLOAD' && arr[2] == 0) {
  497. UPLOADWINRECALL(arr[3], arr[5], arr[6]);
  498. hideWindow('upload', 0);
  499. } else {
  500. var sizelimit = '';
  501. if(arr[7] == 'ban') {
  502. sizelimit = '(附件类型被禁止)';
  503. } else if(arr[7] == 'perday') {
  504. sizelimit = '(不能超过 ' + arr[8] + ' 字节)';
  505. } else if(arr[7] > 0) {
  506. sizelimit = '(不能超过 ' + arr[7] + ' 字节)';
  507. }
  508. showError(STATUSMSG[arr[2]] + sizelimit);
  509. }
  510. if($('attachlimitnotice')) {
  511. ajaxget('forum.php?mod=ajax&action=updateattachlimit&fid=' + fid, 'attachlimitnotice');
  512. }
  513. }
  514. function uploadWindow(recall, type) {
  515. var type = isUndefined(type) ? 'image' : type;
  516. UPLOADWINRECALL = recall;
  517. var fid = (typeof fid == 'undefined' ? '2' : fid);
  518. showWindow('upload', 'forum.php?mod=misc&action=upload&fid=' + fid + '&type=' + type, 'get', 0, {'zindex':601});
  519. }
  520. function updatetradeattach(aid, url, attachurl) {
  521. $('tradeaid').value = aid;
  522. $('tradeattach_image').innerHTML = '<img src="' + attachurl + '/' + url + '" class="spimg" />';
  523. ATTACHORIMAGE = 1;
  524. }
  525. function updateactivityattach(aid, url, attachurl) {
  526. $('activityaid').value = aid;
  527. $('activityattach_image').innerHTML = '<img src="' + attachurl + '/' + url + '" class="spimg" />';
  528. ATTACHORIMAGE = 1;
  529. }
  530. function updatesortattach(aid, url, attachurl, identifier) {
  531. $('sortaid_' + identifier).value = aid;
  532. $('sortattachurl_' + identifier).value = attachurl + '/' + url;
  533. $('sortattach_image_' + identifier).innerHTML = '<img src="' + attachurl + '/' + url + '" class="spimg" />';
  534. ATTACHORIMAGE = 1;
  535. }
  536. function switchpollm(swt) {
  537. t = $('pollchecked').checked && swt ? 2 : 1;
  538. var v = '';
  539. for(var i = 0; i < $('postform').elements.length; i++) {
  540. var e = $('postform').elements[i];
  541. if(!isUndefined(e.name)) {
  542. if(e.name.match('^polloption')) {
  543. if(t == 2 && e.tagName == 'INPUT') {
  544. v += e.value + '\n';
  545. } else if(t == 1 && e.tagName == 'TEXTAREA') {
  546. v += e.value;
  547. }
  548. }
  549. }
  550. }
  551. if(t == 1) {
  552. var a = v.split('\n');
  553. var pcount = 0;
  554. for(var i = 0; i < $('postform').elements.length; i++) {
  555. var e = $('postform').elements[i];
  556. if(!isUndefined(e.name)) {
  557. if(e.name.match('^polloption')) {
  558. pcount++;
  559. if(e.tagName == 'INPUT') e.value = '';
  560. }
  561. }
  562. }
  563. for(var i = 0; i < a.length - pcount + 2; i++) {
  564. addpolloption();
  565. }
  566. var ii = 0;
  567. for(var i = 0; i < $('postform').elements.length; i++) {
  568. var e = $('postform').elements[i];
  569. if(!isUndefined(e.name)) {
  570. if(e.name.match('^polloption') && e.tagName == 'INPUT' && a[ii]) {
  571. e.value = a[ii++];
  572. }
  573. }
  574. }
  575. } else if(t == 2) {
  576. $('postform').polloptions.value = trim(v);
  577. }
  578. $('postform').tpolloption.value = t;
  579. if(swt) {
  580. display('pollm_c_1');
  581. display('pollm_c_2');
  582. }
  583. }
  584. function addpolloption() {
  585. if(curoptions < maxoptions) {
  586. var imgid = 'newpoll_'+curnumber;
  587. var proid = 'pollUploadProgress_'+curnumber;
  588. var pollstr = $('polloption_hidden').innerHTML.replace('newpoll', imgid);
  589. pollstr = pollstr.replace('pollUploadProgress', proid);
  590. $('polloption_new').outerHTML = '<p>' + pollstr + '</p>' + $('polloption_new').outerHTML;
  591. curoptions++;
  592. curnumber++;
  593. addUploadEvent(imgid, proid)
  594. } else {
  595. $('polloption_new').outerHTML = '<span>已达到最大投票数'+maxoptions+'</span>';
  596. }
  597. }
  598. function delpolloption(obj) {
  599. obj.parentNode.parentNode.removeChild(obj.parentNode);
  600. curoptions--;
  601. }
  602. function insertsave(pid) {
  603. var x = new Ajax();
  604. x.get('forum.php?mod=misc&action=loadsave&inajax=yes&pid=' + pid + '&type=' + wysiwyg, function(str, x) {
  605. insertText(str, str.length, 0);
  606. });
  607. }
  608. function userdataoption(op) {
  609. if(!op) {
  610. saveUserdata('forum_'+discuz_uid, '');
  611. display('rstnotice');
  612. } else {
  613. loadData();
  614. checkFocus();
  615. }
  616. doane();
  617. }
  618. function attachoption(type, op) {
  619. if(!op) {
  620. if(type == 'attach') {
  621. delAttach(ATTACHUNUSEDAID, 1);
  622. ATTACHNUM['attachunused'] = 0;
  623. display('attachnotice_attach');
  624. } else {
  625. delImgAttach(IMGUNUSEDAID, 1);
  626. ATTACHNUM['imageunused'] = 0;
  627. display('attachnotice_img');
  628. }
  629. } else if(op == 1) {
  630. var obj = $('unusedwin') ? $('unusedwin') : $('unusedlist_' + type);
  631. list = obj.getElementsByTagName('INPUT'), aids = '';
  632. for(i = 0;i < list.length;i++) {
  633. if(list[i].name.match('unused') && list[i].checked) {
  634. aids += '|' + list[i].value;
  635. }
  636. }
  637. if(aids) {
  638. if(type == 'attach') {
  639. updateAttachList(1, aids);
  640. } else {
  641. list = $('imgattachlist').getElementsByTagName('TD');
  642. re = /^image\_td\_(\d+)$/;
  643. for(i = 0;i < list.length;i++) {
  644. var matches = re.exec(list[i].id);
  645. if(matches != null) {
  646. aids += '|' + matches[1];
  647. }
  648. }
  649. updateImageList(1, aids);
  650. }
  651. }
  652. display('attachnotice_' + type);
  653. } else if(op == 2) {
  654. showDialog('<div id="unusedwin" class="c altw" style="overflow:auto;height:100px;">' + $('unusedlist_' + type).innerHTML + '</div>' +
  655. '<p class="o pns"><span class="z xg1"><label for="unusedwinchkall"><input id="unusedwinchkall" type="checkbox" onclick="attachoption(\'' + type + '\', 3)" checked="checked" />全选</label></span>' +
  656. '<button onclick="attachoption(\'' + type + '\', 1);hideMenu(\'fwin_dialog\', \'dialog\')" class="pn pnc"><strong>使用</strong></button></p>', 'info', '未使用的' + (type == 'attach' ? '附件' : '图片'));
  657. } else if(op == 3) {
  658. list = $('unusedwin').getElementsByTagName('INPUT');
  659. for(i = 0;i < list.length;i++) {
  660. if(list[i].name.match('unused')) {
  661. list[i].checked = $('unusedwinchkall').checked;
  662. }
  663. }
  664. return;
  665. }
  666. doane();
  667. }
  668. function insertAttachTag(aid) {
  669. var txt = '[attach]' + aid + '[/attach]';
  670. seditor_insertunit('fastpost', txt);
  671. }
  672. function insertAttachimgTag(aid) {
  673. var txt = '[attachimg]' + aid + '[/attachimg]';
  674. seditor_insertunit('fastpost', txt);
  675. }
  676. function insertText(str) {
  677. seditor_insertunit('fastpost', str);
  678. }
  679. function insertAllAttachTag() {
  680. var attachListObj = $('e_attachlist').getElementsByTagName("tbody");
  681. for(var i in attachListObj) {
  682. if(typeof attachListObj[i] == "object") {
  683. var attach = attachListObj[i];
  684. var ids = attach.id.split('_');
  685. if(ids[0] == 'attach') {
  686. if($('attachname'+ids[1]) && attach.style.display != 'none') {
  687. if(parseInt($('attachname'+ids[1]).getAttribute('isimage'))) {
  688. insertAttachimgTag(ids[1]);
  689. } else {
  690. insertAttachTag(ids[1]);
  691. }
  692. var txt = wysiwyg ? '\r\n<br/><br/>\r\n' : '\r\n\r\n';
  693. insertText(txt, strlen(txt), 0);
  694. }
  695. }
  696. }
  697. }
  698. doane();
  699. }
  700. function selectAllSaveImg(state) {
  701. var inputListObj = $('imgattachlist').getElementsByTagName("input");
  702. for(i in inputListObj) {
  703. if(typeof inputListObj[i] == "object" && inputListObj[i].id) {
  704. var inputObj = inputListObj[i];
  705. var ids = inputObj.id.split('_');
  706. if(ids[0] == 'albumaidchk' && $('image_td_' + ids[1]).className != 'imgdeleted' && inputObj.checked != state) {
  707. inputObj.click();
  708. }
  709. }
  710. }
  711. }
  712. function showExtra(id) {
  713. if ($(id+'_c').style.display == 'block') {
  714. $(id+'_b').className = 'pn z';
  715. $(id+'_c').style.display = 'none';
  716. } else {
  717. var extraButton = $('post_extra_tb').getElementsByTagName('label');
  718. var extraForm = $('post_extra_c').getElementsByTagName('div');
  719. for (i=0;i<extraButton.length;i++) {
  720. extraButton[i].className = '';
  721. }
  722. for (i=0;i<extraForm.length;i++) {
  723. if(hasClass(extraForm[i],'exfm')) {
  724. extraForm[i].style.display = 'none';
  725. }
  726. }
  727. for (i=0;i<extraForm.length;i++) {
  728. if(hasClass(extraForm[i],'exfm')) {
  729. extraForm[i].style.display = 'none';
  730. }
  731. }
  732. $(id+'_b').className = 'a';
  733. $(id+'_c').style.display = 'block';
  734. }
  735. }
  736. function extraCheck(op) {
  737. if(!op && $('extra_replycredit_chk')) {
  738. $('extra_replycredit_chk').className = $('replycredit_extcredits').value > 0 && $('replycredit_times').value > 0 ? 'a' : '';
  739. } else if(op == 1 && $('readperm')) {
  740. $('extra_readperm_chk').className = $('readperm').value !== '' ? 'a' : '';
  741. } else if(op == 2 && $('price')) {
  742. $('extra_price_chk').className = $('price').value > 0 ? 'a' : '';
  743. } else if(op == 3 && $('rushreply')) {
  744. $('extra_rushreplyset_chk').className = $('rushreply').checked ? 'a' : '';
  745. } else if(op == 4 && $('tags')) {
  746. $('extra_tag_chk').className = $('tags').value !== '' ? 'a' : '';
  747. } else if(op == 5 && $('cronpublish')) {
  748. $('extra_pubdate_chk').className = $('cronpublish').checked ? 'a' : '';
  749. }
  750. }
  751. function hidenFollowBtn(flag) {
  752. var fobj = $('adddynamicspan');
  753. if(fobj) {
  754. if(flag) {
  755. $('adddynamic').checked = !flag;
  756. fobj.style.display = 'none';
  757. } else {
  758. fobj.style.display = '';
  759. }
  760. }
  761. }
  762. function getreplycredit() {
  763. var replycredit_extcredits = $('replycredit_extcredits');
  764. var replycredit_times = $('replycredit_times');
  765. var credit_once = parseInt(replycredit_extcredits.value) > 0 ? parseInt(replycredit_extcredits.value) : 0;
  766. var times = parseInt(replycredit_times.value) > 0 ? parseInt(replycredit_times.value) : 0;
  767. if(parseInt(credit_once * times) - have_replycredit > 0) {
  768. var real_reply_credit = Math.ceil(parseInt(credit_once * times) - have_replycredit + ((parseInt(credit_once * times) - have_replycredit) * creditstax));
  769. } else {
  770. var real_reply_credit = Math.ceil(parseInt(credit_once * times) - have_replycredit);
  771. }
  772. var reply_credits_sum = Math.ceil(parseInt(credit_once * times));
  773. if(real_reply_credit > userextcredit) {
  774. $('replycredit').innerHTML = '<b class="xi1">回帖奖励积分总额过大('+real_reply_credit+')</b>';
  775. } else {
  776. if(have_replycredit > 0 && real_reply_credit < 0) {
  777. $('replycredit').innerHTML = "<font class='xi1'>返还"+Math.abs(real_reply_credit)+"</font>";
  778. } else {
  779. $('replycredit').innerHTML = replycredit_result_lang + (real_reply_credit > 0 ? real_reply_credit : 0 );
  780. }
  781. $('replycredit_sum').innerHTML = reply_credits_sum > 0 ? reply_credits_sum : 0 ;
  782. }
  783. }
  784. function extraCheckall() {
  785. for(i = 0;i < 5;i++) {
  786. extraCheck(i);
  787. }
  788. }
  789. function deleteThread() {
  790. if(confirm('确定要删除该帖子吗?') != 0){
  791. $('delete').value = '1';
  792. $('postform').submit();
  793. }
  794. }
  795. function hideAttachMenu(id) {
  796. if($(editorid + '_' + id + '_menu')) {
  797. $(editorid + '_' + id + '_menu').style.visibility = 'hidden';
  798. }
  799. }