-
Notifications
You must be signed in to change notification settings - Fork 0
/
forum.js?HyH
451 lines (417 loc) · 14.9 KB
/
forum.js?HyH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
/*
[Discuz!] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: forum.js 28137 2012-02-23 03:28:22Z zhengqingpeng $
*/
function saveData(ignoreempty) {
var ignoreempty = isUndefined(ignoreempty) ? 0 : ignoreempty;
var obj = $('postform') && (($('fwin_newthread') && $('fwin_newthread').style.display == '') || ($('fwin_reply') && $('fwin_reply').style.display == '')) ? $('postform') : ($('fastpostform') ? $('fastpostform') : $('postform'));
if(!obj) return;
if(typeof isfirstpost != 'undefined') {
if(typeof wysiwyg != 'undefined' && wysiwyg == 1) {
var messageisnull = trim(html2bbcode(editdoc.body.innerHTML)) === '';
} else {
var messageisnull = $('postform').message.value === '';
}
if(isfirstpost && (messageisnull && $('postform').subject.value === '')) {
return;
}
if(!isfirstpost && messageisnull) {
return;
}
}
var data = subject = message = '';
for(var i = 0; i < obj.elements.length; i++) {
var el = obj.elements[i];
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') {
var elvalue = el.value;
if(el.name == 'subject') {
subject = trim(elvalue);
} else if(el.name == 'message') {
if(typeof wysiwyg != 'undefined' && wysiwyg == 1) {
elvalue = html2bbcode(editdoc.body.innerHTML);
}
message = trim(elvalue);
}
if((el.type == 'checkbox' || el.type == 'radio') && !el.checked) {
continue;
} else if(el.tagName == 'SELECT') {
elvalue = el.value;
} else if(el.type == 'hidden') {
if(el.id) {
eval('var check = typeof ' + el.id + '_upload == \'function\'');
if(check) {
elvalue = elvalue;
if($(el.id + '_url')) {
elvalue += String.fromCharCode(1) + $(el.id + '_url').value;
}
} else {
continue;
}
} else {
continue;
}
}
if(trim(elvalue)) {
data += el.name + String.fromCharCode(9) + el.tagName + String.fromCharCode(9) + el.type + String.fromCharCode(9) + elvalue + String.fromCharCode(9, 9);
}
}
}
if(!subject && !message && !ignoreempty) {
return;
}
saveUserdata('forum_'+discuz_uid, data);
}
function fastUload() {
appendscript(JSPATH + 'forum_post.js?' + VERHASH);
safescript('forum_post_js', function () { uploadWindow(function (aid, url) {updatefastpostattach(aid, url)}, 'file') }, 100, 50);
}
function switchAdvanceMode(url) {
var obj = $('postform') && (($('fwin_newthread') && $('fwin_newthread').style.display == '') || ($('fwin_reply') && $('fwin_reply').style.display == '')) ? $('postform') : $('fastpostform');
if(obj && obj.message.value != '') {
saveData();
url += (url.indexOf('?') != -1 ? '&' : '?') + 'cedit=yes';
}
location.href = url;
return false;
}
function sidebar_collapse(lang) {
if(lang[0]) {
toggle_collapse('sidebar', null, null, lang);
$('wrap').className = $('wrap').className == 'wrap with_side s_clear' ? 'wrap s_clear' : 'wrap with_side s_clear';
} else {
var collapsed = getcookie('collapse');
collapsed = updatestring(collapsed, 'sidebar', 1);
setcookie('collapse', collapsed, (collapsed ? 2592000 : -2592000));
location.reload();
}
}
function keyPageScroll(e, prev, next, url, page) {
e = e ? e : window.event;
var tagname = BROWSER.ie ? e.srcElement.tagName : e.target.tagName;
if(tagname == 'INPUT' || tagname == 'TEXTAREA') return;
actualCode = e.keyCode ? e.keyCode : e.charCode;
if(next && actualCode == 39) {
window.location = url + '&page=' + (page + 1);
}
if(prev && actualCode == 37) {
window.location = url + '&page=' + (page - 1);
}
}
function announcement() {
var ann = new Object();
ann.anndelay = 3000;ann.annst = 0;ann.annstop = 0;ann.annrowcount = 0;ann.anncount = 0;ann.annlis = $('anc').getElementsByTagName("li");ann.annrows = new Array();
ann.announcementScroll = function () {
if(this.annstop) {this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);return;}
if(!this.annst) {
var lasttop = -1;
for(i = 0;i < this.annlis.length;i++) {
if(lasttop != this.annlis[i].offsetTop) {
if(lasttop == -1) lasttop = 0;
this.annrows[this.annrowcount] = this.annlis[i].offsetTop - lasttop;this.annrowcount++;
}
lasttop = this.annlis[i].offsetTop;
}
if(this.annrows.length == 1) {
$('an').onmouseover = $('an').onmouseout = null;
} else {
this.annrows[this.annrowcount] = this.annrows[1];
$('ancl').innerHTML += $('ancl').innerHTML;
this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
$('an').onmouseover = function () {ann.annstop = 1;};
$('an').onmouseout = function () {ann.annstop = 0;};
}
this.annrowcount = 1;
return;
}
if(this.annrowcount >= this.annrows.length) {
$('anc').scrollTop = 0;
this.annrowcount = 1;
this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
} else {
this.anncount = 0;
this.announcementScrollnext(this.annrows[this.annrowcount]);
}
};
ann.announcementScrollnext = function (time) {
$('anc').scrollTop++;
this.anncount++;
if(this.anncount != time) {
this.annst = setTimeout(function () {ann.announcementScrollnext(time);}, 10);
} else {
this.annrowcount++;
this.annst = setTimeout(function () {ann.announcementScroll();}, this.anndelay);
}
};
ann.announcementScroll();
}
function removeindexheats() {
return confirm('您确认要把此主题从热点主题中移除么?');
}
function showTypes(id, mod) {
var o = $(id);
if(!o) return false;
var s = o.className;
mod = isUndefined(mod) ? 1 : mod;
var baseh = o.getElementsByTagName('li')[0].offsetHeight * 2;
var tmph = o.offsetHeight;
var lang = ['展开', '收起'];
var cls = ['unfold', 'fold'];
if(tmph > baseh) {
var octrl = document.createElement('li');
octrl.className = cls[mod];
octrl.innerHTML = lang[mod];
o.insertBefore(octrl, o.firstChild);
o.className = s + ' cttp';
mod && (o.style.height = 'auto');
octrl.onclick = function () {
if(this.className == cls[0]) {
o.style.height = 'auto';
this.className = cls[1];
this.innerHTML = lang[1];
} else {
o.style.height = '';
this.className = cls[0];
this.innerHTML = lang[0];
}
}
}
}
var postpt = 0;
function fastpostvalidate(theform, noajaxpost) {
if(postpt) {
return false;
}
postpt = 1;
setTimeout(function() {postpt = 0}, 2000);
noajaxpost = !noajaxpost ? 0 : noajaxpost;
s = '';
if(typeof fastpostvalidateextra == 'function') {
var v = fastpostvalidateextra();
if(!v) {
return false;
}
}
if(theform.message.value == '' || theform.subject.value == '') {
s = '抱歉,您尚未输入标题或内容';
theform.message.focus();
} else if(mb_strlen(theform.subject.value) > 80) {
s = '您的标题超过 80 个字符的限制';
theform.subject.focus();
}
if(!disablepostctrl && ((postminchars != 0 && mb_strlen(theform.message.value) < postminchars) || (postmaxchars != 0 && mb_strlen(theform.message.value) > postmaxchars))) {
s = '您的帖子长度不符合要求。\n\n当前长度: ' + mb_strlen(theform.message.value) + ' ' + '字节\n系统限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字节';
}
if(s) {
showError(s);
doane();
$('fastpostsubmit').disabled = false;
return false;
}
$('fastpostsubmit').disabled = true;
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]');
theform.message.value = parseurl(theform.message.value);
if(!noajaxpost) {
ajaxpost('fastpostform', 'fastpostreturn', 'fastpostreturn', 'onerror', $('fastpostsubmit'));
return false;
} else {
return true;
}
}
function updatefastpostattach(aid, url) {
ajaxget('forum.php?mod=ajax&action=attachlist&posttime=' + $('posttime').value + (!fid ? '' : '&fid=' + fid), 'attachlist');
$('attach_tblheader').style.display = '';
}
function succeedhandle_fastnewpost(locationhref, message, param) {
location.href = locationhref;
}
function errorhandle_fastnewpost() {
$('fastpostsubmit').disabled = false;
}
function atarget(obj) {
obj.target = getcookie('atarget') > 0 ? '_blank' : '';
}
function setatarget(v) {
$('atarget').className = 'y atarget_' + v;
$('atarget').onclick = function() {setatarget(v == 1 ? -1 : 1);};
setcookie('atarget', v, 2592000);
}
function loadData(quiet, formobj) {
var evalevent = function (obj) {
var script = obj.parentNode.innerHTML;
var re = /onclick="(.+?)["|>]/ig;
var matches = re.exec(script);
if(matches != null) {
matches[1] = matches[1].replace(/this\./ig, 'obj.');
eval(matches[1]);
}
};
var data = '';
data = loadUserdata('forum_'+discuz_uid);
var formobj = !formobj ? $('postform') : formobj;
if(in_array((data = trim(data)), ['', 'null', 'false', null, false])) {
if(!quiet) {
showDialog('没有可以恢复的数据!', 'info');
}
return;
}
if(!quiet && !confirm('此操作将覆盖当前帖子内容,确定要恢复数据吗?')) {
return;
}
var data = data.split(/\x09\x09/);
for(var i = 0; i < formobj.elements.length; i++) {
var el = formobj.elements[i];
if(el.name != '' && (el.tagName == 'SELECT' || el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio' || el.type == 'hidden'))) {
for(var j = 0; j < data.length; j++) {
var ele = data[j].split(/\x09/);
if(ele[0] == el.name) {
elvalue = !isUndefined(ele[3]) ? ele[3] : '';
if(ele[1] == 'INPUT') {
if(ele[2] == 'text') {
el.value = elvalue;
} else if((ele[2] == 'checkbox' || ele[2] == 'radio') && ele[3] == el.value) {
el.checked = true;
evalevent(el);
} else if(ele[2] == 'hidden') {
eval('var check = typeof ' + el.id + '_upload == \'function\'');
if(check) {
var v = elvalue.split(/\x01/);
el.value = v[0];
if(el.value) {
if($(el.id + '_url') && v[1]) {
$(el.id + '_url').value = v[1];
}
eval(el.id + '_upload(\'' + v[0] + '\', \'' + v[1] + '\')');
if($('unused' + v[0])) {
var attachtype = $('unused' + v[0]).parentNode.parentNode.parentNode.parentNode.id.substr(11);
$('unused' + v[0]).parentNode.parentNode.outerHTML = '';
$('unusednum_' + attachtype).innerHTML = parseInt($('unusednum_' + attachtype).innerHTML) - 1;
if($('unusednum_' + attachtype).innerHTML == 0 && $('attachnotice_' + attachtype)) {
$('attachnotice_' + attachtype).style.display = 'none';
}
}
}
}
}
} else if(ele[1] == 'TEXTAREA') {
if(ele[0] == 'message') {
if(!wysiwyg) {
textobj.value = elvalue;
} else {
editdoc.body.innerHTML = bbcode2html(elvalue);
}
} else {
el.value = elvalue;
}
} else if(ele[1] == 'SELECT') {
if($(el.id + '_ctrl_menu')) {
var lis = $(el.id + '_ctrl_menu').getElementsByTagName('li');
for(var k = 0; k < lis.length; k++) {
if(ele[3] == lis[k].k_value) {
lis[k].onclick();
break;
}
}
} else {
for(var k = 0; k < el.options.length; k++) {
if(ele[3] == el.options[k].value) {
el.options[k].selected = true;
break;
}
}
}
}
break;
}
}
}
}
if($('rstnotice')) {
$('rstnotice').style.display = 'none';
}
extraCheckall();
}
var checkForumcount = 0, checkForumtimeout = 30000, checkForumnew_handle;
function checkForumnew(fid, lasttime) {
var timeout = checkForumtimeout;
var x = new Ajax();
x.get('forum.php?mod=ajax&action=forumchecknew&fid=' + fid + '&time=' + lasttime + '&inajax=yes', function(s){
if(s > 0) {
var table = $('separatorline').parentNode;
if(!isUndefined(checkForumnew_handle)) {
clearTimeout(checkForumnew_handle);
}
removetbodyrow(table, 'forumnewshow');
var colspan = table.getElementsByTagName('tbody')[0].rows[0].children.length;
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 }}};
addtbodyrow(table, ['tbody'], ['forumnewshow'], 'separatorline', checknew);
} else {
if(checkForumcount < 50) {
if(checkForumcount > 0) {
var multiple = Math.ceil(50 / checkForumcount);
if(multiple < 5) {
timeout = checkForumtimeout * (5 - multiple + 1);
}
}
checkForumnew_handle = setTimeout(function () {checkForumnew(fid, lasttime);}, timeout);
}
}
checkForumcount++;
});
}
function checkForumnew_btn(fid) {
if(isUndefined(fid)) return;
ajaxget('forum.php?mod=ajax&action=forumchecknew&fid=' + fid+ '&time='+lasttime+'&uncheck=2&inajax=yes', 'forumnew', 'ajaxwaitid');
lasttime = parseInt(Date.parse(new Date()) / 1000);
}
function addtbodyrow (table, insertID, changename, separatorid, jsonval) {
if(isUndefined(table) || isUndefined(insertID[0])) {
return;
}
var insertobj = document.createElement(insertID[0]);
var thread = jsonval.thread;
var tid = !isUndefined(jsonval.tid) ? jsonval.tid : '' ;
if(!isUndefined(changename[1])) {
removetbodyrow(table, changename[1] + tid);
}
insertobj.id = changename[0] + tid;
if(!isUndefined(insertID[1])) {
insertobj.className = insertID[1];
}
if($(separatorid)) {
table.insertBefore(insertobj, $(separatorid).nextSibling);
} else {
table.insertBefore(insertobj, table.firstChild);
}
var newTH = insertobj.insertRow(-1);
for(var value in thread) {
if(value != 0) {
var cell = newTH.insertCell(-1);
if(isUndefined(thread[value]['val'])) {
cell.innerHTML = thread[value];
} else {
cell.innerHTML = thread[value]['val'];
}
if(!isUndefined(thread[value]['className'])) {
cell.className = thread[value]['className'];
}
if(!isUndefined(thread[value]['colspan'])) {
cell.colSpan = thread[value]['colspan'];
}
}
}
if(!isUndefined(insertID[2])) {
_attachEvent(insertobj, insertID[2], function() {insertobj.className = '';});
}
}
function removetbodyrow(from, objid) {
if(!isUndefined(from) && $(objid)) {
from.removeChild($(objid));
}
}
function leftside(id) {
$(id).className = $(id).className == 'a' ? '' : 'a';
if(id == 'lf_fav') {
setcookie('leftsidefav', $(id).className == 'a' ? 0 : 1, 2592000);
}
}