Don't redraw kanban when the tab is not focused

pull/1/head
yflory 4 years ago committed by ansuz
parent d7dfe75746
commit 95f4b2357d

@ -25,10 +25,12 @@
typeof document[hidden] === "undefined"); typeof document[hidden] === "undefined");
}; };
Visible.onChange = function (f) { Visible.onChange = function (f, once) {
document.addEventListener(visibilityChange, function (ev) { document.addEventListener(visibilityChange, function (ev) {
f(!document[hidden], ev); f(!document[hidden], ev);
}, false); }, {
once: once
});
}; };
Visible.currently = function () { Visible.currently = function () {

@ -1,8 +1,9 @@
define([ define([
'jquery', 'jquery',
'/customize/messages.js', '/customize/messages.js',
'/common/visible.js',
'/bower_components/dragula.js/dist/dragula.min.js', '/bower_components/dragula.js/dist/dragula.min.js',
], function ($, Messages, Dragula) { ], function ($, Messages, Visible, Dragula) {
/** /**
* jKanban * jKanban
* Vanilla Javascript plugin for manage kanban boards * Vanilla Javascript plugin for manage kanban boards
@ -739,6 +740,8 @@ define([
return self; return self;
}; };
var todoOnVisible = function () {};
var onVisibleHandler = false;
this.setBoards = function (boards) { this.setBoards = function (boards) {
var scroll = {}; var scroll = {};
// Fix the tags // Fix the tags
@ -754,15 +757,30 @@ define([
this.removeBoard(boardkey); this.removeBoard(boardkey);
} }
this.options.boards = boards; this.options.boards = boards;
// Add all new boards
this.addBoards(); todoOnVisible = function () {
self.options.refresh(); // Add all new boards
// Preserve scroll self.addBoards();
this.options.boards.list.forEach(function (id) { self.options.refresh();
if (!scroll[id]) { return; } // Preserve scroll
$('.kanban-board[data-id="'+id+'"] .kanban-drag').scrollTop(scroll[id]); self.options.boards.list.forEach(function (id) {
}); if (!scroll[id]) { return; }
$el.scrollLeft(scrollLeft); $('.kanban-board[data-id="'+id+'"] .kanban-drag').scrollTop(scroll[id]);
});
$el.scrollLeft(scrollLeft);
};
// If the tab is not focused, redraw on focus
if (!Visible.currently()) {
if (onVisibleHandler) { return; }
onVisibleHandler = true;
return void Visible.onChange(function (visible) {
if (!visible) { return; }
todoOnVisible();
onVisibleHandler = false;
}, true);
}
todoOnVisible();
}; };
this.findBoard = function (id) { this.findBoard = function (id) {

Loading…
Cancel
Save