mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
feature #251 : Set default size in Resize pref panel
This commit is contained in:
47
src/js/controller/settings/resize/DefaultSizeController.js
Normal file
47
src/js/controller/settings/resize/DefaultSizeController.js
Normal 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;
|
||||
};
|
||||
})();
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user