* and data (think: plugins)\r
*/\r
_kiwi.global = {\r
+ settings: undefined,\r
utils: undefined, // Re-usable methods\r
gateway: undefined,\r
user: undefined,\r
start: function (opts) {\r
opts = opts || {};\r
\r
+ // Load the plugin manager\r
+ _kiwi.global.plugins = new _kiwi.model.PluginManager();\r
+\r
+ // Set up the settings datastore\r
+ _kiwi.global.settings = _kiwi.model.DataStore.instance('kiwi.settings');\r
+ _kiwi.global.settings.load();\r
+\r
_kiwi.app = new _kiwi.model.Application(opts);\r
\r
if (opts.kiwi_server) {\r
_kiwi.app.kiwi_server = opts.kiwi_server;\r
}\r
\r
+ // Start the client up\r
_kiwi.app.start();\r
\r
return true;\r
},\r
\r
initialize: function (options) {\r
+ var settings = _kiwi.global.settings;\r
+\r
this.$el = $($('#tmpl_applet_settings').html());\r
+\r
+ this.$el.find('.theme').val(settings.get('theme'));\r
},\r
\r
saveSettings: function () {\r
- var theme = $('.theme', this.$el).val();\r
+ var settings = _kiwi.global.settings;\r
\r
- // Clear any current theme\r
- _kiwi.app.view.$el.removeClass(function (i, css) {\r
- return (css.match (/\btheme_\S+/g) || []).join(' ');\r
- });\r
+ settings.set('theme', $('.theme', this.$el).val());\r
\r
- if (theme) _kiwi.app.view.$el.addClass('theme_' + theme);\r
+ settings.save();\r
}\r
});\r
\r
__dirname + '/model_server.js',\r
__dirname + '/model_applet.js',\r
__dirname + '/model_pluginmanager.js',\r
+ __dirname + '/model_datastore.js',\r
\r
__dirname + '/applet_settings.js',\r
__dirname + '/applet_nickserv.js',\r
\r
[\r
'dev/model_pluginmanager.js',\r
+ 'dev/model_datastore.js',\r
'dev/utils.js',\r
'dev/view.js'\r
]\r
\r
// Best guess at where the kiwi server is\r
this.detectKiwiServer();\r
-\r
- // Load the plugin manager\r
- this.plugins = new _kiwi.model.PluginManager();\r
};\r
\r
this.start = function () {\r
--- /dev/null
+_kiwi.model.DataStore = Backbone.Model.extend({
+ initialize: function () {
+ this._namespace = '';
+ this.new_data = {};
+ },
+
+ namespace: function (new_namespace) {
+ if (new_namespace) this._namespace = new_namespace;
+ return this._namespace;
+ },
+
+ // Overload the original save() method
+ save: function () {
+ localStorage.setItem(this._namespace, JSON.stringify(this.attributes));
+ },
+
+ // Overload the original load() method
+ load: function () {
+ if (!localStorage) return;
+
+ var data;
+
+ try {
+ data = JSON.parse(localStorage.getItem(this._namespace)) || {};
+ } catch (error) {
+ data = {};
+ }
+
+ this.attributes = data;
+ }
+},
+
+{
+ // Generates a new instance of DataStore with a set namespace
+ instance: function (namespace, attributes) {
+ var datastore = new _kiwi.model.DataStore(attributes);
+ datastore.namespace(namespace);
+ return datastore;
+ }
+});
\ No newline at end of file
$('#toolbar').resize(this.doLayout);\r
$('#controlbox').resize(this.doLayout);\r
\r
+ // Change the theme when the config is changed\r
+ _kiwi.global.settings.on('change:theme', this.updateTheme, this);\r
+ this.updateTheme();\r
+\r
this.doLayout();\r
\r
$(document).keydown(this.setKeyFocus);\r
},\r
\r
\r
+\r
+ updateTheme: function (theme_name) {\r
+ // If called by the settings callback, get the correct new_value\r
+ if (theme_name === _kiwi.global.settings) {\r
+ theme_name = arguments[1];\r
+ }\r
+\r
+ // If we have no theme specified, get it from the settings\r
+ if (!theme_name) theme_name = _kiwi.global.settings.get('theme');\r
+\r
+ // Clear any current theme\r
+ this.$el.removeClass(function (i, css) {\r
+ return (css.match (/\btheme_\S+/g) || []).join(' ');\r
+ });\r
+\r
+ // Apply the new theme\r
+ this.$el.addClass('theme_' + (theme_name || 'default'));\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