forked from nto/nto.github.com
-
Notifications
You must be signed in to change notification settings - Fork 20
/
features.js
122 lines (115 loc) · 3.71 KB
/
features.js
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
function toLong(s) {
var ret = s.trim();
try {
if (ret.startsWith("0x")) {
return Long.fromString(ret.substring(2), 16);
}
return Long.fromString(ret, 10);
} catch (e) {
return Long.ZERO;
}
}
function setBitClassName(prefix, value, selected, notSelected) {
for (var i=0; i<65; i++) {
var b = Long.ONE.shiftLeft(i);
var el = document.getElementById(prefix + "-bit" + i);
if (el) {
if (value.and(b).equals(b)) {
el.className = selected;
} else {
el.className = notSelected;
}
}
}
}
function updateFlagTable(prefix, value) {
if (value.equals(Long.ZERO)) {
document.getElementById(prefix + "-output").className = "noscript";
setBitClassName(prefix, Long.ZERO, "", "")
document.getElementById(prefix).className = "";
} else {
document.getElementById(prefix + "-output").className = "";
setBitClassName(prefix, value, "selected", "notSelected")
document.getElementById(prefix).className = "selecting";
}
document.getElementById(prefix + "-dec").innerHTML = value.toString(10);
document.getElementById(prefix + "-hex").innerHTML = "0x" + value.toString(16);
}
function exampleChanged(prefix, fn) {
var el = document.getElementById(prefix + "-examples");
document.getElementById(prefix + "-input").value = el.value;
fn(el);
}
function inputChanged(prefix, fn, bit) {
var el = document.getElementById(prefix + "-input");
document.getElementById(prefix + "-examples").value = "";
document.getElementById(prefix + "-interactive").className = "";
fn(el, bit);
}
function flipBit(prefix, fn, bit) {
var el = document.getElementById(prefix + "-input");
document.getElementById(prefix + "-examples").value = "";
document.getElementById(prefix + "-interactive").className = "";
fn(el, bit)
}
function updateFeatures(el, bit) {
var featuresS = el.value;
var comma = featuresS.indexOf(",");
var features = 0;
if (comma >= 0) {
var high = toLong(featuresS.substring(comma + 1));
var low = toLong(featuresS.substring(0, comma));
features = high.shiftLeft(32).or(low);
} else {
features = toLong(featuresS);
}
if (typeof bit != "undefined") {
var b = Long.ONE.shiftLeft(bit);
features = features.xor(b);
el.value = "0x" + features.toString(16);
}
updateFlagTable("airplay-features", features);
var txt = "0x" + features.and(Long.fromBits(0xffffffff, 0, true)).toString(16) +
",0x" + features.shiftRight(32).toString(16);
document.getElementById("airplay-features-txt").innerHTML = txt;
}
function updateSystemFlags(el, bit) {
var systemFlagsS = el.value;
var systemFlags = 0;
systemFlags = toLong(systemFlagsS);
if (typeof bit != "undefined") {
var b = Long.ONE.shiftLeft(bit);
systemFlags = systemFlags.xor(b);
el.value = "0x" + systemFlags.toString(16);
}
updateFlagTable("airplay-system-flags", systemFlags);
}
function installHandlers(prefix, fn) {
var input = function() {
inputChanged(prefix, fn);
}
var example = function() {
exampleChanged(prefix, fn);
}
var changeBit = function(ev) {
var target = ev.target;
while (target != null && target.tagName != "TR") {
target = target.parentElement;
}
if (target == null) {
return;
}
var bit = parseInt(target.id.substring(prefix.length + "-bit".length));
inputChanged(prefix, fn, bit);
}
var el = document.getElementById(prefix + "-input");
el.onkeyup = input;
el.onpaste = input;
var el = document.getElementById(prefix + "-examples");
el.onchange = example;
var el = document.getElementById(prefix + "-bit0");
el.parentNode.onclick = changeBit;
input();
}
installHandlers("airplay-features", updateFeatures)
installHandlers("airplay-system-flags", updateSystemFlags)