Moved resize+app settings to AbstractSettingController

This commit is contained in:
jdescottes
2015-02-23 00:23:11 +01:00
parent b4c1a4c714
commit 8592cd2e53
12 changed files with 71 additions and 40 deletions

View File

@@ -5,7 +5,8 @@
ns.AnchorWidget = function (container) {
this.container = container;
this.container.addEventListener('click', this.onResizeOriginClick_.bind(this));
this.disabled = false;
pskl.utils.Event.addEventListener(this.container, 'click', this.onResizeOriginClick_, this);
};
ns.AnchorWidget.ORIGIN = {
@@ -20,9 +21,14 @@
BOTTOMRIGHT : 'BOTTOMRIGHT'
};
ns.AnchorWidget.prototype.destroy = function (evt) {
pskl.utils.Event.removeAllEventListeners(this);
this.container = null;
};
ns.AnchorWidget.prototype.onResizeOriginClick_ = function (evt) {
var origin = evt.target.dataset.origin;
if (origin && ns.AnchorWidget.ORIGIN[origin]) {
if (origin && ns.AnchorWidget.ORIGIN[origin] && !this.disabled) {
this.setOrigin(origin);
}
};

View File

@@ -10,6 +10,8 @@
this.anchorWidget = new ns.AnchorWidget(anchorWidgetContainer);
};
pskl.utils.inherit(ns.ResizeController, pskl.controller.settings.AbstractSettingController);
ns.ResizeController.prototype.init = function () {
this.widthInput = this.container.querySelector('[name="resize-width"]');
this.heightInput = this.container.querySelector('[name="resize-height"]');
@@ -17,25 +19,27 @@
this.widthInput.value = this.piskelController.getWidth();
this.heightInput.value = this.piskelController.getHeight();
this.widthInput.addEventListener('keyup', this.onSizeInputKeyUp_.bind(this));
this.heightInput.addEventListener('keyup', this.onSizeInputKeyUp_.bind(this));
this.cancelButton = this.container.querySelector('.resize-cancel-button');
this.cancelButton.addEventListener('click', this.onCancelButtonClicked_.bind(this));
this.addEventListener(this.widthInput, 'keyup', this.onSizeInputKeyUp_);
this.addEventListener(this.heightInput, 'keyup', this.onSizeInputKeyUp_);
this.resizeForm = this.container.querySelector('form');
this.resizeForm.addEventListener('submit', this.onResizeFormSubmit_.bind(this));
this.addEventListener(this.resizeForm, 'submit', this.onResizeFormSubmit_);
this.resizeContentCheckbox = this.container.querySelector('.resize-content-checkbox');
this.resizeContentCheckbox.addEventListener('change', this.onResizeContentChange_.bind(this));
this.addEventListener(this.resizeContentCheckbox, 'change', this.onResizeContentChange_);
this.maintainRatioCheckbox = this.container.querySelector('.resize-ratio-checkbox');
this.maintainRatioCheckbox.addEventListener('change', this.onMaintainRatioChange_.bind(this));
this.addEventListener(this.maintainRatioCheckbox, 'change', this.onMaintainRatioChange_);
this.anchorWidget.setOrigin(ns.AnchorWidget.ORIGIN.TOPLEFT);
this.lastInput = this.widthInput;
};
ns.ResizeController.prototype.destroy = function () {
this.anchorWidget.destroy();
this.superclass.destroy.call(this);
};
ns.ResizeController.prototype.onResizeFormSubmit_ = function (evt) {
evt.preventDefault();
@@ -53,10 +57,6 @@
return pskl.model.Layer.fromFrames(layer.getName(), resizedFrames);
};
ns.ResizeController.prototype.onCancelButtonClicked_ = function () {
$.publish(Events.CLOSE_SETTINGS_DRAWER);
};
ns.ResizeController.prototype.onResizeContentChange_ = function (evt) {
var target = evt.target;
if (target.checked) {
@@ -103,7 +103,7 @@
};
/***********************/
/* RESIZE CANVAS LOGIC */
/* RESIZE LOGIC */
/***********************/
ns.ResizeController.prototype.resizeFrame_ = function (frame) {