feature #251 : Set default size in Resize pref panel

This commit is contained in:
jdescottes
2015-03-04 08:37:37 +01:00
parent 43e60e300c
commit 6254490a23
7 changed files with 77 additions and 7 deletions

View File

@@ -0,0 +1,47 @@
(function () {
var ns = $.namespace('pskl.controller.settings.resize');
ns.DefaultSizeController = function (piskelController) {
this.piskelController = piskelController;
};
pskl.utils.inherit(ns.DefaultSizeController, pskl.controller.settings.AbstractSettingController);
ns.DefaultSizeController.prototype.init = function () {
this.container = document.querySelector('.settings-default-size');
var defaultSize = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
this.widthInput = this.container.querySelector('[name="default-width"]');
this.heightInput = this.container.querySelector('[name="default-height"]');
this.widthInput.value = defaultSize.width;
this.heightInput.value = defaultSize.height;
this.defaultSizeForm = this.container.querySelector('form');
this.addEventListener(this.defaultSizeForm, 'submit', this.onFormSubmit_);
};
ns.DefaultSizeController.prototype.onFormSubmit_ = function (evt) {
evt.preventDefault();
var defaultSize = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
var width = this.toNumber_(this.widthInput.value, defaultSize.width);
var height = this.toNumber_(this.heightInput.value, defaultSize.height);
pskl.UserSettings.set(pskl.UserSettings.DEFAULT_SIZE, {
width : width,
height : height
});
$.publish(Events.CLOSE_SETTINGS_DRAWER);
};
ns.DefaultSizeController.prototype.toNumber_ = function (strValue, defaultValue) {
var value = parseInt(strValue, 10);
if (value === 0 || isNaN(value)) {
value = defaultValue;
}
return value;
};
})();

View File

@@ -8,6 +8,7 @@
var anchorWidgetContainer = this.container.querySelector('.resize-origin-container');
this.anchorWidget = new ns.AnchorWidget(anchorWidgetContainer);
this.defaultSizeController = new ns.DefaultSizeController(piskelController);
};
pskl.utils.inherit(ns.ResizeController, pskl.controller.settings.AbstractSettingController);
@@ -33,6 +34,8 @@
this.anchorWidget.setOrigin(ns.AnchorWidget.ORIGIN.TOPLEFT);
this.lastInput = this.widthInput;
this.defaultSizeController.init();
};
ns.ResizeController.prototype.destroy = function () {