Skip to content

Commit

Permalink
Remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
concon121 committed May 31, 2016
1 parent 23edbe9 commit b1ed806
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions lib/ui-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ UiUtils.prototype.addLineMessage = function (text, fileLine, lineChar, path, lev
}
};

UiUtils.prototype.clearFileMessages = function (path) {
if (this.messages) {
UiUtils.prototype.clear = function (condition) {
if (this.messages && typeof condition === 'function') {
const self = this;
var decrement = 0;
for (var index in self.messages.messages) {
var elem = self.messages.messages[index];
if (elem && elem.file === path && elem.attr('class') === 'line-message') {
if (condition(index, elem)) {
var viewArry = self.messages.messages.splice(index - decrement, 1);
var view = (viewArry.length > 0) ? viewArry[0] : null;
var html = (view !== null && view.length > 0) ? view[0] : null;
Expand All @@ -65,44 +65,22 @@ UiUtils.prototype.clearFileMessages = function (path) {
}
};

UiUtils.prototype.clearFileMessages = function (path) {
this.clear((index, elem) => {
return (elem && elem.file === path && elem.attr('class') === 'line-message');
});
};

UiUtils.prototype.clearInfo = function (path) {
if (this.messages) {
const self = this;
var decrement = 0;
for (var index in self.messages.messages) {
var elem = self.messages.messages[index];
if (elem && elem.attr('class').indexOf('text-info') >= 0) {
var viewArry = self.messages.messages.splice(index - decrement, 1);
var view = (viewArry.length > 0) ? viewArry[0] : null;
var html = (view !== null && view.length > 0) ? view[0] : null;
decrement++;
$(html).remove();
}
}
if (self.messages.messages.length === 0) {
self.messages.toggle();
}
}
this.clear((index, elem) => {
return (elem && elem.attr('class').indexOf('text-info') >= 0);
});
};

UiUtils.prototype.clearSuccess = function (path) {
if (this.messages) {
const self = this;
var decrement = 0;
for (var index in self.messages.messages) {
var elem = self.messages.messages[index];
if (elem && elem.attr('class').indexOf('text-success') >= 0) {
var viewArry = self.messages.messages.splice(index - decrement, 1);
var view = (viewArry.length > 0) ? viewArry[0] : null;
var html = (view !== null && view.length > 0) ? view[0] : null;
decrement++;
$(html).remove();
}
}
if (self.messages.messages.length === 0) {
self.messages.toggle();
}
}
this.clear((index, elem) => {
return (elem && elem.attr('class').indexOf('text-success') >= 0);
});
};

UiUtils.prototype.containsLine = function (file, text) {
Expand Down

0 comments on commit b1ed806

Please sign in to comment.