mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-06 21:44:29 -04:00
refactor umbraAboveBelowOrOnScreen into umbraBehavior object
This commit is contained in:
parent
f2ead0570e
commit
a17b0f3b8d
1 changed files with 20 additions and 22 deletions
|
@ -1,17 +1,4 @@
|
||||||
var umbraEndConditionTarget;
|
var umbraBehavior = {
|
||||||
|
|
||||||
var umbraAboveBelowOrOnScreen = function(e) {
|
|
||||||
var eTop = e.getBoundingClientRect().top;
|
|
||||||
if (eTop < window.scrollY) {
|
|
||||||
return -1; // above
|
|
||||||
} else if (eTop > window.scrollY + window.innerHeight) {
|
|
||||||
return 1; // below
|
|
||||||
} else {
|
|
||||||
return 0; // on screen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var umbraSimpleScrollsAndClicksBehavior = {
|
|
||||||
IDLE_TIMEOUT_SEC : 10,
|
IDLE_TIMEOUT_SEC : 10,
|
||||||
idleSince : null,
|
idleSince : null,
|
||||||
alreadyClicked : {},
|
alreadyClicked : {},
|
||||||
|
@ -39,7 +26,7 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var where = umbraAboveBelowOrOnScreen(clickTargets[i]);
|
var where = this.aboveBelowOrOnScreen(clickTargets[i]);
|
||||||
|
|
||||||
if (where == 0) {
|
if (where == 0) {
|
||||||
console.log("clicking on " + clickTargets[i].outerHTML);
|
console.log("clicking on " + clickTargets[i].outerHTML);
|
||||||
|
@ -66,17 +53,17 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||||
|
|
||||||
if (!clickedSomething) {
|
if (!clickedSomething) {
|
||||||
if (somethingLeftAbove) {
|
if (somethingLeftAbove) {
|
||||||
console.log("scrolling UP because everything on this screen has been clicked but we missed something above");
|
// console.log("scrolling UP because everything on this screen has been clicked but we missed something above");
|
||||||
window.scrollBy(0, -500);
|
window.scrollBy(0, -500);
|
||||||
this.idleSince = null;
|
this.idleSince = null;
|
||||||
} else if (somethingLeftBelow) {
|
} else if (somethingLeftBelow) {
|
||||||
console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight="
|
// console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight="
|
||||||
+ document.body.clientHeight);
|
// + document.body.clientHeight);
|
||||||
window.scrollBy(0, 200);
|
window.scrollBy(0, 200);
|
||||||
this.idleSince = null;
|
this.idleSince = null;
|
||||||
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
|
||||||
console.log("scrolling because we're not to the bottom yet document.body.clientHeight="
|
// console.log("scrolling because we're not to the bottom yet document.body.clientHeight="
|
||||||
+ document.body.clientHeight);
|
// + document.body.clientHeight);
|
||||||
window.scrollBy(0, 200);
|
window.scrollBy(0, 200);
|
||||||
this.idleSince = null;
|
this.idleSince = null;
|
||||||
} else if (this.idleSince == null) {
|
} else if (this.idleSince == null) {
|
||||||
|
@ -105,11 +92,22 @@ var umbraSimpleScrollsAndClicksBehavior = {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
aboveBelowOrOnScreen : function(e) {
|
||||||
|
var eTop = e.getBoundingClientRect().top;
|
||||||
|
if (eTop < window.scrollY) {
|
||||||
|
return -1; // above
|
||||||
|
} else if (eTop > window.scrollY + window.innerHeight) {
|
||||||
|
return 1; // below
|
||||||
|
} else {
|
||||||
|
return 0; // on screen
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Called from outside of this script.
|
// Called from outside of this script.
|
||||||
var umbraBehaviorFinished = function() {
|
var umbraBehaviorFinished = function() {
|
||||||
return umbraSimpleScrollsAndClicksBehavior.isFinished()
|
return umbraBehavior.isFinished()
|
||||||
};
|
};
|
||||||
|
|
||||||
umbraSimpleScrollsAndClicksBehavior.start();
|
umbraBehavior.start();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue