From 626c1246f3025716d5a94a9ad395fd7d0d2b5f26 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 21 Apr 2014 15:47:52 +0100 Subject: [PATCH] Extracting the right_bar into its own view with toggling logic --- client/build.js | 1 + client/src/models/application.js | 1 + client/src/views/application.js | 2 +- client/src/views/apptoolbar.js | 2 +- client/src/views/panel.js | 5 ++--- client/src/views/rightbar.js | 32 ++++++++++++++++++++++++++++++++ server/settingsgenerator.js | 3 ++- 7 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 client/src/views/rightbar.js diff --git a/client/build.js b/client/build.js index 7b41a1c..261d1e1 100644 --- a/client/build.js +++ b/client/build.js @@ -79,6 +79,7 @@ var source_files = [ __dirname + '/src/views/userbox.js', __dirname + '/src/views/channeltools.js', __dirname + '/src/views/channelinfo.js', + __dirname + 'src/views/rightbar.js', __dirname + '/src/applets/settings.js', __dirname + '/src/applets/chanlist.js', diff --git a/client/src/models/application.js b/client/src/models/application.js index 443b38f..60b5207 100644 --- a/client/src/models/application.js +++ b/client/src/models/application.js @@ -88,6 +88,7 @@ */ this.controlbox = new _kiwi.view.ControlBox({el: $('#kiwi .controlbox')[0]}); this.bindControllboxCommands(this.controlbox); + this.rightbar = new _kiwi.view.RightBar({el: this.view.$('.right_bar')[0]}); this.topicbar = new _kiwi.view.TopicBar({el: this.view.$el.find('.topic')[0]}); diff --git a/client/src/views/application.js b/client/src/views/application.js index 5d6a045..b4522bc 100644 --- a/client/src/views/application.js +++ b/client/src/views/application.js @@ -176,7 +176,7 @@ _kiwi.view.Application = Backbone.View.extend({ } // Set the panels width depending on the memberlist visibility - if (el_right_bar.css('display') != 'none') { + if (!el_right_bar.hasClass('disabled')) { // Panels to the side of the memberlist el_panels.css('right', el_right_bar.outerWidth(true)); // The resize handle sits overlapping the panels and memberlist diff --git a/client/src/views/apptoolbar.js b/client/src/views/apptoolbar.js index e69b069..82b4965 100644 --- a/client/src/views/apptoolbar.js +++ b/client/src/views/apptoolbar.js @@ -25,7 +25,7 @@ _kiwi.view.AppToolbar = Backbone.View.extend({ clickHideRightBar: function (event) { event.preventDefault(); - _kiwi.app.view.$('.right_bar').toggleClass('disabled'); + _kiwi.app.rightbar.toggle(); _kiwi.app.view.doLayout(); } }); diff --git a/client/src/views/panel.js b/client/src/views/panel.js index c22d6f0..4b641a0 100644 --- a/client/src/views/panel.js +++ b/client/src/views/panel.js @@ -41,11 +41,10 @@ _kiwi.view.Panel = Backbone.View.extend({ // Show this panels memberlist var members = this.model.get("members"); if (members) { - $('#kiwi .right_bar').removeClass('disabled'); + _kiwi.app.rightbar.show(); members.view.show(); } else { - // Memberlist not found for this panel, hide any active ones - $('#kiwi .right_bar').addClass('disabled').children().removeClass('active'); + _kiwi.app.rightbar.hide(); } // Remove any alerts and activity counters for this panel diff --git a/client/src/views/rightbar.js b/client/src/views/rightbar.js new file mode 100644 index 0000000..67c5c2f --- /dev/null +++ b/client/src/views/rightbar.js @@ -0,0 +1,32 @@ +_kiwi.view.RightBar = Backbone.View.extend({ + initialize: function() { + this.keep_hidden = false; + this.hidden = false; + }, + + + hide: function() { + this.hidden = true; + this.$el.addClass('disabled'); + }, + + + show: function() { + this.hidden = false; + + if (!this.keep_hidden) + this.$el.removeClass('disabled'); + }, + + + // Toggle if the rightbar should be shown or not + toggle: function() { + this.keep_hidden = !this.keep_hidden; + + if (this.keep_hidden || this.hidden) { + this.$el.addClass('disabled'); + } else { + this.$el.removeClass('disabled'); + } + } +}); \ No newline at end of file diff --git a/server/settingsgenerator.js b/server/settingsgenerator.js index ffb1087..0a3463f 100644 --- a/server/settingsgenerator.js +++ b/server/settingsgenerator.js @@ -244,7 +244,8 @@ function addScripts(vars, debug) { 'src/views/topicbar.js', 'src/views/userbox.js', 'src/views/channeltools.js', - 'src/views/channelinfo.js' + 'src/views/channelinfo.js', + 'src/views/rightbar.js' ], [ 'src/applets/settings.js', -- 2.25.1