diff --git a/src/js/Events.js b/src/js/Events.js index 8ef325c8..44676632 100644 --- a/src/js/Events.js +++ b/src/js/Events.js @@ -36,6 +36,8 @@ var Events = { */ PISKEL_RESET: 'PISKEL_RESET', PISKEL_SAVE_STATE: 'PISKEL_SAVE_STATE', + PISKEL_DESCRIPTOR_UPDATED : 'PISKEL_DESCRIPTOR_UPDATED', + PISKEL_SAVED_STATUS_UPDATE : 'PISKEL_SAVED_STATUS_UPDATE', HISTORY_STATE_SAVED: 'HISTORY_STATE_SAVED', HISTORY_STATE_LOADED: 'HISTORY_STATE_LOADED', diff --git a/src/js/controller/HeaderController.js b/src/js/controller/HeaderController.js index d397f347..67053231 100644 --- a/src/js/controller/HeaderController.js +++ b/src/js/controller/HeaderController.js @@ -5,12 +5,9 @@ * When embedded in piskelapp.com, the page adds a header containing the name of the currently edited sprite * This controller will keep the displayed name in sync with the actual piskel name */ - ns.HeaderController = function (piskelController, savedStatusService, interval) { + ns.HeaderController = function (piskelController, savedStatusService) { this.piskelController = piskelController; this.savedStatusService = savedStatusService; - this.interval = interval || 500; - - this.updateHeader_ = this.updateHeader_.bind(this); }; ns.HeaderController.prototype.init = function () { @@ -19,6 +16,10 @@ $.subscribe(Events.BEFORE_SAVING_PISKEL, this.onBeforeSavingPiskelEvent_.bind(this)); $.subscribe(Events.AFTER_SAVING_PISKEL, this.onAfterSavingPiskelEvent_.bind(this)); + $.subscribe(Events.PISKEL_DESCRIPTOR_UPDATED, this.updateHeader_.bind(this)); + $.subscribe(Events.PISKEL_RESET, this.updateHeader_.bind(this)); + $.subscribe(Events.PISKEL_SAVED_STATUS_UPDATE, this.updateHeader_.bind(this)); + this.updateHeader_(); }; @@ -35,8 +36,6 @@ } catch (e) { console.warn('Could not update header : ' + e.message); } - - window.setTimeout(this.updateHeader_, this.interval); }; ns.HeaderController.prototype.onBeforeSavingPiskelEvent_ = function () { diff --git a/src/js/model/Piskel.js b/src/js/model/Piskel.js index 32d00eb0..2ff34e9e 100644 --- a/src/js/model/Piskel.js +++ b/src/js/model/Piskel.js @@ -114,10 +114,12 @@ ns.Piskel.prototype.setDescriptor = function (descriptor) { this.descriptor = descriptor; + $.publish(Events.PISKEL_DESCRIPTOR_UPDATED); }; ns.Piskel.prototype.setName = function (name) { this.descriptor.name = name; + $.publish(Events.PISKEL_DESCRIPTOR_UPDATED); }; ns.Piskel.prototype.getHash = function () { diff --git a/src/js/service/SavedStatusService.js b/src/js/service/SavedStatusService.js index dadbad54..9eb5789d 100644 --- a/src/js/service/SavedStatusService.js +++ b/src/js/service/SavedStatusService.js @@ -32,7 +32,10 @@ ns.SavedStatusService.prototype.updateDirtyStatus = function (status) { var piskel = this.piskelController.getPiskel(); - piskel.isDirty_ = status; + if (piskel.isDirty_ != status) { + piskel.isDirty_ = status; + $.publish(Events.PISKEL_SAVED_STATUS_UPDATE); + } }; ns.SavedStatusService.prototype.isDirty = function (evt) {