2013-08-12 09:31:09 +04:00
|
|
|
|
(function () {
|
|
|
|
|
var ns = $.namespace("pskl.controller.settings");
|
2013-11-01 18:39:42 +04:00
|
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
|
ns.ApplicationSettingsController = function () {};
|
|
|
|
|
|
|
|
|
|
ns.ApplicationSettingsController.prototype.init = function() {
|
2015-02-21 17:41:32 +03:00
|
|
|
|
this.backgroundContainer = document.querySelector('.background-picker-wrapper');
|
|
|
|
|
this.backgroundContainer.addEventListener('click', this.onBackgroundClick_.bind(this));
|
|
|
|
|
|
|
|
|
|
// Highlight selected background :
|
|
|
|
|
var background = pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND);
|
|
|
|
|
var selectedBackground = this.backgroundContainer.querySelector('[data-background=' + background + ']');
|
|
|
|
|
if (selectedBackground) {
|
|
|
|
|
selectedBackground.classList.add('selected');
|
|
|
|
|
}
|
2013-08-12 09:31:09 +04:00
|
|
|
|
|
2014-03-17 01:46:43 +04:00
|
|
|
|
// Grid display and size
|
|
|
|
|
var gridWidth = pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH);
|
2015-02-21 17:41:32 +03:00
|
|
|
|
var gridSelect = document.querySelector('.grid-width-select');
|
|
|
|
|
var selectedOption = gridSelect.querySelector('option[value="'+gridWidth+'"]');
|
|
|
|
|
if (selectedOption) {
|
|
|
|
|
selectedOption.setAttribute('selected', 'selected');
|
|
|
|
|
}
|
|
|
|
|
gridSelect.addEventListener('change', this.onGridWidthChange_.bind(this));
|
2013-11-01 18:39:42 +04:00
|
|
|
|
};
|
|
|
|
|
|
2015-02-21 17:41:32 +03:00
|
|
|
|
ns.ApplicationSettingsController.prototype.onGridWidthChange_ = function (evt) {
|
2014-03-17 01:46:43 +04:00
|
|
|
|
var width = $('#grid-width').val();
|
|
|
|
|
pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, parseInt(width, 10));
|
2013-08-12 09:31:09 +04:00
|
|
|
|
};
|
2013-11-01 18:39:42 +04:00
|
|
|
|
|
2015-02-21 17:41:32 +03:00
|
|
|
|
ns.ApplicationSettingsController.prototype.onBackgroundClick_ = function (evt) {
|
|
|
|
|
var target = evt.target;
|
|
|
|
|
var background = target.dataset.background;
|
|
|
|
|
if (background) {
|
|
|
|
|
pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND, background);
|
|
|
|
|
var selected = this.backgroundContainer.querySelector('.selected');
|
|
|
|
|
if (selected) {
|
|
|
|
|
selected.classList.remove('selected');
|
|
|
|
|
}
|
|
|
|
|
target.classList.add('selected');
|
2013-11-01 18:39:42 +04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-12 09:31:09 +04:00
|
|
|
|
})();
|