Completed
Pull Request — patch_1-1-4 (#3210)
by Emanuele
12:56
created

themes/default/scripts/post.js   F

Complexity

Total Complexity 68
Complexity/F 4

Size

Lines of Code 468
Function Count 17

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 468
rs 2.96
c 0
b 0
f 0
wmc 68
mnd 4
bc 35
fnc 17
bpm 2.0588
cpm 4
noi 62

14 Functions

Rating   Name   Duplication   Size   Complexity  
A post.js ➔ showimage 0 4 1
A post.js ➔ reActivate 0 4 1
A post.js ➔ onReceiveOpener 0 4 1
A post.js ➔ cleanFileInput 0 8 1
A post.js ➔ previewPost 0 28 3
A post.js ➔ addAttachment 0 14 2
A post.js ➔ previewNews 0 27 1
A post.js ➔ previewPM 0 27 1
A post.js ➔ addPollOption 0 19 4
F post.js ➔ onDocSent 0 174 31
A post.js ➔ insertQuoteFast 0 6 1
A post.js ➔ onDocReceived 0 11 2
A post.js ➔ previewControl 0 21 4
D post.js ➔ getFields 0 49 12

How to fix   Complexity   

Complexity

Complex classes like themes/default/scripts/post.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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
11
 */
12
13
/**
14
 * This file contains javascript associated with the posting and previewing
15
 */
16
17
/**
18
 * A q&d wrapper function to call the correct preview function
19
 * @todo could make this a class to be cleaner
20
 */
21
// These are variables the xml response is going to need
22
var bPost;
23
function previewControl()
24
{
25
	// Lets make a background preview request
26
	bPost = false;
27
28
	// call the needed preview function
29
	switch(preview_area)
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
Bug introduced by
The variable preview_area seems to be never declared. If this is a global, consider adding a /** global: preview_area */ 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...
30
	{
31
		case 'pm':
32
			previewPM();
33
			break;
34
		case 'news':
35
			previewNews();
36
			break;
37
		case 'post':
38
			bPost = true;
39
			previewPost();
40
			break;
41
	}
42
	return false;
43
}
44
45
/**
46
 * Used to preview a post
47
 */
48
function previewPost()
49
{
50
	// @todo Currently not sending poll options and option checkboxes.
51
	var textFields = [
52
		'subject', post_box_name, elk_session_var, 'icon', 'guestname', 'email', 'evtitle', 'question', 'topic'
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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
53
	];
54
	var numericFields = [
55
		'board', 'topic', 'last_msg',
56
		'eventid', 'calendar', 'year', 'month', 'day',
57
		'poll_max_votes', 'poll_expire', 'poll_change_vote', 'poll_hide'
58
	];
59
	var checkboxFields = [
60
		'ns'
61
	];
62
63
	// Get the values from the form
64
	var x = [];
0 ignored issues
show
Unused Code introduced by
The assignment to variable x seems to be never used. Consider removing it.
Loading history...
65
	x = getFields(textFields, numericFields, checkboxFields, form_name);
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
66
67
	sendXMLDocument(elk_prepareScriptUrl(elk_scripturl) + 'action=post2' + (current_board ? ';board=' + current_board : '') + (make_poll ? ';poll' : '') + ';preview;xml', x.join('&'), onDocSent);
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable make_poll is declared in the current environment, consider using typeof make_poll === "undefined" instead. This is safe if the variable is not actually declared.
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...
Best Practice introduced by
If you intend to check if the variable current_board is declared in the current environment, consider using typeof current_board === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
68
69
	// Show the preview section and load it with "pending results" text, onDocSent will finish things off
70
	document.getElementById('preview_section').style.display = 'block';
71
	document.getElementById('preview_subject').innerHTML = txt_preview_title;
0 ignored issues
show
Bug introduced by
The variable txt_preview_title seems to be never declared. If this is a global, consider adding a /** global: txt_preview_title */ 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...
72
	document.getElementById('preview_body').innerHTML = txt_preview_fetch;
0 ignored issues
show
Bug introduced by
The variable txt_preview_fetch seems to be never declared. If this is a global, consider adding a /** global: txt_preview_fetch */ 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
	return false;
75
}
76
77
/**
78
 * Used to preview a PM
79
 */
80
function previewPM()
81
{
82
	// define what we want to get from the form
83
	var textFields = [
84
		'subject', post_box_name, 'to', 'bcc'
0 ignored issues
show
Bug introduced by
The variable post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
85
	];
86
	var numericFields = [
87
		'recipient_to[]', 'recipient_bcc[]'
88
	];
89
	var checkboxFields = [
90
		'outbox'
91
	];
92
93
	// And go get them
94
	var x = [];
0 ignored issues
show
Unused Code introduced by
The assignment to variable x seems to be never used. Consider removing it.
Loading history...
95
	x = getFields(textFields, numericFields, checkboxFields, form_name);
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
96
97
	// Send in document for previewing
98
	sendXMLDocument(elk_prepareScriptUrl(elk_scripturl) + 'action=pm;sa=send2;preview;xml', x.join('&'), onDocSent);
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...
99
100
	// Show the preview section and load it with "pending results" text, onDocSent will finish things off
101
	document.getElementById('preview_section').style.display = 'block';
102
	document.getElementById('preview_subject').innerHTML = txt_preview_title;
0 ignored issues
show
Bug introduced by
The variable txt_preview_title seems to be never declared. If this is a global, consider adding a /** global: txt_preview_title */ 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...
103
	document.getElementById('preview_body').innerHTML = txt_preview_fetch;
0 ignored issues
show
Bug introduced by
The variable txt_preview_fetch seems to be never declared. If this is a global, consider adding a /** global: txt_preview_fetch */ 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...
104
105
	return false;
106
}
107
108
/**
109
 * Used to preview a News item
110
 */
111
function previewNews()
112
{
113
	// define what we want to get from the form
114
	var textFields = [
115
		'subject', post_box_name
0 ignored issues
show
Bug introduced by
The variable post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
116
	];
117
	var numericFields = [
118
	];
119
	var checkboxFields = [
120
		'send_html', 'send_pm'
121
	];
122
123
	// And go get them
124
	var x = [];
0 ignored issues
show
Unused Code introduced by
The assignment to variable x seems to be never used. Consider removing it.
Loading history...
125
	x = getFields(textFields, numericFields, checkboxFields, form_name);
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
126
	x[x.length] = 'item=newsletterpreview';
127
128
	// Send in document for previewing
129
	sendXMLDocument(elk_prepareScriptUrl(elk_scripturl) + 'action=xmlpreview;xml', x.join('&'), onDocSent);
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...
130
131
	// Show the preview section and load it with "pending results" text, onDocSent will finish things off
132
	document.getElementById('preview_section').style.display = 'block';
133
	document.getElementById('preview_subject').innerHTML = txt_preview_title;
0 ignored issues
show
Bug introduced by
The variable txt_preview_title seems to be never declared. If this is a global, consider adding a /** global: txt_preview_title */ 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...
134
	document.getElementById('preview_body').innerHTML = txt_preview_fetch;
0 ignored issues
show
Bug introduced by
The variable txt_preview_fetch seems to be never declared. If this is a global, consider adding a /** global: txt_preview_fetch */ 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...
135
136
	return false;
137
}
138
139
/**
140
 * Gets the form data for the selected fields so they can be posted via ajax
141
 *
142
 * @param {string[]} textFields
143
 * @param {string[]} numericFields
144
 * @param {string[]} checkboxFields
145
 * @param {string} form_name
146
 */
147
function getFields(textFields, numericFields, checkboxFields, form_name)
148
{
149
	var fields = [],
150
		i = 0,
151
		n = 0;
152
153
	// Get all of the text fields
154
	for (i = 0, n = textFields.length; i < n; i++)
155
	{
156
		if (textFields[i] in document.forms[form_name])
157
		{
158
			// Handle the editor.
159
			if (textFields[i] === post_box_name && $editor_data[post_box_name] !== undefined)
0 ignored issues
show
Bug introduced by
The variable $editor_data seems to be never declared. If this is a global, consider adding a /** global: $editor_data */ 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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
160
			{
161
				fields[fields.length] = textFields[i] + '=' + $editor_data[post_box_name].getText().replace(/&#/g, '&#38;#').php_urlencode();
162
				fields[fields.length] = 'message_mode=' + $editor_data[post_box_name].inSourceMode();
163
			}
164
			else
165
				fields[fields.length] = textFields[i] + '=' + document.forms[form_name][textFields[i]].value.replace(/&#/g, '&#38;#').php_urlencode();
166
		}
167
	}
168
169
	// All of the numeric fields
170
	for (i = 0, n = numericFields.length; i < n; i++)
171
	{
172
		if (numericFields[i] in document.forms[form_name])
173
		{
174
			if ('value' in document.forms[form_name][numericFields[i]])
175
				fields[fields.length] = numericFields[i] + '=' + parseInt(document.forms[form_name].elements[numericFields[i]].value);
176
			else
177
			{
178
				for (var j = 0, num = document.forms[form_name][numericFields[i]].length; j < num; j++)
179
					fields[fields.length] = numericFields[i] + '=' + parseInt(document.forms[form_name].elements[numericFields[i]][j].value);
180
			}
181
		}
182
	}
183
184
	// And the checkboxes
185
	for (i = 0, n = checkboxFields.length; i < n; i++)
186
	{
187
		if (checkboxFields[i] in document.forms[form_name] && document.forms[form_name].elements[checkboxFields[i]].checked)
188
			fields[fields.length] = checkboxFields[i] + '=' + document.forms[form_name].elements[checkboxFields[i]].value;
189
	}
190
191
	// And some security
192
	fields[fields.length] = elk_session_var + '=' + elk_session_id;
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...
193
194
	return fields;
195
}
196
197
/**
198
 * Callback function of the XMLhttp request
199
 *
200
 * @param {object} XMLDoc
201
 */
202
function onDocSent(XMLDoc)
203
{
204
	var i = 0,
205
		n = 0,
206
		numErrors = 0,
207
		numCaptions = 0,
208
		$editor;
209
210
	if (!XMLDoc || !XMLDoc.getElementsByTagName('elk')[0])
211
	{
212
		document.forms[form_name].preview.onclick = function() {return true;};
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
213
		document.forms[form_name].preview.click();
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
214
		return true;
215
	}
216
217
	// Read the preview section data from the xml response
218
	var preview = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('preview')[0];
219
220
	// Load in the subject
221
	document.getElementById('preview_subject').innerHTML = preview.getElementsByTagName('subject')[0].firstChild.nodeValue;
222
223
	// Load in the body
224
	var bodyText = '';
225
	for (i = 0, n = preview.getElementsByTagName('body')[0].childNodes.length; i < n; i++)
226
		bodyText += preview.getElementsByTagName('body')[0].childNodes[i].nodeValue;
227
228
	document.getElementById('preview_body').innerHTML = bodyText;
229
	document.getElementById('preview_body').className = 'post';
230
231
	// Show a list of errors (if any).
232
	var errors = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('errors')[0],
233
		errorList = '',
234
		errorCode = '',
235
		error_area = 'post_error',
236
		error_list = error_area + '_list',
237
		error_post = false;
238
239
	// @todo: this should stay together with the rest of the error handling or
240
	// should use errorbox_handler (at the moment it cannot be used because is not enough generic)
241
	for (i = 0, numErrors = errors.getElementsByTagName('error').length; i < numErrors; i++)
242
	{
243
		errorCode = errors.getElementsByTagName('error')[i].attributes.getNamedItem("code").value;
244
		if (errorCode === 'no_message' || errorCode === 'long_message')
245
			error_post = true;
246
		errorList += '<li id="' + error_area + '_' + errorCode + '" class="error">' + errors.getElementsByTagName('error')[i].firstChild.nodeValue + '</li>';
247
	}
248
249
	var oError_box = $(document.getElementById(error_area));
250
	if ($.trim(oError_box.children(error_list).html()) === '')
251
		oError_box.append("<ul id='" + error_list + "'></ul>");
252
253
	// Add the error it and show it
254
	if (numErrors === 0)
255
		oError_box.css("display", "none");
256
	else
257
	{
258
		document.getElementById(error_list).innerHTML = errorList;
259
		oError_box.css("display", "");
260
		oError_box.attr('class', parseInt(errors.getAttribute('serious')) === 0 ? 'warningbox' : 'errorbox');
261
	}
262
263
	// Show a warning if the topic has been locked.
264
	if (bPost)
265
		document.getElementById('lock_warning').style.display = parseInt(errors.getAttribute('topic_locked')) === 1 ? '' : 'none';
266
267
	// Adjust the color of captions if the given data is erroneous.
268
	var captions = errors.getElementsByTagName('caption');
269
	for (i = 0, numCaptions = errors.getElementsByTagName('caption').length; i < numCaptions; i++)
270
	{
271
		if (document.getElementById('caption_' + captions[i].getAttribute('name')))
272
			document.getElementById('caption_' + captions[i].getAttribute('name')).className = captions[i].getAttribute('class');
273
	}
274
275
	if (typeof $editor_container[post_box_name] !== 'undefined')
0 ignored issues
show
Bug introduced by
The variable $editor_container seems to be never declared. If this is a global, consider adding a /** global: $editor_container */ 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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
276
		$editor = $editor_container[post_box_name];
277
	else
278
		$editor = $(document.forms[form_name][post_box_name]);
279
280
	if (error_post)
281
		$editor.find("textarea, iframe").addClass('border_error');
282
	else
283
		$editor.find("textarea, iframe").removeClass('border_error');
284
285
	// If this is a post preview, then we have some extra work to do
286
	if (bPost)
287
	{
288
		// Set the new last message id.
289
		if ('last_msg' in document.forms[form_name])
290
			document.forms[form_name].last_msg.value = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('last_msg')[0].firstChild.nodeValue;
291
292
		var new_replies = [],
293
			ignored_replies = [],
294
			ignoring = null,
0 ignored issues
show
Unused Code introduced by
The assignment to ignoring 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...
295
			newPosts = XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('new_posts')[0] ? XMLDoc.getElementsByTagName('elk')[0].getElementsByTagName('new_posts')[0].getElementsByTagName('post') : {length: 0},
296
			numNewPosts = newPosts.length;
297
298
		if (numNewPosts !== 0)
299
		{
300
			var newPostsHTML = '<span id="new_replies"><' + '/span>';
301
			for (i = 0; i < numNewPosts; i++)
302
			{
303
				new_replies[new_replies.length] = newPosts[i].getAttribute("id");
304
305
				ignoring = false;
306
				if (newPosts[i].getElementsByTagName("is_ignored")[0].firstChild.nodeValue !== '0')
307
					ignored_replies[ignored_replies.length] = ignoring = newPosts[i].getAttribute("id");
308
309
				newPostsHTML += '<div class="content' + (++reply_counter % 2 === 0 ? '2' : '') + '"><div class="postarea2" id="msg' + newPosts[i].getAttribute("id") + '"><div class="keyinfo">';
0 ignored issues
show
Bug introduced by
The variable reply_counter seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.reply_counter.
Loading history...
310
				newPostsHTML += '<h5 class="floatleft"><span>' + txt_posted_by + '</span>&nbsp;' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + '&nbsp;-&nbsp;' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue;
0 ignored issues
show
Bug introduced by
The variable txt_posted_by seems to be never declared. If this is a global, consider adding a /** global: txt_posted_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...
311
				newPostsHTML += ' <span class="new_posts" id="image_new_' + newPosts[i].getAttribute("id") + '">' + txt_new + '</span></h5>';
0 ignored issues
show
Bug introduced by
The variable txt_new seems to be never declared. If this is a global, consider adding a /** global: txt_new */ 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...
312
313
				if (can_quote)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable can_quote is declared in the current environment, consider using typeof can_quote === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
314
					newPostsHTML += '<ul class="quickbuttons" id="msg_' + newPosts[i].getAttribute('id') + '_quote"><li class="listlevel1"><a href="#postmodify" onmousedown="return insertQuoteFast(' + newPosts[i].getAttribute('id') + ');" class="linklevel1 quote_button">' + txt_bbc_quote + '</a></li></ul>';
0 ignored issues
show
Bug introduced by
The variable txt_bbc_quote seems to be never declared. If this is a global, consider adding a /** global: txt_bbc_quote */ 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...
315
316
				newPostsHTML += '</div>';
317
318
				if (ignoring)
319
					newPostsHTML += '<div id="msg_' + newPosts[i].getAttribute("id") + '_ignored_prompt">' + txt_ignoring_user + '<a href="#" id="msg_' + newPosts[i].getAttribute("id") + '_ignored_link" class="hide">' + show_ignore_user_post + '</a></div>';
0 ignored issues
show
Bug introduced by
The variable show_ignore_user_post seems to be never declared. If this is a global, consider adding a /** global: show_ignore_user_post */ 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 txt_ignoring_user seems to be never declared. If this is a global, consider adding a /** global: txt_ignoring_user */ 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...
320
321
				newPostsHTML += '<div class="inner" id="msg_' + newPosts[i].getAttribute("id") + '_body">' + newPosts[i].getElementsByTagName("message")[0].firstChild.nodeValue + '</div></div></div>';
322
			}
323
			setOuterHTML(document.getElementById('new_replies'), newPostsHTML);
324
		}
325
326
		// Remove the new image from old-new replies!
327
		for (i = 0; i < new_replies.length; i++)
328
			document.getElementById('image_new_' + new_replies[i]).style.display = 'none';
329
330
		var numIgnoredReplies = ignored_replies.length;
331
		if (numIgnoredReplies !== 0)
332
		{
333
			for (i = 0; i < numIgnoredReplies; i++)
334
			{
335
				aIgnoreToggles[ignored_replies[i]] = 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...
Bug introduced by
The variable aIgnoreToggles seems to be never declared. If this is a global, consider adding a /** global: aIgnoreToggles */ 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...
336
					bToggleEnabled: true,
337
					bCurrentlyCollapsed: true,
338
					aSwappableContainers: [
339
						'msg_' + ignored_replies[i] + '_body',
340
						'msg_' + ignored_replies[i] + '_quote'
341
					],
342
					aSwapLinks: [
343
						{
344
							sId: 'msg_' + ignored_replies[i] + '_ignored_link',
345
							msgExpanded: '',
346
							msgCollapsed: show_ignore_user_post
347
						}
348
					]
349
				});
350
			}
351
		}
352
	}
353
354
	$('html, body').animate({ scrollTop: $('#preview_section').offset().top }, 'slow');
355
356
	// Preview video links if the feature is available
357
	if ($.isFunction($.fn.linkifyvideo))
358
		$().linkifyvideo(oEmbedtext, 'preview_body');
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...
359
360
	// Spoilers, Sweetie
361
	$('.spoilerheader').on('click', function(){
362
		$(this).next().children().slideToggle("fast");
363
	});
364
365
	// Fix and Prettify code blocks
366
	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...
367
		elk_codefix();
368
	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...
369
		prettyPrint();
370
371
	// Prevent lighbox or default action on the preview
372
	$('[data-lightboximage]').on('click.elk_lb', function(e) {
373
		e.preventDefault();
374
	});
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...
375
}
376
377
/**
378
 * Add additional poll option fields
379
 */
380
function addPollOption()
381
{
382
	var pollTabIndex;
383
384
	if (pollOptionNum === 0)
0 ignored issues
show
Bug introduced by
The variable pollOptionNum seems to be never declared. If this is a global, consider adding a /** global: pollOptionNum */ 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...
385
	{
386
		for (var i = 0, n = document.forms[form_name].elements.length; i < n; i++)
0 ignored issues
show
Bug introduced by
The variable form_name seems to be never declared. If this is a global, consider adding a /** global: form_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...
387
			if (document.forms[form_name].elements[i].id.substr(0, 8) === 'options-')
388
			{
389
				pollOptionNum++;
0 ignored issues
show
Bug introduced by
The variable pollOptionNum seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.pollOptionNum.
Loading history...
390
				pollTabIndex = document.forms[form_name].elements[i].tabIndex;
391
			}
392
	}
393
394
	pollOptionNum++;
395
	pollOptionId++;
0 ignored issues
show
Bug introduced by
The variable pollOptionId seems to be never declared. If this is a global, consider adding a /** global: pollOptionId */ 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 pollOptionId seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.pollOptionId.
Loading history...
396
	pollTabIndex++;
397
	setOuterHTML(document.getElementById('pollMoreOptions'), '<li><label for="options-' + pollOptionId + '">' + txt_option + ' ' + pollOptionNum + '</label>: <input type="text" name="options[' + pollOptionId + ']" id="options-' + pollOptionId + '" value="" size="80" maxlength="255" tabindex="' + pollTabIndex + '" class="input_text" /></li><li id="pollMoreOptions"></li>');
0 ignored issues
show
Bug introduced by
The variable txt_option seems to be never declared. If this is a global, consider adding a /** global: txt_option */ 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...
398
}
399
400
/**
401
 * Add additional attachment selection boxes
402
 */
403
function addAttachment()
404
{
405
	/** global: allowed_attachments */
406
	allowed_attachments -= 1;
407
	/** global: current_attachment */
408
	current_attachment += 1;
409
410
	if (allowed_attachments <= 0)
411
		return alert(txt_more_attachments_error);
0 ignored issues
show
Bug introduced by
The variable txt_more_attachments_error seems to be never declared. If this is a global, consider adding a /** global: txt_more_attachments_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...
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
412
413
	setOuterHTML(document.getElementById("moreAttachments"), '<dd class="smalltext"><input type="file" size="60" name="attachment[]" id="attachment' + current_attachment + '" class="input_file" /> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment' + current_attachment + '\');">' + txt_clean_attach + '<\/a>)' + '<\/dd><dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(' + txt_more_attachments + ')</a></dd>');
0 ignored issues
show
Bug introduced by
The variable txt_more_attachments seems to be never declared. If this is a global, consider adding a /** global: txt_more_attachments */ 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 txt_clean_attach seems to be never declared. If this is a global, consider adding a /** global: txt_clean_attach */ 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...
414
415
	return true;
416
}
417
418
/**
419
 * A function used to clear the attachments on post page.  For security reasons
420
 * browsers don't let you set the value of a file input, even to an empty string
421
 * so this work around lets the user clear a choice.
422
 *
423
 * @param {type} idElement
424
 * @returns {undefined}
425
 */
426
function cleanFileInput(idElement)
427
{
428
	var oElement = $('#' + idElement);
429
430
	// Wrap the element in its own form, then reset the wrapper form
431
	oElement.wrap('<form>').closest('form').get(0).reset();
432
    oElement.unwrap();
433
}
434
435
/**
436
 * Insert a quote to the editor via ajax
437
 *
438
 * @param {string} messageid
439
 */
440
function insertQuoteFast(messageid)
441
{
442
	getXMLDocument(elk_prepareScriptUrl(elk_scripturl) + 'action=quotefast;quote=' + messageid + ';xml;pb=' + post_box_name + ';mode=0', onDocReceived);
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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
443
444
	return true;
445
}
446
447
/**
448
 * callback for the quotefast function
449
 *
450
 * @param {object} XMLDoc
451
 */
452
function onDocReceived(XMLDoc)
453
{
454
	var text = '';
455
456
	for (var i = 0, n = XMLDoc.getElementsByTagName('quote')[0].childNodes.length; i < n; i++)
457
		text += XMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue + "\n";
458
459
	$editor_data[post_box_name].insert(text);
0 ignored issues
show
Bug introduced by
The variable $editor_data seems to be never declared. If this is a global, consider adding a /** global: $editor_data */ 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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
460
461
	ajax_indicator(false);
462
}
463
464
/**
465
 * Insert text in to the editor
466
 *
467
 * @param {string} text
468
 */
469
function onReceiveOpener(text)
470
{
471
	$editor_data[post_box_name].insert(text);
0 ignored issues
show
Bug introduced by
The variable $editor_data seems to be never declared. If this is a global, consider adding a /** global: $editor_data */ 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 post_box_name seems to be never declared. If this is a global, consider adding a /** global: post_box_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...
472
}
473
474
/**
475
 * The actual message icon selector, shows the chosen icon on the post screen
476
 */
477
function showimage()
478
{
479
	document.images.icons.src = icon_urls[document.forms.postmodify.icon.options[document.forms.postmodify.icon.selectedIndex].value];
0 ignored issues
show
Bug introduced by
The variable icon_urls seems to be never declared. If this is a global, consider adding a /** global: icon_urls */ 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...
480
}
481
482
/**
483
 * When using Go Back due to fatal_error, allows the form to be re-submitted with change
484
 * Done as a pageshow event listener for FF only
485
 */
486
function reActivate()
487
{
488
	document.forms.postmodify.message.readOnly = false;
489
}
490