forked from timleland/rfoutlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
57 lines (56 loc) · 1.65 KB
/
Copy pathscripts.js
File metadata and controls
57 lines (56 loc) · 1.65 KB
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
function statusCheck() {
$.getJSON('RF.php?token=' + $_GET('token'), function (data) {
var elementDisable, elementEnable;
for (i = 1; i <= 7; i++) {
if (data[i] == 0) {
elementDisable = document.getElementById(i + "on");
elementEnable = document.getElementById(i + "off");
}
else if (data[i] == 1) {
elementDisable = document.getElementById(i + "off");
elementEnable = document.getElementById(i + "on");
}
if (elementDisable.classList.contains("btn-primary")) {
elementDisable.classList.remove("btn-primary");
if (!elementDisable.classList.contains("btn-default")) {
elementDisable.classList.add("btn-default");
}
}
if (elementEnable.classList.contains("btn-default")) {
elementEnable.classList.remove("btn-default");
if (!elementEnable.classList.contains("btn-primary")) {
elementEnable.classList.add("btn-primary");
}
}
}
});
setTimeout(function () {
statusCheck();
}, 5000);
}
function $_GET(name, url) {
"use strict";
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)")
, results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var toggleOutlet = function (buttonClicked) {
var id = buttonClicked.attr('data-outletId');
var powerStatus = buttonClicked.attr('data-outletStatus');
$.get('RF.php', {
outletId: id
, outletStatus: powerStatus
, token: $_GET('token')
}, function (data, status) {
statusCheck()
});
};
$(function () {
$('.toggleOutlet').click(function () {
toggleOutlet($(this));
});
});