Log updates
[beagleboard.org.git] / static / bonescript.js
blob7d9f0955f16b5e4f52d327aa51532007f8ade3bc
1 function require(file) {
2     throw 'Please perform setTargetAddress on a valid target';
5 function setTargetAddress(address, handlers) {
6     var url = address;
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';
14         script.src = url;
15         script.charset = 'UTF-8';
16         var scriptObj = head.appendChild(script);
17         scriptObj.onload = onload;
18     }
19     function addHandlers() {
20         if(typeof handlers == 'function') {
21             handlers();
22             return;
23         }
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;
34         }
35         if(typeof handlers.callback == 'function') handlers.callback();
36     }