1 function require(file) {
2 throw 'Please perform setTargetAddress on a valid target';
5 function setTargetAddress(address, handlers) {
7 url = url.replace(/^(http:\/\/|https:\/\/)*/, 'http://');
8 url = url.replace(/(\/)*$/, '/bonescript.js');
9 loadScript(url, addHandlers);
10 function loadScript(url, onload) {
11 var head = document.getElementsByTagName('head')[0];
12 var script = document.createElement('script');
13 script.type = 'text/javascript';
15 script.charset = 'UTF-8';
16 var scriptObj = head.appendChild(script);
17 scriptObj.onload = onload;
19 function addHandlers() {
20 if(typeof handlers == 'function') {
24 if(typeof _bonescript != 'undefined') {
25 _bonescript.address = address;
26 if(handlers.initialized) _bonescript.on.initialized = handlers.initialized;
27 if(handlers.connect) _bonescript.on.connect = handlers.connect;
28 if(handlers.connecting) _bonescript.on.connecting = handlers.connecting;
29 if(handlers.disconnect) _bonescript.on.disconnect = handlers.disconnect;
30 if(handlers.connect_failed) _bonescript.on.connect_failed = handlers.connect_failed;
31 if(handlers.reconnect_failed) _bonescript.on.reconnect_failed = handlers.reconnect_failed;
32 if(handlers.reconnect) _bonescript.on.reconnect = handlers.reconnect;
33 if(handlers.reconnecting) _bonescript.on.reconnecting = handlers.reconnecting;
35 if(typeof handlers.callback == 'function') handlers.callback();