Passed
Push — myDevel ( 1d4abc...20573a )
by Spuds
02:22
created

portal.js ➔ sp_collapseBlock   B

Complexity

Conditions 1
Paths 8

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 25
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
B portal.js ➔ ... ➔ $(?!?).done 0 22 6
1
/**
2
 * @package SimplePortal ElkArte
3
 *
4
 * @author SimplePortal Team
5
 * @copyright 2015-2017 SimplePortal Team
6
 * @license BSD 3-clause
7
 * @version 1.0.0 RC1
8
 */
9
10
/**
11
 * Used to collapse an individual block
12
 *
13
 * @param {string} id
14
 */
15
function sp_collapseBlock(id)
16
{
17
	$("#sp_block_" + id).slideToggle(300).promise().done(function ()
18
	{
19
		var mode = false;
20
21
		if ($("#sp_block_" + id).is(":visible"))
22
		{
23
			mode = true;
24
		}
25
26
		// Save the choice, one way for guest, or theme options for members
27
		if (elk_member_id === 0)
0 ignored issues
show
Bug introduced by
The variable elk_member_id seems to be never declared. If this is a global, consider adding a /** global: elk_member_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...
28
		{
29
			document.cookie = "sp_block_" + id + "=" + (mode ? 0 : 1);
30
		}
31
		else
32
		{
33
			elk_setThemeOption("sp_block_" + id, mode ? 0 : 1, null, null);
34
		}
35
36
		// Swap the class to change the icon
37
		$("#sp_collapse_" + id).attr("class", mode ? "collapse" : "expand");
38
	});
39
}
40
41
/**
42
 * Used to collapse side (if enabled)
43
 *
44
 * @param {string} id
45
 */
46
function sp_collapseSide(id)
47
{
48
	var sp_sides = [];
49
50
	sp_sides[1] = "sp_left";
51
	sp_sides[4] = "sp_right";
52
53
	mode = document.getElementById(sp_sides[id]).style.display === "" ? 0 : 1;
0 ignored issues
show
Bug introduced by
The variable mode 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.mode.
Loading history...
54
55
	// Guests use a cookie, members a theme option to remember the choice
56
	if (elk_member_id === 0)
0 ignored issues
show
Bug introduced by
The variable elk_member_id seems to be never declared. If this is a global, consider adding a /** global: elk_member_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...
57
	{
58
		document.cookie = sp_sides[id] + "=" + (mode ? 0 : 1);
59
	}
60
	else
61
	{
62
		elk_setThemeOption(sp_sides[id], mode ? 0 : 1, null, null);
63
	}
64
65
	// Update the side expand/collapse image
66
	document.getElementById("sp_collapse_side" + id).className = (mode ? "dot collapse" : "dot expand");
67
68
	// Hide the side with a touch of animation
69
	$('#' + sp_sides[id]).toggle(400);
70
}
71
72
/**
73
 * Used to collapse the smiley box in the shoutbox
74
 *
75
 * @param {string} id
76
 * @param {boolean} has_image
77
 */
78
function sp_collapse_object(id, has_image)
79
{
80
	var mode = document.getElementById("sp_object_" + id).style.display === '' ? 0 : 1;
81
82
	$("#sp_object_" + id).toggle(300);
83
84
	if (typeof(has_image) === "undefined" || has_image === true)
85
	{
86
		document.getElementById("sp_collapse_" + id).src = elk_images_url + (mode ? '/collapse.png' : '/expand.png');
0 ignored issues
show
Bug introduced by
The variable elk_images_url seems to be never declared. If this is a global, consider adding a /** global: elk_images_url */ 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...
87
	}
88
}
89
90
function sp_image_resize()
91
{
92
	var possible_images = document.getElementsByTagName("img");
93
94
	for (var i = 0; i < possible_images.length; i++)
95
	{
96
		if (possible_images[i].className !== "bbc_img sp_article")
97
		{
98
			continue;
99
		}
100
101
		var temp_image = new Image();
0 ignored issues
show
Bug introduced by
The variable Image seems to be never declared. If this is a global, consider adding a /** global: Image */ 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...
102
		temp_image.src = possible_images[i].src;
103
104
		if (temp_image.width > 300)
105
		{
106
			possible_images[i].height = (300 * temp_image.height) / temp_image.width;
107
			possible_images[i].width = 300;
108
		}
109
		else
110
		{
111
			possible_images[i].width = temp_image.width;
112
			possible_images[i].height = temp_image.height;
113
		}
114
	}
115
116
	if (typeof(window_oldSPImageOnload) !== "undefined" && window_oldSPImageOnload)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable window_oldSPImageOnload is declared in the current environment, consider using typeof window_oldSPImageOnload === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
117
	{
118
		window_oldSPImageOnload();
119
		window_oldSPImageOnload = null;
0 ignored issues
show
Bug introduced by
The variable window_oldSPImageOnload 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.window_oldSPImageOnload.
Loading history...
120
	}
121
}
122
123
/**
124
 * Send in a shout for display in a shoutbox
125
 *
126
 * @param {string} shoutbox_id
127
 * @param {string} sSessionVar
128
 * @param {string} sSessionId
129
 */
130
function sp_submit_shout(shoutbox_id, sSessionVar, sSessionId)
131
{
132
	if (window.XMLHttpRequest)
133
	{
134
		shoutbox_indicator(shoutbox_id, true);
135
136
		var shout_body = document.getElementById('new_shout_' + shoutbox_id).value.replace(/&#/g, "&#38;#").php_urlencode();
137
138
		sendXMLDocument(elk_prepareScriptUrl(sp_script_url) + 'action=shoutbox;xml', 'shoutbox_id=' + shoutbox_id + '&shout=' + shout_body + '&' + sSessionVar + '=' + sSessionId, onShoutReceived);
0 ignored issues
show
Bug introduced by
The variable sp_script_url seems to be never declared. If this is a global, consider adding a /** global: sp_script_url */ 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...
139
140
		document.getElementById('new_shout_' + shoutbox_id).value = '';
141
	}
142
143
	return false;
144
}
145
146
/**
147
 * Remove a previous entered shout
148
 *
149
 * @param {string} shoutbox_id
150
 * @param {string} shout_id
151
 * @param {string} sSessionVar
152
 * @param {string} sSessionId
153
 */
154
function sp_delete_shout(shoutbox_id, shout_id, sSessionVar, sSessionId)
155
{
156
	if (window.XMLHttpRequest)
157
	{
158
		shoutbox_indicator(shoutbox_id, true);
159
160
		sendXMLDocument(elk_prepareScriptUrl(sp_script_url) + 'action=shoutbox;xml', 'shoutbox_id=' + shoutbox_id + '&delete=' + shout_id + '&' + sSessionVar + '=' + sSessionId, onShoutReceived);
0 ignored issues
show
Bug introduced by
The variable sp_script_url seems to be never declared. If this is a global, consider adding a /** global: sp_script_url */ 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...
161
	}
162
163
	return false;
164
}
165
166
/**
167
 * Manually refresh the shoutbox ahead of the auto refresh action
168
 *
169
 * @param {string} shoutbox_id
170
 * @param {int} last_refresh
171
 */
172
function sp_refresh_shout(shoutbox_id, last_refresh)
173
{
174
	if (window.XMLHttpRequest)
175
	{
176
		shoutbox_indicator(shoutbox_id, true);
177
178
		getXMLDocument(elk_prepareScriptUrl(sp_script_url) + 'action=shoutbox;shoutbox_id=' + shoutbox_id + ';time=' + last_refresh + ';xml', onShoutReceived);
0 ignored issues
show
Bug introduced by
The variable sp_script_url seems to be never declared. If this is a global, consider adding a /** global: sp_script_url */ 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...
179
	}
180
181
	return false;
182
}
183
184
/**
185
 * Refresh the shoutbox based on the XML response
186
 *
187
 * @param {object} XMLDoc
188
 */
189
function onShoutReceived(XMLDoc)
190
{
191
	var shout, shoutbox_id, updated, error, warning, reverse, id, author, time,
192
		timeclean, delete_link, content, is_me, new_body = '';
193
194
	// All valid response will have these
195
	shoutbox_id = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("shoutbox")[0].childNodes[0].nodeValue;
196
	updated = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("updated")[0].childNodes[0].nodeValue;
197
198
	// Updated response will have the full shoutbox data
199
	if (updated === "1")
200
	{
201
		shouts = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("shout");
0 ignored issues
show
Bug introduced by
The variable shouts 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.shouts.
Loading history...
202
		error = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("error")[0].childNodes[0].nodeValue;
203
		warning = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("warning")[0].childNodes[0].nodeValue;
204
		reverse = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("reverse")[0].childNodes[0].nodeValue;
205
206
		// SHow the "warning" box at the top of the shoutbox
207
		if (warning !== "0")
208
		{
209
			new_body += '<li class="shoutbox_warning smalltext">' + warning + '</li>';
210
		}
211
212
		if (error !== "0")
213
		{
214
			document.getElementById('shouts_' + shoutbox_id).innerHTML = new_body + '<li class="smalltext">' + error + '</li>';
215
		}
216
		else
217
		{
218
			// Display all the shouts
219
			for (var i = 0; i < shouts.length; i++)
220
			{
221
				shout = XMLDoc.getElementsByTagName("elk")[0].getElementsByTagName("shout")[i];
222
				id = shout.getElementsByTagName("id")[0].childNodes[0].nodeValue;
0 ignored issues
show
Unused Code introduced by
The variable id seems to be never used. Consider removing it.
Loading history...
223
				author = shout.getElementsByTagName("author")[0].childNodes[0].nodeValue;
224
				time = shout.getElementsByTagName("time")[0].childNodes[0].nodeValue;
225
				timeclean = shout.getElementsByTagName("timeclean")[0].childNodes[0].nodeValue;
0 ignored issues
show
Unused Code introduced by
The variable timeclean seems to be never used. Consider removing it.
Loading history...
226
				delete_link = shout.getElementsByTagName("delete")[0].childNodes[0].nodeValue;
227
				content = shout.getElementsByTagName("content")[0].childNodes[0].nodeValue;
228
				is_me = shout.getElementsByTagName("is_me")[0].childNodes[0].nodeValue;
229
230
				// Something you said
231
				new_body += '<li>' + (is_me === "0" ? '<strong>' + author + ':</strong> ' : '') + content + '<br />' + (delete_link !== 0 ? ('<span class="shoutbox_delete">' + delete_link + '</span>') : '') + '<span class="smalltext shoutbox_time">' + time + '</span></li>';
232
			}
233
234
			document.getElementById('shouts_' + shoutbox_id).innerHTML = new_body;
235
236
			// Set the display direction
237
			if (reverse !== "0")
238
			{
239
				document.getElementById('shouts_' + shoutbox_id).scrollTop = document.getElementById('shouts_' + shoutbox_id).scrollHeight;
240
			}
241
			else
242
			{
243
				document.getElementById('shouts_' + shoutbox_id).scrollTop = 0;
244
			}
245
		}
246
	}
247
248
	// Turn off the spinner
249
	shoutbox_indicator(shoutbox_id, false);
250
251
	return false;
252
}
253
254
/**
255
 * Toggle the shoutbox spinner for a given box
256
 *
257
 * @param {int} shoutbox_id id of the box to work on
258
 * @param {boolean} turn_on showing or hiding
259
 */
260
function shoutbox_indicator(shoutbox_id, turn_on)
261
{
262
	document.getElementById('shoutbox_load_' + shoutbox_id).style.display = turn_on ? '' : 'none';
263
}
264
265
function sp_catch_enter(key)
266
{
267
	var keycode;
268
269
	if (window.event)
270
	{
271
		keycode = window.event.keyCode;
272
	}
273
	else if (key)
274
	{
275
		keycode = key.which;
276
	}
277
278
	if (keycode === 13)
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if keycode === 13 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Bug introduced by
The variable keycode does not seem to be initialized in case key on line 273 is false. Are you sure this can never be the case?
Loading history...
279
	{
280
		return true;
281
	}
282
}
283
284
function sp_show_ignored_shout(shout_id)
285
{
286
	document.getElementById('ignored_shout_' + shout_id).style.display = '';
287
	document.getElementById('ignored_shout_link_' + shout_id).style.display = 'none';
288
}
289
290
function sp_show_history_ignored_shout(shout_id)
291
{
292
	document.getElementById('history_ignored_shout_' + shout_id).style.display = '';
293
	document.getElementById('history_ignored_shout_link_' + shout_id).style.display = 'none';
294
}
295
296
function sp_showMoreSmileys(postbox, sTitleText, sPickText, sCloseText, elk_theme_url, elk_smileys_url)
297
{
298
	if (typeof(this.oSmileyPopupWindow) !== "undefined" && 'closed' in this.oSmileyPopupWindow && !this.oSmileyPopupWindow.closed)
299
	{
300
		this.oSmileyPopupWindow.focus();
301
		return;
302
	}
303
304
	if (typeof(sp_smileyRowsContent) === "undefined")
0 ignored issues
show
Bug introduced by
The variable sp_smileyRowsContent seems to be never initialized.
Loading history...
Bug introduced by
The variable sp_smileyRowsContent seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
305
	{
306
		var sp_smileyRowsContent = '';
307
308
		for (i = 0; i < sp_smileys.length; i++)
0 ignored issues
show
Bug introduced by
The variable i 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.i.
Loading history...
Bug introduced by
The variable sp_smileys seems to be never declared. If this is a global, consider adding a /** global: sp_smileys */ 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...
309
		{
310
			sp_smileys[i][2] = sp_smileys[i][2].replace(/"/g, '&quot;');
311
			sp_smileys[i][0] = sp_smileys[i][0].replace(/"/g, '&quot;');
312
			sp_smileyRowsContent += '<a href="javascript:void(0);" onclick="window.opener.replaceText(\' ' + sp_smileys[i][0].php_addslashes() + '\', window.opener.document.getElementById(\'new_shout_' + postbox + '\')); window.focus(); return false;"><img src="' + elk_smileys_url + '/' + sp_smileys[i][1] + '" id="sml_' + sp_smileys[i][1] + '" alt="' + sp_smileys[i][2] + '" title="' + sp_smileys[i][2] + '" style="padding: 4px;" border="0" /></a> ';
313
		}
314
	}
315
316
	this.oSmileyPopupWindow = window.open('', 'add_smileys', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=220,resizable=yes');
317
318
	this.oSmileyPopupWindow.document.open('text/html', 'replace');
319
	this.oSmileyPopupWindow.document.write(sp_moreSmileysTemplate.easyReplace({
0 ignored issues
show
Bug introduced by
The variable sp_moreSmileysTemplate seems to be never declared. If this is a global, consider adding a /** global: sp_moreSmileysTemplate */ 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
		smileyRows: sp_smileyRowsContent
0 ignored issues
show
Bug introduced by
The variable sp_smileyRowsContent does not seem to be initialized in case typeof sp_smileyRowsContent === "undefined" on line 304 is false. Are you sure this can never be the case?
Loading history...
Bug introduced by
The variable sp_smileyRowsContent seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
321
	}));
322
323
	this.oSmileyPopupWindow.document.close();
324
}
325
326
/**
327
 * When using html or php, disable the editor so it does not "fight" with what
328
 * the user wants to enter.
329
 *
330
 * @param {string} new_state
331
 * @param {string} original set to true on first invocation from controller
332
 */
333
function sp_update_editor(new_state, original)
334
{
335
	var $_textarea = $("textarea"),
336
		instance = $_textarea.sceditor("instance"),
337
		val = '';
338
339
	// Going back to BBC
340
	if (new_state === "bbc" && typeof(instance) === "undefined")
341
	{
342
		// Get the current textbox contents, treat as if html
343
		if (original === 'html')
344
		{
345
			val = $_textarea.html().php_unhtmlspecialchars();
346
		}
347
		else
348
		{
349
			val = '[code]' + $_textarea.val().replace(/\n/g, '<br \>') + '[/code]';
350
		}
351
352
		// Start the editor again
353
		elk_editor();
354
355
		// load the editor with the html contents, toggle back to bbc so the editor converts it
356
		instance = $_textarea.sceditor("instance");
357
		instance.sourceMode(false);
358
		instance.setWysiwygEditorValue(val);
359
		instance.sourceMode(true);
360
	}
361
	// Toggling from BBC to html or php
362
	else if (new_state !== "bbc" && typeof(instance) !== "undefined" && original !== '')
363
	{
364
		// Update the the original text area with current editor contents and stop the editor
365
		if (new_state === 'html')
366
		{
367
			// Get the editors html value, bypass the bbc plugin, this html will have lost
368
			// its formatting but it is html
369
			if (instance.getSourceEditorValue() !== '')
370
			{
371
				val = instance.getWysiwygEditorValue(false);
372
				val = val.replace(/<span .*>\s?<\/span>/g, '').replace(/<br( \\)?>/g, "\n");
373
			}
374
		}
375
		// From bbc to php
376
		else
377
		{
378
			val = instance.getSourceEditorValue(false).replace(/<br( \\)?>/g, "\n").php_unhtmlspecialchars().replace('[code]', '').replace('[/code]', '');
379
		}
380
381
		// Don't need the editor any longer, back to a text box and set the value we determined
382
		instance.destroy();
383
		$("textarea").val(val);
384
	}
385
	// Load html to the text area
386
	else if (new_state !== "bbc" && typeof(instance) !== "undefined")
387
	{
388
		// Update the the original text area with current editor contents and stop the editor
389
		if (new_state === 'html')
390
		{
391
			instance.updateOriginal();
392
		}
393
394
		instance.destroy();
395
	}
396
}
397
398
/**
399
 * Monitors the onchange and focus events for an element
400
 *
401
 * @param {string} element ID of element to attach change/focus events
402
 */
403
function sp_editor_change_type(element)
404
{
405
	var previous;
406
407
	$('#' + element).on('focus', function ()
408
	{
409
		// Store the current value on focus and on change
410
		previous = this.value;
411
	}).change(function ()
412
	{
413
		// Handle the editor change
414
		sp_update_editor(this.value, previous);
415
416
		// Make sure the previous value is updated
417
		previous = this.value;
418
	});
419
}
420
421
/**
422
 * Used by the theme selection block to swap the preview image
423
 * @param {type} obj
424
 */
425
function sp_theme_select(obj)
426
{
427
	var id = obj.options[obj.selectedIndex].value;
428
	document.getElementById("sp_ts_thumb").src = sp_ts_thumbs[id];
0 ignored issues
show
Bug introduced by
The variable sp_ts_thumbs seems to be never declared. If this is a global, consider adding a /** global: sp_ts_thumbs */ 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...
429
}
430
431
/**
432
 * Used to swap the day on the calendar to update the days events
433
 * @param {type} id
434
 */
435
function sp_collapseCalendar(id)
436
{
437
	new_day = "sp_calendar_" + id;
0 ignored issues
show
Bug introduced by
The variable new_day 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.new_day.
Loading history...
438
439
	if (new_day === current_day)
0 ignored issues
show
Bug introduced by
The variable current_day seems to be never declared. If this is a global, consider adding a /** global: current_day */ 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...
440
	{
441
		return false;
442
	}
443
444
	document.getElementById(current_day).style.display = "none";
445
	document.getElementById(new_day).style.display = "";
446
	current_day = new_day;
0 ignored issues
show
Bug introduced by
The variable current_day 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.current_day.
Loading history...
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...
447
}
448
449
/**
450
 * Admin Blocks area, used to expand the areas under advanced
451
 * @param {type} id
452
 */
453
function sp_collapseObject(id)
454
{
455
	var mode = document.getElementById("sp_object_" + id).style.display;
456
	mode = (mode === "" | mode === "block") ? false : true;
0 ignored issues
show
introduced by
You have used a bitwise operator | in a condition. Did you maybe want to use the logical operator ||
Loading history...
457
458
	// Make it close smoothly
459
	$("#sp_object_" + id).slideToggle(300);
460
461
	document.getElementById("sp_collapse_" + id).src = elk_images_url + (!mode ? "/selected_open.png" : "/selected.png");
0 ignored issues
show
Bug introduced by
The variable elk_images_url seems to be never declared. If this is a global, consider adding a /** global: elk_images_url */ 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...
462
}
463
464
/**
465
 * Used to enable / disable the style options for body and title
466
 */
467
function check_style_options()
468
{
469
	var noTitle = document.getElementById("no_title").checked,
470
		noBody = document.getElementById("no_body").checked;
471
472
	document.getElementById("title_default_class").disabled = noTitle;
473
	document.getElementById("title_custom_class").disabled = noTitle;
474
	document.getElementById("title_custom_style").disabled = noTitle;
475
	document.getElementById("body_default_class").disabled = noBody;
476
	document.getElementById("body_custom_class").disabled = noBody;
477
	document.getElementById("body_custom_style").disabled = noBody;
478
}
479
480
/**
481
 * Surrounds the selected text with text1 and text2.
482
 *  - If no text is selected, simply appends text1/text2 to the end
483
 *
484
 * @param {string} text1
485
 * @param {string} text2
486
 * @param {object} oTextHandle
487
 */
488
function sp_surroundText(text1, text2, oTextHandle)
489
{
490
	// Can a text range be created, start off with Internet explorer < 9.
491
	if ('caretPos' in oTextHandle && 'createTextRange' in oTextHandle)
492
	{
493
		var caretPos = oTextHandle.caretPos,
494
			temp_length = caretPos.text.length;
495
496
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) === ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
497
498
		if (temp_length === 0)
499
		{
500
			caretPos.moveStart('character', -text2.length);
501
			caretPos.moveEnd('character', -text2.length);
502
			caretPos.select();
503
		}
504
		else
505
		{
506
			oTextHandle.focus(caretPos);
507
		}
508
	}
509
	// Compliant text range wrap.
510
	else if ('selectionStart' in oTextHandle)
511
	{
512
		var begin = oTextHandle.value.substr(0, oTextHandle.selectionStart),
513
			selection = oTextHandle.value.substr(oTextHandle.selectionStart, oTextHandle.selectionEnd - oTextHandle.selectionStart),
514
			end = oTextHandle.value.substr(oTextHandle.selectionEnd),
515
			newCursorPos = oTextHandle.selectionStart,
516
			scrollPos = oTextHandle.scrollTop;
517
518
		oTextHandle.value = begin + text1 + selection + text2 + end;
519
520
		if (oTextHandle.setSelectionRange)
521
		{
522
			if (selection.length === 0)
523
			{
524
				oTextHandle.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
525
			}
526
			else
527
			{
528
				oTextHandle.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
529
			}
530
531
			oTextHandle.focus();
532
		}
533
534
		oTextHandle.scrollTop = scrollPos;
535
	}
536
	// Just put them on the end, then.
537
	else
538
	{
539
		oTextHandle.value += text1 + text2;
540
		oTextHandle.focus(oTextHandle.value.length - 1);
541
	}
542
}
543
544
// Updates the current version container with the current version found in the repository
545
function sp_currentVersion()
546
{
547
	var oSPVersionContainer = document.getElementById("spCurrentVersion"),
548
		oinstalledVersionContainer = document.getElementById("spYourVersion"),
549
		sCurrentVersion = oinstalledVersionContainer.innerHTML;
550
551
	$.getJSON('https://api.github.com/repos/SimplePortal/SimplePortal_ElkArte/releases', {format: "json"},
552
		function (data, textStatus, jqXHR)
0 ignored issues
show
Unused Code introduced by
The parameter textStatus 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 jqXHR 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...
553
		{
554
			var mostRecent = {},
555
				init_news = false;
556
557
			$.each(data, function (idx, elem)
558
			{
559
				// No drafts, thank you
560
				if (elem.draft)
561
				{
562
					return;
563
				}
564
565
				mostRecent = elem;
566
567
				// Load announcements for this release
568
				sp_setAnnouncement(init_news, elem);
569
				init_news = true;
570
			});
571
572
			var spVersion = mostRecent.tag_name.replace(/simpleportal/i, '').trim();
573
574
			oSPVersionContainer.innerHTML = spVersion;
575
			if (sCurrentVersion !== spVersion)
576
			{
577
				oinstalledVersionContainer.innerHTML = '<span class="alert">' + sCurrentVersion + '</span>';
578
			}
579
		});
580
}
581
582
// Load in any announcements
583
function sp_setAnnouncement(init_news, announcement)
584
{
585
	var oElem = document.getElementById('spAnnouncements'),
586
		sMessages = init_news ? oElem.innerHTML : '',
587
		sAnnouncementTemplate = '<dl>%content%</dl>',
588
		sAnnouncementMessageTemplate = '<dt><a href="%href%">%subject%</a> :: %time%</dt><dd>%message%</dd>';
589
590
	var sMessage = sAnnouncementMessageTemplate.replace('%href%', announcement.html_url).replace('%subject%', announcement.name).replace('%time%', announcement.published_at.replace(/[TZ]/g, ' ')).replace('%message%', announcement.body).replace(/\n/g, '<br />').replace(/\r/g, '');
591
592
	oElem.innerHTML = sMessages + sAnnouncementTemplate.replace('%content%', sMessage);
593
}
594