\r
// Entry point to start the kiwi application\r
init: function (opts, callback) {\r
- var continueStart, locale, igniteTextTheme, text_theme;\r
+ var continueStart, locale, jobs, igniteTextTheme, text_theme;\r
opts = opts || {};\r
\r
+ jobs = new JobManager();\r
+ jobs.onFinish(callback);\r
+\r
continueInit = function (locale, s, xhr) {\r
if (locale) {\r
_kiwi.global.i18n = new Jed(locale);\r
} else {\r
_kiwi.global.i18n = new Jed();\r
}\r
- \r
+\r
_kiwi.app = new _kiwi.model.Application(opts);\r
\r
// Start the client up\r
// Now everything has started up, load the plugin manager for third party plugins\r
_kiwi.global.plugins = new _kiwi.model.PluginManager();\r
\r
- callback && callback();\r
+ jobs.finishJob('load_locale');\r
};\r
- \r
+\r
igniteTextTheme = function(text_theme, s, xhr) {\r
_kiwi.global.text_theme = new _kiwi.view.TextTheme(text_theme);\r
- \r
- callback && callback();\r
- }\r
+\r
+ jobs.finishJob('load_text_theme');\r
+ };\r
\r
// Set up the settings datastore\r
_kiwi.global.settings = _kiwi.model.DataStore.instance('kiwi.settings');\r
// Set the window title\r
window.document.title = opts.server_settings.client.window_title || 'Kiwi IRC';\r
\r
+ jobs.registerJob('load_locale');\r
locale = _kiwi.global.settings.get('locale');\r
if (!locale) {\r
$.getJSON(opts.base_path + '/assets/locales/magic.json', continueInit);\r
$.getJSON(opts.base_path + '/assets/locales/' + locale + '.json', continueInit);\r
}\r
\r
+ jobs.registerJob('load_text_theme');\r
text_theme = opts.text_theme;\r
if (!text_theme) {\r
$.getJSON(opts.base_path + '/assets/text_themes/default.json', igniteTextTheme);\r
}\r
}\r
\r
+ /**\r
+ * Get alerted when a group of jobs have been completed.\r
+ * Eg. .registerJob('job1'); .registerJob('job2');\r
+ * .onFinish(function(){ alert('Jobs finished!'); });\r
+ * .finishJob('job1');\r
+ * .finishJob('job2');\r
+ */\r
+ function JobManager() {\r
+ var completed_jobs = { };\r
+\r
+ // Functions to call once all jobs have completed\r
+ var completed_callbacks = [];\r
+\r
+\r
+ function callCompletedFunctions(fn) {\r
+ $.each(completed_callbacks, function(idx, fn) {\r
+ fn();\r
+ });\r
+\r
+ completed_callbacks = [];\r
+ };\r
+\r
+\r
+ this.finishJob = function(job_name) {\r
+ if (typeof completed_jobs[job_name] === 'undefined') {\r
+ return;\r
+ }\r
+\r
+ completed_jobs[job_name] = true;\r
+\r
+ // Check if all our jobs have completed\r
+ var all_jobs_completed = true;\r
+ $.each(completed_jobs, function(idx, completed) {\r
+ if (!completed) {\r
+ all_jobs_completed = false;\r
+ return false;\r
+ }\r
+ });\r
+\r
+ if (all_jobs_completed) {\r
+ callCompletedFunctions();\r
+ }\r
+ };\r
+\r
+\r
+ this.onFinish = function(fn) {\r
+ completed_callbacks.push(fn);\r
+ };\r
+\r
+\r
+ this.registerJob = function(job_name) {\r
+ completed_jobs[job_name] = false;\r
+ };\r
+ }\r
+\r
(function () {\r
var base_path = '<%base_path%>', // Entry path for the kiwi application\r
scripts = [],\r
* Job bootup manager\r
* Once all jobs have completed, call any registered completed functions\r
*/\r
- var jobs = new (function BootManager() {\r
- var completed_jobs = { };\r
-\r
- // Functions to call once all jobs have completed\r
- var completed_callbacks = [];\r
-\r
-\r
- function callCompletedFunctions(fn) {\r
- $.each(completed_callbacks, function(idx, fn) {\r
- fn();\r
- });\r
-\r
- completed_callbacks = [];\r
- };\r
-\r
-\r
- this.finishJob = function(job_name) {\r
- if (typeof completed_jobs[job_name] === 'undefined') {\r
- return;\r
- }\r
-\r
- completed_jobs[job_name] = true;\r
-\r
- // Check if all our jobs have completed\r
- var all_jobs_completed = true;\r
- $.each(completed_jobs, function(idx, completed) {\r
- if (!completed) {\r
- all_jobs_completed = false;\r
- return false;\r
- }\r
- });\r
-\r
- if (all_jobs_completed) {\r
- callCompletedFunctions();\r
- }\r
- };\r
-\r
-\r
- this.onFinish = function(fn) {\r
- completed_callbacks.push(fn);\r
- };\r
-\r
-\r
- this.registerJob = function(job_name) {\r
- completed_jobs[job_name] = false;\r
- };\r
- })();\r
+ var jobs = new JobManager();\r
\r
\r
// Run after all dependancies have been loaded\r