Fixed : spectrum pickers where no destroyed properly

This commit is contained in:
jdescottes 2014-03-30 16:20:58 +02:00
parent 7f17e17cff
commit 5b7e07e11e
3 changed files with 56 additions and 8 deletions

View File

@ -8,23 +8,43 @@
left: 0; left: 0;
padding: 50px 150px; padding: 50px 150px;
overflow: hidden;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing : border-box; -moz-box-sizing : border-box;
background-color: rgba(0,0,0,0.8);
opacity: 0;
pointer-events: none;
transition: opacity 0.5s;
color: white; color: white;
background: rgba(0,0,0,0.5); }
display : none;
#dialog-container-wrapper.show {
opacity: 1;
pointer-events: auto;
transition: opacity 0.5s;
} }
#dialog-container { #dialog-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
margin-top: -1500px;
transition:margin-top 0.5s;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing : border-box; -moz-box-sizing : border-box;
border-radius: 3px; border-radius: 3px;
background: rgba(0,0,0,0.9); background: rgba(0,0,0,0.9);
overflow: auto; overflow: auto;
} }
.show #dialog-container {
margin-top: 0;
}

View File

@ -27,9 +27,14 @@
var config = dialogs[dialogId]; var config = dialogs[dialogId];
if (config) { if (config) {
this.dialogContainer_.innerHTML = pskl.utils.Template.get(config.template); this.dialogContainer_.innerHTML = pskl.utils.Template.get(config.template);
(new config.controller(this.piskelController)).init(); var controller = new config.controller(this.piskelController);
controller.init();
this.showDialogWrapper_(); this.showDialogWrapper_();
this.currentDialog_ = dialogId; this.currentDialog_ = {
id : dialogId,
controller : controller
};
} else { } else {
console.error('Could not find dialog configuration for dialogId : ' + dialogId); console.error('Could not find dialog configuration for dialogId : ' + dialogId);
} }
@ -42,17 +47,22 @@
ns.DialogsController.prototype.showDialogWrapper_ = function () { ns.DialogsController.prototype.showDialogWrapper_ = function () {
pskl.app.shortcutService.addShortcut('ESC', this.hideDialog.bind(this)); pskl.app.shortcutService.addShortcut('ESC', this.hideDialog.bind(this));
this.dialogWrapper_.style.display = 'block'; this.dialogWrapper_.classList.add('show');
}; };
ns.DialogsController.prototype.hideDialog = function () { ns.DialogsController.prototype.hideDialog = function () {
var currentDialog = this.currentDialog_;
if (currentDialog) {
currentDialog.controller.destroy();
}
this.hideDialogWrapper_(); this.hideDialogWrapper_();
this.currentDialog_ = null; this.currentDialog_ = null;
}; };
ns.DialogsController.prototype.hideDialogWrapper_ = function () { ns.DialogsController.prototype.hideDialogWrapper_ = function () {
pskl.app.shortcutService.removeShortcut('ESC'); pskl.app.shortcutService.removeShortcut('ESC');
this.dialogWrapper_.style.display = 'none'; this.dialogWrapper_.classList.remove('show');
}; };
ns.DialogsController.prototype.isDisplayed = function () { ns.DialogsController.prototype.isDisplayed = function () {

View File

@ -45,6 +45,10 @@
} }
}; };
ns.PaletteManagerController.prototype.destroy = function () {
this.destroySpectrumPickers();
};
ns.PaletteManagerController.prototype.closeDialog = function () { ns.PaletteManagerController.prototype.closeDialog = function () {
$.publish(Events.DIALOG_HIDE); $.publish(Events.DIALOG_HIDE);
}; };
@ -78,6 +82,9 @@
}; };
ns.PaletteManagerController.prototype.refreshPaletteDetails = function () { ns.PaletteManagerController.prototype.refreshPaletteDetails = function () {
// Destroy and disconnect events
this.destroySpectrumPickers();
this.createPaletteHeadMarkup(); this.createPaletteHeadMarkup();
this.createPaletteBodyMarkup(); this.createPaletteBodyMarkup();
this.initPaletteDetailsEvents(); this.initPaletteDetailsEvents();
@ -182,9 +189,13 @@
} }
}; };
ns.PaletteManagerController.prototype.getSpectrumSelector_ = function () {
return ':not(.' + NEW_COLOR_CLASS + ')>.palette-manager-color-square';
};
ns.PaletteManagerController.prototype.initPaletteCardsSpectrum = function () { ns.PaletteManagerController.prototype.initPaletteCardsSpectrum = function () {
var oSelf = this; var oSelf = this;
var colorSquares = $(':not(.' + NEW_COLOR_CLASS + ')>.palette-manager-color-square'); var colorSquares = $(this.getSpectrumSelector_());
colorSquares.spectrum({ colorSquares.spectrum({
clickoutFiresChange : true, clickoutFiresChange : true,
showInput: true, showInput: true,
@ -204,6 +215,13 @@
}); });
}; };
ns.PaletteManagerController.prototype.destroySpectrumPickers = function () {
var sp = $(this.getSpectrumSelector_());
if (sp) {
sp.spectrum("destroy");
}
};
ns.PaletteManagerController.prototype.updateColorInSelectedPalette = function (colorId, color) { ns.PaletteManagerController.prototype.updateColorInSelectedPalette = function (colorId, color) {
var palette = this.getSelectedPalette(); var palette = this.getSelectedPalette();
palette.colors.splice(colorId, 1, '#' + (color.toHex().toUpperCase())); palette.colors.splice(colorId, 1, '#' + (color.toHex().toUpperCase()));