OpenROV /
openrov-cockpit
| 1 | /*jshint esnext:true */ |
||
| 2 | (function (window, document) { |
||
| 3 | |||
| 4 | var hostname = document.location.hostname ? document.location.hostname : 'localhost'; |
||
| 5 | |||
| 6 | //Cockpit is inheriting from EventEmitter2. |
||
| 7 | //http://stackoverflow.com/questions/3900168/how-to-make-a-javascript-singleton-with-a-constructor-without-using-return |
||
| 8 | var Cockpit = function Cockpit(csocket) { |
||
| 9 | if (Cockpit.instance) { |
||
| 10 | alert('intercepted second instance of cockpit'); |
||
| 11 | return Cockpit.instance; |
||
| 12 | } |
||
| 13 | Cockpit.instance = this; |
||
| 14 | var self = this; |
||
| 15 | this.rov = csocket; |
||
| 16 | this.storeAndForward = new window.EventEmiiterStoreAndForward(this); |
||
| 17 | this.sendUpdateEnabled = true; |
||
| 18 | this.loadedPlugins = []; |
||
| 19 | this.loadUiTheme(function () { |
||
| 20 | // self.loadPlugins(); |
||
| 21 | // console.log('loaded plugins'); |
||
| 22 | self.listen(); |
||
| 23 | }); |
||
| 24 | }; |
||
| 25 | Cockpit.prototype = new EventEmitter2(); |
||
| 26 | Cockpit.prototype.constructor = Cockpit; |
||
| 27 | |||
| 28 | Cockpit.prototype.listen = function listen() { |
||
| 29 | var cockpit = this; |
||
| 30 | }; |
||
| 31 | |||
| 32 | Cockpit.prototype.loadUiTheme = function (done) { |
||
| 33 | done(); |
||
| 34 | return; |
||
| 35 | }; |
||
| 36 | Cockpit.prototype.loadPlugins = function loadPlugins() { |
||
| 37 | var cockpit = this; |
||
| 38 | Cockpit.plugins.forEach(function (plugin) { |
||
| 39 | var loadedPlugin = null; |
||
| 40 | try { |
||
| 41 | loadedPlugin = new plugin(cockpit); |
||
| 42 | } catch (err) { |
||
| 43 | console.log('error loading a plugin!!!' + err); |
||
| 44 | console.dir(err); |
||
| 45 | } |
||
| 46 | if (loadedPlugin != null && loadedPlugin !== undefined) { |
||
|
0 ignored issues
–
show
|
|||
| 47 | if (loadedPlugin.Plugin_Meta !== undefined && loadedPlugin.Plugin_Meta.name == undefined) { |
||
|
0 ignored issues
–
show
It is recommended to use
=== to compare with undefined.
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. Loading history...
|
|||
| 48 | //This alert should help plugin authurs find they missed a required section for a plugin |
||
| 49 | alert('Plugin ' + loadedPlugin + 'has to define a name property!'); |
||
| 50 | } |
||
| 51 | cockpit.loadedPlugins.push(loadedPlugin); |
||
| 52 | } |
||
| 53 | }); |
||
| 54 | var plugins_done_loading = false; |
||
| 55 | $(document).ready(function (event) { |
||
| 56 | console.log('#### What Up ####'); |
||
| 57 | if (plugins_done_loading) |
||
| 58 | return; |
||
| 59 | //find a way to unload instead? |
||
| 60 | plugins_done_loading = true; |
||
| 61 | cockpit.loadedPlugins.forEach(function (plugin) { |
||
| 62 | if (plugin.listen !== undefined) { |
||
| 63 | plugin.listen(); |
||
| 64 | } |
||
| 65 | }); |
||
| 66 | }); |
||
| 67 | Cockpit.plugins = []; |
||
| 68 | //flush them out for now. May move to a loaded array if we use in the future |
||
| 69 | cockpit.rov.emit('cockpit.pluginsLoaded'); |
||
| 70 | }; |
||
| 71 | Cockpit.prototype.addPlugin = function addPlugin(plugin) { |
||
| 72 | var cockpit = this; |
||
| 73 | Cockpit.plugins.push(plugin); |
||
| 74 | new plugin(cockpit); |
||
| 75 | }; |
||
| 76 | // Static array containing all plugins to load |
||
| 77 | Cockpit.plugins = []; |
||
| 78 | Cockpit.UIs = []; |
||
| 79 | window.Cockpit = Cockpit; |
||
| 80 | }(window, document)); |
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.
Read more about comparison operations.