qqgroup.js
12.3 KB
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
var cloudj = jQuery.noConflict();
if (typeof disallowfloat == 'undefined' || disallowfloat === null) {
var disallowfloat = '';
}
var currentNormalEditDisplay = 0;
cloudj(document).ready(function() {
ajaxGetSearchResultThreads();
cloudj('#previewForm').submit(function() {
return previewFormSubmit();
});
});
function previewFormSubmit() {
saveAllThread();
if (!selectedTopicId) {
alert('请推送头条信息');
return false;
}
if (selectedNormalIds.length < 1) {
alert('请至少推送一条信息到列表区域');
return false;
}
var i = 1;
for (var k = 1; k <= 5; k++) {
var input_displayorder = cloudj('#normal_thread_' + k).find('.preview_displayorder');
if (input_displayorder.size()) {
input_displayorder.val(i);
i++;
}
}
return true;
}
function initSelect() {
var initTopicObj = cloudj('#search_result .qqqun_op .qqqun_op_topon');
initTopicObj.addClass('qqqun_op_top');
initTopicObj.removeClass('qqqun_op_topon');
var initNormalObj = cloudj('#search_result .qqqun_op .qqqun_op_liston');
initNormalObj.addClass('qqqun_op_list');
initNormalObj.removeClass('qqqun_op_liston');
selectedTopicId = parseInt(selectedTopicId);
if (selectedTopicId) {
cloudj('#thread_addtop_' + selectedTopicId).addClass('qqqun_op_topon');
cloudj('#thread_addtop_' + selectedTopicId).removeClass('qqqun_op_top');
}
cloudj.each(selectedNormalIds, function(k, v) {
v = parseInt(v);
if (v) {
cloudj('#thread_addlist_' + v).addClass('qqqun_op_liston');
cloudj('#thread_addlist_' + v).removeClass('qqqun_op_list');
}
});
}
function ajaxChangeSearch() {
cloudj('#srchtid').val('');
ajaxGetSearchResultThreads();
}
function ajaxGetSearchResultThreads() {
cloudj('#search_result').html('<tr><td colspan="3">加载中...</td></tr>');
qqgroupajaxpost('search_form', 'search_result', 'search_result', null, null, function() {initSelect(); return false});
return false;
}
function ajaxGetPageResultThreads(page, mpurl) {
cloudj('#search_result').html('<tr><td colspan="3">加载中...</td></tr>');
if (typeof page == 'undefined' || page === null) {
page = 1;
}
if (typeof mpurl == 'undefined' || !mpurl) {
return false;
}
ajaxget(mpurl + '&page=' + page, 'search_result', null, null, null, function() {initSelect();} );
}
function addMiniportalTop(tid) {
tid = parseInt(tid);
if (cloudj.inArray(tid, selectedNormalIds) > -1) {
removeNormalThreadByTid(tid);
}
addMiniportalTopId(tid);
initSelect();
ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread&tid=' + tid, 'topicDiv', null, null, null, function() { clickTopicEditor(); });
}
function addMiniportalTopId(tid) {
selectedTopicId = tid;
}
function showPreviewEditor(topic, hideall) {
if (hideall) {
cloudj('.qqqun_list .qqqun_editor').hide();
cloudj('.qqqun_list .qqqun_xl li').removeClass('current');
cloudj('.qqqun_list').removeClass('qqqun_list_editor');
cloudj('.qqqun_top .qqqun_editor').hide();
cloudj('.qqqun_top').removeClass('qqqun_top_editor');
} else {
if (topic) {
cloudj('.qqqun_list .qqqun_editor').hide();
cloudj('.qqqun_list .qqqun_xl li').removeClass('current');
cloudj('.qqqun_list').removeClass('qqqun_list_editor');
cloudj('.qqqun_top .qqqun_editor').show();
cloudj('.qqqun_top').addClass('qqqun_top_editor');
} else {
cloudj('.qqqun_list .qqqun_editor').show();
cloudj('.qqqun_list').addClass('qqqun_list_editor');
cloudj('.qqqun_list .qqqun_xl li').removeClass('current');
cloudj('.qqqun_top .qqqun_editor').hide();
cloudj('.qqqun_top').removeClass('qqqun_top_editor');
}
}
}
function clickTopicEditor(topicFocus) {
if (typeof topicFocus == 'undefined') {
var topicFocus = 'title';
}
showPreviewEditor(true, false);
if (topicFocus == 'title') {
cloudj('#topic-editor-input-title').addClass('pt_focus');
cloudj('#topic-editor-input-title').focus();
} else if (topicFocus == 'content') {
cloudj('#topic-editor-textarea-content').addClass('pt_focus');
cloudj('#topic-editor-textarea-content').focus();
}
currentNormalEditDisplay = 0;
}
function blurTopic(obj) {
var thisobj = cloudj(obj);
thisobj.removeClass('pt_focus');
}
function clickNormalEditor(obj) {
var thisobj = cloudj(obj);
showPreviewEditor(false, false);
thisobj.addClass('pt_focus');
thisobj.focus();
currentNormalEditDisplay = parseInt(thisobj.parent().attr('displayorder'));
}
function blurNormalTextarea(obj) {
var thisobj = cloudj(obj);
liObj = thisobj.parent();
var displayorder = parseInt(liObj.attr('displayorder'));
if (displayorder == currentNormalEditDisplay) {
liObj.addClass('current');
}
cloudj('.qqqun_list .qqqun_xl textarea').removeClass('pt_focus');
}
function addMiniportalList(tid) {
tid = parseInt(tid);
if (cloudj.inArray(tid, selectedNormalIds) > -1) {
return false;
}
if (selectedNormalIds.length >= 5) {
alert('推送帖子已达到5条,请在右侧取消一些再重试。');
return false;
}
if (tid == selectedTopicId) {
selectedTopicId = 0;
ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread&tid=0', 'topicDiv');
}
addMiniportalListId(tid);
initSelect();
var insertPos = 'normal_thread_' + selectedNormalIds.length;
ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getNormalThread&tid=' + tid, insertPos, null, null, null, function() { clickNormalEditor(cloudj('#' + insertPos).find('textarea')); });
}
function addMiniportalListId(tid) {
selectedNormalIds.push(tid);
}
function editNormalThread() {
var threadLi = cloudj('#normal_thread_' + currentNormalEditDisplay);
clickNormalEditor(threadLi.find('textarea'));
}
function saveAllThread() {
showPreviewEditor(false, true);
currentNormalEditDisplay = 0;
}
function moveNormalThread(up) {
var displayorder = currentNormalEditDisplay;
var threadLi = cloudj('#normal_thread_' + displayorder);
if (!threadLi.attr('id') || !displayorder) {
return false;
}
var newDisplayorder = 0;
if (up) {
newDisplayorder = displayorder - 1;
} else {
newDisplayorder = displayorder + 1;
}
if (newDisplayorder < 1 || newDisplayorder > 5) {
return false;
}
var newLiId = 'normal_thread_' + newDisplayorder;
var newThreadLi = cloudj('#' + newLiId);
if (!newThreadLi.find('textarea').size()) {
return false;
}
var tmpHtml = newThreadLi.html();
newThreadLi.html(threadLi.html());
threadLi.html(tmpHtml);
newThreadLi.addClass('current');
threadLi.removeClass('current');
currentNormalEditDisplay = newDisplayorder;
}
function removeTopicThread(tid) {
tid = parseInt(tid);
selectedTopicId = 0;
initSelect();
ajaxget(adminscript + '?action=cloud&operation=qqgroup&anchor=block&op=getTopicThread', 'topicDiv', null, null, null, function() { showPreviewEditor(false, true)});
}
function removeNormalThread() {
var displayorder = currentNormalEditDisplay;
var removeTid = parseInt(cloudj('#normal_thread_' + displayorder).find('.normal_thread_tid').val());
return removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, true);
}
function removeNormalThreadByTid(tid) {
tid = parseInt(tid);
var threadInput = cloudj('.qqqun_list .qqqun_xl .normal_thread_tid[value="' + tid + '"]');
if (threadInput.size()) {
var displayorder = threadInput.parent().attr('displayorder');
var removeTid = tid;
return removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, false);
}
}
function removeNormalThreadByDisplayorderAndTid(displayorder, removeTid, inNormalEditor) {
displayorder = parseInt(displayorder);
removeTid = parseInt(removeTid);
var threadLi = cloudj('#normal_thread_' + displayorder);
if (!threadLi.attr('id') || !displayorder) {
return false;
}
threadLi.removeClass('current');
var index = cloudj.inArray(removeTid, selectedNormalIds);
if (index != -1) {
selectedNormalIds.splice(index, 1);
}
initSelect();
if (typeof inNormalEditor == 'udefined') {
var inNormalEditor = false;
}
threadLi.slideUp(100, function() { removeNormalThreadRecall(displayorder, inNormalEditor)});
}
function removeNormalThreadRecall(displayorder, inNormalEditor) {
for (var i = displayorder; i <= 5; i++) {
var currentDisplayorder = i;
var nextDisplayorder = i + 1;
var currentLiId = 'normal_thread_' + currentDisplayorder;
var currentThreadLi = cloudj('#' + currentLiId);
var nextLiId = 'normal_thread_' + nextDisplayorder;
var nextThreadLi = cloudj('#' + nextLiId);
if (nextThreadLi.find('textarea').size()) {
currentThreadLi.html(nextThreadLi.html());
currentThreadLi.show();
} else {
currentThreadLi.html('');
currentThreadLi.hide();
break;
}
}
var threadLi = cloudj('#normal_thread_' + displayorder);
var prevDisplayorder = displayorder - 1;
if (threadLi.find('textarea').size()) {
if (inNormalEditor) {
threadLi.addClass('current');
}
currentNormalEditDisplay = displayorder;
} else if (prevDisplayorder) {
var prevThreadLi = cloudj('#normal_thread_' + prevDisplayorder);
if (inNormalEditor) {
prevThreadLi.addClass('current');
}
currentNormalEditDisplay = prevDisplayorder;
} else {
var firstThreadLi = cloudj('#normal_thread_1');
if (inNormalEditor) {
saveAllThread();
}
firstThreadLi.html('<div class="tips">点击左侧 <img src="static/image/admincp/cloud/qun_op_list.png" align="absmiddle" /> 将信息推送到列表</div>');
firstThreadLi.show();
}
}
function ajaxUploadQQGroupImage() {
cloudj('#uploadImageResult').parent().show();
cloudj('#uploadImageResult').text('图片上传中,请稍后...');
qqgroupajaxpost('uploadImage', 'uploadImageResult', 'uploadImageResult', null, null, 'uploadRecall()');
}
function uploadRecall() {
if(cloudj('#uploadImageResult').find('#upload_msg_success').size()) {
cloudj('#uploadImageResult').parent().show();
var debug_rand = Math.random();
var imagePath = cloudj('#uploadImageResult #upload_msg_imgpath').text();
var imageUrl = cloudj('#uploadImageResult #upload_msg_imgurl').text();
cloudj('#topic_image_value').val(imagePath);
cloudj('#topic_editor_thumb').attr('src', imageUrl + '?' + debug_rand);
cloudj('#topic_preview_thumb').attr('src', imageUrl + '?' + debug_rand);
setTimeout(function() {hideWindow('uploadImgWin');}, 2000);
}
}
function qqgroupajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
var showidclass = !showidclass ? '' : showidclass;
var ajaxframeid = 'ajaxframe';
var ajaxframe = $(ajaxframeid);
var formtarget = $(formid).target;
var handleResult = function() {
var s = '';
var evaled = false;
showloading('none');
ajaxResponse = cloudj('#' + ajaxframeid).contents().text();
var regex = /<\!\[CDATA\[(.*)\]\]>/;
var regexed = regex.exec(ajaxResponse);
if (regexed && regexed[1]) {
s = regexed[1];
} else {
s = ajaxResponse;
}
if (!s) {
s = '内部错误,无法显示此内容';
}
if(s != '' && s.indexOf('ajaxerror') != -1) {
evalscript(s);
evaled = true;
}
if(showidclass) {
if(showidclass != 'onerror') {
cloudj(showid).addClass(showidclass);
} else {
showError(s);
ajaxerror = true;
}
}
if(submitbtn) {
cloudj(submitbtn).attr('disabled', false);
}
if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
ajaxinnerhtml($(showid), s);
}
ajaxerror = null;
cloudj('#' + formid).attr('target', formtarget);
if(typeof recall == 'function') {
recall();
} else {
eval(recall);
}
if(!evaled) evalscript(s);
ajaxframe.loading = 0;
cloudj(ajaxframe.parentNode).remove();
};
if(!ajaxframe) {
var div = cloudj('<div>');
div.css('display', 'none');
div.html('<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '" loading="1">');
cloudj('#append_parent').append(div);
ajaxframe = $(ajaxframeid);
} else if(ajaxframe.loading) {
return false;
}
_attachEvent(ajaxframe, 'load', handleResult);
showloading();
cloudj('#' + formid).attr('target', ajaxframeid);
var action = cloudj('#' + formid).attr('action');
action = hostconvert(action);
cloudj('#' + formid).attr('action', action.replace(/\&inajax\=1/g, '')+'&inajax=1');
$(formid).submit();
if(submitbtn) {
cloudj(submitbtn).attr('disabled', true);
}
doane();
return false;
}