Completed
Pull Request — development (#2977)
by Stephen
15:23 queued 06:19
created

topic.js ➔ ... ➔ $(window).resize.lb   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 9.6666
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 Release Candidate 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);
0 ignored issues
show
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable sendXMLDocument seems to be never declared. If this is a global, consider adding a /** global: sendXMLDocument */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
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, "&#38;#").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);
0 ignored issues
show
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable sendXMLDocument seems to be never declared. If this is a global, consider adding a /** global: sendXMLDocument */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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>';
0 ignored issues
show
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable elk_session_id seems to be never declared. If this is a global, consider adding a /** global: elk_session_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_session_var seems to be never declared. If this is a global, consider adding a /** global: elk_session_var */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter oEvent is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
227
{
228
	if (this.bInEditMode && !this.bMouseOnDiv)
229
		this.modify_topic_save(elk_session_id, elk_session_var);
0 ignored issues
show
Bug introduced by
The variable elk_session_var seems to be never declared. If this is a global, consider adding a /** global: elk_session_var */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_session_id seems to be never declared. If this is a global, consider adding a /** global: elk_session_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
230
};
231
232
// Moved out of the editing div
233
QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent)
0 ignored issues
show
Unused Code introduced by
The parameter oEvent is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter xDeprecated is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable sendXMLDocument seems to be never declared. If this is a global, consider adding a /** global: sendXMLDocument */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter sSessionId is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter sSessionVar is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
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, "&#38;#").php_urlencode();
561
	x[x.length] = 'message=' + document.forms.quickModForm.message.value.replace(/&#/g, "&#38;#").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);
0 ignored issues
show
Bug introduced by
The variable sendXMLDocument seems to be never declared. If this is a global, consider adding a /** global: sendXMLDocument */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_session_var seems to be never declared. If this is a global, consider adding a /** global: elk_session_var */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_session_id seems to be never declared. If this is a global, consider adding a /** global: elk_session_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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 (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);
0 ignored issues
show
Bug introduced by
The variable oEmbedtext seems to be never declared. If this is a global, consider adding a /** global: oEmbedtext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The variable elk_codefix seems to be never declared. If this is a global, consider adding a /** global: elk_codefix */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
654
			elk_codefix();
655
656
		// And pretty the code
657
		if (typeof prettyPrint === 'function')
0 ignored issues
show
Bug introduced by
The variable prettyPrint seems to be never declared. If this is a global, consider adding a /** global: prettyPrint */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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 = '';
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))
0 ignored issues
show
Debugging Code Best Practice introduced by
The confirm UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The code break after return is not reachable.
Loading history...
Unused Code introduced by
This break statement is unnecessary and may be removed.
Loading history...
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
		$elk_expand_icon = $('<span id="elk_lb_expand"></span>'),
871
		$elk_lightbox = $('#elk_lightbox'),
872
		$elk_lb_content = $('#elk_lb_content'),
873
		ajaxIndicatorOn = function () {
874
			$('<div id="lightbox-loading"><i class="icon icon-spin icon-xl i-spinner"></i><div>').appendTo($elk_lb_content);
875
			$('html, body').addClass('elk_lb_no_scrolling');
876
		},
877
		ajaxIndicatorOff = function () {
878
			$('#lightbox-loading').remove();
879
		},
880
		closeLightbox = function () {
881
			// Close the lightbox and remove handlers
882
			$elk_expand_icon.off('click');
883
			$elk_lightbox.hide();
884
			$elk_lb_content.html('').removeAttr('style').removeClass('expand');
885
			$('html, body').removeClass('elk_lb_no_scrolling');
886
			$(window).off('resize.lb');
887
			$(window).off('keydown.lb');
888
		},
889
		openLightbox = function () {
890
			// Load and open an image in the lightbox
891
			$('<img id="elk_lb_img" src="' + link.href + '">')
892
				.on('load', function () {
893
					var screenWidth = (window.innerWidth ? window.innerWidth : $(window).width()) * (is_mobile ? 0.8 : 0.9),
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable is_mobile is declared in the current environment, consider using typeof is_mobile === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
894
						screenHeight = (window.innerHeight ? window.innerHeight : $(window).height()) * 0.9;
895
896
					$(this).css({
897
						'max-width': Math.floor(screenWidth) + 'px',
898
						'max-height': Math.floor(screenHeight) + 'px'
899
					});
900
901
					$elk_lb_content.html($(this)).append($elk_expand_icon);
902
903
					ajaxIndicatorOff();
904
				})
905
				.on('error', function () {
906
					// Perhaps a message, but for now make it look like we tried and failed
907
					setTimeout(function () {
908
						ajaxIndicatorOff();
909
						closeLightbox();
910
					}, 1500);
911
				});
912
		},
913
		nextNav = function () {
914
			// Get / Set the next image ID in the array (with wrap around)
915
			thumbID = navigation[($.inArray(thumbID, navigation) + 1) % navigation.length];
916
		},
917
		prevNav = function () {
918
			// Get / Set the previous image ID in the array (with wrap around)
919
			thumbID =  navigation[($.inArray(thumbID, navigation) - 1 + navigation.length) % navigation.length];
920
		},
921
		navLightbox = function () {
922
			// Navigate to the next image and show it in the lightbox
923
			$elk_lb_content.html('').removeAttr('style').removeClass('expand');
924
			ajaxIndicatorOn();
925
			$elk_expand_icon.off('click');
926
			link = document.getElementById('link_' + thumbID);
927
			openLightbox();
928
			expandLightbox();
929
		},
930
		expandLightbox = function () {
931
			// Add an expand the image to full size when the expand icon is clicked
932
			$elk_expand_icon.on('click', function () {
933
				$('#elk_lb_content').addClass('expand').css({
934
					'height': Math.floor(window.innerHeight * 0.95) + 'px',
935
					'width': Math.floor(window.innerWidth * 0.9) + 'px',
936
					'left': '0'
937
				});
938
				$('#elk_lb_img').removeAttr('style');
939
				$elk_expand_icon.hide();
940
			});
941
		};
942
943
	// Create the lightbox container only if needed
944
	if ($elk_lightbox.length <= 0) {
945
		// For easy manipulation
946
		$elk_lightbox = $('<div id="elk_lightbox"></div>');
947
		$elk_lb_content = $('<div id="elk_lb_content"></div>');
948
949
		$('body').append($elk_lightbox.append($elk_lb_content));
950
	}
951
952
	// Load the navigation array
953
	siblings.each(function () {
954
		navigation[navigation.length] = $(this).data('lightboximage');
955
	});
956
957
	// Load and show the initial lightbox container div
958
	ajaxIndicatorOn();
959
	$elk_lightbox.fadeIn(200);
960
	openLightbox();
961
	expandLightbox();
962
963
	// Click anywhere on the page (except the expand icon) to close the lightbox
964
	$elk_lightbox.on('click', function (event) {
965
		if (event.target.id !== $elk_expand_icon.attr('id')) {
966
			event.preventDefault();
967
			closeLightbox();
968
		}
969
	});
970
971
	// Provide some keyboard navigation
972
	$(window).on('keydown.lb', function (event) {
973
		event.preventDefault();
974
975
		// escape
976
		if (event.keyCode === 27) {
977
			closeLightbox();
978
		}
979
980
		// left
981
		if (event.keyCode === 37) {
982
			prevNav();
983
			navLightbox();
984
		}
985
986
		// right
987
		if (event.keyCode === 39) {
988
			nextNav();
989
			navLightbox();
990
		}
991
	});
992
993
	// Make the image size fluid as the browser window changes
994
	$(window).on('resize.lb', function () {
995
		// Account for either a normal or expanded view
996
		var $_elk_lb_content = $('#elk_lb_content');
997
998
		if ($_elk_lb_content.hasClass('expand'))
999
			$_elk_lb_content.css({'height': window.innerHeight * 0.85, 'width': window.innerWidth * 0.9});
1000
		else
1001
			$('#elk_lb_img').css({'max-height': window.innerHeight * 0.9, 'max-width': window.innerWidth * 0.8});
1002
	});
1003
1004
	return false;
1005
}
1006
1007
/**
1008
 * Expands an attachment thumbnail when its clicked
1009
 *
1010
 * @param {string} thumbID
1011
 */
1012
function expandThumb(thumbID)
1013
{
1014
	var img = document.getElementById('thumb_' + thumbID),
1015
		link = document.getElementById('link_' + thumbID),
1016
		name = link.nextSibling;
1017
1018
	// Some browsers will add empty text so loop to the next element node
1019
	while (name && name.nodeType !== 1) {
1020
		name = name.nextSibling;
1021
	}
1022
	var details = name.nextSibling;
1023
	while (details && details.nodeType !== 1) {
1024
		details = details.nextSibling;
1025
	}
1026
1027
	// Save the currently displayed image attributes
1028
	var tmp_src = img.src,
1029
		tmp_height = img.style.height,
1030
		tmp_width = img.style.width;
1031
1032
	// Set the displayed image attributes to the link attributes, this will expand in place
1033
	img.src = link.href;
1034
	img.style.width = link.style.width;
1035
	img.style.height = link.style.height;
1036
1037
	// Swap the class name on the title/desc
1038
	name.className = name.className.includes('_exp') ? 'attachment_name' : 'attachment_name attachment_name_exp';
1039
	details.className = details.className.includes('_exp') ? 'attachment_details' : 'attachment_details attachment_details_exp';
1040
1041
	// Now place the image attributes back
1042
	link.href = tmp_src;
1043
	link.style.width = tmp_width;
1044
	link.style.height = tmp_height;
1045
1046
	return false;
1047
}
1048
1049
/**
1050
 * Provides a way to toggle an ignored message(s) visibility
1051
 *
1052
 * @param {object} msgids
1053
 * @param {string} text
1054
 */
1055
function ignore_toggles(msgids, text)
1056
{
1057
	for (var i = 0; i < msgids.length; i++)
1058
	{
1059
		var msgid = msgids[i];
1060
1061
		var discard = new elk_Toggle({
0 ignored issues
show
Bug introduced by
The variable elk_Toggle seems to be never declared. If this is a global, consider adding a /** global: elk_Toggle */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The variable discard seems to be never used. Consider removing it.
Loading history...
1062
			bToggleEnabled: true,
1063
			bCurrentlyCollapsed: true,
1064
			aSwappableContainers: [
1065
				'msg_' + msgid + '_extra_info',
1066
				'msg_' + msgid,
1067
				'msg_' + msgid + '_footer',
1068
				'msg_' + msgid + '_quick_mod',
1069
				'modify_button_' + msgid,
1070
				'msg_' + msgid + '_signature'
1071
			],
1072
			aSwapLinks: [
1073
				{
1074
					sId: 'msg_' + msgid + '_ignored_link',
1075
					msgExpanded: '',
1076
					msgCollapsed: text
1077
				}
1078
			]
1079
		});
1080
	}
1081
}
1082
1083
/**
1084
 * Open the sendtopic overlay div
1085
 * @todo make these... "things" look nice
1086
 *
1087
 * @param {type} desktopURL
1088
 * @param {type} sHeader
1089
 * @param {type} sIcon
1090
 */
1091
function sendtopicOverlayDiv(desktopURL, sHeader, sIcon)
1092
{
1093
	// Set up our div details
1094
	var sAjax_indicator = '<div class="centertext"><i class="icon icon-spin i-spinner"></i></div>',
1095
		oPopup_body;
1096
1097
	// TODO: Even if we weren't purging icons, this is still not the right icon for this.
1098
	sIcon = typeof(sIcon) === 'string' ? sIcon : 'i-envelope';
1099
	sHeader = typeof(sHeader) === 'string' ? sHeader : help_popup_heading_text;
0 ignored issues
show
Bug introduced by
The variable help_popup_heading_text seems to be never declared. If this is a global, consider adding a /** global: help_popup_heading_text */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1100
1101
	// Load the send topic overlay div
1102
	$.ajax({
1103
		url: desktopURL,
1104
		type: "GET",
1105
		dataType: "html"
1106
	})
1107
	.done(function (data) {
1108
			var $base_obj = $('<div id="temp_help">').html(data).find('#send_topic'),
1109
				title = '';
1110
1111
			$base_obj.find('h3').each(function () {
1112
				title = $(this).text();
1113
				$(this).remove();
1114
			});
1115
1116
			var form = $base_obj.find('form'),
0 ignored issues
show
Unused Code introduced by
The variable form seems to be never used. Consider removing it.
Loading history...
1117
				url = $base_obj.find('form').attr('action');
1118
1119
			// Create the div that we are going to load
1120
			var oContainer = new smc_Popup({heading: (title !== '' ? title : sHeader), content: sAjax_indicator, icon: sIcon});
0 ignored issues
show
Bug introduced by
The variable smc_Popup seems to be never declared. If this is a global, consider adding a /** global: smc_Popup */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1121
			oPopup_body = $('#' + oContainer.popup_id).find('.popup_content');
1122
			oPopup_body.html($base_obj.html());
1123
1124
			// Tweak the width of the popup for this special window
1125
			$('.popup_window').css({'width': '640px'});
1126
1127
			sendtopicForm(oPopup_body, url, oContainer);
1128
	})
1129
	.fail(function (xhr, textStatus, errorThrown) {
0 ignored issues
show
Unused Code introduced by
The parameter errorThrown is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
1130
			oPopup_body.html(textStatus);
1131
	});
1132
1133
	return false;
1134
}
1135
1136
/**
1137
 * Helper function for sendtopicForm, highlights missing fields that must
1138
 * be filled in in order to send the topic
1139
 *
1140
 * @param {type} $this_form
1141
 * @param {string} classname
1142
 * @param {boolean} focused
1143
 */
1144
function addRequiredElem($this_form, classname, focused)
1145
{
1146
	if (typeof(focused) === 'undefined')
1147
		focused = false;
1148
1149
	$this_form.find('input[name="' + classname + '"]').after($('<span class="requiredfield" />').text(required_field).fadeIn());
0 ignored issues
show
Bug introduced by
The variable required_field seems to be never declared. If this is a global, consider adding a /** global: required_field */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1150
	$this_form.find('input[name="' + classname + '"]').keyup(function () {
1151
		$this_form.find('.' + classname + ' .requiredfield').fadeOut(function () {
1152
			$(this).remove();
1153
		});
1154
	});
1155
1156
	if (!focused)
1157
	{
1158
		$this_form.find('input[name="' + classname + '"]').focus();
1159
		focused = true;
0 ignored issues
show
Unused Code introduced by
The assignment to variable focused seems to be never used. Consider removing it.
Loading history...
1160
	}
1161
}
1162
1163
/**
1164
 * Send in the send topic form
1165
 *
1166
 * @param {object} oPopup_body
1167
 * @param {string} url
1168
 * @param {object} oContainer
1169
 */
1170
function sendtopicForm(oPopup_body, url, oContainer)
1171
{
1172
	if (typeof(this_body) !== 'undefined')
0 ignored issues
show
Bug introduced by
The variable this_body seems to be never declared. If this is a global, consider adding a /** global: this_body */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1173
		oPopup_body.html(this_body);
1174
1175
	var $this_form = $(oPopup_body).find('form');
1176
1177
	if (typeof(send_comment) !== 'undefined')
0 ignored issues
show
Bug introduced by
The variable send_comment seems to be never declared. If this is a global, consider adding a /** global: send_comment */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1178
	{
1179
		$this_form.find('input[name="comment"]').val(send_comment);
1180
		$this_form.find('input[name="y_name"]').val(sender_name);
0 ignored issues
show
Bug introduced by
The variable sender_name seems to be never declared. If this is a global, consider adding a /** global: sender_name */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1181
		$this_form.find('input[name="y_email"]').val(sender_mail);
0 ignored issues
show
Bug introduced by
The variable sender_mail seems to be never declared. If this is a global, consider adding a /** global: sender_mail */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1182
		$this_form.find('input[name="r_name"]').val(recipient_name);
0 ignored issues
show
Bug introduced by
The variable recipient_name seems to be never declared. If this is a global, consider adding a /** global: recipient_name */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1183
		$this_form.find('input[name="r_email"]').val(recipient_mail);
0 ignored issues
show
Bug introduced by
The variable recipient_mail seems to be never declared. If this is a global, consider adding a /** global: recipient_mail */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1184
	}
1185
1186
	oPopup_body.find('input[name="send"]').on('click', function (event) {
1187
		event.preventDefault();
1188
1189
		var data = $this_form.serialize() + '&send=1',
1190
			sender_name = $this_form.find('input[name="y_name"]').val(),
1191
			sender_mail = $this_form.find('input[name="y_email"]').val,
1192
			recipient_name = $this_form.find('input[name="r_name"]').val(),
1193
			recipient_mail = $this_form.find('input[name="r_email"]').val(),
1194
			missing_elems = false;
1195
1196
		// Check for any input fields that were not filled in
1197
		if (sender_name === '')
1198
		{
1199
			addRequiredElem($this_form, 'y_name', missing_elems);
1200
			missing_elems = true;
1201
		}
1202
1203
		if (sender_mail === '')
1204
		{
1205
			addRequiredElem($this_form, 'y_email', missing_elems);
1206
			missing_elems = true;
1207
		}
1208
1209
		if (recipient_name === '')
1210
		{
1211
			addRequiredElem($this_form, 'r_name', missing_elems);
1212
			missing_elems = true;
1213
		}
1214
1215
		if (recipient_mail === '')
1216
		{
1217
			addRequiredElem($this_form, 'r_email', missing_elems);
1218
			missing_elems = true;
1219
		}
1220
1221
		// Missing required elements, back we go
1222
		if (missing_elems)
1223
			return;
1224
1225
		// Send it to the server to validate the input
1226
		$.ajax({
1227
			type: 'post',
1228
			url: url + ';api',
1229
			data: data
1230
		})
1231
		.done(function (request) {
1232
			var oElement = $(request).find('elk')[0],
1233
				text = null;
0 ignored issues
show
Unused Code introduced by
The assignment to text seems to be never used. If you intend to free memory here, this is not necessary since the variable leaves the scope anyway.
Loading history...
1234
1235
			// No errors in the response, lets say it sent.
1236
			if (oElement.getElementsByTagName('error').length === 0)
1237
			{
1238
				text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities();
1239
				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"/>';
0 ignored issues
show
Bug introduced by
The variable sendtopic_back seems to be never declared. If this is a global, consider adding a /** global: sendtopic_back */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable sendtopic_close seems to be never declared. If this is a global, consider adding a /** global: sendtopic_close */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1240
1241
				oPopup_body.html(text);
1242
1243
				// Setup the cancel button to end this entire process
1244
				oPopup_body.find('input[name="cancel"]').each(function () {
1245
					$(this).on('click', function (event) {
1246
						event.preventDefault();
1247
						oContainer.hide();
1248
					});
1249
				});
1250
			}
1251
			// Invalid data in the form, like a bad email etc, show the message text
1252
			else
1253
			{
1254
				if (oElement.getElementsByTagName('text').length !== 0)
1255
				{
1256
					text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities();
1257
					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"/>';
0 ignored issues
show
Bug introduced by
The variable sendtopic_back seems to be never declared. If this is a global, consider adding a /** global: sendtopic_back */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable sendtopic_close seems to be never declared. If this is a global, consider adding a /** global: sendtopic_close */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1258
1259
					oPopup_body.html(text);
1260
					oPopup_body.find('input[name="send"]').each(function () {
1261
						$(this).on('click', function (event) {
1262
							event.preventDefault();
1263
							data = $(oPopup_body).find('form').serialize() + '&send=1';
1264
							sendtopicForm(oPopup_body, url, oContainer);
1265
						});
1266
					});
1267
1268
					// Cancel means cancel
1269
					oPopup_body.find('input[name="cancel"]').each(function () {
1270
						$(this).on('click', function (event) {
1271
							event.preventDefault();
1272
							oContainer.hide();
1273
						});
1274
					});
1275
				}
1276
1277
				if (oElement.getElementsByTagName('url').length !== 0)
1278
				{
1279
					var url_redir = oElement.getElementsByTagName('url')[0].firstChild.nodeValue;
1280
					oPopup_body.html(sendtopic_error.replace('{href}', url_redir));
0 ignored issues
show
Bug introduced by
The variable sendtopic_error seems to be never declared. If this is a global, consider adding a /** global: sendtopic_error */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1281
				}
1282
			}
1283
		})
1284
		.fail(function() {
1285
			oPopup_body.html(sendtopic_error.replace('{href}', url));
0 ignored issues
show
Bug introduced by
The variable sendtopic_error seems to be never declared. If this is a global, consider adding a /** global: sendtopic_error */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1286
		});
1287
	});
1288
}
1289
1290
1291
1292
/**
1293
 * Used to split a topic.
1294
 * Allows selecting a message so it can be moved from the original to the spit topic or back
1295
 *
1296
 * @param {string} direction up / down / reset
1297
 * @param {int} msg_id message id that is being moved
1298
 */
1299
function topicSplitselect(direction, msg_id)
1300
{
1301
	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);
0 ignored issues
show
Bug introduced by
The variable start seems to be never declared. If this is a global, consider adding a /** global: start */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable topic_subject seems to be never declared. If this is a global, consider adding a /** global: topic_subject */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable topic_id seems to be never declared. If this is a global, consider adding a /** global: topic_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1302
	return false;
1303
}
1304
1305
/**
1306
 * Callback function for topicSplitselect
1307
 *
1308
 * @param {xmlCallback} XMLDoc
1309
 */
1310
function onTopicSplitReceived(XMLDoc)
1311
{
1312
	var i,
1313
		j,
1314
		pageIndex;
1315
1316
	// Find the selected and not_selected page index containers
1317
	for (i = 0; i < 2; i++)
1318
	{
1319
		pageIndex = XMLDoc.getElementsByTagName("pageIndex")[i];
1320
1321
		// Update the page container with our xml response
1322
		document.getElementById("pageindex_" + pageIndex.getAttribute("section")).innerHTML = pageIndex.firstChild.nodeValue;
1323
		start[i] = pageIndex.getAttribute("startFrom");
0 ignored issues
show
Bug introduced by
The variable start seems to be never declared. If this is a global, consider adding a /** global: start */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1324
	}
1325
1326
	var numChanges = XMLDoc.getElementsByTagName("change").length,
1327
		curChange,
1328
		curSection,
1329
		curAction,
1330
		curId,
1331
		curList,
1332
		newItem,
1333
		sInsertBeforeId,
1334
		oListItems,
1335
		right_arrow = '<i class="icon icon-lg i-chevron-circle-right"></i>',
1336
		left_arrow = '<i class="icon icon-lg i-chevron-circle-left"></i>';
1337
1338
	// Loop through all of the changes returned in the xml response
1339
	for (i = 0; i < numChanges; i++)
1340
	{
1341
		curChange = XMLDoc.getElementsByTagName("change")[i];
1342
		curSection = curChange.getAttribute("section");
1343
		curAction = curChange.getAttribute("curAction");
1344
		curId = curChange.getAttribute("id");
1345
		curList = document.getElementById("messages_" + curSection);
1346
1347
		// Remove it from the source list so we can insert it in the destination list
1348
		if (curAction === "remove")
1349
			curList.removeChild(document.getElementById(curSection + "_" + curId));
1350
		// Insert a message.
1351
		else
1352
		{
1353
			// By default, insert the element at the end of the list.
1354
			sInsertBeforeId = null;
1355
1356
			// Loop through the list to try and find an item to insert after.
1357
			oListItems = curList.getElementsByTagName("li");
1358
			for (j = 0; j < oListItems.length; j++)
1359
			{
1360
				if (parseInt(oListItems[j].id.substr(curSection.length + 1)) < curId)
1361
				{
1362
					// This would be a nice place to insert the row.
1363
					sInsertBeforeId = oListItems[j].id;
1364
1365
					// We're done for now. Escape the loop.
1366
					j = oListItems.length + 1;
1367
				}
1368
			}
1369
1370
			// Let's create a nice container for the message.
1371
			newItem = document.createElement("li");
1372
			newItem.className = "";
1373
			newItem.id = curSection + "_" + curId;
1374
			newItem.innerHTML = '' +
1375
				'<div class="content">' +
1376
					'<div class="message_header">' +
1377
						'<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 + ');">' +
0 ignored issues
show
Bug introduced by
The variable selected_start seems to be never declared. If this is a global, consider adding a /** global: selected_start */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable topic_subject seems to be never declared. If this is a global, consider adding a /** global: topic_subject */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable elk_scripturl seems to be never declared. If this is a global, consider adding a /** global: elk_scripturl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable not_selected_start seems to be never declared. If this is a global, consider adding a /** global: not_selected_start */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable topic_id seems to be never declared. If this is a global, consider adding a /** global: topic_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1378
							(curSection === "selected" ? left_arrow : right_arrow) +
1379
						'</a>' +
1380
						'<strong>' + curChange.getElementsByTagName("subject")[0].firstChild.nodeValue + '</strong> ' + txt_by + ' <strong>' + curChange.getElementsByTagName("poster")[0].firstChild.nodeValue + '</strong>' +
0 ignored issues
show
Bug introduced by
The variable txt_by seems to be never declared. If this is a global, consider adding a /** global: txt_by */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1381
						'<br />' +
1382
						'<em>' + curChange.getElementsByTagName("time")[0].firstChild.nodeValue + '</em>' +
1383
					'</div>' +
1384
					'<div class="post">' + curChange.getElementsByTagName("body")[0].firstChild.nodeValue + '</div>' +
1385
				'</div>';
1386
1387
			// So, where do we insert it?
1388
			if (typeof sInsertBeforeId === "string")
1389
				curList.insertBefore(newItem, document.getElementById(sInsertBeforeId));
1390
			else
1391
				curList.appendChild(newItem);
1392
		}
1393
	}
1394
}
1395