Add paper.debug switch, set it to true by default when loading code through load.js and use it to ignore focus / blur events in Event.requestAnimationFrame() during development.

This commit is contained in:
Jürg Lehni 2011-04-26 12:48:46 +01:00
parent 9d2459d799
commit ba0c6dafea
2 changed files with 23 additions and 13 deletions

View file

@ -102,4 +102,12 @@ if (window.tests) {
for (var i = 0; i < sources.length; i++) { for (var i = 0; i < sources.length; i++) {
document.write('<script type="text/javascript" src="' + (window.root || '') document.write('<script type="text/javascript" src="' + (window.root || '')
+ sources[i] + '"></script>'); + sources[i] + '"></script>');
if (sources[i] == 'src/paper.js') {
// Activate paper.debug for code loaded through load.js, as we're in
// development mode.
document.write('<script type="text/javascript">'
+ 'paper.debug = true;'
+ '</script>');
}
} }

View file

@ -79,6 +79,7 @@ Event.requestAnimationFrame = new function() {
var callbacks = [], var callbacks = [],
fastRate = 1000 / 60, fastRate = 1000 / 60,
slowRate = 1000, slowRate = 1000,
focused = true,
timer; timer;
// Installs interval timer that checks all callbacks. This results in much // Installs interval timer that checks all callbacks. This results in much
@ -103,19 +104,20 @@ Event.requestAnimationFrame = new function() {
}, timeout); }, timeout);
} }
var focused = true; if (!paper.debug) {
Event.add(window, { Event.add(window, {
focus: function() { focus: function() {
focused = true; focused = true;
// Switch to falst checkCallback calls while window is focused. // Switch to falst checkCallback calls while window is focused.
timer && setTimer(fastRate); timer && setTimer(fastRate);
}, },
blur: function() { blur: function() {
focused = false; focused = false;
// Switch to slow checkCallback calls while window is blured. // Switch to slow checkCallback calls while window is blured.
timer && setTimer(slowRate); timer && setTimer(slowRate);
} }
}); });
}
return function(callback, element) { return function(callback, element) {
if (request) if (request)