f60b47b83b17eafbb2f34d168b8f1dddf4041bdd
2 var View
= Backbone
.View
.extend({
4 'change [data-setting]': 'saveSettings',
5 'click [data-setting="theme"]': 'selectTheme',
6 'click .register_protocol': 'registerProtocol',
7 'click .enable_notifications': 'enableNotifications'
10 initialize: function (options
) {
11 function t(key
, vars
) {
12 var trans
= _kiwi
.global
.i18n
.translate(key
);
13 return trans
.fetch
.apply(trans
, Array
.prototype.slice
.call(arguments
, 1));
16 tabs
: t('client_applets_settings_channelview_tabs'),
17 list
: t('client_applets_settings_channelview_list'),
18 large_amounts_of_chans
: t('client_applets_settings_channelview_list_notice'),
19 join_part
: t('client_applets_settings_notification_joinpart'),
20 count_all_activity
: t('client_applets_settings_notification_count_all_activity'),
21 timestamps
: t('client_applets_settings_timestamp'),
22 timestamp_24
: t('client_applets_settings_timestamp_24_hour'),
23 mute
: t('client_applets_settings_notification_sound'),
24 emoticons
: t('client_applets_settings_emoticons'),
25 scroll_history
: t('client_applets_settings_history_length'),
26 languages
: _kiwi
.app
.translations
,
27 default_client
: t('client_applets_settings_default_client'),
28 make_default
: t('client_applets_settings_default_client_enable'),
29 locale_restart_needed
: t('client_applets_settings_locale_restart_needed'),
30 default_note
: t('client_applets_settings_default_client_notice', '<a href="chrome://settings/handlers">chrome://settings/handlers</a>'),
31 html5_notifications
: t('client_applets_settings_html5_notifications'),
32 enable_notifications
: t('client_applets_settings_enable_notifications'),
33 theme_thumbnails
: _
.map(_kiwi
.app
.themes
, function (theme
) {
34 return _
.template($('#tmpl_theme_thumbnail').html().trim(), theme
);
37 this.$el
= $(_
.template($('#tmpl_applet_settings').html().trim(), text
));
39 if (!navigator
.registerProtocolHandler
) {
40 this.$('.protocol_handler').remove();
43 if (!(window
.Notification
|| window
.webkitNotifications
|| navigator
.mozNotification
)) {
44 this.$('notification_enabler').remove();
47 // Incase any settings change while we have this open, update them
48 _kiwi
.global
.settings
.on('change', this.loadSettings
, this);
50 // Now actually show the current settings
55 loadSettings: function () {
59 $.each(_kiwi
.global
.settings
.attributes
, function(key
, value
) {
61 var $el
= that
.$('[data-setting="' + key
+ '"]');
63 // Only deal with settings we have a UI element for
67 switch ($el
.prop('type')) {
69 $el
.prop('checked', value
);
72 $('[data-setting="' + key
+ '"][value="' + value
+ '"]', that
.$el
).prop('checked', true);
78 $('[value="' + value
+ '"]', that
.$el
).prop('selected', true);
81 $('[data-setting="' + key
+ '"][data-value="' + value
+ '"]', that
.$el
).addClass('active');
87 saveSettings: function (event
) {
89 settings
= _kiwi
.global
.settings
,
90 $setting
= this.$(event
.currentTarget
);
92 switch (event
.currentTarget
.type
) {
94 value
= $setting
.is(':checked');
98 value
= $setting
.val();
101 value
= $(event
.currentTarget
[$setting
.prop('selectedIndex')]).val();
104 value
= $setting
.data('value');
108 // Stop settings being updated while we're saving one by one
109 _kiwi
.global
.settings
.off('change', this.loadSettings
, this);
110 settings
.set($setting
.data('setting'), value
);
113 // Continue listening for setting changes
114 _kiwi
.global
.settings
.on('change', this.loadSettings
, this);
117 selectTheme: function(event
) {
118 event
.preventDefault();
120 this.$('[data-setting="theme"].active').removeClass('active');
121 $(event
.currentTarget
).addClass('active').trigger('change');
124 registerProtocol: function (event
) {
125 event
.preventDefault();
127 navigator
.registerProtocolHandler('irc', document
.location
.origin
+ _kiwi
.app
.get('base_path') + '/%s', 'Kiwi IRC');
128 navigator
.registerProtocolHandler('ircs', document
.location
.origin
+ _kiwi
.app
.get('base_path') + '/%s', 'Kiwi IRC');
131 enableNotifications: function(event
) {
132 event
.preventDefault();
133 var Notify
= window
.Notification
|| window
.webkitNotifications
;
136 Notify
.requestPermission();
143 var Applet
= Backbone
.Model
.extend({
144 initialize: function () {
145 this.set('title', _kiwi
.global
.i18n
.translate('client_applets_settings_title').fetch());
146 this.view
= new View();
151 _kiwi
.model
.Applet
.register('kiwi_settings', Applet
);