|
1
|
|
|
/*! |
|
2
|
|
|
* @name ElkArte Forum |
|
3
|
|
|
* @copyright ElkArte Forum contributors |
|
4
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause |
|
5
|
|
|
* |
|
6
|
|
|
* This file contains code covered by: |
|
7
|
|
|
* copyright: 2011 Simple Machines (http://www.simplemachines.org) |
|
8
|
|
|
* license: BSD, See included LICENSE.TXT for terms and conditions. |
|
9
|
|
|
* |
|
10
|
|
|
* @version 1.1.1 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This file contains javascript associated with the topic viewing including |
|
15
|
|
|
* Quick Modify, Quick Reply, In Topic Moderation, thumbnail expansion etc |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* *** QuickModifyTopic object. |
|
20
|
|
|
* Used to quick edit a topic subject by double clicking next to the subject name |
|
21
|
|
|
* in a topic listing |
|
22
|
|
|
* |
|
23
|
|
|
* @param {object} oOptions |
|
24
|
|
|
*/ |
|
25
|
|
|
function QuickModifyTopic(oOptions) |
|
26
|
|
|
{ |
|
27
|
|
|
this.opt = oOptions; |
|
28
|
|
|
this.aHidePrefixes = this.opt.aHidePrefixes; |
|
29
|
|
|
this.iCurTopicId = 0; |
|
30
|
|
|
this.sCurMessageId = ''; |
|
31
|
|
|
this.sBuffSubject = ''; |
|
32
|
|
|
this.oSavetipElem = false; |
|
33
|
|
|
this.oCurSubjectDiv = null; |
|
34
|
|
|
this.oTopicModHandle = document; |
|
35
|
|
|
this.bInEditMode = false; |
|
36
|
|
|
this.bMouseOnDiv = false; |
|
37
|
|
|
this.init(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Used to initialise the object event handlers |
|
41
|
|
|
QuickModifyTopic.prototype.init = function () |
|
42
|
|
|
{ |
|
43
|
|
|
// Attach some events to it so we can respond to actions |
|
44
|
|
|
this.oTopicModHandle.instanceRef = this; |
|
45
|
|
|
|
|
46
|
|
|
// Detect and act on keypress |
|
47
|
|
|
this.oTopicModHandle.onkeydown = function (oEvent) {return this.instanceRef.modify_topic_keypress(oEvent);}; |
|
48
|
|
|
|
|
49
|
|
|
// Used to detect when we've stopped editing. |
|
50
|
|
|
this.oTopicModHandle.onclick = function (oEvent) {return this.instanceRef.modify_topic_click(oEvent);}; |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
// called from the double click in the div |
|
54
|
|
|
QuickModifyTopic.prototype.modify_topic = function (topic_id, first_msg_id) |
|
55
|
|
|
{ |
|
56
|
|
|
// already editing |
|
57
|
|
|
if (this.bInEditMode) |
|
58
|
|
|
{ |
|
59
|
|
|
// Same message then just return, otherwise drop out of this edit. |
|
60
|
|
|
if (this.iCurTopicId === topic_id) |
|
61
|
|
|
return; |
|
|
|
|
|
|
62
|
|
|
else |
|
63
|
|
|
this.modify_topic_cancel(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
this.bInEditMode = true; |
|
67
|
|
|
this.bMouseOnDiv = true; |
|
68
|
|
|
this.iCurTopicId = topic_id; |
|
69
|
|
|
|
|
70
|
|
|
// Get the topics current subject |
|
71
|
|
|
ajax_indicator(true); |
|
72
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", '', this.onDocReceived_modify_topic); |
|
|
|
|
|
|
73
|
|
|
}; |
|
74
|
|
|
|
|
75
|
|
|
// Callback function from the modify_topic ajax call |
|
76
|
|
|
QuickModifyTopic.prototype.onDocReceived_modify_topic = function (XMLDoc) |
|
77
|
|
|
{ |
|
78
|
|
|
// If it is not valid then clean up |
|
79
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('message')) |
|
80
|
|
|
{ |
|
81
|
|
|
this.modify_topic_cancel(); |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
this.sCurMessageId = XMLDoc.getElementsByTagName("message")[0].getAttribute("id"); |
|
86
|
|
|
this.oCurSubjectDiv = document.getElementById('msg_' + this.sCurMessageId.substr(4)); |
|
87
|
|
|
this.sBuffSubject = this.oCurSubjectDiv.innerHTML; |
|
88
|
|
|
|
|
89
|
|
|
// Hide the tooltip text, don't want them for this element during the edit |
|
90
|
|
|
if ($.isFunction($.fn.SiteTooltip)) |
|
91
|
|
|
{ |
|
92
|
|
|
this.oSavetipElem = this.oCurSubjectDiv.nextSibling; |
|
93
|
|
|
this.sSavetip = this.oSavetipElem.innerHTML; |
|
94
|
|
|
this.oSavetipElem.innerHTML = ''; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Here we hide any other things they want hidden on edit. |
|
98
|
|
|
this.set_hidden_topic_areas('none'); |
|
99
|
|
|
|
|
100
|
|
|
// Show we are in edit mode and allow the edit |
|
101
|
|
|
ajax_indicator(false); |
|
102
|
|
|
this.modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue); |
|
|
|
|
|
|
103
|
|
|
}; |
|
104
|
|
|
|
|
105
|
|
|
// Cancel out of an edit and return things to back to what they were |
|
106
|
|
|
QuickModifyTopic.prototype.modify_topic_cancel = function () |
|
107
|
|
|
{ |
|
108
|
|
|
this.oCurSubjectDiv.innerHTML = this.sBuffSubject; |
|
109
|
|
|
this.set_hidden_topic_areas(''); |
|
110
|
|
|
this.bInEditMode = false; |
|
111
|
|
|
|
|
112
|
|
|
// Put back the hover text |
|
113
|
|
|
if (this.oSavetipElem !== false) |
|
114
|
|
|
this.oSavetipElem.innerHTML = this.sSavetip; |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
return false; |
|
117
|
|
|
}; |
|
118
|
|
|
|
|
119
|
|
|
// Simply restore/show any hidden bits during topic editing. |
|
120
|
|
|
QuickModifyTopic.prototype.set_hidden_topic_areas = function (set_style) |
|
121
|
|
|
{ |
|
122
|
|
|
for (var i = 0; i < this.aHidePrefixes.length; i++) |
|
123
|
|
|
{ |
|
124
|
|
|
if (document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)) !== null) |
|
125
|
|
|
document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)).style.display = set_style; |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
}; |
|
128
|
|
|
|
|
129
|
|
|
// For templating, shown that an inline edit is being made. |
|
130
|
|
|
QuickModifyTopic.prototype.modify_topic_show_edit = function (subject) |
|
131
|
|
|
{ |
|
132
|
|
|
// Just template the subject. |
|
133
|
|
|
this.oCurSubjectDiv.innerHTML = '<input type="text" name="subject" value="' + subject + '" size="60" style="width: 95%;" maxlength="80" class="input_text" autocomplete="off" /><input type="hidden" name="topic" value="' + this.iCurTopicId + '" /><input type="hidden" name="msg" value="' + this.sCurMessageId.substr(4) + '" />'; |
|
134
|
|
|
|
|
135
|
|
|
// Attach mouse over and out events to this new div |
|
136
|
|
|
this.oCurSubjectDiv.instanceRef = this; |
|
137
|
|
|
this.oCurSubjectDiv.onmouseout = function (oEvent) {return this.instanceRef.modify_topic_mouseout(oEvent);}; |
|
138
|
|
|
this.oCurSubjectDiv.onmouseover = function (oEvent) {return this.instanceRef.modify_topic_mouseover(oEvent);}; |
|
139
|
|
|
}; |
|
140
|
|
|
|
|
141
|
|
|
// Yup that's right, save it |
|
142
|
|
|
QuickModifyTopic.prototype.modify_topic_save = function (cur_session_id, cur_session_var) |
|
143
|
|
|
{ |
|
144
|
|
|
if (!this.bInEditMode) |
|
145
|
|
|
return true; |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
var x = []; |
|
148
|
|
|
|
|
149
|
|
|
x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, "&#").php_urlencode(); |
|
150
|
|
|
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value); |
|
151
|
|
|
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value); |
|
152
|
|
|
|
|
153
|
|
|
// Send in the call to save the updated topic subject |
|
154
|
|
|
ajax_indicator(true); |
|
155
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements.topic.value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), this.modify_topic_done); |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
return false; |
|
158
|
|
|
}; |
|
159
|
|
|
|
|
160
|
|
|
// Done with the edit, if all went well show the new topic title |
|
161
|
|
|
QuickModifyTopic.prototype.modify_topic_done = function (XMLDoc) |
|
162
|
|
|
{ |
|
163
|
|
|
ajax_indicator(false); |
|
164
|
|
|
|
|
165
|
|
|
// If it is not valid then clean up |
|
166
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('subject')) |
|
167
|
|
|
{ |
|
168
|
|
|
this.modify_topic_cancel(); |
|
169
|
|
|
return true; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
var message = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("message")[0], |
|
173
|
|
|
subject = message.getElementsByTagName("subject")[0], |
|
174
|
|
|
error = message.getElementsByTagName("error")[0]; |
|
175
|
|
|
|
|
176
|
|
|
// No subject or other error? |
|
177
|
|
|
if (!subject || error) |
|
178
|
|
|
return false; |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
this.modify_topic_hide_edit(subject.childNodes[0].nodeValue); |
|
181
|
|
|
this.set_hidden_topic_areas(''); |
|
182
|
|
|
this.bInEditMode = false; |
|
183
|
|
|
|
|
184
|
|
|
// Redo tooltips if they are on since we just pulled the rug out on this one |
|
185
|
|
|
if ($.isFunction($.fn.SiteTooltip)) |
|
186
|
|
|
{ |
|
187
|
|
|
this.oSavetipElem.innerHTML = this.sSavetip; |
|
188
|
|
|
$('.preview').SiteTooltip(); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
return false; |
|
192
|
|
|
}; |
|
193
|
|
|
|
|
194
|
|
|
// Done with the edit, put in new subject and link. |
|
195
|
|
|
QuickModifyTopic.prototype.modify_topic_hide_edit = function (subject) |
|
196
|
|
|
{ |
|
197
|
|
|
// Re-template the subject! |
|
198
|
|
|
this.oCurSubjectDiv.innerHTML = '<a href="' + elk_scripturl + '?topic=' + this.iCurTopicId + '.0">' + subject + '<' +'/a>'; |
|
|
|
|
|
|
199
|
|
|
}; |
|
200
|
|
|
|
|
201
|
|
|
// keypress event ... like enter or escape |
|
202
|
|
|
QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent) |
|
203
|
|
|
{ |
|
204
|
|
|
if (typeof(oEvent.keyCode) !== "undefined" && this.bInEditMode) |
|
205
|
|
|
{ |
|
206
|
|
|
if (oEvent.keyCode === 27) |
|
207
|
|
|
{ |
|
208
|
|
|
this.modify_topic_cancel(); |
|
209
|
|
|
if (typeof(oEvent.preventDefault) === "undefined") |
|
210
|
|
|
oEvent.returnValue = false; |
|
|
|
|
|
|
211
|
|
|
else |
|
212
|
|
|
oEvent.preventDefault(); |
|
213
|
|
|
} |
|
214
|
|
|
else if (oEvent.keyCode === 13) |
|
215
|
|
|
{ |
|
216
|
|
|
this.modify_topic_save(elk_session_id, elk_session_var); |
|
|
|
|
|
|
217
|
|
|
if (typeof(oEvent.preventDefault) === "undefined") |
|
218
|
|
|
oEvent.returnValue = false; |
|
|
|
|
|
|
219
|
|
|
else |
|
220
|
|
|
oEvent.preventDefault(); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
}; |
|
224
|
|
|
|
|
225
|
|
|
// A click event to signal the finish of the edit |
|
226
|
|
|
QuickModifyTopic.prototype.modify_topic_click = function (oEvent) |
|
|
|
|
|
|
227
|
|
|
{ |
|
228
|
|
|
if (this.bInEditMode && !this.bMouseOnDiv) |
|
229
|
|
|
this.modify_topic_save(elk_session_id, elk_session_var); |
|
|
|
|
|
|
230
|
|
|
}; |
|
231
|
|
|
|
|
232
|
|
|
// Moved out of the editing div |
|
233
|
|
|
QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent) |
|
|
|
|
|
|
234
|
|
|
{ |
|
235
|
|
|
this.bMouseOnDiv = false; |
|
236
|
|
|
}; |
|
237
|
|
|
|
|
238
|
|
|
// Moved back over the editing div |
|
239
|
|
|
QuickModifyTopic.prototype.modify_topic_mouseover = function (oEvent) |
|
240
|
|
|
{ |
|
241
|
|
|
this.bMouseOnDiv = true; |
|
242
|
|
|
oEvent.preventDefault(); |
|
243
|
|
|
}; |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* QuickReply object, this allows for selecting the quote button and |
|
247
|
|
|
* having the quote appear in the quick reply box |
|
248
|
|
|
* |
|
249
|
|
|
* @param {type} oOptions |
|
250
|
|
|
*/ |
|
251
|
|
|
function QuickReply(oOptions) |
|
252
|
|
|
{ |
|
253
|
|
|
this.opt = oOptions; |
|
254
|
|
|
this.bCollapsed = this.opt.bDefaultCollapsed; |
|
255
|
|
|
this.bIsFull = this.opt.bIsFull; |
|
256
|
|
|
|
|
257
|
|
|
// If the initial state is to be collapsed, collapse it. |
|
258
|
|
|
if (this.bCollapsed) |
|
259
|
|
|
this.swap(true); |
|
|
|
|
|
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
// When a user presses quote, put it in the quick reply box (if expanded). |
|
263
|
|
|
QuickReply.prototype.quote = function (iMessageId, xDeprecated) |
|
|
|
|
|
|
264
|
|
|
{ |
|
265
|
|
|
ajax_indicator(true); |
|
266
|
|
|
|
|
267
|
|
|
// Collapsed on a quote, then simply got to the full post screen |
|
268
|
|
|
if (this.bCollapsed) |
|
269
|
|
|
{ |
|
270
|
|
|
window.location.href = elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=post;quote=' + iMessageId + ';topic=' + this.opt.iTopicId + '.' + this.opt.iStart; |
|
271
|
|
|
return false; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// Insert the quote |
|
275
|
|
|
if (this.bIsFull) |
|
276
|
|
|
insertQuoteFast(iMessageId); |
|
|
|
|
|
|
277
|
|
|
else |
|
278
|
|
|
getXMLDocument(elk_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';xml', this.onQuoteReceived); |
|
279
|
|
|
|
|
280
|
|
|
// Move the view to the quick reply box. |
|
281
|
|
|
if (navigator.appName === 'Microsoft Internet Explorer') |
|
|
|
|
|
|
282
|
|
|
window.location.hash = this.opt.sJumpAnchor; |
|
|
|
|
|
|
283
|
|
|
else |
|
284
|
|
|
window.location.hash = '#' + this.opt.sJumpAnchor; |
|
285
|
|
|
|
|
286
|
|
|
return false; |
|
287
|
|
|
}; |
|
288
|
|
|
|
|
289
|
|
|
// This is the callback function used after the XMLhttp request. |
|
290
|
|
|
QuickReply.prototype.onQuoteReceived = function (oXMLDoc) |
|
291
|
|
|
{ |
|
292
|
|
|
var sQuoteText = ''; |
|
293
|
|
|
|
|
294
|
|
|
for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++) |
|
295
|
|
|
sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue; |
|
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
replaceText(sQuoteText, document.forms.postmodify.message); |
|
298
|
|
|
|
|
299
|
|
|
ajax_indicator(false); |
|
300
|
|
|
}; |
|
301
|
|
|
|
|
302
|
|
|
// The function handling the swapping of the quick reply area |
|
303
|
|
|
QuickReply.prototype.swap = function (bInit, bSavestate) |
|
304
|
|
|
{ |
|
305
|
|
|
var oQuickReplyContainer = document.getElementById(this.opt.sClassId), |
|
306
|
|
|
sEditorId = this.opt.sContainerId, |
|
307
|
|
|
bIsFull = this.opt.bIsFull; |
|
308
|
|
|
|
|
309
|
|
|
// Default bInit to false and bSavestate to true |
|
310
|
|
|
bInit = typeof(bInit) !== 'undefined'; |
|
311
|
|
|
bSavestate = typeof(bSavestate) === 'undefined'; |
|
312
|
|
|
|
|
313
|
|
|
// Flip our current state if not responding to an initial loading |
|
314
|
|
|
if (!bInit) |
|
315
|
|
|
this.bCollapsed = !this.bCollapsed; |
|
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
// Swap the class on the expcol image as needed |
|
318
|
|
|
var sTargetClass = !this.bCollapsed ? this.opt.sClassCollapsed : this.opt.sClassExpanded; |
|
319
|
|
|
if (oQuickReplyContainer.className !== sTargetClass) |
|
320
|
|
|
oQuickReplyContainer.className = sTargetClass; |
|
|
|
|
|
|
321
|
|
|
|
|
322
|
|
|
// And show the new title |
|
323
|
|
|
oQuickReplyContainer.title = oQuickReplyContainer.title = this.bCollapsed ? this.opt.sTitleCollapsed : this.opt.sTitleExpanded; |
|
324
|
|
|
|
|
325
|
|
|
// Show or hide away |
|
326
|
|
|
if (this.bCollapsed) |
|
327
|
|
|
$('#' + this.opt.sContainerId).slideUp(); |
|
|
|
|
|
|
328
|
|
|
else |
|
329
|
|
|
{ |
|
330
|
|
|
$('#' + this.opt.sContainerId).slideDown(); |
|
331
|
|
|
if (bIsFull) |
|
332
|
|
|
$('#' + sEditorId).resize(); |
|
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
// Using a cookie for guests? |
|
336
|
|
|
if (bSavestate && 'oCookieOptions' in this.opt && this.opt.oCookieOptions.bUseCookie) |
|
337
|
|
|
this.oCookie.set(this.opt.oCookieOptions.sCookieName, this.bCollapsed ? '1' : '0'); |
|
|
|
|
|
|
338
|
|
|
|
|
339
|
|
|
// Save the expand /collapse preference |
|
340
|
|
|
if (!bInit && bSavestate && 'oThemeOptions' in this.opt && this.opt.oThemeOptions.bUseThemeSettings) |
|
341
|
|
|
elk_setThemeOption(this.opt.oThemeOptions.sOptionName, this.bCollapsed ? '1' : '0', 'sThemeId' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sThemeId : null, 'sAdditionalVars' in this.opt.oThemeOptions ? this.opt.oThemeOptions.sAdditionalVars : null); |
|
|
|
|
|
|
342
|
|
|
}; |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* QuickModify object. |
|
346
|
|
|
* This will allow for the quick editing of a post via ajax |
|
347
|
|
|
* |
|
348
|
|
|
* @param {object} oOptions |
|
349
|
|
|
*/ |
|
350
|
|
|
function QuickModify(oOptions) |
|
351
|
|
|
{ |
|
352
|
|
|
this.opt = oOptions; |
|
353
|
|
|
this.bInEditMode = false; |
|
354
|
|
|
this.sCurMessageId = ''; |
|
355
|
|
|
this.oCurMessageDiv = null; |
|
356
|
|
|
this.oCurInfoDiv = null; |
|
357
|
|
|
this.oCurSubjectDiv = null; |
|
358
|
|
|
this.oMsgIcon = null; |
|
359
|
|
|
this.sMessageBuffer = ''; |
|
360
|
|
|
this.sSubjectBuffer = ''; |
|
361
|
|
|
this.sInfoBuffer = ''; |
|
362
|
|
|
this.aAccessKeys = []; |
|
363
|
|
|
|
|
364
|
|
|
// Show the edit buttons |
|
365
|
|
|
var aShowQuickModify = document.getElementsByClassName(this.opt.sClassName); |
|
366
|
|
|
for (var i = 0, length = aShowQuickModify.length; i < length; i++) |
|
367
|
|
|
aShowQuickModify[i].style.display = "inline"; |
|
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
// Function called when a user presses the edit button. |
|
371
|
|
|
QuickModify.prototype.modifyMsg = function (iMessageId) |
|
372
|
|
|
{ |
|
373
|
|
|
// Removes the accesskeys from the quickreply inputs and saves them in an array to use them later |
|
374
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
375
|
|
|
{ |
|
376
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
377
|
|
|
{ |
|
378
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
379
|
|
|
for (var i = 0; i < aInputs.length; i++) |
|
380
|
|
|
{ |
|
381
|
|
|
if (aInputs[i].accessKey !== '') |
|
382
|
|
|
{ |
|
383
|
|
|
this.aAccessKeys[aInputs[i].name] = aInputs[i].accessKey; |
|
384
|
|
|
aInputs[i].accessKey = ''; |
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
// First cancel if there's another message still being edited. |
|
391
|
|
|
if (this.bInEditMode) |
|
392
|
|
|
this.modifyCancel(); |
|
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
// At least NOW we're in edit mode |
|
395
|
|
|
this.bInEditMode = true; |
|
396
|
|
|
|
|
397
|
|
|
// Send out the XMLhttp request to get more info |
|
398
|
|
|
ajax_indicator(true); |
|
399
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(elk_scripturl) + 'action=quotefast;quote=' + iMessageId + ';modify;xml', '', this.onMessageReceived); |
|
|
|
|
|
|
400
|
|
|
}; |
|
401
|
|
|
|
|
402
|
|
|
// The callback function used for the XMLhttp request retrieving the message. |
|
403
|
|
|
QuickModify.prototype.onMessageReceived = function (XMLDoc) |
|
404
|
|
|
{ |
|
405
|
|
|
var sBodyText = '', |
|
406
|
|
|
sSubjectText; |
|
407
|
|
|
|
|
408
|
|
|
// No longer show the 'loading...' sign. |
|
409
|
|
|
ajax_indicator(false); |
|
410
|
|
|
|
|
411
|
|
|
// Grab the message ID. |
|
412
|
|
|
this.sCurMessageId = XMLDoc.getElementsByTagName('message')[0].getAttribute('id'); |
|
413
|
|
|
|
|
414
|
|
|
// Show the message icon if it was hidden and its set |
|
415
|
|
|
if (this.opt.sIconHide !== null) |
|
416
|
|
|
{ |
|
417
|
|
|
this.oMsgIcon = document.getElementById('messageicon_' + this.sCurMessageId.replace("msg_", "")); |
|
418
|
|
|
if (this.oMsgIcon !== null && getComputedStyle(this.oMsgIcon).getPropertyValue("display") === 'none') |
|
419
|
|
|
this.oMsgIcon.style.display = 'inline'; |
|
|
|
|
|
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
// If this is not valid then simply give up. |
|
423
|
|
|
if (!document.getElementById(this.sCurMessageId)) |
|
424
|
|
|
return this.modifyCancel(); |
|
|
|
|
|
|
425
|
|
|
|
|
426
|
|
|
// Replace the body part. |
|
427
|
|
|
for (var i = 0; i < XMLDoc.getElementsByTagName("message")[0].childNodes.length; i++) |
|
428
|
|
|
sBodyText += XMLDoc.getElementsByTagName("message")[0].childNodes[i].nodeValue; |
|
|
|
|
|
|
429
|
|
|
|
|
430
|
|
|
this.oCurMessageDiv = document.getElementById(this.sCurMessageId); |
|
431
|
|
|
this.sMessageBuffer = this.oCurMessageDiv.innerHTML; |
|
432
|
|
|
|
|
433
|
|
|
// We have to force the body to lose its dollar signs thanks to IE. |
|
434
|
|
|
sBodyText = sBodyText.replace(/\$/g, '{&dollarfix;$}'); |
|
435
|
|
|
|
|
436
|
|
|
// Actually create the content, with a bodge for disappearing dollar signs. |
|
437
|
|
|
this.oCurMessageDiv.innerHTML = this.opt.sTemplateBodyEdit.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%body%/, sBodyText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
438
|
|
|
|
|
439
|
|
|
// Save and hide the existing subject div |
|
440
|
|
|
if (this.opt.sIDSubject !== null) |
|
441
|
|
|
{ |
|
442
|
|
|
this.oCurSubjectDiv = document.getElementById(this.opt.sIDSubject + this.sCurMessageId.substr(4)); |
|
443
|
|
|
if (this.oCurSubjectDiv !== null) |
|
444
|
|
|
{ |
|
445
|
|
|
this.oCurSubjectDiv.style.display = 'none'; |
|
446
|
|
|
this.sSubjectBuffer = this.oCurSubjectDiv.innerHTML; |
|
447
|
|
|
} |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
// Save the info div, then open an input field on it |
|
451
|
|
|
sSubjectText = XMLDoc.getElementsByTagName('subject')[0].childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}'); |
|
452
|
|
|
if (this.opt.sIDInfo !== null) |
|
453
|
|
|
{ |
|
454
|
|
|
this.oCurInfoDiv = document.getElementById(this.opt.sIDInfo + this.sCurMessageId.substr(4)); |
|
455
|
|
|
if (this.oCurInfoDiv !== null) |
|
456
|
|
|
{ |
|
457
|
|
|
this.sInfoBuffer = this.oCurInfoDiv.innerHTML; |
|
458
|
|
|
this.oCurInfoDiv.innerHTML = this.opt.sTemplateSubjectEdit.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
// Position the editor in the window |
|
463
|
|
|
location.hash = '#info_' + this.sCurMessageId.substr(this.sCurMessageId.lastIndexOf("_") + 1); |
|
464
|
|
|
|
|
465
|
|
|
// Handle custom function hook before showing the new select. |
|
466
|
|
|
if ('funcOnAfterCreate' in this.opt) |
|
467
|
|
|
{ |
|
468
|
|
|
this.tmpMethod = this.opt.funcOnAfterCreate; |
|
469
|
|
|
this.tmpMethod(this); |
|
470
|
|
|
delete this.tmpMethod; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
return true; |
|
474
|
|
|
}; |
|
475
|
|
|
|
|
476
|
|
|
// Function in case the user presses cancel (or other circumstances cause it). |
|
477
|
|
|
QuickModify.prototype.modifyCancel = function () |
|
478
|
|
|
{ |
|
479
|
|
|
// Roll back the HTML to its original state. |
|
480
|
|
|
if (this.oCurMessageDiv) |
|
481
|
|
|
{ |
|
482
|
|
|
this.oCurMessageDiv.innerHTML = this.sMessageBuffer; |
|
483
|
|
|
this.oCurInfoDiv.innerHTML = this.sInfoBuffer; |
|
484
|
|
|
this.oCurSubjectDiv.innerHTML = this.sSubjectBuffer; |
|
485
|
|
|
if (this.oCurSubjectDiv !== null) |
|
486
|
|
|
{ |
|
487
|
|
|
this.oCurSubjectDiv.style.display = ''; |
|
488
|
|
|
} |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
// Hide the message icon if we are doing that |
|
492
|
|
|
if (this.opt.sIconHide) |
|
493
|
|
|
{ |
|
494
|
|
|
var oCurrentMsgIcon = document.getElementById('msg_icon_' + this.sCurMessageId.replace("msg_", "")); |
|
495
|
|
|
|
|
496
|
|
|
if (oCurrentMsgIcon !== null && oCurrentMsgIcon.src.indexOf(this.opt.sIconHide) > 0) |
|
497
|
|
|
this.oMsgIcon.style.display = 'none'; |
|
|
|
|
|
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
// No longer in edit mode, that's right. |
|
501
|
|
|
this.bInEditMode = false; |
|
502
|
|
|
|
|
503
|
|
|
// Let's put back the accesskeys to their original place |
|
504
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
505
|
|
|
{ |
|
506
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
507
|
|
|
{ |
|
508
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
509
|
|
|
for (var i = 0; i < aInputs.length; i++) |
|
510
|
|
|
{ |
|
511
|
|
|
if (typeof(this.aAccessKeys[aInputs[i].name]) !== 'undefined') |
|
512
|
|
|
{ |
|
513
|
|
|
aInputs[i].accessKey = this.aAccessKeys[aInputs[i].name]; |
|
514
|
|
|
} |
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
return false; |
|
520
|
|
|
}; |
|
521
|
|
|
|
|
522
|
|
|
// The function called after a user wants to save his precious message. |
|
523
|
|
|
QuickModify.prototype.modifySave = function (sSessionId, sSessionVar) |
|
|
|
|
|
|
524
|
|
|
{ |
|
525
|
|
|
var i = 0, |
|
526
|
|
|
x = [], |
|
527
|
|
|
uIds = []; |
|
528
|
|
|
|
|
529
|
|
|
// We cannot save if we weren't in edit mode. |
|
530
|
|
|
if (!this.bInEditMode) |
|
531
|
|
|
return true; |
|
|
|
|
|
|
532
|
|
|
|
|
533
|
|
|
this.bInEditMode = false; |
|
534
|
|
|
|
|
535
|
|
|
// Let's put back the accesskeys to their original place |
|
536
|
|
|
if (typeof(this.opt.sFormRemoveAccessKeys) !== 'undefined') |
|
537
|
|
|
{ |
|
538
|
|
|
if (typeof(document.forms[this.opt.sFormRemoveAccessKeys])) |
|
539
|
|
|
{ |
|
540
|
|
|
var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input'); |
|
541
|
|
|
for (i = 0; i < aInputs.length; i++) |
|
542
|
|
|
{ |
|
543
|
|
|
if (typeof(this.aAccessKeys[aInputs[i].name]) !== 'undefined') |
|
544
|
|
|
{ |
|
545
|
|
|
aInputs[i].accessKey = this.aAccessKeys[aInputs[i].name]; |
|
546
|
|
|
} |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
var oInputs = document.forms.quickModForm.getElementsByTagName('input'); |
|
552
|
|
|
for (i = 0; i < oInputs.length; i++) |
|
553
|
|
|
{ |
|
554
|
|
|
if (oInputs[i].name === 'uid[]') |
|
555
|
|
|
{ |
|
556
|
|
|
uIds.push('uid[' + i + ']=' + parseInt(oInputs[i].value)); |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
|
|
560
|
|
|
x[x.length] = 'subject=' + document.forms.quickModForm.subject.value.replace(/&#/g, "&#").php_urlencode(); |
|
561
|
|
|
x[x.length] = 'message=' + document.forms.quickModForm.message.value.replace(/&#/g, "&#").php_urlencode(); |
|
562
|
|
|
x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements.topic.value); |
|
563
|
|
|
x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements.msg.value); |
|
564
|
|
|
if (uIds.length > 0) |
|
565
|
|
|
x[x.length] = uIds.join("&"); |
|
|
|
|
|
|
566
|
|
|
|
|
567
|
|
|
// Send in the XMLhttp request and let's hope for the best. |
|
568
|
|
|
ajax_indicator(true); |
|
569
|
|
|
sendXMLDocument.call(this, elk_prepareScriptUrl(this.opt.sScriptUrl) + "action=jsmodify;topic=" + this.opt.iTopicId + ";" + elk_session_var + "=" + elk_session_id + ";xml", x.join("&"), this.onModifyDone); |
|
|
|
|
|
|
570
|
|
|
|
|
571
|
|
|
return false; |
|
572
|
|
|
}; |
|
573
|
|
|
|
|
574
|
|
|
// Callback function of the XMLhttp request sending the modified message. |
|
575
|
|
|
QuickModify.prototype.onModifyDone = function (XMLDoc) |
|
576
|
|
|
{ |
|
577
|
|
|
var oErrordiv; |
|
578
|
|
|
|
|
579
|
|
|
// We've finished the loading stuff. |
|
580
|
|
|
ajax_indicator(false); |
|
581
|
|
|
|
|
582
|
|
|
// If we didn't get a valid document, just cancel. |
|
583
|
|
|
if (!XMLDoc || !XMLDoc.getElementsByTagName('elk')[0]) |
|
584
|
|
|
{ |
|
585
|
|
|
// Mozilla will nicely tell us what's wrong. |
|
586
|
|
|
if (typeof XMLDoc.childNodes !== 'undefined' && XMLDoc.childNodes.length > 0 && XMLDoc.firstChild.nodeName === 'parsererror') |
|
587
|
|
|
{ |
|
588
|
|
|
oErrordiv = document.getElementById('error_box'); |
|
589
|
|
|
oErrordiv.innerHTML = XMLDoc.firstChild.textContent; |
|
590
|
|
|
oErrordiv.style.display = ''; |
|
591
|
|
|
} |
|
592
|
|
|
else |
|
593
|
|
|
this.modifyCancel(); |
|
|
|
|
|
|
594
|
|
|
return; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
var message = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('message')[0], |
|
598
|
|
|
body = message.getElementsByTagName('body')[0], |
|
599
|
|
|
error = message.getElementsByTagName('error')[0]; |
|
600
|
|
|
|
|
601
|
|
|
$(document.forms.quickModForm.message).removeClass('border_error'); |
|
602
|
|
|
$(document.forms.quickModForm.subject).removeClass('border_error'); |
|
603
|
|
|
|
|
604
|
|
|
if (body) |
|
605
|
|
|
{ |
|
606
|
|
|
// Show new body. |
|
607
|
|
|
var bodyText = ''; |
|
608
|
|
|
for (var i = 0; i < body.childNodes.length; i++) |
|
609
|
|
|
bodyText += body.childNodes[i].nodeValue; |
|
|
|
|
|
|
610
|
|
|
|
|
611
|
|
|
this.sMessageBuffer = this.opt.sTemplateBodyNormal.replace(/%body%/, bodyText.replace(/\$/g, '{&dollarfix;$}')).replace(/\{&dollarfix;\$\}/g,'$'); |
|
612
|
|
|
this.oCurMessageDiv.innerHTML = this.sMessageBuffer; |
|
613
|
|
|
|
|
614
|
|
|
// Show new subject div, update in case it changed |
|
615
|
|
|
var oSubject = message.getElementsByTagName('subject')[0], |
|
616
|
|
|
sSubjectText = oSubject.childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}'); |
|
617
|
|
|
|
|
618
|
|
|
this.sSubjectBuffer = this.opt.sTemplateSubjectNormal.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'); |
|
619
|
|
|
this.oCurSubjectDiv.innerHTML = this.sSubjectBuffer; |
|
620
|
|
|
this.oCurSubjectDiv.style.display = ''; |
|
621
|
|
|
|
|
622
|
|
|
// Restore the info bar div |
|
623
|
|
|
this.oCurInfoDiv.innerHTML = this.sInfoBuffer; |
|
624
|
|
|
|
|
625
|
|
|
// Show this message as 'modified on x by y'. |
|
626
|
|
|
if (this.opt.bShowModify) |
|
627
|
|
|
{ |
|
628
|
|
|
var modified_element = document.getElementById('modified_' + this.sCurMessageId.substr(4)); |
|
629
|
|
|
modified_element.innerHTML = message.getElementsByTagName('modified')[0].childNodes[0].nodeValue; |
|
630
|
|
|
|
|
631
|
|
|
// Just in case it's the first time the message is modified and the element is hidden |
|
632
|
|
|
modified_element.style.display = 'block'; |
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
// Hide the icon if we were told to |
|
636
|
|
|
if (this.opt.sIconHide !== null) |
|
637
|
|
|
{ |
|
638
|
|
|
var oCurrentMsgIcon = document.getElementById('msg_icon_' + this.sCurMessageId.replace("msg_", "")); |
|
639
|
|
|
if (oCurrentMsgIcon !== null && oCurrentMsgIcon.src.indexOf(this.opt.sIconHide) > 0) |
|
640
|
|
|
this.oMsgIcon.style.display = 'none'; |
|
|
|
|
|
|
641
|
|
|
} |
|
642
|
|
|
|
|
643
|
|
|
// Re embed any video links if the feature is available |
|
644
|
|
|
if ($.isFunction($.fn.linkifyvideo)) |
|
645
|
|
|
$().linkifyvideo(oEmbedtext, this.sCurMessageId); |
|
|
|
|
|
|
646
|
|
|
|
|
647
|
|
|
// Hello, Sweetie |
|
648
|
|
|
$('#' + this.sCurMessageId + ' .spoilerheader').click(function(){ |
|
649
|
|
|
$(this).next().children().slideToggle("fast"); |
|
650
|
|
|
}); |
|
651
|
|
|
|
|
652
|
|
|
// Re-Fix code blocks |
|
653
|
|
|
if (typeof elk_codefix === 'function') |
|
|
|
|
|
|
654
|
|
|
elk_codefix(); |
|
|
|
|
|
|
655
|
|
|
|
|
656
|
|
|
// And pretty the code |
|
657
|
|
|
if (typeof prettyPrint === 'function') |
|
|
|
|
|
|
658
|
|
|
prettyPrint(); |
|
|
|
|
|
|
659
|
|
|
} |
|
660
|
|
|
else if (error) |
|
661
|
|
|
{ |
|
662
|
|
|
oErrordiv = document.getElementById('error_box'); |
|
663
|
|
|
oErrordiv.innerHTML = error.childNodes[0].nodeValue; |
|
664
|
|
|
oErrordiv.style.display = ''; |
|
665
|
|
|
if (error.getAttribute('in_body') === '1') |
|
666
|
|
|
$(document.forms.quickModForm.message).addClass('border_error'); |
|
|
|
|
|
|
667
|
|
|
if (error.getAttribute('in_subject') === '1') |
|
668
|
|
|
$(document.forms.quickModForm.subject).addClass('border_error'); |
|
|
|
|
|
|
669
|
|
|
} |
|
670
|
|
|
}; |
|
671
|
|
|
|
|
672
|
|
|
/** |
|
673
|
|
|
* Quick Moderation for the topic view |
|
674
|
|
|
* |
|
675
|
|
|
* @param {type} oOptions |
|
676
|
|
|
*/ |
|
677
|
|
|
function InTopicModeration(oOptions) |
|
678
|
|
|
{ |
|
679
|
|
|
this.opt = oOptions; |
|
680
|
|
|
this.bButtonsShown = false; |
|
681
|
|
|
this.iNumSelected = 0; |
|
682
|
|
|
|
|
683
|
|
|
// Add backwards compatibility with old themes. |
|
684
|
|
|
if (typeof(this.opt.sSessionVar) === 'undefined') |
|
685
|
|
|
this.opt.sSessionVar = 'sesc'; |
|
|
|
|
|
|
686
|
|
|
|
|
687
|
|
|
this.init(); |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
InTopicModeration.prototype.init = function() |
|
691
|
|
|
{ |
|
692
|
|
|
// Add checkboxes to all the messages. |
|
693
|
|
|
for (var i = 0, n = this.opt.aMessageIds.length; i < n; i++) |
|
694
|
|
|
{ |
|
695
|
|
|
// Create the checkbox. |
|
696
|
|
|
var oCheckbox = document.createElement('input'); |
|
697
|
|
|
|
|
698
|
|
|
oCheckbox.type = 'checkbox'; |
|
699
|
|
|
oCheckbox.className = 'input_check'; |
|
700
|
|
|
oCheckbox.name = 'msgs[]'; |
|
701
|
|
|
oCheckbox.value = this.opt.aMessageIds[i]; |
|
702
|
|
|
oCheckbox.instanceRef = this; |
|
703
|
|
|
oCheckbox.onclick = function () { |
|
704
|
|
|
this.instanceRef.handleClick(this); |
|
705
|
|
|
}; |
|
706
|
|
|
|
|
707
|
|
|
// Append it to the container |
|
708
|
|
|
var oCheckboxContainer = document.getElementById(this.opt.sCheckboxContainerMask + this.opt.aMessageIds[i]); |
|
709
|
|
|
oCheckboxContainer.appendChild(oCheckbox); |
|
710
|
|
|
oCheckboxContainer.style.display = 'inline'; |
|
711
|
|
|
} |
|
712
|
|
|
}; |
|
713
|
|
|
|
|
714
|
|
|
// They clicked a checkbox in a message so we show the button options to them |
|
715
|
|
|
InTopicModeration.prototype.handleClick = function(oCheckbox) |
|
716
|
|
|
{ |
|
717
|
|
|
if (!this.bButtonsShown && this.opt.sButtonStripDisplay) |
|
718
|
|
|
{ |
|
719
|
|
|
var oButtonStrip = document.getElementById(this.opt.sButtonStrip), |
|
720
|
|
|
oButtonStripDisplay = document.getElementById(this.opt.sButtonStripDisplay); |
|
721
|
|
|
|
|
722
|
|
|
// Make sure it can go somewhere. |
|
723
|
|
|
if (typeof(oButtonStripDisplay) === 'object' && oButtonStripDisplay !== null) |
|
724
|
|
|
oButtonStripDisplay.style.display = ""; |
|
|
|
|
|
|
725
|
|
|
else |
|
726
|
|
|
{ |
|
727
|
|
|
var oNewDiv = document.createElement('div'), |
|
728
|
|
|
oNewList = document.createElement('ul'); |
|
729
|
|
|
|
|
730
|
|
|
oNewDiv.id = this.opt.sButtonStripDisplay; |
|
731
|
|
|
oNewDiv.className = this.opt.sButtonStripClass ? this.opt.sButtonStripClass : 'buttonlist floatbottom'; |
|
732
|
|
|
|
|
733
|
|
|
oNewDiv.appendChild(oNewList); |
|
734
|
|
|
oButtonStrip.appendChild(oNewDiv); |
|
735
|
|
|
} |
|
736
|
|
|
|
|
737
|
|
|
// Add the 'remove selected items' button. |
|
738
|
|
|
if (this.opt.bCanRemove) |
|
739
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
|
|
|
|
|
740
|
|
|
sId: this.opt.sSelf + '_remove_button', |
|
741
|
|
|
sText: this.opt.sRemoveButtonLabel, |
|
742
|
|
|
sImage: this.opt.sRemoveButtonImage, |
|
743
|
|
|
sUrl: '#', |
|
744
|
|
|
sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'remove\')"' |
|
745
|
|
|
}); |
|
746
|
|
|
|
|
747
|
|
|
// Add the 'restore selected items' button. |
|
748
|
|
|
if (this.opt.bCanRestore) |
|
749
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
|
|
|
|
|
750
|
|
|
sId: this.opt.sSelf + '_restore_button', |
|
751
|
|
|
sText: this.opt.sRestoreButtonLabel, |
|
752
|
|
|
sImage: this.opt.sRestoreButtonImage, |
|
753
|
|
|
sUrl: '#', |
|
754
|
|
|
sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'restore\')"' |
|
755
|
|
|
}); |
|
756
|
|
|
|
|
757
|
|
|
// Add the 'split selected items' button. |
|
758
|
|
|
if (this.opt.bCanSplit) |
|
759
|
|
|
elk_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, { |
|
|
|
|
|
|
760
|
|
|
sId: this.opt.sSelf + '_split_button', |
|
761
|
|
|
sText: this.opt.sSplitButtonLabel, |
|
762
|
|
|
sImage: this.opt.sSplitButtonImage, |
|
763
|
|
|
sUrl: '#', |
|
764
|
|
|
sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'split\')"' |
|
765
|
|
|
}); |
|
766
|
|
|
|
|
767
|
|
|
// Adding these buttons once should be enough. |
|
768
|
|
|
this.bButtonsShown = true; |
|
769
|
|
|
} |
|
770
|
|
|
|
|
771
|
|
|
// Keep stats on how many items were selected. |
|
772
|
|
|
this.iNumSelected += oCheckbox.checked ? 1 : -1; |
|
773
|
|
|
|
|
774
|
|
|
// Show the number of messages selected in each of the buttons. |
|
775
|
|
|
if (this.opt.bCanRemove && !this.opt.bUseImageButton) |
|
776
|
|
|
{ |
|
777
|
|
|
document.getElementById(this.opt.sSelf + '_remove_button_text').innerHTML = this.opt.sRemoveButtonLabel + ' [' + this.iNumSelected + ']'; |
|
778
|
|
|
document.getElementById(this.opt.sSelf + '_remove_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
if (this.opt.bCanRestore && !this.opt.bUseImageButton) |
|
782
|
|
|
{ |
|
783
|
|
|
document.getElementById(this.opt.sSelf + '_restore_button_text').innerHTML = this.opt.sRestoreButtonLabel + ' [' + this.iNumSelected + ']'; |
|
784
|
|
|
document.getElementById(this.opt.sSelf + '_restore_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
if (this.opt.bCanSplit && !this.opt.bUseImageButton) |
|
788
|
|
|
{ |
|
789
|
|
|
document.getElementById(this.opt.sSelf + '_split_button_text').innerHTML = this.opt.sSplitButtonLabel + ' [' + this.iNumSelected + ']'; |
|
790
|
|
|
document.getElementById(this.opt.sSelf + '_split_button').style.display = this.iNumSelected < 1 ? "none" : ""; |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
// Try to restore the correct position. |
|
794
|
|
|
var aItems = document.getElementById(this.opt.sButtonStrip).getElementsByTagName('span'); |
|
795
|
|
|
if (aItems.length > 3) |
|
796
|
|
|
{ |
|
797
|
|
|
if (this.iNumSelected < 1) |
|
798
|
|
|
{ |
|
799
|
|
|
aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*position_holder/, 'last'); |
|
800
|
|
|
aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*position_holder/, 'last'); |
|
801
|
|
|
} |
|
802
|
|
|
else |
|
803
|
|
|
{ |
|
804
|
|
|
aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*last/, 'position_holder'); |
|
805
|
|
|
aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*last/, 'position_holder'); |
|
806
|
|
|
} |
|
807
|
|
|
} |
|
808
|
|
|
}; |
|
809
|
|
|
|
|
810
|
|
|
// Called when the user clicks one of the buttons that we added |
|
811
|
|
|
InTopicModeration.prototype.handleSubmit = function (sSubmitType) |
|
812
|
|
|
{ |
|
813
|
|
|
var oForm = document.getElementById(this.opt.sFormId); |
|
814
|
|
|
|
|
815
|
|
|
// Make sure this form isn't submitted in another way than this function. |
|
816
|
|
|
var oInput = document.createElement('input'); |
|
817
|
|
|
|
|
818
|
|
|
oInput.type = 'hidden'; |
|
819
|
|
|
oInput.name = this.opt.sSessionVar; |
|
820
|
|
|
oInput.value = this.opt.sSessionId; |
|
821
|
|
|
oForm.appendChild(oInput); |
|
822
|
|
|
|
|
823
|
|
|
// Set the form action based on the button they clicked |
|
824
|
|
|
switch (sSubmitType) |
|
825
|
|
|
{ |
|
826
|
|
|
case 'remove': |
|
827
|
|
|
if (!confirm(this.opt.sRemoveButtonConfirm)) |
|
|
|
|
|
|
828
|
|
|
return false; |
|
|
|
|
|
|
829
|
|
|
|
|
830
|
|
|
oForm.action = oForm.action.replace(/;split_selection=1/, ''); |
|
831
|
|
|
oForm.action = oForm.action.replace(/;restore_selected=1/, ''); |
|
832
|
|
|
break; |
|
833
|
|
|
|
|
834
|
|
|
case 'restore': |
|
835
|
|
|
if (!confirm(this.opt.sRestoreButtonConfirm)) |
|
836
|
|
|
return false; |
|
|
|
|
|
|
837
|
|
|
|
|
838
|
|
|
oForm.action = oForm.action.replace(/;split_selection=1/, ''); |
|
839
|
|
|
oForm.action += ';restore_selected=1'; |
|
840
|
|
|
break; |
|
841
|
|
|
|
|
842
|
|
|
case 'split': |
|
843
|
|
|
if (!confirm(this.opt.sRestoreButtonConfirm)) |
|
844
|
|
|
return false; |
|
|
|
|
|
|
845
|
|
|
|
|
846
|
|
|
oForm.action = oForm.action.replace(/;restore_selected=1/, ''); |
|
847
|
|
|
oForm.action += ';split_selection=1'; |
|
848
|
|
|
break; |
|
849
|
|
|
|
|
850
|
|
|
default: |
|
851
|
|
|
return false; |
|
852
|
|
|
break; |
|
|
|
|
|
|
853
|
|
|
} |
|
854
|
|
|
|
|
855
|
|
|
oForm.submit(); |
|
856
|
|
|
return true; |
|
857
|
|
|
}; |
|
858
|
|
|
|
|
859
|
|
|
|
|
860
|
|
|
/** |
|
861
|
|
|
* Expands an attachment thumbnail when its clicked |
|
862
|
|
|
* |
|
863
|
|
|
* @param {string} thumbID |
|
864
|
|
|
* @param {string} messageID |
|
865
|
|
|
*/ |
|
866
|
|
|
function expandThumbLB(thumbID, messageID) { |
|
867
|
|
|
var link = document.getElementById('link_' + thumbID), |
|
868
|
|
|
siblings = $('a[data-lightboxmessage="' + messageID + '"]'), |
|
869
|
|
|
navigation = [], |
|
870
|
|
|
xDown = null, |
|
871
|
|
|
yDown = null, |
|
872
|
|
|
$elk_expand_icon = $('<span id="elk_lb_expand"></span>'), |
|
873
|
|
|
$elk_next_icon = $('<span id="elk_lb_next"></span>'), |
|
874
|
|
|
$elk_prev_icon = $('<span id="elk_lb_prev"></span>'), |
|
875
|
|
|
$elk_lightbox = $('#elk_lightbox'), |
|
876
|
|
|
$elk_lb_content = $('#elk_lb_content'), |
|
877
|
|
|
ajaxIndicatorOn = function () { |
|
878
|
|
|
$('<div id="lightbox-loading"><i class="icon icon-spin icon-xl i-spinner"></i><div>').appendTo($elk_lb_content); |
|
879
|
|
|
$('html, body').addClass('elk_lb_no_scrolling'); |
|
880
|
|
|
}, |
|
881
|
|
|
ajaxIndicatorOff = function () { |
|
882
|
|
|
$('#lightbox-loading').remove(); |
|
883
|
|
|
}, |
|
884
|
|
|
closeLightbox = function () { |
|
885
|
|
|
// Close the lightbox and remove handlers |
|
886
|
|
|
$elk_expand_icon.off('click'); |
|
887
|
|
|
$elk_next_icon.off('click'); |
|
888
|
|
|
$elk_prev_icon.off('click'); |
|
889
|
|
|
$elk_lightbox.hide(); |
|
890
|
|
|
$elk_lb_content.html('').removeAttr('style').removeClass('expand'); |
|
891
|
|
|
$('html, body').removeClass('elk_lb_no_scrolling'); |
|
892
|
|
|
$(window).off('resize.lb'); |
|
893
|
|
|
$(window).off('keydown.lb'); |
|
894
|
|
|
$(window).off('touchstart.lb'); |
|
895
|
|
|
$(window).off('touchmove.lb'); |
|
896
|
|
|
}, |
|
897
|
|
|
openLightbox = function () { |
|
898
|
|
|
// Load and open an image in the lightbox |
|
899
|
|
|
$('<img id="elk_lb_img" src="' + link.href + '">') |
|
900
|
|
|
.on('load', function () { |
|
901
|
|
|
var screenWidth = (window.innerWidth ? window.innerWidth : $(window).width()) * (is_mobile ? 0.8 : 0.9), |
|
|
|
|
|
|
902
|
|
|
screenHeight = (window.innerHeight ? window.innerHeight : $(window).height()) * 0.9; |
|
903
|
|
|
|
|
904
|
|
|
$(this).css({ |
|
905
|
|
|
'max-width': Math.floor(screenWidth) + 'px', |
|
906
|
|
|
'max-height': Math.floor(screenHeight) + 'px' |
|
907
|
|
|
}); |
|
908
|
|
|
|
|
909
|
|
|
$elk_lb_content.html($(this)).append($elk_expand_icon) |
|
910
|
|
|
.append($elk_next_icon).append($elk_prev_icon); |
|
911
|
|
|
|
|
912
|
|
|
ajaxIndicatorOff(); |
|
913
|
|
|
}) |
|
914
|
|
|
.on('error', function () { |
|
915
|
|
|
// Perhaps a message, but for now make it look like we tried and failed |
|
916
|
|
|
setTimeout(function () { |
|
917
|
|
|
ajaxIndicatorOff(); |
|
918
|
|
|
closeLightbox(); |
|
919
|
|
|
window.location = link.href; |
|
920
|
|
|
}, 1500); |
|
921
|
|
|
}); |
|
922
|
|
|
}, |
|
923
|
|
|
nextNav = function () { |
|
924
|
|
|
// Get / Set the next image ID in the array (with wrap around) |
|
925
|
|
|
thumbID = navigation[($.inArray(thumbID, navigation) + 1) % navigation.length]; |
|
926
|
|
|
}, |
|
927
|
|
|
prevNav = function () { |
|
928
|
|
|
// Get / Set the previous image ID in the array (with wrap around) |
|
929
|
|
|
thumbID = navigation[($.inArray(thumbID, navigation) - 1 + navigation.length) % navigation.length]; |
|
930
|
|
|
}, |
|
931
|
|
|
navLightbox = function () { |
|
932
|
|
|
// Navigate to the next image and show it in the lightbox |
|
933
|
|
|
$elk_lb_content.html('').removeAttr('style').removeClass('expand'); |
|
934
|
|
|
ajaxIndicatorOn(); |
|
935
|
|
|
$elk_expand_icon.off('click'); |
|
936
|
|
|
$elk_next_icon.off('click'); |
|
937
|
|
|
$elk_prev_icon.off('click'); |
|
938
|
|
|
link = document.getElementById('link_' + thumbID); |
|
939
|
|
|
openLightbox(); |
|
940
|
|
|
expandLightbox(); |
|
941
|
|
|
}, |
|
942
|
|
|
expandLightbox = function () { |
|
943
|
|
|
// Add an expand the image to full size when the expand icon is clicked |
|
944
|
|
|
$elk_expand_icon.on('click', function () { |
|
945
|
|
|
$('#elk_lb_content').addClass('expand').css({ |
|
946
|
|
|
'height': Math.floor(window.innerHeight * 0.95) + 'px', |
|
947
|
|
|
'width': Math.floor(window.innerWidth * 0.9) + 'px', |
|
948
|
|
|
'left': '0' |
|
949
|
|
|
}); |
|
950
|
|
|
$('#elk_lb_img').removeAttr('style'); |
|
951
|
|
|
$elk_expand_icon.hide(); |
|
952
|
|
|
$(window).off('keydown.lb'); |
|
953
|
|
|
$(window).off('touchmove.lb'); |
|
954
|
|
|
}); |
|
955
|
|
|
$elk_next_icon.on('click', function (event) { |
|
956
|
|
|
event.preventDefault(); |
|
957
|
|
|
event.stopPropagation(); |
|
958
|
|
|
nextNav(); |
|
959
|
|
|
navLightbox(); |
|
960
|
|
|
}); |
|
961
|
|
|
$elk_prev_icon.on('click', function (event) { |
|
962
|
|
|
event.preventDefault(); |
|
963
|
|
|
event.stopPropagation(); |
|
964
|
|
|
prevNav(); |
|
965
|
|
|
navLightbox(); |
|
966
|
|
|
}); |
|
967
|
|
|
}; |
|
968
|
|
|
|
|
969
|
|
|
// Create the lightbox container only if needed |
|
970
|
|
|
if ($elk_lightbox.length <= 0) { |
|
971
|
|
|
// For easy manipulation |
|
972
|
|
|
$elk_lightbox = $('<div id="elk_lightbox"></div>'); |
|
973
|
|
|
$elk_lb_content = $('<div id="elk_lb_content"></div>'); |
|
974
|
|
|
|
|
975
|
|
|
$('body').append($elk_lightbox.append($elk_lb_content)); |
|
976
|
|
|
} |
|
977
|
|
|
|
|
978
|
|
|
// Load the navigation array |
|
979
|
|
|
siblings.each(function () { |
|
980
|
|
|
navigation[navigation.length] = $(this).data('lightboximage'); |
|
981
|
|
|
}); |
|
982
|
|
|
|
|
983
|
|
|
// We should always have at least the thumbID |
|
984
|
|
|
if (navigation.length === 0) { |
|
985
|
|
|
navigation[navigation.length] = thumbID; |
|
986
|
|
|
} |
|
987
|
|
|
|
|
988
|
|
|
// Load and show the initial lightbox container div |
|
989
|
|
|
ajaxIndicatorOn(); |
|
990
|
|
|
$elk_lightbox.fadeIn(200); |
|
991
|
|
|
openLightbox(); |
|
992
|
|
|
expandLightbox(); |
|
993
|
|
|
|
|
994
|
|
|
// Click anywhere on the page (except the expand icon) to close the lightbox |
|
995
|
|
|
$elk_lightbox.on('click', function (event) { |
|
996
|
|
|
if (event.target.id !== $elk_expand_icon.attr('id')) { |
|
997
|
|
|
event.preventDefault(); |
|
998
|
|
|
closeLightbox(); |
|
999
|
|
|
} |
|
1000
|
|
|
}); |
|
1001
|
|
|
|
|
1002
|
|
|
// Provide some keyboard navigation |
|
1003
|
|
|
$(window).on('keydown.lb', function (event) { |
|
1004
|
|
|
event.preventDefault(); |
|
1005
|
|
|
|
|
1006
|
|
|
// escape |
|
1007
|
|
|
if (event.keyCode === 27) { |
|
1008
|
|
|
closeLightbox(); |
|
1009
|
|
|
} |
|
1010
|
|
|
|
|
1011
|
|
|
// left |
|
1012
|
|
|
if (event.keyCode === 37) { |
|
1013
|
|
|
prevNav(); |
|
1014
|
|
|
navLightbox(); |
|
1015
|
|
|
} |
|
1016
|
|
|
|
|
1017
|
|
|
// right |
|
1018
|
|
|
if (event.keyCode === 39) { |
|
1019
|
|
|
nextNav(); |
|
1020
|
|
|
navLightbox(); |
|
1021
|
|
|
} |
|
1022
|
|
|
}); |
|
1023
|
|
|
|
|
1024
|
|
|
// Make the image size fluid as the browser window changes |
|
1025
|
|
|
$(window).on('resize.lb', function () { |
|
1026
|
|
|
// Account for either a normal or expanded view |
|
1027
|
|
|
var $_elk_lb_content = $('#elk_lb_content'); |
|
1028
|
|
|
|
|
1029
|
|
|
if ($_elk_lb_content.hasClass('expand')) |
|
1030
|
|
|
$_elk_lb_content.css({'height': window.innerHeight * 0.85, 'width': window.innerWidth * 0.9}); |
|
|
|
|
|
|
1031
|
|
|
else |
|
1032
|
|
|
$('#elk_lb_img').css({'max-height': window.innerHeight * 0.9, 'max-width': window.innerWidth * 0.8}); |
|
1033
|
|
|
}); |
|
1034
|
|
|
|
|
1035
|
|
|
// Swipe navigation start, record press x/y |
|
1036
|
|
|
$(window).on('touchstart.lb', function (event) { |
|
1037
|
|
|
xDown = event.originalEvent.touches[0].clientX; |
|
1038
|
|
|
yDown = event.originalEvent.touches[0].clientY; |
|
1039
|
|
|
}); |
|
1040
|
|
|
|
|
1041
|
|
|
// Swipe navigation left / right detection |
|
1042
|
|
|
$(window).on('touchmove.lb', function(event) { |
|
1043
|
|
|
// No known start point ? |
|
1044
|
|
|
if (!xDown || !yDown) |
|
1045
|
|
|
return; |
|
|
|
|
|
|
1046
|
|
|
|
|
1047
|
|
|
// Where are we now |
|
1048
|
|
|
var xUp = event.originalEvent.touches[0].clientX, |
|
1049
|
|
|
yUp = event.originalEvent.touches[0].clientY, |
|
1050
|
|
|
xDiff = xDown - xUp, |
|
1051
|
|
|
yDiff = yDown - yUp; |
|
1052
|
|
|
|
|
1053
|
|
|
// Moved enough to know what direction they are swiping |
|
1054
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) { |
|
1055
|
|
|
if (xDiff > 0) { |
|
1056
|
|
|
// Swipe left |
|
1057
|
|
|
prevNav(); |
|
1058
|
|
|
navLightbox(); |
|
1059
|
|
|
} else { |
|
1060
|
|
|
// Swipe right |
|
1061
|
|
|
nextNav(); |
|
1062
|
|
|
navLightbox(); |
|
1063
|
|
|
} |
|
1064
|
|
|
} |
|
1065
|
|
|
|
|
1066
|
|
|
// Reset values |
|
1067
|
|
|
xDown = null; |
|
1068
|
|
|
yDown = null; |
|
1069
|
|
|
}); |
|
1070
|
|
|
|
|
1071
|
|
|
return false; |
|
1072
|
|
|
} |
|
1073
|
|
|
|
|
1074
|
|
|
/** |
|
1075
|
|
|
* Expands an attachment thumbnail when its clicked |
|
1076
|
|
|
* |
|
1077
|
|
|
* @param {string} thumbID |
|
1078
|
|
|
*/ |
|
1079
|
|
|
function expandThumb(thumbID) |
|
1080
|
|
|
{ |
|
1081
|
|
|
var img = document.getElementById('thumb_' + thumbID), |
|
1082
|
|
|
link = document.getElementById('link_' + thumbID), |
|
1083
|
|
|
name = link.nextSibling; |
|
1084
|
|
|
|
|
1085
|
|
|
// Some browsers will add empty text so loop to the next element node |
|
1086
|
|
|
while (name && name.nodeType !== 1) { |
|
1087
|
|
|
name = name.nextSibling; |
|
1088
|
|
|
} |
|
1089
|
|
|
var details = name.nextSibling; |
|
1090
|
|
|
while (details && details.nodeType !== 1) { |
|
1091
|
|
|
details = details.nextSibling; |
|
1092
|
|
|
} |
|
1093
|
|
|
|
|
1094
|
|
|
// Save the currently displayed image attributes |
|
1095
|
|
|
var tmp_src = img.src, |
|
1096
|
|
|
tmp_height = img.style.height, |
|
1097
|
|
|
tmp_width = img.style.width; |
|
1098
|
|
|
|
|
1099
|
|
|
// Set the displayed image attributes to the link attributes, this will expand in place |
|
1100
|
|
|
img.src = link.href; |
|
1101
|
|
|
img.style.width = link.style.width; |
|
1102
|
|
|
img.style.height = link.style.height; |
|
1103
|
|
|
|
|
1104
|
|
|
// Swap the class name on the title/desc |
|
1105
|
|
|
name.className = name.className.includes('_exp') ? 'attachment_name' : 'attachment_name attachment_name_exp'; |
|
1106
|
|
|
details.className = details.className.includes('_exp') ? 'attachment_details' : 'attachment_details attachment_details_exp'; |
|
1107
|
|
|
|
|
1108
|
|
|
// Now place the image attributes back |
|
1109
|
|
|
link.href = tmp_src; |
|
1110
|
|
|
link.style.width = tmp_width; |
|
1111
|
|
|
link.style.height = tmp_height; |
|
1112
|
|
|
|
|
1113
|
|
|
return false; |
|
1114
|
|
|
} |
|
1115
|
|
|
|
|
1116
|
|
|
/** |
|
1117
|
|
|
* Provides a way to toggle an ignored message(s) visibility |
|
1118
|
|
|
* |
|
1119
|
|
|
* @param {object} msgids |
|
1120
|
|
|
* @param {string} text |
|
1121
|
|
|
*/ |
|
1122
|
|
|
function ignore_toggles(msgids, text) |
|
1123
|
|
|
{ |
|
1124
|
|
|
for (var i = 0; i < msgids.length; i++) |
|
1125
|
|
|
{ |
|
1126
|
|
|
var msgid = msgids[i]; |
|
1127
|
|
|
|
|
1128
|
|
|
var discard = new elk_Toggle({ |
|
|
|
|
|
|
1129
|
|
|
bToggleEnabled: true, |
|
1130
|
|
|
bCurrentlyCollapsed: true, |
|
1131
|
|
|
aSwappableContainers: [ |
|
1132
|
|
|
'msg_' + msgid + '_extra_info', |
|
1133
|
|
|
'msg_' + msgid, |
|
1134
|
|
|
'msg_' + msgid + '_footer', |
|
1135
|
|
|
'msg_' + msgid + '_quick_mod', |
|
1136
|
|
|
'modify_button_' + msgid, |
|
1137
|
|
|
'msg_' + msgid + '_signature' |
|
1138
|
|
|
], |
|
1139
|
|
|
aSwapLinks: [ |
|
1140
|
|
|
{ |
|
1141
|
|
|
sId: 'msg_' + msgid + '_ignored_link', |
|
1142
|
|
|
msgExpanded: '', |
|
1143
|
|
|
msgCollapsed: text |
|
1144
|
|
|
} |
|
1145
|
|
|
] |
|
1146
|
|
|
}); |
|
1147
|
|
|
} |
|
1148
|
|
|
} |
|
1149
|
|
|
|
|
1150
|
|
|
/** |
|
1151
|
|
|
* Open the sendtopic overlay div |
|
1152
|
|
|
* @todo make these... "things" look nice |
|
1153
|
|
|
* |
|
1154
|
|
|
* @param {type} desktopURL |
|
1155
|
|
|
* @param {type} sHeader |
|
1156
|
|
|
* @param {type} sIcon |
|
1157
|
|
|
*/ |
|
1158
|
|
|
function sendtopicOverlayDiv(desktopURL, sHeader, sIcon) |
|
1159
|
|
|
{ |
|
1160
|
|
|
// Set up our div details |
|
1161
|
|
|
var sAjax_indicator = '<div class="centertext"><i class="icon icon-spin i-spinner"></i></div>', |
|
1162
|
|
|
oPopup_body; |
|
1163
|
|
|
|
|
1164
|
|
|
// TODO: Even if we weren't purging icons, this is still not the right icon for this. |
|
1165
|
|
|
sIcon = typeof(sIcon) === 'string' ? sIcon : 'i-envelope'; |
|
1166
|
|
|
sHeader = typeof(sHeader) === 'string' ? sHeader : help_popup_heading_text; |
|
|
|
|
|
|
1167
|
|
|
|
|
1168
|
|
|
// Load the send topic overlay div |
|
1169
|
|
|
$.ajax({ |
|
1170
|
|
|
url: desktopURL, |
|
1171
|
|
|
type: "GET", |
|
1172
|
|
|
dataType: "html" |
|
1173
|
|
|
}) |
|
1174
|
|
|
.done(function (data) { |
|
1175
|
|
|
var $base_obj = $('<div id="temp_help">').html(data).find('#send_topic'), |
|
1176
|
|
|
title = ''; |
|
1177
|
|
|
|
|
1178
|
|
|
$base_obj.find('h3').each(function () { |
|
1179
|
|
|
title = $(this).text(); |
|
1180
|
|
|
$(this).remove(); |
|
1181
|
|
|
}); |
|
1182
|
|
|
|
|
1183
|
|
|
var form = $base_obj.find('form'), |
|
|
|
|
|
|
1184
|
|
|
url = $base_obj.find('form').attr('action'); |
|
1185
|
|
|
|
|
1186
|
|
|
// Create the div that we are going to load |
|
1187
|
|
|
var oContainer = new smc_Popup({heading: (title !== '' ? title : sHeader), content: sAjax_indicator, icon: sIcon}); |
|
|
|
|
|
|
1188
|
|
|
oPopup_body = $('#' + oContainer.popup_id).find('.popup_content'); |
|
1189
|
|
|
oPopup_body.html($base_obj.html()); |
|
1190
|
|
|
|
|
1191
|
|
|
// Tweak the width of the popup for this special window |
|
1192
|
|
|
$('.popup_window').css({'width': '640px'}); |
|
1193
|
|
|
|
|
1194
|
|
|
sendtopicForm(oPopup_body, url, oContainer); |
|
1195
|
|
|
}) |
|
1196
|
|
|
.fail(function (xhr, textStatus, errorThrown) { |
|
|
|
|
|
|
1197
|
|
|
oPopup_body.html(textStatus); |
|
1198
|
|
|
}); |
|
1199
|
|
|
|
|
1200
|
|
|
return false; |
|
1201
|
|
|
} |
|
1202
|
|
|
|
|
1203
|
|
|
/** |
|
1204
|
|
|
* Helper function for sendtopicForm, highlights missing fields that must |
|
1205
|
|
|
* be filled in in order to send the topic |
|
1206
|
|
|
* |
|
1207
|
|
|
* @param {type} $this_form |
|
1208
|
|
|
* @param {string} classname |
|
1209
|
|
|
* @param {boolean} focused |
|
1210
|
|
|
*/ |
|
1211
|
|
|
function addRequiredElem($this_form, classname, focused) |
|
1212
|
|
|
{ |
|
1213
|
|
|
if (typeof(focused) === 'undefined') |
|
1214
|
|
|
focused = false; |
|
|
|
|
|
|
1215
|
|
|
|
|
1216
|
|
|
$this_form.find('input[name="' + classname + '"]').after($('<span class="requiredfield" />').text(required_field).fadeIn()); |
|
|
|
|
|
|
1217
|
|
|
$this_form.find('input[name="' + classname + '"]').keyup(function () { |
|
1218
|
|
|
$this_form.find('.' + classname + ' .requiredfield').fadeOut(function () { |
|
1219
|
|
|
$(this).remove(); |
|
1220
|
|
|
}); |
|
1221
|
|
|
}); |
|
1222
|
|
|
|
|
1223
|
|
|
if (!focused) |
|
1224
|
|
|
{ |
|
1225
|
|
|
$this_form.find('input[name="' + classname + '"]').focus(); |
|
1226
|
|
|
focused = true; |
|
|
|
|
|
|
1227
|
|
|
} |
|
1228
|
|
|
} |
|
1229
|
|
|
|
|
1230
|
|
|
/** |
|
1231
|
|
|
* Send in the send topic form |
|
1232
|
|
|
* |
|
1233
|
|
|
* @param {object} oPopup_body |
|
1234
|
|
|
* @param {string} url |
|
1235
|
|
|
* @param {object} oContainer |
|
1236
|
|
|
*/ |
|
1237
|
|
|
function sendtopicForm(oPopup_body, url, oContainer) |
|
1238
|
|
|
{ |
|
1239
|
|
|
if (typeof(this_body) !== 'undefined') |
|
|
|
|
|
|
1240
|
|
|
oPopup_body.html(this_body); |
|
|
|
|
|
|
1241
|
|
|
|
|
1242
|
|
|
var $this_form = $(oPopup_body).find('form'); |
|
1243
|
|
|
|
|
1244
|
|
|
if (typeof(send_comment) !== 'undefined') |
|
|
|
|
|
|
1245
|
|
|
{ |
|
1246
|
|
|
$this_form.find('input[name="comment"]').val(send_comment); |
|
1247
|
|
|
$this_form.find('input[name="y_name"]').val(sender_name); |
|
|
|
|
|
|
1248
|
|
|
$this_form.find('input[name="y_email"]').val(sender_mail); |
|
|
|
|
|
|
1249
|
|
|
$this_form.find('input[name="r_name"]').val(recipient_name); |
|
|
|
|
|
|
1250
|
|
|
$this_form.find('input[name="r_email"]').val(recipient_mail); |
|
|
|
|
|
|
1251
|
|
|
} |
|
1252
|
|
|
|
|
1253
|
|
|
oPopup_body.find('input[name="send"]').on('click', function (event) { |
|
1254
|
|
|
event.preventDefault(); |
|
1255
|
|
|
|
|
1256
|
|
|
var data = $this_form.serialize() + '&send=1', |
|
1257
|
|
|
sender_name = $this_form.find('input[name="y_name"]').val(), |
|
1258
|
|
|
sender_mail = $this_form.find('input[name="y_email"]').val, |
|
1259
|
|
|
recipient_name = $this_form.find('input[name="r_name"]').val(), |
|
1260
|
|
|
recipient_mail = $this_form.find('input[name="r_email"]').val(), |
|
1261
|
|
|
missing_elems = false; |
|
1262
|
|
|
|
|
1263
|
|
|
// Check for any input fields that were not filled in |
|
1264
|
|
|
if (sender_name === '') |
|
1265
|
|
|
{ |
|
1266
|
|
|
addRequiredElem($this_form, 'y_name', missing_elems); |
|
1267
|
|
|
missing_elems = true; |
|
1268
|
|
|
} |
|
1269
|
|
|
|
|
1270
|
|
|
if (sender_mail === '') |
|
1271
|
|
|
{ |
|
1272
|
|
|
addRequiredElem($this_form, 'y_email', missing_elems); |
|
1273
|
|
|
missing_elems = true; |
|
1274
|
|
|
} |
|
1275
|
|
|
|
|
1276
|
|
|
if (recipient_name === '') |
|
1277
|
|
|
{ |
|
1278
|
|
|
addRequiredElem($this_form, 'r_name', missing_elems); |
|
1279
|
|
|
missing_elems = true; |
|
1280
|
|
|
} |
|
1281
|
|
|
|
|
1282
|
|
|
if (recipient_mail === '') |
|
1283
|
|
|
{ |
|
1284
|
|
|
addRequiredElem($this_form, 'r_email', missing_elems); |
|
1285
|
|
|
missing_elems = true; |
|
1286
|
|
|
} |
|
1287
|
|
|
|
|
1288
|
|
|
// Missing required elements, back we go |
|
1289
|
|
|
if (missing_elems) |
|
1290
|
|
|
return; |
|
|
|
|
|
|
1291
|
|
|
|
|
1292
|
|
|
// Send it to the server to validate the input |
|
1293
|
|
|
$.ajax({ |
|
1294
|
|
|
type: 'post', |
|
1295
|
|
|
url: url + ';api', |
|
1296
|
|
|
data: data |
|
1297
|
|
|
}) |
|
1298
|
|
|
.done(function (request) { |
|
1299
|
|
|
var oElement = $(request).find('elk')[0], |
|
1300
|
|
|
text = null; |
|
|
|
|
|
|
1301
|
|
|
|
|
1302
|
|
|
// No errors in the response, lets say it sent. |
|
1303
|
|
|
if (oElement.getElementsByTagName('error').length === 0) |
|
1304
|
|
|
{ |
|
1305
|
|
|
text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities(); |
|
1306
|
|
|
text += '<br /><br /><input type="submit" name="send" value="' + sendtopic_back + '" class="button_submit"/><input type="submit" name="cancel" value="' + sendtopic_close + '" class="button_submit"/>'; |
|
|
|
|
|
|
1307
|
|
|
|
|
1308
|
|
|
oPopup_body.html(text); |
|
1309
|
|
|
|
|
1310
|
|
|
// Setup the cancel button to end this entire process |
|
1311
|
|
|
oPopup_body.find('input[name="cancel"]').each(function () { |
|
1312
|
|
|
$(this).on('click', function (event) { |
|
1313
|
|
|
event.preventDefault(); |
|
1314
|
|
|
oContainer.hide(); |
|
1315
|
|
|
}); |
|
1316
|
|
|
}); |
|
1317
|
|
|
} |
|
1318
|
|
|
// Invalid data in the form, like a bad email etc, show the message text |
|
1319
|
|
|
else |
|
1320
|
|
|
{ |
|
1321
|
|
|
if (oElement.getElementsByTagName('text').length !== 0) |
|
1322
|
|
|
{ |
|
1323
|
|
|
text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities(); |
|
1324
|
|
|
text += '<br /><br /><input type="submit" name="send" value="' + sendtopic_back + '" class="button_submit"/><input type="submit" name="cancel" value="' + sendtopic_close + '" class="button_submit"/>'; |
|
1325
|
|
|
|
|
1326
|
|
|
oPopup_body.html(text); |
|
1327
|
|
|
oPopup_body.find('input[name="send"]').each(function () { |
|
1328
|
|
|
$(this).on('click', function (event) { |
|
1329
|
|
|
event.preventDefault(); |
|
1330
|
|
|
data = $(oPopup_body).find('form').serialize() + '&send=1'; |
|
1331
|
|
|
sendtopicForm(oPopup_body, url, oContainer); |
|
1332
|
|
|
}); |
|
1333
|
|
|
}); |
|
1334
|
|
|
|
|
1335
|
|
|
// Cancel means cancel |
|
1336
|
|
|
oPopup_body.find('input[name="cancel"]').each(function () { |
|
1337
|
|
|
$(this).on('click', function (event) { |
|
1338
|
|
|
event.preventDefault(); |
|
1339
|
|
|
oContainer.hide(); |
|
1340
|
|
|
}); |
|
1341
|
|
|
}); |
|
1342
|
|
|
} |
|
1343
|
|
|
|
|
1344
|
|
|
if (oElement.getElementsByTagName('url').length !== 0) |
|
1345
|
|
|
{ |
|
1346
|
|
|
var url_redir = oElement.getElementsByTagName('url')[0].firstChild.nodeValue; |
|
1347
|
|
|
oPopup_body.html(sendtopic_error.replace('{href}', url_redir)); |
|
|
|
|
|
|
1348
|
|
|
} |
|
1349
|
|
|
} |
|
1350
|
|
|
}) |
|
1351
|
|
|
.fail(function() { |
|
1352
|
|
|
oPopup_body.html(sendtopic_error.replace('{href}', url)); |
|
|
|
|
|
|
1353
|
|
|
}); |
|
1354
|
|
|
}); |
|
1355
|
|
|
} |
|
1356
|
|
|
|
|
1357
|
|
|
|
|
1358
|
|
|
|
|
1359
|
|
|
/** |
|
1360
|
|
|
* Used to split a topic. |
|
1361
|
|
|
* Allows selecting a message so it can be moved from the original to the spit topic or back |
|
1362
|
|
|
* |
|
1363
|
|
|
* @param {string} direction up / down / reset |
|
1364
|
|
|
* @param {int} msg_id message id that is being moved |
|
1365
|
|
|
*/ |
|
1366
|
|
|
function topicSplitselect(direction, msg_id) |
|
1367
|
|
|
{ |
|
1368
|
|
|
getXMLDocument(elk_prepareScriptUrl(elk_scripturl) + "action=splittopics;sa=selectTopics;subname=" + topic_subject + ";topic=" + topic_id + "." + start[0] + ";start2=" + start[1] + ";move=" + direction + ";msg=" + msg_id + ";xml", onTopicSplitReceived); |
|
|
|
|
|
|
1369
|
|
|
return false; |
|
1370
|
|
|
} |
|
1371
|
|
|
|
|
1372
|
|
|
/** |
|
1373
|
|
|
* Callback function for topicSplitselect |
|
1374
|
|
|
* |
|
1375
|
|
|
* @param {xmlCallback} XMLDoc |
|
1376
|
|
|
*/ |
|
1377
|
|
|
function onTopicSplitReceived(XMLDoc) |
|
1378
|
|
|
{ |
|
1379
|
|
|
var i, |
|
1380
|
|
|
j, |
|
1381
|
|
|
pageIndex; |
|
1382
|
|
|
|
|
1383
|
|
|
// Find the selected and not_selected page index containers |
|
1384
|
|
|
for (i = 0; i < 2; i++) |
|
1385
|
|
|
{ |
|
1386
|
|
|
pageIndex = XMLDoc.getElementsByTagName("pageIndex")[i]; |
|
1387
|
|
|
|
|
1388
|
|
|
// Update the page container with our xml response |
|
1389
|
|
|
document.getElementById("pageindex_" + pageIndex.getAttribute("section")).innerHTML = pageIndex.firstChild.nodeValue; |
|
1390
|
|
|
start[i] = pageIndex.getAttribute("startFrom"); |
|
|
|
|
|
|
1391
|
|
|
} |
|
1392
|
|
|
|
|
1393
|
|
|
var numChanges = XMLDoc.getElementsByTagName("change").length, |
|
1394
|
|
|
curChange, |
|
1395
|
|
|
curSection, |
|
1396
|
|
|
curAction, |
|
1397
|
|
|
curId, |
|
1398
|
|
|
curList, |
|
1399
|
|
|
newItem, |
|
1400
|
|
|
sInsertBeforeId, |
|
1401
|
|
|
oListItems, |
|
1402
|
|
|
right_arrow = '<i class="icon icon-lg i-chevron-circle-right"></i>', |
|
1403
|
|
|
left_arrow = '<i class="icon icon-lg i-chevron-circle-left"></i>'; |
|
1404
|
|
|
|
|
1405
|
|
|
// Loop through all of the changes returned in the xml response |
|
1406
|
|
|
for (i = 0; i < numChanges; i++) |
|
1407
|
|
|
{ |
|
1408
|
|
|
curChange = XMLDoc.getElementsByTagName("change")[i]; |
|
1409
|
|
|
curSection = curChange.getAttribute("section"); |
|
1410
|
|
|
curAction = curChange.getAttribute("curAction"); |
|
1411
|
|
|
curId = curChange.getAttribute("id"); |
|
1412
|
|
|
curList = document.getElementById("messages_" + curSection); |
|
1413
|
|
|
|
|
1414
|
|
|
// Remove it from the source list so we can insert it in the destination list |
|
1415
|
|
|
if (curAction === "remove") |
|
1416
|
|
|
curList.removeChild(document.getElementById(curSection + "_" + curId)); |
|
|
|
|
|
|
1417
|
|
|
// Insert a message. |
|
1418
|
|
|
else |
|
1419
|
|
|
{ |
|
1420
|
|
|
// By default, insert the element at the end of the list. |
|
1421
|
|
|
sInsertBeforeId = null; |
|
1422
|
|
|
|
|
1423
|
|
|
// Loop through the list to try and find an item to insert after. |
|
1424
|
|
|
oListItems = curList.getElementsByTagName("li"); |
|
1425
|
|
|
for (j = 0; j < oListItems.length; j++) |
|
1426
|
|
|
{ |
|
1427
|
|
|
if (parseInt(oListItems[j].id.substr(curSection.length + 1)) < curId) |
|
1428
|
|
|
{ |
|
1429
|
|
|
// This would be a nice place to insert the row. |
|
1430
|
|
|
sInsertBeforeId = oListItems[j].id; |
|
1431
|
|
|
|
|
1432
|
|
|
// We're done for now. Escape the loop. |
|
1433
|
|
|
j = oListItems.length + 1; |
|
|
|
|
|
|
1434
|
|
|
} |
|
1435
|
|
|
} |
|
1436
|
|
|
|
|
1437
|
|
|
// Let's create a nice container for the message. |
|
1438
|
|
|
newItem = document.createElement("li"); |
|
1439
|
|
|
newItem.className = ""; |
|
1440
|
|
|
newItem.id = curSection + "_" + curId; |
|
1441
|
|
|
newItem.innerHTML = '' + |
|
1442
|
|
|
'<div class="content">' + |
|
1443
|
|
|
'<div class="message_header">' + |
|
1444
|
|
|
'<a class="split_icon float' + (curSection === "selected" ? "left" : "right") + '" href="' + elk_prepareScriptUrl(elk_scripturl) + 'action=splittopics;sa=selectTopics;subname=' + topic_subject + ';topic=' + topic_id + '.' + not_selected_start + ';start2=' + selected_start + ';move=' + (curSection === "selected" ? "up" : "down") + ';msg=' + curId + '" onclick="return topicSplitselect(\'' + (curSection === "selected" ? 'up' : 'down') + '\', ' + curId + ');">' + |
|
|
|
|
|
|
1445
|
|
|
(curSection === "selected" ? left_arrow : right_arrow) + |
|
1446
|
|
|
'</a>' + |
|
1447
|
|
|
'<strong>' + curChange.getElementsByTagName("subject")[0].firstChild.nodeValue + '</strong> ' + txt_by + ' <strong>' + curChange.getElementsByTagName("poster")[0].firstChild.nodeValue + '</strong>' + |
|
|
|
|
|
|
1448
|
|
|
'<br />' + |
|
1449
|
|
|
'<em>' + curChange.getElementsByTagName("time")[0].firstChild.nodeValue + '</em>' + |
|
1450
|
|
|
'</div>' + |
|
1451
|
|
|
'<div class="post">' + curChange.getElementsByTagName("body")[0].firstChild.nodeValue + '</div>' + |
|
1452
|
|
|
'</div>'; |
|
1453
|
|
|
|
|
1454
|
|
|
// So, where do we insert it? |
|
1455
|
|
|
if (typeof sInsertBeforeId === "string") |
|
1456
|
|
|
curList.insertBefore(newItem, document.getElementById(sInsertBeforeId)); |
|
|
|
|
|
|
1457
|
|
|
else |
|
1458
|
|
|
curList.appendChild(newItem); |
|
1459
|
|
|
} |
|
1460
|
|
|
} |
|
1461
|
|
|
} |
|
1462
|
|
|
|
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.