forum.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. [Discuz!] (C)2001-2099 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: forum.js 33824 2013-08-19 08:26:11Z nemohou $
  5. */
  6. function saveData(ignoreempty) {
  7. var ignoreempty = isUndefined(ignoreempty) ? 0 : ignoreempty;
  8. var obj = $('postform') && (($('fwin_newthread') && $('fwin_newthread').style.display == '') || ($('fwin_reply') && $('fwin_reply').style.display == '')) ? $('postform') : ($('fastpostform') ? $('fastpostform') : $('postform'));
  9. if(!obj) return;
  10. if(typeof isfirstpost != 'undefined') {
  11. if(typeof wysiwyg != 'undefined' && wysiwyg == 1) {
  12. var messageisnull = trim(html2bbcode(editdoc.body.innerHTML)) === '';
  13. } else {
  14. var messageisnull = $('postform').message.value === '';
  15. }
  16. if(isfirstpost && (messageisnull && $('postform').subject.value === '')) {
  17. return;
  18. }
  19. if(!isfirstpost && messageisnull) {
  20. return;
  21. }
  22. }
  23. var data = subject = message = '';
  24. for(var i = 0; i < obj.elements.length; i++) {
  25. var el = obj.elements[i];
  26. if(el.name != '' && (el.tagName == 'SELECT' || el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio' || el.type == 'hidden' || el.type == 'select')) && el.name.substr(0, 6) != 'attach') {
  27. var elvalue = el.value;
  28. if(el.name == 'subject') {
  29. subject = trim(elvalue);
  30. } else if(el.name == 'message') {
  31. if(typeof wysiwyg != 'undefined' && wysiwyg == 1) {
  32. elvalue = html2bbcode(editdoc.body.innerHTML);
  33. }
  34. message = trim(elvalue);
  35. }
  36. if((el.type == 'checkbox' || el.type == 'radio') && !el.checked) {
  37. continue;
  38. } else if(el.tagName == 'SELECT') {
  39. elvalue = el.value;
  40. } else if(el.type == 'hidden') {
  41. if(el.id) {
  42. eval('var check = typeof ' + el.id + '_upload == \'function\'');
  43. if(check) {
  44. elvalue = elvalue;
  45. if($(el.id + '_url')) {
  46. elvalue += String.fromCharCode(1) + $(el.id + '_url').value;
  47. }
  48. } else {
  49. continue;
  50. }
  51. } else {
  52. continue;
  53. }
  54. }
  55. if(trim(elvalue)) {
  56. data += el.name + String.fromCharCode(9) + el.tagName + String.fromCharCode(9) + el.type + String.fromCharCode(9) + elvalue + String.fromCharCode(9, 9);
  57. }
  58. }
  59. }
  60. if(!subject && !message && !ignoreempty) {
  61. return;
  62. }
  63. saveUserdata('forum_'+discuz_uid, data);
  64. }
  65. function fastUload() {
  66. appendscript(JSPATH + 'forum_post.js?' + VERHASH);
  67. safescript('forum_post_js', function () { uploadWindow(function (aid, url) {updatefastpostattach(aid, url)}, 'file') }, 100, 50);
  68. }
  69. function switchAdvanceMode(url) {
  70. var obj = $('postform') && (($('fwin_newthread') && $('fwin_newthread').style.display == '') || ($('fwin_reply') && $('fwin_reply').style.display == '')) ? $('postform') : $('fastpostform');
  71. if(obj && obj.message.value != '') {
  72. saveData();
  73. url += (url.indexOf('?') != -1 ? '&' : '?') + 'cedit=yes';
  74. }
  75. location.href = url;
  76. return false;
  77. }
  78. function sidebar_collapse(lang) {
  79. if(lang[0]) {
  80. toggle_collapse('sidebar', null, null, lang);
  81. $('wrap').className = $('wrap').className == 'wrap with_side s_clear' ? 'wrap s_clear' : 'wrap with_side s_clear';
  82. } else {
  83. var collapsed = getcookie('collapse');
  84. collapsed = updatestring(collapsed, 'sidebar', 1);
  85. setcookie('collapse', collapsed, (collapsed ? 2592000 : -2592000));
  86. location.reload();
  87. }
  88. }
  89. function keyPageScroll(e, prev, next, url, page) {
  90. if(loadUserdata('is_blindman')) {
  91. return true;
  92. }
  93. e = e ? e : window.event;
  94. var tagname = BROWSER.ie ? e.srcElement.tagName : e.target.tagName;
  95. if(tagname == 'INPUT' || tagname == 'TEXTAREA') return;
  96. actualCode = e.keyCode ? e.keyCode : e.charCode;
  97. if(next && actualCode == 39) {
  98. window.location = url + '&page=' + (page + 1);
  99. }
  100. if(prev && actualCode == 37) {
  101. window.location = url + '&page=' + (page - 1);
  102. }
  103. }
  104. function announcement() {
  105. var ann = new Object();
  106. ann.anndelay = 3000;ann.annst = 0;ann.annstop = 0;ann.annrowcount = 0;ann.anncount = 0;ann.annlis = $('anc').getElementsByTagName("li");ann.annrows = new Array();
  107. ann.announcementScroll = function () {
  108. if(this.annstop) {this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);return;}
  109. if(!this.annst) {
  110. var lasttop = -1;
  111. for(i = 0;i < this.annlis.length;i++) {
  112. if(lasttop != this.annlis[i].offsetTop) {
  113. if(lasttop == -1) lasttop = 0;
  114. this.annrows[this.annrowcount] = this.annlis[i].offsetTop - lasttop;this.annrowcount++;
  115. }
  116. lasttop = this.annlis[i].offsetTop;
  117. }
  118. if(this.annrows.length == 1) {
  119. $('an').onmouseover = $('an').onmouseout = null;
  120. } else {
  121. this.annrows[this.annrowcount] = this.annrows[1];
  122. $('ancl').innerHTML += $('ancl').innerHTML;
  123. this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
  124. $('an').onmouseover = function () {ann.annstop = 1;};
  125. $('an').onmouseout = function () {ann.annstop = 0;};
  126. }
  127. this.annrowcount = 1;
  128. return;
  129. }
  130. if(this.annrowcount >= this.annrows.length) {
  131. $('anc').scrollTop = 0;
  132. this.annrowcount = 1;
  133. this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
  134. } else {
  135. this.anncount = 0;
  136. this.announcementScrollnext(this.annrows[this.annrowcount]);
  137. }
  138. };
  139. ann.announcementScrollnext = function (time) {
  140. $('anc').scrollTop++;
  141. this.anncount++;
  142. if(this.anncount != time) {
  143. this.annst = setTimeout(function () {ann.announcementScrollnext(time);}, 10);
  144. } else {
  145. this.annrowcount++;
  146. this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
  147. }
  148. };
  149. ann.announcementScroll();
  150. }
  151. function removeindexheats() {
  152. return confirm('您确认要把此主题从热点主题中移除么?');
  153. }
  154. function showTypes(id, mod) {
  155. var o = $(id);
  156. if(!o) return false;
  157. var s = o.className;
  158. mod = isUndefined(mod) ? 1 : mod;
  159. var baseh = o.getElementsByTagName('li')[0].offsetHeight * 2;
  160. var tmph = o.offsetHeight;
  161. var lang = ['展开', '收起'];
  162. var cls = ['unfold', 'fold'];
  163. if(tmph > baseh) {
  164. var octrl = document.createElement('li');
  165. octrl.className = cls[mod];
  166. octrl.innerHTML = lang[mod];
  167. o.insertBefore(octrl, o.firstChild);
  168. o.className = s + ' cttp';
  169. mod && (o.style.height = 'auto');
  170. octrl.onclick = function () {
  171. if(this.className == cls[0]) {
  172. o.style.height = 'auto';
  173. this.className = cls[1];
  174. this.innerHTML = lang[1];
  175. } else {
  176. o.style.height = '';
  177. this.className = cls[0];
  178. this.innerHTML = lang[0];
  179. }
  180. }
  181. }
  182. }
  183. var postpt = 0;
  184. function fastpostvalidate(theform, noajaxpost) {
  185. if(postpt) {
  186. return false;
  187. }
  188. postpt = 1;
  189. setTimeout(function() {postpt = 0}, 2000);
  190. noajaxpost = !noajaxpost ? 0 : noajaxpost;
  191. s = '';
  192. if(typeof fastpostvalidateextra == 'function') {
  193. var v = fastpostvalidateextra();
  194. if(!v) {
  195. return false;
  196. }
  197. }
  198. if(theform.message.value == '' || theform.subject.value == '') {
  199. s = '抱歉,您尚未输入标题或内容';
  200. theform.message.focus();
  201. } else if(mb_strlen(theform.subject.value) > 80) {
  202. s = '您的标题超过 80 个字符的限制';
  203. theform.subject.focus();
  204. }
  205. if(!disablepostctrl && ((postminchars != 0 && mb_strlen(theform.message.value) < postminchars) || (postmaxchars != 0 && mb_strlen(theform.message.value) > postmaxchars))) {
  206. s = '您的帖子长度不符合要求。\n\n当前长度: ' + mb_strlen(theform.message.value) + ' ' + '字节\n系统限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字节';
  207. }
  208. if(s) {
  209. showError(s);
  210. doane();
  211. $('fastpostsubmit').disabled = false;
  212. return false;
  213. }
  214. $('fastpostsubmit').disabled = true;
  215. theform.message.value = theform.message.value.replace(/([^>=\]"'\/]|^)((((https?|ftp):\/\/)|www\.)([\w\-]+\.)*[\w\-\u4e00-\u9fa5]+\.([\.a-zA-Z0-9]+|\u4E2D\u56FD|\u7F51\u7EDC|\u516C\u53F8)((\?|\/|:)+[\w\.\/=\?%\-&~`@':+!]*)+\.(jpg|gif|png|bmp))/ig, '$1[img]$2[/img]');
  216. theform.message.value = parseurl(theform.message.value);
  217. if(!noajaxpost) {
  218. ajaxpost('fastpostform', 'fastpostreturn', 'fastpostreturn', 'onerror', $('fastpostsubmit'));
  219. return false;
  220. } else {
  221. return true;
  222. }
  223. }
  224. function checkpostrule(showid, extra) {
  225. var x = new Ajax();
  226. x.get('forum.php?mod=ajax&action=checkpostrule&inajax=yes&' + extra, function(s) {
  227. ajaxinnerhtml($(showid), s);evalscript(s);
  228. });
  229. }
  230. function updatefastpostattach(aid, url) {
  231. ajaxget('forum.php?mod=ajax&action=attachlist&posttime=' + $('posttime').value + (!fid ? '' : '&fid=' + fid), 'attachlist');
  232. $('attach_tblheader').style.display = '';
  233. }
  234. function succeedhandle_fastnewpost(locationhref, message, param) {
  235. location.href = locationhref;
  236. }
  237. function errorhandle_fastnewpost() {
  238. $('fastpostsubmit').disabled = false;
  239. }
  240. function atarget(obj) {
  241. obj.target = getcookie('atarget') > 0 ? '_blank' : '';
  242. }
  243. function setatarget(v) {
  244. $('atarget').className = 'y atarget_' + v;
  245. $('atarget').onclick = function() {setatarget(v == 1 ? -1 : 1);};
  246. setcookie('atarget', v, 2592000);
  247. }
  248. function loadData(quiet, formobj) {
  249. var evalevent = function (obj) {
  250. var script = obj.parentNode.innerHTML;
  251. var re = /onclick="(.+?)["|>]/ig;
  252. var matches = re.exec(script);
  253. if(matches != null) {
  254. matches[1] = matches[1].replace(/this\./ig, 'obj.');
  255. eval(matches[1]);
  256. }
  257. };
  258. var data = '';
  259. data = loadUserdata('forum_'+discuz_uid);
  260. var formobj = !formobj ? $('postform') : formobj;
  261. if(in_array((data = trim(data)), ['', 'null', 'false', null, false])) {
  262. if(!quiet) {
  263. showDialog('没有可以恢复的数据!', 'info');
  264. }
  265. return;
  266. }
  267. if(!quiet && !confirm('此操作将覆盖当前帖子内容,确定要恢复数据吗?')) {
  268. return;
  269. }
  270. var data = data.split(/\x09\x09/);
  271. for(var i = 0; i < formobj.elements.length; i++) {
  272. var el = formobj.elements[i];
  273. if(el.name != '' && (el.tagName == 'SELECT' || el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio' || el.type == 'hidden'))) {
  274. for(var j = 0; j < data.length; j++) {
  275. var ele = data[j].split(/\x09/);
  276. if(ele[0] == el.name) {
  277. elvalue = !isUndefined(ele[3]) ? ele[3] : '';
  278. if(ele[1] == 'INPUT') {
  279. if(ele[2] == 'text') {
  280. el.value = elvalue;
  281. } else if((ele[2] == 'checkbox' || ele[2] == 'radio') && ele[3] == el.value) {
  282. el.checked = true;
  283. evalevent(el);
  284. } else if(ele[2] == 'hidden') {
  285. eval('var check = typeof ' + el.id + '_upload == \'function\'');
  286. if(check) {
  287. var v = elvalue.split(/\x01/);
  288. el.value = v[0];
  289. if(el.value) {
  290. if($(el.id + '_url') && v[1]) {
  291. $(el.id + '_url').value = v[1];
  292. }
  293. eval(el.id + '_upload(\'' + v[0] + '\', \'' + v[1] + '\')');
  294. if($('unused' + v[0])) {
  295. var attachtype = $('unused' + v[0]).parentNode.parentNode.parentNode.parentNode.id.substr(11);
  296. $('unused' + v[0]).parentNode.parentNode.outerHTML = '';
  297. $('unusednum_' + attachtype).innerHTML = parseInt($('unusednum_' + attachtype).innerHTML) - 1;
  298. if($('unusednum_' + attachtype).innerHTML == 0 && $('attachnotice_' + attachtype)) {
  299. $('attachnotice_' + attachtype).style.display = 'none';
  300. }
  301. }
  302. }
  303. }
  304. }
  305. } else if(ele[1] == 'TEXTAREA') {
  306. if(ele[0] == 'message') {
  307. if(!wysiwyg) {
  308. textobj.value = elvalue;
  309. } else {
  310. editdoc.body.innerHTML = bbcode2html(elvalue);
  311. }
  312. } else {
  313. el.value = elvalue;
  314. }
  315. } else if(ele[1] == 'SELECT') {
  316. if($(el.id + '_ctrl_menu')) {
  317. var lis = $(el.id + '_ctrl_menu').getElementsByTagName('li');
  318. for(var k = 0; k < lis.length; k++) {
  319. if(ele[3] == lis[k].k_value) {
  320. lis[k].onclick();
  321. break;
  322. }
  323. }
  324. } else {
  325. for(var k = 0; k < el.options.length; k++) {
  326. if(ele[3] == el.options[k].value) {
  327. el.options[k].selected = true;
  328. break;
  329. }
  330. }
  331. }
  332. }
  333. break;
  334. }
  335. }
  336. }
  337. }
  338. if($('rstnotice')) {
  339. $('rstnotice').style.display = 'none';
  340. }
  341. extraCheckall();
  342. }
  343. var checkForumcount = 0, checkForumtimeout = 30000, checkForumnew_handle;
  344. function checkForumnew(fid, lasttime) {
  345. var timeout = checkForumtimeout;
  346. var x = new Ajax();
  347. x.get('forum.php?mod=ajax&action=forumchecknew&fid=' + fid + '&time=' + lasttime + '&inajax=yes', function(s){
  348. if(s > 0) {
  349. var table = $('separatorline').parentNode;
  350. if(!isUndefined(checkForumnew_handle)) {
  351. clearTimeout(checkForumnew_handle);
  352. }
  353. removetbodyrow(table, 'forumnewshow');
  354. var colspan = table.getElementsByTagName('tbody')[0].rows[0].children.length;
  355. var checknew = {'tid':'', 'thread':{'common':{'className':'', 'val':'<a href="javascript:void(0);" onclick="ajaxget(\'forum.php?mod=ajax&action=forumchecknew&fid=' + fid+ '&time='+lasttime+'&uncheck=1&inajax=yes\', \'forumnew\');">有新回复的主题,点击查看', 'colspan': colspan }}};
  356. addtbodyrow(table, ['tbody'], ['forumnewshow'], 'separatorline', checknew);
  357. } else {
  358. if(checkForumcount < 50) {
  359. if(checkForumcount > 0) {
  360. var multiple = Math.ceil(50 / checkForumcount);
  361. if(multiple < 5) {
  362. timeout = checkForumtimeout * (5 - multiple + 1);
  363. }
  364. }
  365. checkForumnew_handle = setTimeout(function () {checkForumnew(fid, lasttime);}, timeout);
  366. }
  367. }
  368. checkForumcount++;
  369. });
  370. }
  371. function checkForumnew_btn(fid) {
  372. if(isUndefined(fid)) return;
  373. ajaxget('forum.php?mod=ajax&action=forumchecknew&fid=' + fid+ '&time='+lasttime+'&uncheck=2&inajax=yes', 'forumnew', 'ajaxwaitid');
  374. lasttime = parseInt(Date.parse(new Date()) / 1000);
  375. }
  376. function display_blocked_thread() {
  377. var table = $('threadlisttableid');
  378. if(!table) {
  379. return;
  380. }
  381. var tbodys = table.getElementsByTagName('tbody');
  382. for(i = 0;i < tbodys.length;i++) {
  383. var tbody = tbodys[i];
  384. if(tbody.style.display == 'none') {
  385. table.appendChild(tbody);
  386. tbody.style.display = '';
  387. }
  388. }
  389. $('hiddenthread').style.display = 'none';
  390. }
  391. function addtbodyrow(table, insertID, changename, separatorid, jsonval) {
  392. if(isUndefined(table) || isUndefined(insertID[0])) {
  393. return;
  394. }
  395. var insertobj = document.createElement(insertID[0]);
  396. var thread = jsonval.thread;
  397. var tid = !isUndefined(jsonval.tid) ? jsonval.tid : '' ;
  398. if(!isUndefined(changename[1])) {
  399. removetbodyrow(table, changename[1] + tid);
  400. }
  401. insertobj.id = changename[0] + tid;
  402. if(!isUndefined(insertID[1])) {
  403. insertobj.className = insertID[1];
  404. }
  405. if($(separatorid)) {
  406. table.insertBefore(insertobj, $(separatorid).nextSibling);
  407. } else {
  408. table.insertBefore(insertobj, table.firstChild);
  409. }
  410. var newTH = insertobj.insertRow(-1);
  411. for(var value in thread) {
  412. if(value != 0) {
  413. var cell = newTH.insertCell(-1);
  414. if(isUndefined(thread[value]['val'])) {
  415. cell.innerHTML = thread[value];
  416. } else {
  417. cell.innerHTML = thread[value]['val'];
  418. }
  419. if(!isUndefined(thread[value]['className'])) {
  420. cell.className = thread[value]['className'];
  421. }
  422. if(!isUndefined(thread[value]['colspan'])) {
  423. cell.colSpan = thread[value]['colspan'];
  424. }
  425. }
  426. }
  427. if(!isUndefined(insertID[2])) {
  428. _attachEvent(insertobj, insertID[2], function() {insertobj.className = '';});
  429. }
  430. }
  431. function removetbodyrow(from, objid) {
  432. if(!isUndefined(from) && $(objid)) {
  433. from.removeChild($(objid));
  434. }
  435. }
  436. function leftside(id) {
  437. $(id).className = $(id).className == 'a' ? '' : 'a';
  438. if(id == 'lf_fav') {
  439. setcookie('leftsidefav', $(id).className == 'a' ? 0 : 1, 2592000);
  440. }
  441. }
  442. var DTimers = new Array();
  443. var DItemIDs = new Array();
  444. var DTimers_exists = false;
  445. function settimer(timer, itemid) {
  446. if(timer && itemid) {
  447. DTimers.push(timer);
  448. DItemIDs.push(itemid);
  449. }
  450. if(!DTimers_exists) {
  451. setTimeout("showtime()", 1000);
  452. DTimers_exists = true;
  453. }
  454. }
  455. function showtime() {
  456. for(i=0; i<=DTimers.length; i++) {
  457. if(DItemIDs[i]) {
  458. if(DTimers[i] == 0) {
  459. $(DItemIDs[i]).innerHTML = '已结束';
  460. DItemIDs[i] = '';
  461. continue;
  462. }
  463. var timestr = '';
  464. var timer_day = Math.floor(DTimers[i] / 86400);
  465. var timer_hour = Math.floor((DTimers[i] % 86400) / 3600);
  466. var timer_minute = Math.floor(((DTimers[i] % 86400) % 3600) / 60);
  467. var timer_second = (((DTimers[i] % 86400) % 3600) % 60);
  468. if(timer_day > 0) {
  469. timestr += timer_day + '天';
  470. }
  471. if(timer_hour > 0) {
  472. timestr += timer_hour + '小时'
  473. }
  474. if(timer_minute > 0) {
  475. timestr += timer_minute + '分'
  476. }
  477. if(timer_second > 0) {
  478. timestr += timer_second + '秒'
  479. }
  480. DTimers[i] = DTimers[i] - 1;
  481. $(DItemIDs[i]).innerHTML = timestr;
  482. }
  483. }
  484. setTimeout("showtime()", 1000);
  485. }
  486. function fixed_top_nv(eleid, disbind) {
  487. this.nv = eleid && $(eleid) || $('nv');
  488. this.openflag = this.nv && BROWSER.ie != 6;
  489. this.nvdata = {};
  490. this.init = function (disattachevent) {
  491. if(this.openflag) {
  492. if(!disattachevent) {
  493. var obj = this;
  494. _attachEvent(window, 'resize', function(){obj.reset();obj.init(1);obj.run();});
  495. var switchwidth = $('switchwidth');
  496. if(switchwidth) {
  497. _attachEvent(switchwidth, 'click', function(){obj.reset();obj.openflag=false;});
  498. }
  499. }
  500. var next = this.nv;
  501. try {
  502. while((next = next.nextSibling).nodeType != 1 || next.style.display === 'none') {}
  503. this.nvdata.next = next;
  504. this.nvdata.height = parseInt(this.nv.offsetHeight, 10);
  505. this.nvdata.width = parseInt(this.nv.offsetWidth, 10);
  506. this.nvdata.left = this.nv.getBoundingClientRect().left - document.documentElement.clientLeft;
  507. this.nvdata.position = this.nv.style.position;
  508. this.nvdata.opacity = this.nv.style.opacity;
  509. } catch (e) {
  510. this.nvdata.next = null;
  511. }
  512. }
  513. };
  514. this.run = function () {
  515. var fixedheight = 0;
  516. if(this.openflag && this.nvdata.next){
  517. var nvnexttop = document.body.scrollTop || document.documentElement.scrollTop;
  518. var dofixed = nvnexttop !== 0 && document.documentElement.clientHeight >= 15 && this.nvdata.next.getBoundingClientRect().top - this.nvdata.height < 0;
  519. if(dofixed) {
  520. if(this.nv.style.position != 'fixed') {
  521. this.nv.style.borderLeftWidth = '0';
  522. this.nv.style.borderRightWidth = '0';
  523. this.nv.style.height = this.nvdata.height + 'px';
  524. this.nv.style.width = this.nvdata.width + 'px';
  525. this.nv.style.top = '0';
  526. this.nv.style.left = this.nvdata.left + 'px';
  527. this.nv.style.position = 'fixed';
  528. this.nv.style.zIndex = '199';
  529. this.nv.style.opacity = 0.85;
  530. }
  531. } else {
  532. if(this.nv.style.position != this.nvdata.position) {
  533. this.reset();
  534. }
  535. }
  536. if(this.nv.style.position == 'fixed') {
  537. fixedheight = this.nvdata.height;
  538. }
  539. }
  540. return fixedheight;
  541. };
  542. this.reset = function () {
  543. if(this.nv) {
  544. this.nv.style.position = this.nvdata.position;
  545. this.nv.style.borderLeftWidth = '';
  546. this.nv.style.borderRightWidth = '';
  547. this.nv.style.height = '';
  548. this.nv.style.width = '';
  549. this.nv.style.opacity = this.nvdata.opacity;
  550. }
  551. };
  552. if(!disbind && this.openflag) {
  553. this.init();
  554. _attachEvent(window, 'scroll', this.run);
  555. }
  556. }
  557. var previewTbody = null, previewTid = null, previewDiv = null;
  558. function previewThread(tid, tbody) {
  559. if(!$('threadPreviewTR_'+tid)) {
  560. appendscript(JSPATH + 'forum_viewthread.js?' + VERHASH);
  561. newTr = document.createElement('tr');
  562. newTr.id = 'threadPreviewTR_'+tid;
  563. newTr.className = 'threadpre';
  564. $(tbody).appendChild(newTr);
  565. newTd = document.createElement('td');
  566. newTd.colSpan = listcolspan;
  567. newTd.className = 'threadpretd';
  568. newTr.appendChild(newTd);
  569. newTr.style.display = 'none';
  570. previewTbody = tbody;
  571. previewTid = tid;
  572. if(BROWSER.ie) {
  573. previewDiv = document.createElement('div');
  574. previewDiv.id = 'threadPreview_'+tid;
  575. previewDiv.style.id = 'none';
  576. var x = Ajax();
  577. x.get('forum.php?mod=viewthread&tid='+tid+'&inajax=1&from=preview', function(ret) {
  578. var evaled = false;
  579. if(ret.indexOf('ajaxerror') != -1) {
  580. evalscript(ret);
  581. evaled = true;
  582. }
  583. previewDiv.innerHTML = ret;
  584. newTd.appendChild(previewDiv);
  585. if(!evaled) evalscript(ret);
  586. newTr.style.display = '';
  587. });
  588. } else {
  589. newTd.innerHTML += '<div id="threadPreview_'+tid+'"></div>';
  590. ajaxget('forum.php?mod=viewthread&tid='+tid+'&from=preview', 'threadPreview_'+tid, null, null, null, function() {newTr.style.display = '';});
  591. }
  592. } else {
  593. $(tbody).removeChild($('threadPreviewTR_'+tid));
  594. previewTbody = previewTid = null;
  595. }
  596. }
  597. function hideStickThread(tid) {
  598. var pre = 'stickthread_';
  599. var tids = (new Function("return ("+(loadUserdata('sticktids') || '[]')+")"))();
  600. var format = function (data) {
  601. var str = '{';
  602. for (var i in data) {
  603. if(data[i] instanceof Array) {
  604. str += i + ':' + '[';
  605. for (var j = data[i].length - 1; j >= 0; j--) {
  606. str += data[i][j] + ',';
  607. };
  608. str = str.substr(0, str.length -1);
  609. str += '],';
  610. }
  611. }
  612. str = str.substr(0, str.length -1);
  613. str += '}';
  614. return str;
  615. };
  616. if(!tid) {
  617. if(tids.length > 0) {
  618. for (var i = tids.length - 1; i >= 0; i--) {
  619. var ele = $(pre+tids[i]);
  620. if(ele) {
  621. ele.parentNode.removeChild(ele);
  622. }
  623. };
  624. }
  625. } else {
  626. var eletbody = $(pre+tid);
  627. if(eletbody) {
  628. eletbody.parentNode.removeChild(eletbody);
  629. tids.push(tid);
  630. saveUserdata('sticktids', '['+tids.join(',')+']');
  631. }
  632. }
  633. var clearstickthread = $('clearstickthread');
  634. if(clearstickthread) {
  635. if(tids.length > 0) {
  636. $('clearstickthread').style.display = '';
  637. } else {
  638. $('clearstickthread').style.display = 'none';
  639. }
  640. }
  641. var separatorline = $('separatorline');
  642. if(separatorline) {
  643. try {
  644. if(typeof separatorline.previousElementSibling === 'undefined') {
  645. var findele = separatorline.previousSibling;
  646. while(findele && findele.nodeType != 1){
  647. findele = findele.previousSibling;
  648. }
  649. if(findele === null) {
  650. separatorline.parentNode.removeChild(separatorline);
  651. }
  652. } else {
  653. if(separatorline.previousElementSibling === null) {
  654. separatorline.parentNode.removeChild(separatorline);
  655. }
  656. }
  657. } catch(e) {
  658. }
  659. }
  660. }
  661. function viewhot() {
  662. var obj = $('hottime');
  663. window.location.href = "forum.php?mod=forumdisplay&filter=hot&fid="+obj.getAttribute('fid')+"&time="+obj.value;
  664. }
  665. function clearStickThread () {
  666. saveUserdata('sticktids', '[]');
  667. location.reload();
  668. }