summaryrefslogtreecommitdiffstats
path: root/script/slx-fixes.js
blob: 12db9c7963be5f5dcebe434ecdf054e50297ce5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Give file select dialogs a modern style and feel
$(document).on('change', '.btn-file :file', function() {
	var input = $(this);
	var numFiles = input.get(0).files ? input.get(0).files.length : 1;
	var label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
	input.trigger('fileselect', [numFiles, label]);
});
$(document).ready(function() {
	$('.btn-file :file').on('fileselect', function(event, numFiles, label) {
		var input = $(this).parents('.upload-ex').find(':text');
		var log = numFiles > 1 ? numFiles + ' files selected' : label;
		if (input.length) {
			input.val(log);
		}
	});
});
$('.upload-ex :text').click(function () {
	$(this).parents('.upload-ex').find(':file').click();
});

// Replace message query params in URL, so you won't see them again if you bookmark or share the link
if (history && history.replaceState && window && window.location && window.location.search && window.location.search.indexOf('message[]=') !== -1) {
	var str = window.location.search;
	console.log('TRUE: ' + str);
	do {
		var repl = str.match(/([\?&])message\[\]=[^&]+(&|$)/);
		console.log(repl);
		if (!repl) break;
		if (repl[2].length === 0) {
			str = str.replace(repl[0], '');
		} else {
			str = str.replace(repl[0], repl[1]);
		}
		console.log('Replace: ' + str);
	} while (1);
	history.replaceState(null, null, window.location.pathname + str);
}

// Simple decollapse functionality for tables
$('.slx-decollapse').click(function () {
	$(this).siblings('.collapse').removeClass('collapse');
});