piskel/js/controller/SettingsController.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2013-06-16 12:17:50 +04:00
(function () {
var ns = $.namespace("pskl.controller");
2013-06-16 12:17:50 +04:00
var settings = {
user : {
template : 'templates/settings-application.html',
controller : ns.settings.ApplicationSettingsController
},
gif : {
template : 'templates/settings-export-gif.html',
controller : ns.settings.GifExportController
}
};
var SEL_SETTING_CLS = 'has-expanded-drawer';
var EXP_DRAWER_CLS = 'expanded';
ns.SettingsController = function (piskelController) {
this.piskelController = piskelController;
this.drawerContainer = document.getElementById("drawer-container");
2013-09-07 19:50:43 +04:00
this.settingsContainer = $('[data-pskl-controller=settings]');
this.expanded = false;
this.currentSetting = null;
};
2013-06-16 12:17:50 +04:00
/**
* @public
*/
ns.SettingsController.prototype.init = function() {
// Expand drawer when clicking 'Settings' tab.
$('[data-setting]').click(function(evt) {
2013-09-07 19:50:43 +04:00
var el = evt.originalEvent.currentTarget;
var setting = el.getAttribute("data-setting");
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-06-16 12:17:50 +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);
(new settings[setting].controller(this.piskelController)).init();
this.settingsContainer.addClass(EXP_DRAWER_CLS);
$('.' + SEL_SETTING_CLS).removeClass(SEL_SETTING_CLS);
$('[data-setting='+setting+']').addClass(SEL_SETTING_CLS);
2013-09-07 19:50:43 +04:00
this.expanded = true;
this.currentSetting = setting;
};
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;
this.currentSetting = null;
};
2013-06-16 12:17:50 +04:00
})();