Kiwi globals; Built kiwi within closure
[KiwiIRC.git] / client_backbone / kiwi.js
index d27609a66a6a49b0ea3f1ac70810939202e74130..d4e594b68e1d2c7ac22812c4f09cb7d35ef6ce07 100644 (file)
@@ -1,10 +1,10 @@
-(function (window) {
+(function (global) {
 
 // Holds anything kiwi client specific (ie. front, gateway, kiwi.plugs..)\r
 /**\r
 *   @namespace\r
 */\r
-var kiwi = window.kiwi = {};\r
+var kiwi = {};\r
 \r
 kiwi.model = {};\r
 kiwi.view = {};\r
@@ -13,20 +13,38 @@ kiwi.view = {};
 /**\r
  * A global container for third party access\r
  * Will be used to access a limited subset of kiwi functionality\r
- * and data\r
+ * and data (think: plugins)\r
  */\r
-if (typeof global === 'undefined') {\r
-       global = {};\r
-}\r
-\r
-global.kiwi = {\r
+kiwi.global = {\r
        gateway: undefined,\r
        user: undefined,\r
        server: undefined,\r
        channels: undefined,\r
 \r
+       // Entry point to start the kiwi application\r
+       start: function (opts) {\r
+               opts = opts || {};\r
+\r
+               kiwi.app = new kiwi.model.Application(opts);\r
+\r
+               if (opts.kiwi_server) {\r
+                       kiwi.app.kiwi_server = opts.kiwi_server;\r
+               }\r
+\r
+               kiwi.app.start();\r
+\r
+               return true;\r
+       },\r
+\r
        utils: undefined // Re-usable methods\r
-};
+};\r
+\r
+\r
+\r
+// If within a closure, expose the kiwi globals\r
+if (typeof global !== 'undefined') {\r
+       global.kiwi = kiwi.global;\r
+}
 
 
 kiwi.model.Application = Backbone.Model.extend(new (function () {\r
@@ -679,7 +697,6 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () {
         this.socket.on('connect', function () {\r
             this.emit('irc connect', that.get('nick'), host, port, ssl, password, callback);\r
             that.trigger('connect', {});\r
-            console.log("kiwi.gateway.socket.on('connect')", host, port);\r
         });\r
 \r
         this.socket.on('too_many_connections', function () {\r
@@ -731,7 +748,7 @@ kiwi.model.Gateway = Backbone.Model.extend(new (function () {
     *   Parses the response from the server\r
     */\r
     this.parse = function (item) {\r
-        console.log('gateway event', item);\r
+        //console.log('gateway event', item);\r
         if (item.event !== undefined) {\r
             that.trigger('on' + item.event, item);\r
 \r
@@ -1973,8 +1990,6 @@ kiwi.data = new kiwi.dataStore('kiwi');
 /*jslint white:true, regexp: true, nomen: true, devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */\r
 /*global kiwi */\r
 \r
-kiwi.view = {};\r
-\r
 kiwi.view.MemberList = Backbone.View.extend({\r
     tagName: "ul",\r
     events: {\r