diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-05-17 20:59:17 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-05-17 20:59:17 -0400 |
commit | e71b5e0b4e96d36905f0312a77146fe80b675f1c (patch) | |
tree | 051bf4b1d52552f5262619c218fc79b929a3b623 /assets/js/board.js | |
parent | aed7fb5cf5b04b296689771e3337b19a4a281f55 (diff) |
Refresh the board only if the tab is visible
Diffstat (limited to 'assets/js/board.js')
-rw-r--r-- | assets/js/board.js | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/assets/js/board.js b/assets/js/board.js index 1d936a27..84aca8b3 100644 --- a/assets/js/board.js +++ b/assets/js/board.js @@ -76,7 +76,7 @@ $("#board").remove(); $("#main").append(data); board_load_events(); - applyFilter(getSelectedUserFilter(), hasDueDateFilter()); + filter_apply(filter_get_user_id(), filter_has_due_date()); } }); } @@ -87,7 +87,7 @@ var projectId = $("#board").attr("data-project-id"); var timestamp = $("#board").attr("data-time"); - if (projectId != undefined && timestamp != undefined) { + if (is_visible() && projectId != undefined && timestamp != undefined) { $.ajax({ url: "?controller=board&action=check&project_id=" + projectId + "×tamp=" + timestamp, statusCode: { @@ -96,7 +96,7 @@ $("#main").append(data); board_unload_events(); board_load_events(); - applyFilter(getSelectedUserFilter(), hasDueDateFilter()); + filter_apply(filter_get_user_id(), filter_has_due_date()); } } }); @@ -104,19 +104,19 @@ } // Get the selected user id - function getSelectedUserFilter() + function filter_get_user_id() { return $("#form-user_id").val(); } // Return true if the filter is activated - function hasDueDateFilter() + function filter_has_due_date() { return $("#filter-due-date").hasClass("filter-on"); } // Apply user or date filter (change tasks opacity) - function applyFilter(selectedUserId, filterDueDate) + function filter_apply(selectedUserId, filterDueDate) { $("[data-task-id]").each(function(index, item) { @@ -140,12 +140,12 @@ function filter_load_events() { $("#form-user_id").change(function() { - applyFilter(getSelectedUserFilter(), hasDueDateFilter()); + filter_apply(filter_get_user_id(), filter_has_due_date()); }); $("#filter-due-date").click(function(e) { $(this).toggleClass("filter-on"); - applyFilter(getSelectedUserFilter(), hasDueDateFilter()); + filter_apply(filter_get_user_id(), filter_has_due_date()); e.preventDefault(); }); } @@ -164,6 +164,28 @@ }); } + // Return true if the page is visible + function is_visible() + { + var property = ""; + + if (typeof document.hidden !== "undefined") { + property = "visibilityState"; + } else if (typeof document.mozHidden !== "undefined") { + property = "mozVisibilityState"; + } else if (typeof document.msHidden !== "undefined") { + property = "msVisibilityState"; + } else if (typeof document.webkitHidden !== "undefined") { + property = "webkitVisibilityState"; + } + + if (property != "") { + return document[property] == "visible"; + } + + return true; + } + // Initialization $(function() { board_load_events(); |