[Status] Clean up classes when destroyed

This commit is contained in:
Victor Woeltjen 2015-11-19 13:44:06 -08:00
parent 29fdb6d641
commit 0d07c3c289

View File

@ -48,6 +48,17 @@ define(
this.lastClasses = []; this.lastClasses = [];
} }
/**
* Remove any status-related classes from this representation.
* @private
*/
StatusRepresenter.prototype.clearClasses = function () {
var element = this.element;
this.lastClasses.forEach(function (c) {
element.removeClass(c);
});
};
StatusRepresenter.prototype.represent = function (representation, domainObject) { StatusRepresenter.prototype.represent = function (representation, domainObject) {
var self = this, var self = this,
statusCapability = domainObject.getCapability('status'); statusCapability = domainObject.getCapability('status');
@ -57,9 +68,7 @@ define(
return STATUS_CLASS_PREFIX + flag; return STATUS_CLASS_PREFIX + flag;
}); });
self.lastClasses.forEach(function (c) { self.clearClasses();
self.element.removeClass(c);
});
newClasses.forEach(function (c) { newClasses.forEach(function (c) {
self.element.addClass(c); self.element.addClass(c);
@ -73,6 +82,7 @@ define(
}; };
StatusRepresenter.prototype.destroy = function () { StatusRepresenter.prototype.destroy = function () {
this.clearClasses();
if (this.unlisten) { if (this.unlisten) {
this.unlisten(); this.unlisten();
this.unlisten = undefined; this.unlisten = undefined;