(function () { var domconf_event_prefix = "event_"; function domconf(domobj, obj) { var key; for (key in obj) { if (key.substring(0, domconf_event_prefix.length) == domconf_event_prefix) { domobj.addEventListener( key.substring(domconf_event_prefix.length), obj[key] ); } else { domobj.setAttribute(key, obj[key]) } } return domobj; } function tag(tag_name, obj) { return domconf(document.createElement(tag_name), obj); } function HubClient(ws_uri, open, close, message) { this.close = close.bind(this); this.message = message.bind(this); this.open = open.bind(this); this.ws = domconf( new WebSocket( {"http:": "ws:", "https:": "wss:"}[window.location.protocol] + "//" + window.location.host + ws_uri ), { "event_close": this.close, "event_message": this.message, "event_open": this.open, }, ); this.send = this.ws.send.bind(this.ws); } function write(output, msg) { if (output.childNodes.length > 0) { output.append(tag("br")); } if (typeof msg !== "string") { msg = String(msg); } output.append(document.createTextNode(msg)); } function setup(callback) { domconf( document, { "event_readystatechange": function (event) { if (!event) { event = window.event; } if (event.target.readyState !== "complete") { return; } callback(event); } }, ); } function make_key_event(callback) { var wrapper = function (event) { event = event || window.event; callback(event, event.target || event.srcElement, event.code || event.key); }; return wrapper; } function input_with_keydown_event(callback) { return common.tag("input", {"event_keydown": make_key_event(callback)}); } window.common = { "tag": tag, "HubClient": HubClient, "write": write, "setup": setup, "input_with_keydown_event": input_with_keydown_event, }; }());