Skip to content

Commit 40a2923

Browse files
committed
Make sure the code will be executed only when the DOM is fully loaded
1 parent d151e59 commit 40a2923

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cncjs-pendant-tinyweb",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A tiny web console for small 320x240 LCD display",
55
"homepage": "https://github.com/cncjs/cncjs-pendant-tinyweb",
66
"author": "Cheton Wu <cheton@gmail.com>",

src/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
(function(root) {
1+
$(function() {
22

3+
var root = window;
34
var cnc = root.cnc || {};
45
var controller = cnc.controller;
56

@@ -253,4 +254,4 @@ $('[data-route="axes"] [data-name="btn-dropdown"]').dropdown();
253254
$('[data-route="axes"] [data-name="active-state"]').text('Not connected');
254255
$('[data-route="axes"] select[data-name="select-distance"]').val('1');
255256

256-
})(this);
257+
});

src/controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
(function(root) {
1+
$(function() {
22

3-
// token
3+
var root = window;
44
var token = '';
55

66
try {
@@ -235,4 +235,4 @@ CNCController.prototype.writeln = function(data, context) {
235235

236236
root.cnc.controller = new CNCController();
237237

238-
})(this);
238+
});

src/index.html

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,17 @@
363363
<script src="vendor/js-cookie/js.cookie.js"></script>
364364
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
365365
<script>
366-
var root = window;
367-
root.cnc = {
368-
router: null,
369-
controller: null,
370-
controllerType: Cookies.get('cnc.controllerType'),
371-
port: Cookies.get('cnc.port'),
372-
baudrate: Cookies.get('cnc.baudrate'),
373-
connected: false
374-
};
375-
</script>
376-
<script src="controller.js"></script>
377-
<script>
378366
$('document').ready(function() {
379367
var root = window;
380-
var routes = {
368+
root.cnc = {
369+
router: null,
370+
controller: null,
371+
controllerType: Cookies.get('cnc.controllerType'),
372+
port: Cookies.get('cnc.port'),
373+
baudrate: Cookies.get('cnc.baudrate'),
374+
connected: false
375+
};
376+
root.cnc.router = window.Router({
381377
'/': function() {
382378
if (root.cnc.connected) {
383379
window.location = '#/workspace';
@@ -391,8 +387,7 @@
391387
},
392388
'/axes': function() {
393389
}
394-
};
395-
root.cnc.router = window.Router(routes);
390+
});
396391
root.cnc.router.configure({
397392
on: function() {
398393
var route = window.location.hash.slice(2);
@@ -407,6 +402,7 @@
407402
});
408403
});
409404
</script>
405+
<script src="controller.js"></script>
410406
<script src="app.js"></script>
411407
</body>
412408
</html>

0 commit comments

Comments
 (0)