]>
git.mar77i.info Git - hublib/blob - webroot/common.js
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(
8 key
.substring(domconf_event_prefix
.length
), obj
[key
]
11 domobj
.setAttribute(key
, obj
[key
])
17 function tag(tag_name
, obj
) {
18 return domconf(document
.createElement(tag_name
), obj
);
21 function HubClient(ws_uri
, open
, close
, message
) {
22 this.close
= close
.bind(this);
23 this.message
= message
.bind(this);
24 this.open
= open
.bind(this);
27 {"http:": "ws:", "https:": "wss:"}[window
.location
.protocol
] +
29 window
.location
.host
+
33 "event_close": this.close
,
34 "event_message": this.message
,
35 "event_open": this.open
,
38 this.send
= this.ws
.send
.bind(this.ws
);
41 function write(output
, msg
) {
42 if (output
.childNodes
.length
> 0) {
43 output
.append(tag("br"));
45 if (typeof msg
!== "string") {
48 output
.append(document
.createTextNode(msg
));
51 function setup(callback
) {
55 "event_readystatechange": function (event
) {
59 if (event
.target
.readyState
!== "complete") {
68 function make_key_event(callback
) {
69 var wrapper = function (event
) {
70 event
= event
|| window
.event
;
71 callback(event
, event
.target
|| event
.srcElement
, event
.code
|| event
.key
);
76 function input_with_keydown_event(callback
) {
77 return common
.tag("input", {"event_keydown": make_key_event(callback
)});
82 "HubClient": HubClient
,
85 "input_with_keydown_event": input_with_keydown_event
,