2013-06-16 12:17:50 +04:00
|
|
|
(function () {
|
2013-10-11 02:04:40 +04:00
|
|
|
var ns = $.namespace("pskl.controller.settings");
|
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
var settings = {
|
2013-10-11 02:04:40 +04:00
|
|
|
'user' : {
|
|
|
|
template : 'templates/settings/application.html',
|
|
|
|
controller : ns.ApplicationSettingsController
|
|
|
|
},
|
|
|
|
'gif' : {
|
|
|
|
template : 'templates/settings/export-gif.html',
|
|
|
|
controller : ns.GifExportController
|
2013-08-12 09:31:09 +04:00
|
|
|
},
|
2013-10-11 02:04:40 +04:00
|
|
|
'import' : {
|
|
|
|
template : 'templates/settings/import.html',
|
|
|
|
controller : ns.ImportController
|
2013-12-06 21:04:04 +04:00
|
|
|
},
|
|
|
|
'save' : {
|
|
|
|
template : 'templates/settings/save.html',
|
|
|
|
controller : ns.SaveController
|
2013-08-12 09:31:09 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var SEL_SETTING_CLS = 'has-expanded-drawer';
|
|
|
|
var EXP_DRAWER_CLS = 'expanded';
|
|
|
|
|
2013-09-22 23:02:43 +04:00
|
|
|
ns.SettingsController = function (piskelController) {
|
|
|
|
this.piskelController = piskelController;
|
2013-08-12 09:31:09 +04:00
|
|
|
this.drawerContainer = document.getElementById("drawer-container");
|
2013-09-07 19:50:43 +04:00
|
|
|
this.settingsContainer = $('[data-pskl-controller=settings]');
|
2013-08-12 09:31:09 +04:00
|
|
|
this.expanded = false;
|
|
|
|
this.currentSetting = null;
|
|
|
|
};
|
2013-06-16 12:17:50 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
ns.SettingsController.prototype.init = function() {
|
2013-08-12 09:31:09 +04:00
|
|
|
// Expand drawer when clicking 'Settings' tab.
|
|
|
|
$('[data-setting]').click(function(evt) {
|
2013-09-07 19:50:43 +04:00
|
|
|
var el = evt.originalEvent.currentTarget;
|
2013-09-25 02:11:12 +04:00
|
|
|
var setting = el.getAttribute("data-setting");
|
2013-08-12 09:31:09 +04:00
|
|
|
if (this.currentSetting != setting) {
|
|
|
|
this.loadSetting(setting);
|
|
|
|
} else {
|
|
|
|
this.closeDrawer();
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-09-07 19:50:43 +04:00
|
|
|
|
|
|
|
$('body').click(function (evt) {
|
|
|
|
var isInSettingsContainer = $.contains(this.settingsContainer.get(0), evt.target);
|
|
|
|
if (this.expanded && !isInSettingsContainer) {
|
|
|
|
this.closeDrawer();
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-10-23 03:01:35 +04:00
|
|
|
|
|
|
|
$.subscribe(Events.CLOSE_SETTINGS_DRAWER, this.closeDrawer.bind(this));
|
2013-08-12 09:31:09 +04:00
|
|
|
};
|
2013-06-16 12:17:50 +04:00
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
ns.SettingsController.prototype.loadSetting = function (setting) {
|
2013-09-07 19:50:43 +04:00
|
|
|
this.drawerContainer.innerHTML = pskl.utils.Template.get(settings[setting].template);
|
2013-09-22 23:02:43 +04:00
|
|
|
(new settings[setting].controller(this.piskelController)).init();
|
2013-10-11 02:04:40 +04:00
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
this.settingsContainer.addClass(EXP_DRAWER_CLS);
|
2013-10-11 02:04:40 +04:00
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
$('.' + SEL_SETTING_CLS).removeClass(SEL_SETTING_CLS);
|
|
|
|
$('[data-setting='+setting+']').addClass(SEL_SETTING_CLS);
|
2013-06-18 01:10:35 +04:00
|
|
|
|
2013-09-07 19:50:43 +04:00
|
|
|
this.expanded = true;
|
2013-08-12 09:31:09 +04:00
|
|
|
this.currentSetting = setting;
|
|
|
|
};
|
2013-06-17 21:54:43 +04:00
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
ns.SettingsController.prototype.closeDrawer = function () {
|
|
|
|
this.settingsContainer.removeClass(EXP_DRAWER_CLS);
|
|
|
|
$('.' + SEL_SETTING_CLS).removeClass(SEL_SETTING_CLS);
|
|
|
|
|
2013-09-07 19:50:43 +04:00
|
|
|
this.expanded = false;
|
2013-08-12 09:31:09 +04:00
|
|
|
this.currentSetting = null;
|
2013-08-10 14:11:16 +04:00
|
|
|
};
|
2013-10-11 02:04:40 +04:00
|
|
|
|
2013-06-16 12:17:50 +04:00
|
|
|
})();
|