提交 57a4c02c 编写于 作者: K Kohsuke Kawaguchi

Merge branch 'pull-506'

...@@ -58,6 +58,9 @@ Upcoming changes</a> ...@@ -58,6 +58,9 @@ Upcoming changes</a>
<li class=bug> <li class=bug>
Fix French translation Fix French translation
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-13274">issue 13274</a>) (<a href="https://issues.jenkins-ci.org/browse/JENKINS-13274">issue 13274</a>)
<li class=rfe>
Avoid doing AJAX updates if the page becomes invisible.
(<a href="https://github.com/jenkinsci/jenkins/pull/506">pull 506</a>)
<li class=rfe> <li class=rfe>
Added a new extension point to listen to polling activities. Added a new extension point to listen to polling activities.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-14178">issue 14178</a>) (<a href="https://issues.jenkins-ci.org/browse/JENKINS-14178">issue 14178</a>)
......
...@@ -36,6 +36,50 @@ function object(o) { ...@@ -36,6 +36,50 @@ function object(o) {
return new F(); return new F();
} }
/**
* A function that returns false if the page is known to be invisible.
*/
var isPageVisible = (function(){
// @see https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API
// Set the name of the hidden property and the change event for visibility
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
// By default, visibility set to true
var pageIsVisible = true;
// If the page is hidden, prevent any polling
// if the page is shown, restore pollings
function onVisibilityChange() {
pageIsVisible = !document[hidden];
}
// Warn if the browser doesn't support addEventListener or the Page Visibility API
if (typeof document.addEventListener !== "undefined" && typeof hidden !== "undefined") {
// Init the value to the real state of the page
pageIsVisible = !document[hidden];
// Handle page visibility change
document.addEventListener(visibilityChange, onVisibilityChange, false);
}
return function() {
return pageIsVisible;
}
})();
// id generator // id generator
var iota = 0; var iota = 0;
...@@ -1439,26 +1483,33 @@ function expandTextArea(button,id) { ...@@ -1439,26 +1483,33 @@ function expandTextArea(button,id) {
// by using the contents fetched from the given URL. // by using the contents fetched from the given URL.
function refreshPart(id,url) { function refreshPart(id,url) {
var f = function() { var f = function() {
new Ajax.Request(url, { if(isPageVisible()) {
onSuccess: function(rsp) { new Ajax.Request(url, {
var hist = $(id); onSuccess: function(rsp) {
var p = hist.up(); var hist = $(id);
var next = hist.next(); var p = hist.up();
p.removeChild(hist); var next = hist.next();
p.removeChild(hist);
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = rsp.responseText; div.innerHTML = rsp.responseText;
var node = $(div).firstDescendant(); var node = $(div).firstDescendant();
p.insertBefore(node, next); p.insertBefore(node, next);
Behaviour.applySubtree(node); Behaviour.applySubtree(node);
layoutUpdateCallback.call(); layoutUpdateCallback.call();
if(isRunAsTest) return; if(isRunAsTest) return;
refreshPart(id,url); refreshPart(id,url);
} }
}); });
} else {
// Reschedule
if(isRunAsTest) return;
refreshPart(id,url);
}
}; };
// if run as test, just do it once and do it now to make sure it's working, // if run as test, just do it once and do it now to make sure it's working,
// but don't repeat. // but don't repeat.
...@@ -1534,35 +1585,40 @@ function updateBuildHistory(ajaxUrl,nBuild) { ...@@ -1534,35 +1585,40 @@ function updateBuildHistory(ajaxUrl,nBuild) {
$('buildHistory').headers = ["n",nBuild]; $('buildHistory').headers = ["n",nBuild];
function updateBuilds() { function updateBuilds() {
var bh = $('buildHistory'); if(isPageVisible()){
if (bh.headers == null) { var bh = $('buildHistory');
// Yahoo.log("Missing headers in buildHistory element"); if (bh.headers == null) {
} // Yahoo.log("Missing headers in buildHistory element");
new Ajax.Request(ajaxUrl, { }
requestHeaders: bh.headers, new Ajax.Request(ajaxUrl, {
onSuccess: function(rsp) { requestHeaders: bh.headers,
var rows = bh.rows; onSuccess: function(rsp) {
var rows = bh.rows;
//delete rows with transitive data
while (rows.length > 2 && Element.hasClassName(rows[1], "transitive")) //delete rows with transitive data
Element.remove(rows[1]); while (rows.length > 2 && Element.hasClassName(rows[1], "transitive"))
Element.remove(rows[1]);
// insert new rows
var div = document.createElement('div'); // insert new rows
div.innerHTML = rsp.responseText; var div = document.createElement('div');
Behaviour.applySubtree(div); div.innerHTML = rsp.responseText;
Behaviour.applySubtree(div);
var pivot = rows[0];
var newRows = $(div).firstDescendant().rows;
for (var i = newRows.length - 1; i >= 0; i--) {
pivot.parentNode.insertBefore(newRows[i], pivot.nextSibling);
}
var pivot = rows[0]; // next update
var newRows = $(div).firstDescendant().rows; bh.headers = ["n",rsp.getResponseHeader("n")];
for (var i = newRows.length - 1; i >= 0; i--) { window.setTimeout(updateBuilds, 5000);
pivot.parentNode.insertBefore(newRows[i], pivot.nextSibling);
} }
});
// next update } else {
bh.headers = ["n",rsp.getResponseHeader("n")]; // Reschedule again
window.setTimeout(updateBuilds, 5000); window.setTimeout(updateBuilds, 5000);
} }
});
} }
window.setTimeout(updateBuilds, 5000); window.setTimeout(updateBuilds, 5000);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册