Files
karma/assets/static/grid.js
Łukasz Mierzwa a21be4db4d Move tab visibility code from grid.js to unsee.js
Instead of grid update run a full update, after keeping tab in the background for too long some alert groups are kept in the DOM where they should be purged. Chrome does some really complex background tab throttling, interwebz states that after >=10s in the background a tab can only use 1% of the cpu. Future code might need to use Web Workers API, assuming other vendors will use it too (https://arstechnica.com/information-technology/2017/03/chrome-57-background-tab-suspension-download/). For now let's just reload alerts when user switches to a previously background tab after more than a single refresh cycle, this will ensure that there's no dead alerts presents since that can be confusing
2017-07-07 19:49:02 -07:00

74 lines
1.5 KiB
JavaScript

/* globals Config */
/* exported Grid */
var Grid = (function() {
var selectors = {
alerts: "#alerts",
incident: ".incident",
gridSizer: ".grid-sizer",
};
var grid;
var init = function() {
grid = $(selectors.alerts).masonry({
itemSelector: selectors.incident,
columnWidth: selectors.gridSizer,
percentPosition: true,
transitionDuration: "0.4s",
hiddenStyle: {
opacity: 0
},
visibleStyle: {
opacity: 1
}
});
};
var clear = function() {
grid.masonry("remove", $(selectors.incident));
$(selectors.incident).remove();
};
var redraw = function() {
grid.masonry("layout");
};
var remove = function(elem) {
grid.masonry("remove", elem);
};
var append = function(elem) {
if (Config.GetOption("appendtop").Get()) {
grid.prepend(elem).masonry("prepended", elem);
} else {
grid.append(elem).masonry("appended", elem);
}
};
var items = function() {
return grid.masonry("getItemElements");
};
var hide = function() {
$(selectors.alerts).hide();
};
var show = function() {
$(selectors.alerts).show();
};
return {
Init: init,
Clear: clear,
Hide: hide,
Show: show,
Redraw: redraw,
Append: append,
Remove: remove,
Items: items
};
})();