]>
git.mar77i.info Git - hublib/blob - webroot/common.js
57ae142b7d7272eeb1ee6004b4d74ff75e5c3fe3
2 var domconf_event_prefix
= "event_";
3 function domconf(domobj
, obj
) {
6 if (key
.substring(0, domconf_event_prefix
.length
) == domconf_event_prefix
) {
7 domobj
.addEventListener(key
.substring(domconf_event_prefix
.length
), obj
[key
]);
9 domobj
.setAttribute(key
, obj
[key
])
15 function tag(tag_name
, obj
) {
16 return domconf(document
.createElement(tag_name
), obj
);
19 function HubClient(ws_uri
, open
, close
, message
) {
20 this.close
= close
.bind(this);
21 this.message
= message
.bind(this);
22 this.open
= open
.bind(this);
25 {"http:": "ws:", "https:": "wss:"}[window
.location
.protocol
] +
27 window
.location
.host
+
31 "event_close": this.close
,
32 "event_message": this.message
,
33 "event_open": this.open
,
36 this.send
= this.ws
.send
.bind(this.ws
);
39 function write(output
, msg
) {
40 if (output
.childNodes
.length
> 0) {
41 output
.append(tag("br"));
43 if (typeof msg
!== "string") {
46 output
.append(document
.createTextNode(msg
));
49 function setup(callback
) {
53 "event_readystatechange": function (event
) {
57 if (event
.target
.readyState
!== "complete") {
66 function make_key_event(callback
) {
67 var wrapper = function (event
) {
68 event
= event
|| window
.event
;
69 callback(event
, event
.target
|| event
.srcElement
, event
.code
|| event
.key
);
74 function input_with_keydown_event(callback
) {
75 return common
.tag("input", {"event_keydown": make_key_event(callback
)});
80 "HubClient": HubClient
,
83 "input_with_keydown_event": input_with_keydown_event
,