|
| 1 | +function toLong(s) { |
| 2 | + var ret = s.trim(); |
| 3 | + try { |
| 4 | + if (ret.startsWith("0x")) { |
| 5 | + return Long.fromString(ret.substring(2), 16); |
| 6 | + } |
| 7 | + return Long.fromString(ret, 10); |
| 8 | + } catch (e) { |
| 9 | + return Long.ZERO; |
| 10 | + } |
| 11 | +} |
| 12 | +function setBitClassName(prefix, value, selected, notSelected) { |
| 13 | + for (var i=0; i<65; i++) { |
| 14 | + var b = Long.ONE.shiftLeft(i); |
| 15 | + var el = document.getElementById(prefix + "-bit" + i); |
| 16 | + if (el) { |
| 17 | + if (value.and(b).equals(b)) { |
| 18 | + el.className = selected; |
| 19 | + } else { |
| 20 | + el.className = notSelected; |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | +function featuresExample(el) { |
| 26 | + document.getElementById("airplay-features-input").value = el.value; |
| 27 | + updateFeatures(el.value); |
| 28 | +} |
| 29 | +function featuresChanged(el) { |
| 30 | + document.getElementById("airplay-features-examples").value = ""; |
| 31 | + updateFeatures(el.value); |
| 32 | +} |
| 33 | + |
| 34 | +function updateFeatures(featuresS) { |
| 35 | + var comma = featuresS.indexOf(","); |
| 36 | + var features = 0; |
| 37 | + if (comma >= 0) { |
| 38 | + var high = toLong(featuresS.substring(comma + 1)); |
| 39 | + var low = toLong(featuresS.substring(0, comma)); |
| 40 | + features = high.shiftLeft(32).or(low); |
| 41 | + } else { |
| 42 | + features = toLong(featuresS); |
| 43 | + } |
| 44 | + if (features.equals(Long.ZERO)) { |
| 45 | + document.getElementById("airplay-features-output").className = "noscript"; |
| 46 | + setBitClassName("airplay-features", Long.ZERO, "", "") |
| 47 | + } else { |
| 48 | + document.getElementById("airplay-features-output").className = ""; |
| 49 | + setBitClassName("airplay-features", features, "selected", "notSelected") |
| 50 | + } |
| 51 | + |
| 52 | + document.getElementById("airplay-features-dec").innerHTML = features.toString(10); |
| 53 | + document.getElementById("airplay-features-hex").innerHTML = "0x" + features.toString(16); |
| 54 | + var txt = "0x" + features.and(Long.fromBits(0xffffffff, 0, true)).toString(16) + |
| 55 | + ",0x" + features.shiftRight(32).toString(16); |
| 56 | + document.getElementById("airplay-features-txt").innerHTML = txt; |
| 57 | +} |
| 58 | +featuresChanged(document.getElementById("airplay-features-input")); |
| 59 | +document.getElementById("airplay-features-interactive").className = ""; |
0 commit comments