aboutsummaryrefslogtreecommitdiff
path: root/settings.html
blob: 42b3611f84b86579527292029bedec22d29acdc0 (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
<html>
	<head>
		<link rel="stylesheet" href="style.css">
		<script src="jquery.min.js"></script>
		<meta charset="utf-8"> 
		<title>root</title>
	</head>
	<body style="padding: 30px;">
		<h1>Настройки администратора</h1>
		<input id="variant" type="text" placeholder="Вариант?" />
		<a href="#" id="save" class="answer-button">Сохранить</a>
		<script>
			function setCookie(name, value, options) {
			  options = options || {};

			  var expires = options.expires;

			  if (typeof expires == "number" && expires) {
				var d = new Date();
				d.setTime(d.getTime() + expires*1000);
				expires = options.expires = d;
			  }
			  if (expires && expires.toUTCString) { 
				options.expires = expires.toUTCString();
			  }

			  value = encodeURIComponent(value);

			  var updatedCookie = name + "=" + value;

			  for(var propName in options) {
				updatedCookie += "; " + propName;
				var propValue = options[propName];    
				if (propValue !== true) { 
				  updatedCookie += "=" + propValue;
				 }
			  }

			  document.cookie = updatedCookie;
			}


			$("#save").click(function() {
				$.ajax({
					dataType: "json",
					url: "vars/" + $("#variant").val() + ".json",
					success: function(json) {
						setCookie("variant", $("#variant").val(), { expires: 0xFFFFFFF })
						alert("Вариант сохранился");
					},
					error: function() {
						alert("Такого варианта нет!")
					}
					
				});
			});
		</script>
	</body>
</html>