mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
28 lines
964 B
JavaScript
28 lines
964 B
JavaScript
|
(function () {
|
||
|
var ns = $.namespace('pskl.controller');
|
||
|
|
||
|
ns.CanvasBackgroundController = function () {
|
||
|
this.body = document.body;
|
||
|
};
|
||
|
|
||
|
ns.CanvasBackgroundController.prototype.init = function () {
|
||
|
$.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_.bind(this));
|
||
|
this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
|
||
|
};
|
||
|
|
||
|
ns.CanvasBackgroundController.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
|
||
|
if (settingName == pskl.UserSettings.CANVAS_BACKGROUND) {
|
||
|
this.updateBackgroundClass_(settingValue);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
ns.CanvasBackgroundController.prototype.updateBackgroundClass_ = function (newClass) {
|
||
|
var currentClass = this.body.dataset.currentBackgroundClass;
|
||
|
if (currentClass) {
|
||
|
this.body.classList.remove(currentClass);
|
||
|
}
|
||
|
this.body.classList.add(newClass);
|
||
|
this.body.dataset.currentBackgroundClass = newClass;
|
||
|
};
|
||
|
})();
|