f68e52b8d3cb8f25edc29d8ddfc77b6b6ccb27d4
1 _kiwi
.view
.Application
= Backbone
.View
.extend({
2 initialize: function () {
5 this.$el
.append($('#tmpl_application').html().trim());
8 panels
: this.$el
.find('.panels'),
9 memberlists
: this.$el
.find('.memberlists'),
10 toolbar
: this.$el
.find('.toolbar'),
11 controlbox
: this.$el
.find('.controlbox'),
12 resize_handle
: this.$el
.find('.memberlists_resize_handle')
15 $(window
).resize(function() { that
.doLayout
.apply(that
); });
16 this.elements
.toolbar
.resize(function() { that
.doLayout
.apply(that
); });
17 this.elements
.controlbox
.resize(function() { that
.doLayout
.apply(that
); });
19 // Change the theme when the config is changed
20 _kiwi
.global
.settings
.on('change:theme', this.updateTheme
, this);
21 this.updateTheme(getQueryVariable('theme'));
23 _kiwi
.global
.settings
.on('change:channel_list_style', this.setTabLayout
, this);
24 this.setTabLayout(_kiwi
.global
.settings
.get('channel_list_style'));
26 _kiwi
.global
.settings
.on('change:show_timestamps', this.displayTimestamps
, this);
27 this.displayTimestamps(_kiwi
.global
.settings
.get('show_timestamps'));
29 this.$el
.appendTo($('body'));
32 $(document
).keydown(this.setKeyFocus
);
34 // Confirmation require to leave the page
35 window
.onbeforeunload = function () {
36 if (_kiwi
.gateway
.isConnected()) {
37 return _kiwi
.global
.i18n
.translate('client_views_application_close_notice').fetch();
41 // Keep tabs on the browser having focus
42 this.has_focus
= true;
44 $(window
).on('focus', function () {
45 that
.has_focus
= true;
47 $(window
).on('blur', function () {
48 that
.has_focus
= false;
52 this.favicon
= new _kiwi
.view
.Favicon();
58 updateTheme: function (theme_name
) {
59 // If called by the settings callback, get the correct new_value
60 if (theme_name
=== _kiwi
.global
.settings
) {
61 theme_name
= arguments
[1];
64 // If we have no theme specified, get it from the settings
65 if (!theme_name
) theme_name
= _kiwi
.global
.settings
.get('theme');
67 // Clear any current theme
68 this.$el
.removeClass(function (i
, css
) {
69 return (css
.match(/\btheme_\S+/g) || []).join(' ');
72 // Apply the new theme
73 this.$el
.addClass('theme_' + (theme_name
|| 'relaxed'));
77 setTabLayout: function (layout_style
) {
78 // If called by the settings callback, get the correct new_value
79 if (layout_style
=== _kiwi
.global
.settings
) {
80 layout_style
= arguments
[1];
83 if (layout_style
== 'list') {
84 this.$el
.addClass('chanlist_treeview');
86 this.$el
.removeClass('chanlist_treeview');
93 displayTimestamps: function (show_timestamps
) {
94 // If called by the settings callback, get the correct new_value
95 if (show_timestamps
=== _kiwi
.global
.settings
) {
96 show_timestamps
= arguments
[1];
99 if (show_timestamps
) {
100 this.$el
.addClass('timestamps');
102 this.$el
.removeClass('timestamps');
107 // Globally shift focus to the command input box on a keypress
108 setKeyFocus: function (ev
) {
109 // If we're copying text, don't shift focus
110 if (ev
.ctrlKey
|| ev
.altKey
|| ev
.metaKey
) {
114 // If we're typing into an input box somewhere, ignore
115 if ((ev
.target
.tagName
.toLowerCase() === 'input') || (ev
.target
.tagName
.toLowerCase() === 'textarea') || $(ev
.target
).attr('contenteditable')) {
119 $('#kiwi .controlbox .inp').focus();
123 doLayout: function () {
124 var el_kiwi
= this.$el
;
125 var el_panels
= this.elements
.panels
;
126 var el_memberlists
= this.elements
.memberlists
;
127 var el_toolbar
= this.elements
.toolbar
;
128 var el_controlbox
= this.elements
.controlbox
;
129 var el_resize_handle
= this.elements
.resize_handle
;
131 if (!el_kiwi
.is(':visible')) {
136 top
: el_toolbar
.outerHeight(true),
137 bottom
: el_controlbox
.outerHeight(true)
141 // If any elements are not visible, full size the panals instead
142 if (!el_toolbar
.is(':visible')) {
146 if (!el_controlbox
.is(':visible')) {
147 css_heights
.bottom
= 0;
150 // Apply the CSS sizes
151 el_panels
.css(css_heights
);
152 el_memberlists
.css(css_heights
);
153 el_resize_handle
.css(css_heights
);
155 // If we have channel tabs on the side, adjust the height
156 if (el_kiwi
.hasClass('chanlist_treeview')) {
157 this.$el
.find('.tabs', el_kiwi
).css(css_heights
);
160 // Determine if we have a narrow window (mobile/tablet/or even small desktop window)
161 if (el_kiwi
.outerWidth() < 400) {
162 el_kiwi
.addClass('narrow');
164 el_kiwi
.removeClass('narrow');
167 // Set the panels width depending on the memberlist visibility
168 if (el_memberlists
.css('display') != 'none') {
169 // Panels to the side of the memberlist
170 el_panels
.css('right', el_memberlists
.outerWidth(true));
171 // The resize handle sits overlapping the panels and memberlist
172 el_resize_handle
.css('left', el_memberlists
.position().left
- (el_resize_handle
.outerWidth(true) / 2));
174 // Memberlist is hidden so panels to the right edge
175 el_panels
.css('right', 0);
176 // And move the handle just out of sight to the right
177 el_resize_handle
.css('left', el_panels
.outerWidth(true));
180 var input_wrap_width
= parseInt($('#kiwi .controlbox .input_tools').outerWidth());
181 el_controlbox
.find('.input_wrap').css('right', input_wrap_width
+ 7);
185 alertWindow: function (title
) {
186 if (!this.alertWindowTimer
) {
187 this.alertWindowTimer
= new (function () {
190 var has_focus
= true;
192 var default_title
= 'Kiwi IRC';
193 var title
= 'Kiwi IRC';
195 this.setTitle = function (new_title
) {
196 new_title
= new_title
|| default_title
;
197 window
.document
.title
= new_title
;
201 this.start = function (new_title
) {
202 // Don't alert if we already have focus
203 if (has_focus
) return;
207 tmr
= setInterval(this.update
, 1000);
210 this.stop = function () {
211 // Stop the timer and clear the title
212 if (tmr
) clearInterval(tmr
);
216 // Some browsers don't always update the last title correctly
217 // Wait a few seconds and then reset
218 setTimeout(this.reset
, 2000);
221 this.reset = function () {
227 this.update = function () {
229 that
.setTitle(title
);
237 $(window
).focus(function (event
) {
241 // Some browsers don't always update the last title correctly
242 // Wait a few seconds and then reset
243 setTimeout(that
.reset
, 2000);
246 $(window
).blur(function (event
) {
252 this.alertWindowTimer
.start(title
);
256 barsHide: function (instant
) {
260 this.$el
.find('.toolbar').slideUp({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
261 $('#kiwi .controlbox').slideUp({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
263 this.$el
.find('.toolbar').slideUp(0);
264 $('#kiwi .controlbox').slideUp(0);
269 barsShow: function (instant
) {
273 this.$el
.find('.toolbar').slideDown({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
274 $('#kiwi .controlbox').slideDown({queue
: false, duration
: 400, step
: $.proxy(this.doLayout
, this)});
276 this.$el
.find('.toolbar').slideDown(0);
277 $('#kiwi .controlbox').slideDown(0);
283 initSound: function () {
285 base_path
= this.model
.get('base_path');
287 $script(base_path
+ '/assets/libs/soundmanager2/soundmanager2-nodebug-jsmin.js', function() {
288 if (typeof soundManager
=== 'undefined')
292 url
: base_path
+ '/assets/libs/soundmanager2/',
293 flashVersion
: 9, // optional: shiny features (default = 8)// optional: ignore Flash where possible, use 100% HTML5 mode
296 onready: function() {
297 that
.sound_object
= soundManager
.createSound({
299 url
: base_path
+ '/assets/sound/highlight.mp3'
307 playSound: function (sound_id
) {
308 if (!this.sound_object
) return;
310 if (_kiwi
.global
.settings
.get('mute_sounds'))
313 soundManager
.play(sound_id
);
317 showNotification: function(title
, message
) {
318 var icon
= this.model
.get('base_path') + '/assets/img/ico.png';
320 // Check if we have notification support
321 if (!window
.webkitNotifications
)
327 if (webkitNotifications
.checkPermission() === 0){
328 window
.webkitNotifications
.createNotification(icon
, title
, message
).show();