summaryrefslogtreecommitdiff
path: root/js/script.js
blob: 37786dc192a724936b9ec71021ac0156c5d277c1 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function addUser(username) {

	var colorlist = document.getElementById('usernames');

	// The user was already in the list
	if (document.mainform.highlight_names.value.indexOf(username) >= 0) {

		// Remove the username from the list
		var myvalue = document.mainform.highlight_names.value;
		myvalue = myvalue.replace(username, "");
		myvalue = myvalue.replace(/;;/g,";");
		myvalue = myvalue.replace(/^;/, "");
		myvalue = myvalue.replace(/;$/, "");
		document.mainform.highlight_names.value = myvalue;

		// Unmark the lines of the user
		for (var k = 0; k < document.styleSheets.length; k++) {
			var rules = document.styleSheets[k].cssRules || document.styleSheets[k].rules;
			for (var x = 0; x < rules.length; x++) {
				if (rules[x].selectorText == ('span.user_' + username)) {
					rules[x].style.color = '';
				}
			}
		}

		// Now drop the username from the colorlist
		colorlist.removeChild(document.getElementById('user_' + username));

	} else {

		// Add the username to the list
		if (document.mainform.highlight_names.value !== '') {
			document.mainform.highlight_names.value += ';';
		}
		document.mainform.highlight_names.value += username;

		// Mark all the lines of the newly selected user
		var color = CryptoJS.SHA1(username).toString().substr(0, 6);
		var styleSheet = document.styleSheets[0];
		if (styleSheet.addRule) {
			styleSheet.addRule('span.user_' + username , 'color: #' + color, 0);
		} else if (styleSheet.insertRule) {
			styleSheet.insertRule('span.user_' + username + ' { color: #' + color + '; }', 0);
		} else {
			document.mainform.submit();
		}

		// Now add the username to the colorlist
		var listelement = document.createElement('li');
		listelement.setAttribute('id', 'user_' + username);
		var spanelement = document.createElement('span');
		spanelement.setAttribute('class', 'checkbox user_' + username);
		listelement.appendChild(spanelement);
		spanelement.innerHTML = '<a href="javascript:addUser(\'' + username + '\');">' + username + '</a>';
		colorlist.appendChild(listelement);
	}

	var semicolons = (document.mainform.highlight_names.value.match(/;/g) || []).length;
	document.getElementById('users_label').innerHTML = 'Users ' + (document.mainform.highlight_names.value.length ? ' (' + (semicolons + 1) + ')' : '');

	document.cookie = 'stored_users=' + escape(document.mainform.highlight_names.value) + '; path=/';
}