/** * @description Set of short commonly used methods for handling HTML elements * @author Ylian Saint-Hilaire * @version v0.0.1b */ // Add startsWith for IE browser if (!String.prototype.startsWith) { String.prototype.startsWith = function (str) { return this.lastIndexOf(str, 0) === 0; }; } if (!String.prototype.endsWith) { String.prototype.endsWith = function (str) { return this.indexOf(str, this.length - str.length) !== -1; }; } // Quick UI functions, a bit of a replacement for jQuery //function Q(x) { if (document.getElementById(x) == null) { console.log('Invalid element: ' + x); } return document.getElementById(x); } // "Q" function Q(x) { return document.getElementById(x); } // "Q" function QS(x) { try { return Q(x).style; } catch (x) { } } // "Q" style function QE(x, y) { try { Q(x).disabled = !y; } catch (x) { } } // "Q" enable function QV(x, y) { try { QS(x).display = (y ? '' : 'none'); } catch (x) { } } // "Q" visible function QA(x, y) { Q(x).innerHTML += y; } // "Q" append function QH(x, y) { Q(x).innerHTML = y; } // "Q" html // Move cursor to end of input box function inputBoxFocus(x) { Q(x).focus(); var v = Q(x).value; Q(x).value = ''; Q(x).value = v; } // Binary encoding and decoding functions function ReadShort(v, p) { return (v.charCodeAt(p) << 8) + v.charCodeAt(p + 1); } function ReadShortX(v, p) { return (v.charCodeAt(p + 1) << 8) + v.charCodeAt(p); } function ReadInt(v, p) { return (v.charCodeAt(p) * 0x1000000) + (v.charCodeAt(p + 1) << 16) + (v.charCodeAt(p + 2) << 8) + v.charCodeAt(p + 3); } // We use "*0x1000000" instead of "<<24" because the shift converts the number to signed int32. function ReadSInt(v, p) { return (v.charCodeAt(p) << 24) + (v.charCodeAt(p + 1) << 16) + (v.charCodeAt(p + 2) << 8) + v.charCodeAt(p + 3); } function ReadIntX(v, p) { return (v.charCodeAt(p + 3) * 0x1000000) + (v.charCodeAt(p + 2) << 16) + (v.charCodeAt(p + 1) << 8) + v.charCodeAt(p); } function ShortToStr(v) { return String.fromCharCode((v >> 8) & 0xFF, v & 0xFF); } function ShortToStrX(v) { return String.fromCharCode(v & 0xFF, (v >> 8) & 0xFF); } function IntToStr(v) { return String.fromCharCode((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF); } function IntToStrX(v) { return String.fromCharCode(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF, (v >> 24) & 0xFF); } function MakeToArray(v) { if (!v || v == null || typeof v == 'object') return v; return [v]; } function SplitArray(v) { return v.split(','); } function Clone(v) { return JSON.parse(JSON.stringify(v)); } function EscapeHtml(x) { if (typeof x == 'string') return x.replace(/&/g, '&').replace(/>/g, '>').replace(/