forked from m4recek/panasonic-viera-remote-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
183 lines (163 loc) · 4.31 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<html>
<head>
<title>Panasonic TV Remote HTML Tester</title>
</head>
<body>
<div class="tv-remote">
<div class="settings collapsed">
<div class="github">
Panasonic Viera Remote control,
<a href="https://github.com/m4recek/panasonic-viera-remote-control">GitHub</a>
</div>
<i class="icon fa fa-cogs"></i>
<div class="container">
<input type="text" placeholder="Enter IP">
<input type="submit" value="OK">
</div>
</div>
<span class="message">...</span>
<div class="commands"></div>
</div>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="./VieraTVRemote.js"></script>
<script>
$(document).ready(function() {
/**
* initialize tvRemote
*/
var tvRemote = new VieraTVRemote();
tvRemote.execute = function(requestUrl, requestMethod, requestHeaders, requestData) {
return $.ajax(
requestUrl,
{
method: requestMethod,
headers: requestHeaders,
data: requestData,
error: function(xhr, status, error) {
console.error('TVRemote->execute()', status, error, xhr);
Error.showError('Error, see console log for details');
},
success: function(data, status) {
console.info(status, data);
Error.hideError('Done');
}
}
);
};
// create commands buttons
var elements = [];
VieraTVRemote.COMMANDS.map(function(value) {
//skip separate ON/OFF commands, we dont need them for functional testing
if (value.indexOf('ONOFF') === -1) {
return
} else {
var element = $('<span />').text(value).attr('data-command', value);
element.on('click', function() {
var command = $(this).attr('data-command');
if (tvRemote.sendCommand(command)) {
Error.hideError();
} else {
Error.showError('Error, check console for details');
}
});
element.mousedown(function(e){ e.preventDefault(); });
elements.push(element)
}
}, this);
$('.tv-remote .commands').append(elements);
/**
* settings
*/
var settings = $('.settings');
//autoload last ip from localStorage
var ipInput = settings.find('input[type="text"]');
var ipValue = window.localStorage.getItem('tv-ip');
if (ipValue) {
ipInput.attr('placeholder', ipValue);
tvRemote.setIp(ipValue);
}
settings.find('input[type="submit"]').on('click', function() {
var ipValue = ipInput.val();
Error.hideError();
if (tvRemote.setIp(ipValue)) {
ipInput.attr('placeholder', ipValue).val('');
window.localStorage.setItem('tv-ip', ipValue);
Error.hideError('IP set');
} else {
Error.showError('Please enter an ip of your TV');
}
});
var Error = {};
Error.showError = function(message) {
message += `<br>When testing you need to run chrome with <b>chrome --disable-web-security</b> command
<a href='http://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome'
target='_blank'>see this link</a>`;
$('.message').addClass('error').html(message);
};
Error.hideError = function(message) {
$('.message').removeClass('error').html(message || '...');
};
});
</script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<style>
* {
box-sizing: border-box;
}
.tv-remote .github {
padding: 5px;
font-weight: bold;
}
.tv-remote .github a,
.tv-remote .github a:visited {
color: #444D7D;
}
.tv-remote .commands {
--webkit-user-select: none;
user-select: none;
}
.tv-remote .commands * {
--webkit-user-select: none;
user-select: none;
display: inline-block;
border: 1px solid gray;
padding: 2px 8px;
margin: 2px 8px;
cursor: pointer;
}
.tv-remote .settings {
width: 100%;
line-height: 20px;
padding: 4px 8px;
background-color: silver;
}
.tv-remote .settings input[type="text"] {
color: #E24B4B;
}
.tv-remote .settings input[type="text"],
.tv-remote .settings input[type="submit"] {
border: 1px solid gray;
padding: 5px;
height: 30px;
}
.tv-remote .message {
background-color: silver;
width: 100%;
display: inline-block;
padding: 4px 16px;
margin-bottom: 10px;
}
.tv-remote .message.error {
background-color: #FFC253;
}
.tv-remote .settings input[type=submit] {
font-weight: bold;
cursor: pointer;
}
.tv-remote .settings .icon {
float: left;
margin: 5px 12px 5px 8px;
}
</style>
</body>
</html>