Plugin tool icons on control_input
[KiwiIRC.git] / client / assets / dev / view.js
index 1bcbbdca2062113f625d1ec53bf9b3220edacb1c..d9522a1e6783d561ff63d0b24efbe026a3721a9a 100644 (file)
@@ -150,6 +150,15 @@ _kiwi.view.ServerSelect = function () {
         },\r
 \r
         submitForm: function (event) {\r
+            event.preventDefault();\r
+\r
+            // Make sure a nick is chosen\r
+            if (!$('input.nick', this.$el).val().trim()) {\r
+                this.setStatus('Select a nickname first!');\r
+                $('input.nick', this.$el).select();\r
+                return;\r
+            }\r
+\r
             if (state === 'nick_change') {\r
                 this.submitNickChange(event);\r
             } else {\r
@@ -157,7 +166,7 @@ _kiwi.view.ServerSelect = function () {
             }\r
 \r
             $('button', this.$el).attr('disabled', 1);\r
-            return false;\r
+            return;\r
         },\r
 \r
         submitLogin: function (event) {\r
@@ -245,7 +254,7 @@ _kiwi.view.ServerSelect = function () {
             $('.status', this.$el)\r
                 .text(text)\r
                 .attr('class', 'status')\r
-                .addClass(class_name)\r
+                .addClass(class_name||'')\r
                 .show();\r
         },\r
         clearStatus: function () {\r
@@ -579,7 +588,10 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         this.initializePanel(options);\r
         this.model.bind('change:topic', this.topic, this);\r
 \r
-        this.$el.append('<div class="initial_loader" style="margin:1em;">Joining channel.. <span class="loader"></span></div>');\r
+        // Only show the loader if this is a channel (ie. not a query)\r
+        if (this.model.isChannel()) {\r
+            this.$el.append('<div class="initial_loader" style="margin:1em;text-align:center;">Joining channel.. <span class="loader"></span></div>');\r
+        }\r
     },\r
 \r
     // Override the existing newMsg() method to remove the joining channel loader\r
@@ -587,6 +599,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         this.$el.find('.initial_loader').slideUp(function () {\r
             $(this).remove();\r
         });\r
+\r
         return this.constructor.__super__.newMsg.apply(this, arguments);\r
     },\r
 \r
@@ -880,12 +893,20 @@ _kiwi.view.ControlBox = Backbone.View.extend({
             }\r
             \r
             (function () {\r
-                var tokens = inp_val.substring(0, inp[0].selectionStart).split(' '),\r
-                    val,\r
-                    p1,\r
-                    newnick,\r
-                    range,\r
-                    nick = tokens[tokens.length - 1];\r
+                var tokens,              // Words before the cursor position\r
+                    val,                 // New value being built up\r
+                    p1,                  // Position in the value just before the nick \r
+                    newnick,             // New nick to be displayed (cycles through)\r
+                    range,               // TextRange for setting new text cursor position\r
+                    nick,                // Current nick in the value\r
+                    trailing = ': ';     // Text to be inserted after a tabbed nick\r
+\r
+                tokens = inp_val.substring(0, inp[0].selectionStart).split(' ');\r
+                if (tokens[tokens.length-1] == ':')\r
+                    tokens.pop();\r
+\r
+                nick  = tokens[tokens.length - 1];\r
+\r
                 if (this.tabcomplete.prefix === '') {\r
                     this.tabcomplete.prefix = nick;\r
                 }\r
@@ -895,21 +916,31 @@ _kiwi.view.ControlBox = Backbone.View.extend({
                 });\r
 \r
                 if (this.tabcomplete.data.length > 0) {\r
+                    // Get the current value before cursor position\r
                     p1 = inp[0].selectionStart - (nick.length);\r
                     val = inp_val.substr(0, p1);\r
+\r
+                    // Include the current selected nick\r
                     newnick = this.tabcomplete.data.shift();\r
                     this.tabcomplete.data.push(newnick);\r
                     val += newnick;\r
+\r
+                    if (inp_val.substr(inp[0].selectionStart, 2) !== trailing)\r
+                        val += trailing;\r
+\r
+                    // Now include the rest of the current value\r
                     val += inp_val.substr(inp[0].selectionStart);\r
+\r
                     inp.val(val);\r
 \r
+                    // Move the cursor position to the end of the nick\r
                     if (inp[0].setSelectionRange) {\r
-                        inp[0].setSelectionRange(p1 + newnick.length, p1 + newnick.length);\r
+                        inp[0].setSelectionRange(p1 + newnick.length + trailing.length, p1 + newnick.length + trailing.length);\r
                     } else if (inp[0].createTextRange) { // not sure if this bit is actually needed....\r
                         range = inp[0].createTextRange();\r
                         range.collapse(true);\r
-                        range.moveEnd('character', p1 + newnick.length);\r
-                        range.moveStart('character', p1 + newnick.length);\r
+                        range.moveEnd('character', p1 + newnick.length + trailing.length);\r
+                        range.moveStart('character', p1 + newnick.length + trailing.length);\r
                         range.select();\r
                     }\r
                 }\r
@@ -951,11 +982,11 @@ _kiwi.view.ControlBox = Backbone.View.extend({
 \r
         // Trigger the command events\r
         this.trigger('command', {command: command, params: params});\r
-        this.trigger('command_' + command, {command: command, params: params});\r
+        this.trigger('command:' + command, {command: command, params: params});\r
 \r
         // If we didn't have any listeners for this event, fire a special case\r
         // TODO: This feels dirty. Should this really be done..?\r
-        if (!this._callbacks['command_' + command]) {\r
+        if (!this._callbacks['command:' + command]) {\r
             this.trigger('unknown_command', {command: command, params: params});\r
         }\r
     }\r
@@ -979,7 +1010,7 @@ _kiwi.view.StatusMessage = Backbone.View.extend({
         opt.timeout = opt.timeout || 5000;\r
 \r
         this.$el.text(text).attr('class', opt.type);\r
-        this.$el.slideDown(_kiwi.app.view.doLayout);\r
+        this.$el.slideDown($.proxy(_kiwi.app.view.doLayout, this));\r
 \r
         if (opt.timeout) this.doTimeout(opt.timeout);\r
     },\r
@@ -997,7 +1028,7 @@ _kiwi.view.StatusMessage = Backbone.View.extend({
     },\r
 \r
     hide: function () {\r
-        this.$el.slideUp(_kiwi.app.view.doLayout);\r
+        this.$el.slideUp($.proxy(_kiwi.app.view.doLayout, this));\r
     },\r
 \r
     doTimeout: function (length) {\r
@@ -1059,9 +1090,11 @@ _kiwi.view.AppToolbar = Backbone.View.extend({
 \r
 _kiwi.view.Application = Backbone.View.extend({\r
     initialize: function () {\r
-        $(window).resize(this.doLayout);\r
-        $('#toolbar').resize(this.doLayout);\r
-        $('#controlbox').resize(this.doLayout);\r
+        var that = this;\r
+\r
+        $(window).resize(function() { that.doLayout.apply(that); });\r
+        $('#toolbar').resize(function() { that.doLayout.apply(that); });\r
+        $('#controlbox').resize(function() { that.doLayout.apply(that); });\r
 \r
         // Change the theme when the config is changed\r
         _kiwi.global.settings.on('change:theme', this.updateTheme, this);\r
@@ -1070,6 +1103,9 @@ _kiwi.view.Application = Backbone.View.extend({
         _kiwi.global.settings.on('change:channel_list_style', this.setTabLayout, this);\r
         this.setTabLayout(_kiwi.global.settings.get('channel_list_style'));\r
 \r
+        _kiwi.global.settings.on('change:show_timestamps', this.displayTimestamps, this);\r
+        this.displayTimestamps(_kiwi.global.settings.get('show_timestamps'));\r
+\r
         this.doLayout();\r
 \r
         $(document).keydown(this.setKeyFocus);\r
@@ -1119,6 +1155,20 @@ _kiwi.view.Application = Backbone.View.extend({
     },\r
 \r
 \r
+    displayTimestamps: function (show_timestamps) {\r
+        // If called by the settings callback, get the correct new_value\r
+        if (show_timestamps === _kiwi.global.settings) {\r
+            show_timestamps = arguments[1];\r
+        }\r
+\r
+        if (show_timestamps) {\r
+            this.$el.addClass('timestamps');\r
+        } else {\r
+            this.$el.removeClass('timestamps');\r
+        }\r
+    },\r
+\r
+\r
     // Globally shift focus to the command input box on a keypress\r
     setKeyFocus: function (ev) {\r
         // If we're copying text, don't shift focus\r
@@ -1127,7 +1177,7 @@ _kiwi.view.Application = Backbone.View.extend({
         }\r
 \r
         // If we're typing into an input box somewhere, ignore\r
-        if ((ev.target.tagName.toLowerCase() === 'input') || $(ev.target).attr('contenteditable')) {\r
+        if ((ev.target.tagName.toLowerCase() === 'input') || (ev.target.tagName.toLowerCase() === 'textarea') || $(ev.target).attr('contenteditable')) {\r
             return;\r
         }\r
 \r
@@ -1136,12 +1186,12 @@ _kiwi.view.Application = Backbone.View.extend({
 \r
 \r
     doLayout: function () {\r
-        var el_kiwi = $('#kiwi');\r
-        var el_panels = $('#panels');\r
-        var el_memberlists = $('#memberlists');\r
-        var el_toolbar = $('#toolbar');\r
-        var el_controlbox = $('#controlbox');\r
-        var el_resize_handle = $('#memberlists_resize_handle');\r
+        var el_kiwi = this.$el;\r
+        var el_panels = $('#kiwi #panels');\r
+        var el_memberlists = $('#kiwi #memberlists');\r
+        var el_toolbar = $('#kiwi #toolbar');\r
+        var el_controlbox = $('#kiwi #controlbox');\r
+        var el_resize_handle = $('#kiwi #memberlists_resize_handle');\r
 \r
         var css_heights = {\r
             top: el_toolbar.outerHeight(true),\r
@@ -1165,7 +1215,7 @@ _kiwi.view.Application = Backbone.View.extend({
 \r
         // If we have channel tabs on the side, adjust the height\r
         if (el_kiwi.hasClass('chanlist_treeview')) {\r
-            $('#kiwi #tabs').css(css_heights);\r
+            $('#tabs', el_kiwi).css(css_heights);\r
         }\r
 \r
         // Determine if we have a narrow window (mobile/tablet/or even small desktop window)\r
@@ -1187,6 +1237,9 @@ _kiwi.view.Application = Backbone.View.extend({
             // And move the handle just out of sight to the right\r
             el_resize_handle.css('left', el_panels.outerWidth(true));\r
         }\r
+\r
+        var input_wrap_width = parseInt($('#kiwi #controlbox .input_tools').outerWidth());\r
+        el_controlbox.find('.input_wrap').css('right', input_wrap_width + 7);\r
     },\r
 \r
 \r
@@ -1265,8 +1318,8 @@ _kiwi.view.Application = Backbone.View.extend({
         var that = this;\r
 \r
         if (!instant) {\r
-            $('#toolbar').slideUp({queue: false, duration: 400, step: this.doLayout});\r
-            $('#controlbox').slideUp({queue: false, duration: 400, step: this.doLayout});\r
+            $('#toolbar').slideUp({queue: false, duration: 400, step: $.proxy(this.doLayout, this)});\r
+            $('#controlbox').slideUp({queue: false, duration: 400, step: $.proxy(this.doLayout, this)});\r
         } else {\r
             $('#toolbar').slideUp(0);\r
             $('#controlbox').slideUp(0);\r
@@ -1278,8 +1331,8 @@ _kiwi.view.Application = Backbone.View.extend({
         var that = this;\r
 \r
         if (!instant) {\r
-            $('#toolbar').slideDown({queue: false, duration: 400, step: this.doLayout});\r
-            $('#controlbox').slideDown({queue: false, duration: 400, step: this.doLayout});\r
+            $('#toolbar').slideDown({queue: false, duration: 400, step: $.proxy(this.doLayout, this)});\r
+            $('#controlbox').slideDown({queue: false, duration: 400, step: $.proxy(this.doLayout, this)});\r
         } else {\r
             $('#toolbar').slideDown(0);\r
             $('#controlbox').slideDown(0);\r