Cleaning up client-side files, including one or two variables leaking into the global...
authorJack Allnutt <m2ys4u@Gmail.com>
Thu, 8 Sep 2011 00:40:10 +0000 (01:40 +0100)
committerJack Allnutt <m2ys4u@Gmail.com>
Thu, 8 Sep 2011 00:40:10 +0000 (01:40 +0100)
js/front.js
js/gateway.js
js/util.js

index fd5c2796a1703330c569f80bdf8d7336125a4f66..25ba6768a7f2a72f7fb1959deffcdc5d59128448 100644 (file)
@@ -1,5 +1,5 @@
-/*jslint undef: true, browser: true, continue: true, sloppy: true, evil: true, forin: true, newcap: false, plusplus: true, maxerr: 50, indent: 4 */
-/*global gateway, io, $, iScroll, agent, touchscreen*/
+/*jslint devel: true, undef: true, browser: true, continue: true, sloppy: true, forin: true, newcap: true, plusplus: true, maxerr: 50, indent: 4 */
+/*global gateway, io, $, iScroll, agent, touchscreen, init_data, plugs, registerTouches, randomString */
 var front = {
     revision: 38,
     
@@ -15,7 +15,8 @@ var front = {
     original_topic: '',
     
     init: function () {
-        var about_info, supportsOrientationChange, orientationEvent;
+        /*global Box, touch_scroll:true */
+        var about_info, supportsOrientationChange, orientationEvent, scroll_opts;
         gateway.nick = 'kiwi_' + Math.ceil(100 * Math.random()) + Math.ceil(100 * Math.random());
         gateway.session_id = null;
         
@@ -163,7 +164,7 @@ var front = {
         });
 
 
-        $('#windows a.chan').live('click', function() {
+        $('#windows a.chan').live('click', function () {
             front.joinChannel($(this).text());
             return false;
         });
@@ -203,7 +204,8 @@ var front = {
     
     joinChannel: function (chan_name) {
         var chans = chan_name.split(','),
-            i;
+            i,
+            chan;
         for (i in chans) {
             chan = chans[i];
             if (front.tabviews[chan.toLowerCase()] === undefined || (front.tabviews[chan.toLowerCase()] !== undefined && front.tabviews[chan.toLowerCase()].safe_to_close === true)) {
@@ -217,12 +219,14 @@ var front = {
     
     
     run: function (msg) {
-        var parts, dest, t, pos, textRange, d, plugin_event;
+        var parts, dest, t, pos, textRange, d, plugin_event, msg_sliced;
         
         // Run through any plugins
         plugin_event = {command: msg};
         plugin_event = plugs.run('command_run', plugin_event);
-        if (!plugin_event || typeof plugin_event.command === 'undefined') return;
+        if (!plugin_event || typeof plugin_event.command === 'undefined') {
+            return;
+        }
 
         // Update msg if it's been changed by any plugins
         msg = plugin_event.command.toString();
@@ -294,7 +298,7 @@ var front = {
             case '/m':
             case '/msg':
                 if (typeof parts[1] !== "undefined") {
-                    var msg_sliced = msg.split(' ').slice(2).join(' ');
+                    msg_sliced = msg.split(' ').slice(2).join(' ');
                     gateway.msg(parts[1], msg_sliced);
 
                     if (!front.tabviewExists(parts[1])) {
@@ -381,9 +385,11 @@ var front = {
             destination = data.channel.toLowerCase();    
         }
         
-        plugin_event = {nick: data.nick, msg:data.msg, destination: destination};
+        plugin_event = {nick: data.nick, msg: data.msg, destination: destination};
         plugin_event = plugs.run('msg_recieved', plugin_event);
-        if (!plugin_event) return;
+        if (!plugin_event) {
+            return;
+        }
 
         if (!front.tabviewExists(plugin_event.destination)) {
             front.tabviewAdd(plugin_event.destination);
@@ -420,8 +426,8 @@ var front = {
     },
     
     onNotice: function (e, data) {
-        var nick = (data.nick === undefined) ? '' : data.nick;
-        var enick = '[' + nick + ']';
+        var nick = (data.nick === undefined) ? '' : data.nick,
+            enick = '[' + nick + ']';
 
         if (front.tabviewExists(data.target)) {
             front.tabviews[data.target.toLowerCase()].addMsg(null, enick, data.msg, 'notice');
@@ -654,7 +660,7 @@ var front = {
     
     registerKeys: function () {
         $('#kiwi_msginput').bind('keydown', function (e) {
-            var windows, meta, num, msg, data, candidates, word_pos, word;
+            var windows, meta, num, msg, data, candidates, word_pos, word, i;
             windows = $('#windows');
             //var meta = e.altKey;
             meta = e.ctrlKey;
@@ -720,6 +726,7 @@ var front = {
                 // Get possible autocompletions
                 data = [];
                 front.cur_channel.userlist.children().each(function () {
+                    var nick;
                     nick = front.nickStripPrefix($('a.nick', this).text());
                     data.push(nick);
                 });
@@ -764,7 +771,6 @@ var front = {
         
         
         $('#kiwi .plugins .load_plugin_file').click(function () {
-            var lst, j, txt;
             if (typeof front.boxes.plugins !== "undefined") {
                 return;
             }
@@ -774,7 +780,8 @@ var front = {
             front.boxes.plugins.box.css('top', -(front.boxes.plugins.height + 40));
             
             // Populate the plugin list..
-            function enumPlugins () {
+            function enumPlugins() {
+                var lst, j, txt;
                 lst = $('#plugin_list');
                 lst.find('option').remove();
                 for (j in plugs.loaded) {
@@ -786,7 +793,7 @@ var front = {
             
             // Event bindings
             $('#kiwi .plugin_file').submit(function () {
-                $('<div></div>').load($('.txtpluginfile').val(), function(e){
+                $('<div></div>').load($('.txtpluginfile').val(), function (e) {
                     enumPlugins();
                 });
                 return false;
@@ -868,6 +875,7 @@ var front = {
     },
     
     tabviewAdd: function (v_name) {
+        /*global Tabview */
         var re, htmlsafe_name, tmp_divname, tmp_userlistname, tmp_tabname, userlist_enabled = true;
 
         if (v_name.charAt(0) === gateway.channel_prefix) {
@@ -896,7 +904,9 @@ var front = {
         front.tabviews[v_name.toLowerCase()].div = $('#' + tmp_divname);
         front.tabviews[v_name.toLowerCase()].userlist = $('#' + tmp_userlistname);
         front.tabviews[v_name.toLowerCase()].tab = $('#' + tmp_tabname);
-        if (!userlist_enabled) front.tabviews[v_name.toLowerCase()].userlist_width = 0;
+        if (!userlist_enabled) {
+            front.tabviews[v_name.toLowerCase()].userlist_width = 0;
+        }
         front.tabviews[v_name.toLowerCase()].show();
         
         if (typeof registerTouches === "function") {
@@ -979,21 +989,20 @@ var front = {
     
     
     nickStripPrefix: function (nick) {
-        var tmp = nick, i;
+        var tmp = nick, i, prefix;
         
         prefix = tmp.charAt(0);
         for (i in gateway.user_prefixes) {
-            if (gateway.user_prefixes[i].symbol !== prefix) {
-                continue;
+            if (gateway.user_prefixes[i].symbol === prefix) {
+                return tmp.substring(1);
             }
-            return tmp.substring(1);
         }
 
         return tmp;
     },
     
     nickGetPrefix: function (nick) {
-        var tmp = nick, i;
+        var tmp = nick, i, prefix;
         
         prefix = tmp.charAt(0);
         for (i in gateway.user_prefixes) {
@@ -1006,6 +1015,7 @@ var front = {
     },
     
     isChannel: function (name) {
+        var prefix, is_chan;
         prefix = name.charAt(0);
         if (gateway.channel_prefix.indexOf(prefix) > -1) {
             is_chan = true;
@@ -1104,10 +1114,10 @@ var front = {
  */
 
 var Utilityview = function (name) {
-    var rand_name = randomString(15);
-    var tmp_divname = 'kiwi_window_' + rand_name;
-    var tmp_userlistname = 'kiwi_userlist_' + rand_name;
-    var tmp_tabname = 'kiwi_tab_' + rand_name;
+    var rand_name = randomString(15),
+        tmp_divname = 'kiwi_window_' + rand_name,
+        tmp_userlistname = 'kiwi_userlist_' + rand_name,
+        tmp_tabname = 'kiwi_tab_' + rand_name;
     
     this.name = rand_name;
     this.title = name;
@@ -1116,7 +1126,7 @@ var Utilityview = function (name) {
     $('#kiwi .windows .scroller').append('<div id="' + tmp_divname + '" class="messages"></div>');
 
     this.tab = $('<li id="' + tmp_tabname + '">' + this.title + '</li>');
-    this.tab.click(function(){
+    this.tab.click(function () {
         front.utilityviews[rand_name.toLowerCase()].show();
     });
     $('#kiwi .utilityviewlist ul').append(this.tab);
@@ -1152,7 +1162,7 @@ Utilityview.prototype.show = function () {
     if (touch_scroll) {
         touch_scroll.refresh();
     }
-}
+};
 
 Utilityview.prototype.close = function () {
     this.div.remove();
@@ -1228,7 +1238,9 @@ Tabview.prototype.show = function () {
 
     // Activate this tab!
     this.div.addClass('active');
-    if (this.userlist_width > 0) this.userlist.addClass('active');
+    if (this.userlist_width > 0) {
+        this.userlist.addClass('active');
+    }
     this.tab.addClass('active');
     
     // Add the part image to the tab
@@ -1288,13 +1300,15 @@ Tabview.prototype.clearPartImage = function () {
 };
 
 Tabview.prototype.addMsg = function (time, nick, msg, type, style) {
-    var self, tmp, plugin_ret, i, d, re, line_msg;
+    var self, tmp, plugin_ret, i, d, re, line_msg, next;
     
     self = this;
     
     tmp = {msg: msg, time: time, nick: nick, tabview: this.name};
     tmp = plugs.run('addmsg', tmp);
-    if (!tmp) return;
+    if (!tmp) {
+        return;
+    }
     
 
     msg = tmp.msg;
@@ -1391,7 +1405,8 @@ Tabview.prototype.changeNick = function (newNick, oldNick) {
 
 Tabview.prototype.userlistSort = function () {
     var ul = this.userlist,
-        listitems = ul.children('li').get();
+        listitems = ul.children('li').get(),
+        prefix;
     listitems.sort(function (a, b) {
         var compA = $(a).text().toUpperCase(),
             compB = $(b).text().toUpperCase(),
index 675d9a39fba5f9eb347f7b33abf3a64c66176914..83d341dfb099cd381e69f8ec176dd1b730250d29 100644 (file)
@@ -1,5 +1,5 @@
 /*jslint browser: true, confusion: true, sloppy: true, maxerr: 50, indent: 4 */
-/*globals io, $ */
+/*globals io, $, kiwi_server */
 var gateway = {
 
     revision: 16,
index 37ac40a8700a41c0eba45e5bcc4ef5628f22b070..85988b088782a21c121140a59aa3fc3c7ae960b4 100644 (file)
-function manageDebug(debug){  
-    if(window.console){  
-        var consoleBackUp = window.console.log;  
-        window.console.log = function(str){  
-            if(debug){  
-                consoleBackUp.call(this,str);  
+/*jslint devel: true, browser: true, continue: true, sloppy: true, forin: true, plusplus: true, maxerr: 50, indent: 4 */
+/*globals $, front, gateway, Utilityview */
+function manageDebug(debug) {
+    var log, consoleBackUp;
+    if (window.console) {  
+        consoleBackUp = window.console.log;  
+        window.console.log = function (str) {  
+            if (debug) {  
+                consoleBackUp.call(this, str);  
             }  
-        }  
-    }else{  
-        var log = window.opera ? window.opera.postError : alert;  
+        };  
+    } else {  
+        log = window.opera ? window.opera.postError : alert;  
         window.console = {};  
-        window.console.log = function(str){  
-            if(debug){  
+        window.console.log = function (str) {  
+            if (debug) {  
                 log(str);  
             }  
-        }  
+        };
     }  
 }
 
 
 function randomString(string_length) {
-       var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
-       var randomstring = '';
-       for (var i=0; i<string_length; i++) {
-               var rnum = Math.floor(Math.random() * chars.length);
-               randomstring += chars.substring(rnum,rnum+1);
-       }
-       return randomstring;
+    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
+        randomstring = '',
+        i,
+        rnum;
+    for (i = 0; i < string_length; i++) {
+        rnum = Math.floor(Math.random() * chars.length);
+        randomstring += chars.substring(rnum, rnum + 1);
+    }
+    return randomstring;
 }
 
-String.prototype.trim = function() {
-  return this.replace(/^\s+|\s+$/g, "");
+String.prototype.trim = function () {
+    return this.replace(/^\s+|\s+$/g, "");
 };
 
-String.prototype.lpad = function(length, character){
-       var padding = "";
-       for(var i=0; i<length; i++) padding += character;
-       return (padding + this).slice (-length)
+String.prototype.lpad = function (length, character) {
+    var padding = "",
+        i;
+    for (i = 0; i < length; i++) {
+        padding += character;
+    }
+    return (padding + this).slice(-length);
 };
 
 
 
 /*
-       PLUGINS
-       Each function in each object is looped through and ran. The resulting text
-       is expected to be returned.
+    PLUGINS
+    Each function in each object is looped through and ran. The resulting text
+    is expected to be returned.
 */
 var plugins = [
-       {
-               name: "images",
-               onaddmsg: function(event, opts){
-                       if( !event.msg ) return event;
-
-                       event.msg = event.msg.replace(/^((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/gi,function(url){
-                               // Don't let any future plugins change it (ie. html_safe plugins)
-                               event.event_bubbles = false;
-
-                               var img = '<img class="link_img_a" src="'+url+'" height="100%" width="100%" />';
-                               return '<a class="link_ext link_img" target="_blank" rel="nofollow" href="'+ url +'" style="height:50px;width:50px;display:block">'+ img +'<div class="tt box"></div></a>';
-                       });
-                       
-                       return event;
-               }
-       },
-
-       {
-               name: "html_safe",
-               onaddmsg: function(event, opts){
-                       event.msg = $('<div/>').text(event.msg).html();
-                       event.nick = $('<div/>').text(event.nick).html();
-
-                       return event;
-               }
-       },
-
-       {
-               name: "activity",
-               onaddmsg: function(event, opts){
-                       if(front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name){
-                               front.tabviews[event.tabview].activity();
-                       }
-
-                       return event;
-               }
-       },
-       
-       {
-               name: "highlight",
-               onaddmsg: function(event, opts){
-                       if(event.msg.toLowerCase().indexOf(gateway.nick.toLowerCase()) > -1){
-                               if(front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name){
-                                       front.tabviews[event.tabview].highlight();
-                               }
-                               if(front.isChannel(front.tabviews[event.tabview].name)){
-                                       event.msg = '<span style="color:red;">'+event.msg+'</span>';
-                               }
-                       }
-                       
-                       if(
-                               !front.isChannel(front.tabviews[event.tabview].name) && front.tabviews[event.tabview].name != "server"
-                               && front.cur_channel.name.toLowerCase() != front.tabviews[event.tabview.toLowerCase()].name
-                       ){
-                               front.tabviews[event.tabview].highlight();
-                       }
-
-                       return event;
-               }
-       },      
-       
-       
-       
-       {
-               //Following method taken from: http://snipplr.com/view/13533/convert-text-urls-into-links/
-               name: "linkify_plain",
-               onaddmsg: function(event, opts){
-                       if( !event.msg ) return event;
-                       
-                       event.msg = event.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(url){
-                               // If it's any of the supported images in the images plugin, skip it
-                               if(url.match('(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$')) return url;
-
-                               nice = url;
-                               if(url.match('^https?:\/\/')){
-                                       //nice = nice.replace(/^https?:\/\//i,'')
-                               } else {
-                                       url = 'http://'+url;
-                               }
-                               
-                               return '<a class="link_ext" target="_blank" rel="nofollow" href="'+ url +'">'+ nice +'<div class="tt box"></div></a>';
-                       });
-                       
-                       return event;
-               }
-       },
+    {
+        name: "images",
+        onaddmsg: function (event, opts) {
+            if (!event.msg) {
+                return event;
+            }
+
+            event.msg = event.msg.replace(/^((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/gi, function (url) {
+                // Don't let any future plugins change it (ie. html_safe plugins)
+                event.event_bubbles = false;
+
+                var img = '<img class="link_img_a" src="' + url + '" height="100%" width="100%" />';
+                return '<a class="link_ext link_img" target="_blank" rel="nofollow" href="' + url + '" style="height:50px;width:50px;display:block">' + img + '<div class="tt box"></div></a>';
+            });
+            
+            return event;
+        }
+    },
 
     {
-               name: "lftobr",
-               onaddmsg: function(event, opts){
-                       if( !event.msg ) return event;
-                       
-                       event.msg = event.msg.replace(/\n/gi,function(txt){
-                               return '<br/>';
-                       });
-                       
-                       return event;
-               }
-       },
-
-
-       {
-               name: "inBrowser",
-               oninit: function(event, opts){
-               $('#windows a.link_ext').live('mouseover', this.mouseover);
-               $('#windows a.link_ext').live('mouseout', this.mouseout);
-               $('#windows a.link_ext').live('click', this.mouseclick);
-               },
-
-               onunload: function(event, opts){
-                       // TODO: make this work
-                       $('#windows a.link_ext').die('mouseover', this.mouseover);
-                       $('#windows a.link_ext').die('mouseout', this.mouseout);
-                       $('#windows a.link_ext').die('click', this.mouseclick);
-               },
-
-
-
-               mouseover: function(e){
-            var a = $(this);
-            var tt = $('.tt', a);
+        name: "html_safe",
+        onaddmsg: function (event, opts) {
+            event.msg = $('<div/>').text(event.msg).html();
+            event.nick = $('<div/>').text(event.nick).html();
+
+            return event;
+        }
+    },
+
+    {
+        name: "activity",
+        onaddmsg: function (event, opts) {
+            if (front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name) {
+                front.tabviews[event.tabview].activity();
+            }
+
+            return event;
+        }
+    },
+    
+    {
+        name: "highlight",
+        onaddmsg: function (event, opts) {
+            if (event.msg.toLowerCase().indexOf(gateway.nick.toLowerCase()) > -1) {
+                if (front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name) {
+                    front.tabviews[event.tabview].highlight();
+                }
+                if (front.isChannel(front.tabviews[event.tabview].name)) {
+                    event.msg = '<span style="color:red;">' + event.msg + '</span>';
+                }
+            }
+            
+            if (
+                !front.isChannel(front.tabviews[event.tabview].name) && front.tabviews[event.tabview].name !== "server"
+                    && front.cur_channel.name.toLowerCase() !== front.tabviews[event.tabview.toLowerCase()].name
+            ) {
+                front.tabviews[event.tabview].highlight();
+            }
+
+            return event;
+        }
+    },    
+    
+    
+    
+    {
+        //Following method taken from: http://snipplr.com/view/13533/convert-text-urls-into-links/
+        name: "linkify_plain",
+        onaddmsg: function (event, opts) {
+            if (!event.msg) {
+                return event;
+            }
+            
+            event.msg = event.msg.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function (url) {
+                var nice;
+                // If it's any of the supported images in the images plugin, skip it
+                if (url.match(/(\.jpg|\.jpeg|\.gif|\.bmp|\.png)$/)) {
+                    return url;
+                }
+
+                nice = url;
+                if (url.match('^https?:\/\/')) {
+                    //nice = nice.replace(/^https?:\/\//i,'')
+                    nice = url; // Shutting up JSLint...
+                } else {
+                    url = 'http://' + url;
+                }
+                
+                return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url + '">' + nice + '<div class="tt box"></div></a>';
+            });
+            
+            return event;
+        }
+    },
+
+    {
+        name: "lftobr",
+        onaddmsg: function (event, opts) {
+            if (!event.msg) {
+                return event;
+            }
+            
+            event.msg = event.msg.replace(/\n/gi, function (txt) {
+                return '<br/>';
+            });
+            
+            return event;
+        }
+    },
+
+
+    {
+        name: "inBrowser",
+        oninit: function (event, opts) {
+            $('#windows a.link_ext').live('mouseover', this.mouseover);
+            $('#windows a.link_ext').live('mouseout', this.mouseout);
+            $('#windows a.link_ext').live('click', this.mouseclick);
+        },
+
+        onunload: function (event, opts) {
+            // TODO: make this work
+            $('#windows a.link_ext').die('mouseover', this.mouseover);
+            $('#windows a.link_ext').die('mouseout', this.mouseout);
+            $('#windows a.link_ext').die('click', this.mouseclick);
+        },
+
+
+
+        mouseover: function (e) {
+            var a = $(this),
+                tt = $('.tt', a),
+                tooltip;
 
             if (tt.text() === '') {
-                var tooltip = $('<a class="link_ext_browser">Open in Kiwi..</a>');
+                tooltip = $('<a class="link_ext_browser">Open in Kiwi..</a>');
                 tt.append(tooltip);
             }
 
-            tt.css('top', -tt.outerHeight()+'px');
+            tt.css('top', -tt.outerHeight() + 'px');
             tt.css('left', (a.outerWidth() / 2) - (tt.outerWidth() / 2));
-               },
+        },
 
-               mouseout: function(e){
-            var a = $(this);
-            var tt = $('.tt', a);
-               },
+        mouseout: function (e) {
+            var a = $(this),
+                tt = $('.tt', a);
+        },
 
-               mouseclick: function(e){
-            var a = $(this);
+        mouseclick: function (e) {
+            var a = $(this),
+                t;
             
             switch (e.target.className) {
             case 'link_ext':
             case 'link_img_a':
                 return true;
-                break;
+                //break;
             case 'link_ext_browser':
-                var t = new Utilityview('Browser');
+                t = new Utilityview('Browser');
                 t.topic = a.attr('href');
 
-                               t.iframe = $('<iframe border="0" class="utility_view" src="" style="width:100%;height:100%;border:none;"></iframe>');
-                           t.iframe.attr('src', a.attr('href'));
-                           t.div.append(t.iframe);
+                t.iframe = $('<iframe border="0" class="utility_view" src="" style="width:100%;height:100%;border:none;"></iframe>');
+                t.iframe.attr('src', a.attr('href'));
+                t.div.append(t.iframe);
                 t.show();
                 break;
             }
             return false;
-               }
-       }
+        }
+    }
 ];
 
 
@@ -213,24 +233,31 @@ var plugins = [
 
 
 
-plugs = {};
+var plugs = {};
 plugs.loaded = {};
 plugs.loadPlugin = function (plugin) {
-       if (typeof plugin.name !== 'string') return false;
+    var plugin_ret;
+    if (typeof plugin.name !== 'string') {
+        return false;
+    }
 
-       var plugin_ret = plugs.run('plugin_load', {plugin: plugin});
-    if (typeof plugin_ret === 'object') plugs.loaded[plugin_ret.plugin.name] = plugin_ret.plugin;
+    plugin_ret = plugs.run('plugin_load', {plugin: plugin});
+    if (typeof plugin_ret === 'object') {
+        plugs.loaded[plugin_ret.plugin.name] = plugin_ret.plugin;
+    }
     plugs.run('init', {}, {run_only: plugin_ret.plugin.name});
 
     return true;
 };
 
 plugs.unloadPlugin = function (plugin_name) {
-       if (typeof plugs.loaded[plugin_name] !== 'object') return;
+    if (typeof plugs.loaded[plugin_name] !== 'object') {
+        return;
+    }
 
-       plugs.run('unload', {}, {run_only: plugin_name});
-       delete plugs.loaded[plugin_name];
-}
+    plugs.run('unload', {}, {run_only: plugin_name});
+    delete plugs.loaded[plugin_name];
+};
 
 
 
@@ -239,15 +266,18 @@ plugs.unloadPlugin = function (plugin_name) {
  */
 plugs.run = function (event_name, event_data, opts) {
     var ret = event_data,
-        ret_tmp, plugin_name;
+        ret_tmp,
+        plugin_name;
     
     // Set some defaults if not provided
     event_data = (typeof event_data === 'undefined') ? {} : event_data;
     opts = (typeof opts === 'undefined') ? {} : opts;
     
     for (plugin_name in plugs.loaded) {
-       // If we're only calling 1 plugin, make sure it's that one
-       if (typeof opts.run_only === 'string' && opts.run_only !== plugin_name) continue;
+        // If we're only calling 1 plugin, make sure it's that one
+        if (typeof opts.run_only === 'string' && opts.run_only !== plugin_name) {
+            continue;
+        }
 
         if (typeof plugs.loaded[plugin_name]['on' + event_name] === 'function') {
             try {
@@ -256,10 +286,10 @@ plugs.run = function (event_name, event_data, opts) {
                     return null;
                 }
                 ret = ret_tmp;
-                       
-                if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false){
-                       delete ret.event_bubbles;
-                       return ret;
+                   
+                if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false) {
+                    delete ret.event_bubbles;
+                    return ret;
                 }
             } catch (e) {
             }
@@ -269,10 +299,12 @@ plugs.run = function (event_name, event_data, opts) {
     return ret;
 };
 
-
-for(var i in plugins) plugs.loadPlugin(plugins[i]);
-
-
+(function () {
+    var i;
+    for (i in plugins) {
+        plugs.loadPlugin(plugins[i]);
+    }
+}());