|
10 | 10 |
|
11 | 11 | var inspector; |
12 | 12 |
|
13 | | -var socket = io('http://localhost:8081'); |
14 | | -socket.on('connect', function(){ |
15 | | - socket.on('log', function(data){ |
16 | | - addToLog(data.message); |
17 | | - }); |
18 | | - socket.on('disconnect', function(){ |
19 | | - document.querySelector('#serverlogs').innerHTML = 'Socket Disconnected'; |
20 | | - }); |
21 | | -}); |
| 13 | +if (typeof io !== 'undefined') { |
| 14 | + var socket = io('http://localhost:8081'); |
| 15 | + socket.on('connect', function(){ |
| 16 | + socket.on('log', function(data){ |
| 17 | + addToLog(data.message); |
| 18 | + }); |
| 19 | + socket.on('disconnect', function(){ |
| 20 | + document.querySelector('#serverlogs').innerHTML = 'Socket Disconnected'; |
| 21 | + }); |
| 22 | + }); |
| 23 | +} |
22 | 24 |
|
23 | 25 | function processMainIncomingMessage(msg) { |
24 | 26 | switch(msg.msgType) { |
@@ -100,17 +102,23 @@ function updateStatus(status) { //Update status panel in footer |
100 | 102 | } |
101 | 103 |
|
102 | 104 | function addToLog(msg) { |
103 | | - var logContainer = document.querySelector('#serverlogs'); |
104 | | - logContainer.innerHTML += msg + '\n'; |
105 | | - logContainer.scrollTop = logContainer.scrollHeight; |
| 105 | + if (document.querySelector('#serverlogs')) { |
| 106 | + var logContainer = document.querySelector('#serverlogs'); |
| 107 | + logContainer.innerHTML += msg + '\n'; |
| 108 | + logContainer.scrollTop = logContainer.scrollHeight; |
| 109 | + } |
106 | 110 | } |
107 | 111 |
|
108 | 112 | function clearLog() { |
109 | 113 | document.querySelector('#serverlogs').innerHTML = ''; |
110 | 114 | } |
111 | 115 |
|
112 | | -window.onload = function() { |
113 | | - var clearButton = document.querySelector('#logclear'); |
114 | | - clearButton.addEventListener('click', clearLog, false); |
115 | | - $('#sidePanel').resizable({ minWidth: 120, handles: 'e'}); |
116 | | -}; |
| 116 | +window.addEventListener('load', function() { |
| 117 | + if (document.querySelector('#logclear')) { |
| 118 | + var clearButton = document.querySelector('#logclear'); |
| 119 | + clearButton.addEventListener('click', clearLog, false); |
| 120 | + } |
| 121 | + if (document.querySelector('#sidePanel')) { |
| 122 | + $('#sidePanel').resizable({ minWidth: 120, handles: 'e'}); |
| 123 | + } |
| 124 | +}, false); |
0 commit comments