1 _kiwi
.view
.Application
= Backbone
.View
.extend({
2 initialize: function () {
5 $(window
).resize(function() { that
.doLayout
.apply(that
); });
6 this.$el
.find('.toolbar').resize(function() { that
.doLayout
.apply(that
); });
7 $('#kiwi .controlbox').resize(function() { that
.doLayout
.apply(that
); });
9 // Change the theme when the config is changed
10 _kiwi
.global
.settings
.on('change:theme', this.updateTheme
, this);
11 this.updateTheme(getQueryVariable('theme'));
13 _kiwi
.global
.settings
.on('change:channel_list_style', this.setTabLayout
, this);
14 this.setTabLayout(_kiwi
.global
.settings
.get('channel_list_style'));
16 _kiwi
.global
.settings
.on('change:show_timestamps', this.displayTimestamps
, this);
17 this.displayTimestamps(_kiwi
.global
.settings
.get('show_timestamps'));
21 $(document
).keydown(this.setKeyFocus
);
23 // Confirmation require to leave the page
24 window
.onbeforeunload = function () {
25 if (_kiwi
.gateway
.isConnected()) {
26 return 'This will close all KiwiIRC conversations. Are you sure you want to close this window?';
35 updateTheme: function (theme_name
) {
36 // If called by the settings callback, get the correct new_value
37 if (theme_name
=== _kiwi
.global
.settings
) {
38 theme_name
= arguments
[1];
41 // If we have no theme specified, get it from the settings
42 if (!theme_name
) theme_name
= _kiwi
.global
.settings
.get('theme');
44 // Clear any current theme
45 this.$el
.removeClass(function (i
, css
) {
46 return (css
.match(/\btheme_\S+/g) || []).join(' ');
49 // Apply the new theme
50 this.$el
.addClass('theme_' + (theme_name
|| 'relaxed'));
54 setTabLayout: function (layout_style
) {
55 // If called by the settings callback, get the correct new_value
56 if (layout_style
=== _kiwi
.global
.settings
) {
57 layout_style
= arguments
[1];
60 if (layout_style
== 'list') {
61 this.$el
.addClass('chanlist_treeview');
63 this.$el
.removeClass('chanlist_treeview');
70 displayTimestamps: function (show_timestamps
) {
71 // If called by the settings callback, get the correct new_value
72 if (show_timestamps
=== _kiwi
.global
.settings
) {
73 show_timestamps
= arguments
[1];
76 if (show_timestamps
) {
77 this.$el
.addClass('timestamps');
79 this.$el
.removeClass('timestamps');
84 // Globally shift focus to the command input box on a keypress
85 setKeyFocus: function (ev
) {
86 // If we're copying text, don't shift focus
87 if (ev
.ctrlKey
|| ev
.altKey
|| ev
.metaKey
) {
91 // If we're typing into an input box somewhere, ignore
92 if ((ev
.target
.tagName
.toLowerCase() === 'input') || (ev
.target
.tagName
.toLowerCase() === 'textarea') || $(ev
.target
).attr('contenteditable')) {
96 $('#kiwi .controlbox .inp').focus();
100 doLayout: function () {
101 var el_kiwi
= this.$el
;
102 var el_panels
= $('#kiwi .panels');
103 var el_memberlists
= $('#kiwi .memberlists');
104 var el_toolbar
= this.$el
.find('.toolbar');
105 var el_controlbox
= $('#kiwi .controlbox');
106 var el_resize_handle
= $('#kiwi .memberlists_resize_handle');
109 top
: el_toolbar
.outerHeight(true),
110 bottom
: el_controlbox
.outerHeight(true)
114 // If any elements are not visible, full size the panals instead
115 if (!el_toolbar
.is(':visible')) {
119 if (!el_controlbox
.is(':visible')) {
120 css_heights
.bottom
= 0;
123 // Apply the CSS sizes
124 el_panels
.css(css_heights
);
125 el_memberlists
.css(css_heights
);
126 el_resize_handle
.css(css_heights
);
128 // If we have channel tabs on the side, adjust the height
129 if (el_kiwi
.hasClass('chanlist_treeview')) {
130 this.$el
.find('.tabs', el_kiwi
).css(css_heights
);
133 // Determine if we have a narrow window (mobile/tablet/or even small desktop window)
134 if (el_kiwi
.outerWidth() < 400) {
135 el_kiwi
.addClass('narrow');
137 el_kiwi
.removeClass('narrow');
140 // Set the panels width depending on the memberlist visibility
141 if (el_memberlists
.css('display') != 'none') {
142 // Panels to the side of the memberlist
143 el_panels
.css('right', el_memberlists
.outerWidth(true));
144 // The resize handle sits overlapping the panels and memberlist
145 el_resize_handle
.css('left', el_memberlists
.position().left
- (el_resize_handle
.outerWidth(true) / 2));
147 // Memberlist is hidden so panels to the right edge
148 el_panels
.css('right', 0);
149 // And move the handle just out of sight to the right
150 el_resize_handle
.css('left', el_panels
.outerWidth(true));
153 var input_wrap_width
= parseInt($('#kiwi .controlbox .input_tools').outerWidth());
154 el_controlbox
.find('.input_wrap').css('right', input_wrap_width
+ 7);
158 alertWindow: function (title
) {
159 if (!this.alertWindowTimer
) {
160 this.alertWindowTimer
= new (function () {
163 var has_focus
= true;
165 var default_title
= 'Kiwi IRC';
166 var title
= 'Kiwi IRC';
168 this.setTitle = function (new_title
) {
169 new_title
= new_title
|| default_title
;
170 window
.document
.title
= new_title
;
174 this.start = function (new_title
) {
175 // Don't alert if we already have focus
176 if (has_focus
) return;
180 tmr
= setInterval(this.update
, 1000);
183 this.stop = function () {
184 // Stop the timer and clear the title
185 if (tmr
) clearInterval(tmr
);
189 // Some browsers don't always update the last title correctly
190 // Wait a few seconds and then reset
191 setTimeout(this.reset
, 2000);
194 this.reset = function () {
200 this.update = function () {
202 that
.setTitle(title
);
210 $(window
).focus(function (event
) {
214 // Some browsers don't always update the last title correctly
215 // Wait a few seconds and then reset
216 setTimeout(that
.reset
, 2000);
219 $(window
).blur(function (event
) {
225 this.alertWindowTimer
.start(title
);
229 barsHide: function (instant
) {
233 this.$el
.find('.toolbar').slideUp({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
234 $('#kiwi .controlbox').slideUp({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
236 this.$el
.find('.toolbar').slideUp(0);
237 $('#kiwi .controlbox').slideUp(0);
242 barsShow: function (instant
) {
246 this.$el
.find('.toolbar').slideDown({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
247 $('#kiwi .controlbox').slideDown({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
249 this.$el
.find('.toolbar').slideDown(0);
250 $('#kiwi .controlbox').slideDown(0);
256 initSound: function () {
258 base_path
= this.model
.get('base_path');
260 $script(base_path
+ '/assets/libs/soundmanager2/soundmanager2-nodebug-jsmin.js', function() {
261 if (typeof soundManager
=== 'undefined')
265 url
: base_path
+ '/assets/libs/soundmanager2/',
266 flashVersion
: 9, // optional: shiny features (default = 8)// optional: ignore Flash where possible, use 100% HTML5 mode
269 onready: function() {
270 that
.sound_object
= soundManager
.createSound({
272 url
: base_path
+ '/assets/sound/highlight.mp3'
280 playSound: function (sound_id
) {
281 if (!this.sound_object
) return;
283 if (_kiwi
.global
.settings
.get('mute_sounds'))
286 soundManager
.play(sound_id
);