mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-17 10:40:41 -04:00
Merge branch 'behavior-refactor' into qa
This commit is contained in:
commit
bd83f079a7
2 changed files with 83 additions and 80 deletions
|
@ -42,9 +42,7 @@
|
||||||
behavior_js_template: umbraBehavior.js.j2
|
behavior_js_template: umbraBehavior.js.j2
|
||||||
default_parameters:
|
default_parameters:
|
||||||
actions:
|
actions:
|
||||||
- selector: li.pager__item a
|
- selector: div.teaser, li.pager__item a
|
||||||
limit: 4
|
|
||||||
- selector: div.teaser
|
|
||||||
-
|
-
|
||||||
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
|
||||||
behavior_js_template: huffpostslides.js
|
behavior_js_template: huffpostslides.js
|
||||||
|
@ -122,7 +120,10 @@
|
||||||
actions:
|
actions:
|
||||||
- selector: .menu-item a
|
- selector: .menu-item a
|
||||||
do: mouseover
|
do: mouseover
|
||||||
|
<<<<<<< HEAD
|
||||||
do_until_hard_timeout: False
|
do_until_hard_timeout: False
|
||||||
|
=======
|
||||||
|
>>>>>>> behavior-refactor
|
||||||
- url_regex: '^https?://(?:www\.)?news\.com\.au/.*$'
|
- url_regex: '^https?://(?:www\.)?news\.com\.au/.*$'
|
||||||
behavior_js_template: mouseovers.js.j2
|
behavior_js_template: mouseovers.js.j2
|
||||||
default_parameters:
|
default_parameters:
|
||||||
|
|
|
@ -22,15 +22,15 @@ var umbraBehavior = {
|
||||||
alreadyDone : [],
|
alreadyDone : [],
|
||||||
idleSince : null,
|
idleSince : null,
|
||||||
intervalId : null,
|
intervalId : null,
|
||||||
|
state : null,
|
||||||
|
|
||||||
actions : {{actions|json}},
|
actions : {{actions|json}},
|
||||||
|
|
||||||
intervalFunc: function() {
|
intervalFunc: function() {
|
||||||
var actionsLength = this.actions.length;
|
if (!this.state) {
|
||||||
for (var k = 0; k < actionsLength; k++) {
|
this.state = this.actions.length === 1 ? "simple" : "fancy";
|
||||||
var didSomething = false;
|
}
|
||||||
var somethingLeftBelow = false;
|
for (var k = 0; k < this.actions.length; k++) {
|
||||||
var somethingLeftAbove = false;
|
|
||||||
|
|
||||||
var selector = this.actions[k].selector;
|
var selector = this.actions[k].selector;
|
||||||
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
var action = this.actions[k].do ? this.actions[k].do : 'click';
|
||||||
var limit = this.actions[k].limit ? this.actions[k].limit : 0;
|
var limit = this.actions[k].limit ? this.actions[k].limit : 0;
|
||||||
|
@ -41,6 +41,11 @@ var umbraBehavior = {
|
||||||
this.actions[k].alreadyDone = [];
|
this.actions[k].alreadyDone = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.state === "simple") {
|
||||||
|
var didSomething = false;
|
||||||
|
var somethingLeftBelow = false;
|
||||||
|
var somethingLeftAbove = false;
|
||||||
|
|
||||||
var iframes = document.querySelectorAll("iframe");
|
var iframes = document.querySelectorAll("iframe");
|
||||||
var documents = Array(iframes.length + 1);
|
var documents = Array(iframes.length + 1);
|
||||||
documents[0] = document;
|
documents[0] = document;
|
||||||
|
@ -69,67 +74,47 @@ var umbraBehavior = {
|
||||||
if (!this.isVisible(doTargets[i])) {
|
if (!this.isVisible(doTargets[i])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var where = this.aboveBelowOrOnScreen(doTargets[i]);
|
var where = this.aboveBelowOrOnScreen(doTargets[i]);
|
||||||
if (where == 0) {
|
if (where == 0) {
|
||||||
this.doTarget(doTargets[i], action);
|
this.doTarget(doTargets[i], action);
|
||||||
didSomething = true;
|
|
||||||
if (this.actions[k].alreadyDone) {
|
if (this.actions[k].alreadyDone) {
|
||||||
this.actions[k].alreadyDone.push(doTargets[i]);
|
this.actions[k].alreadyDone.push(doTargets[i]);
|
||||||
}
|
}
|
||||||
|
didSomething = true;
|
||||||
|
break; // break from doTargets loop, but not from documents loop
|
||||||
} else if (where > 0) {
|
} else if (where > 0) {
|
||||||
somethingLeftBelow = true;
|
somethingLeftBelow = true;
|
||||||
} else if (where < 0) {
|
} else if (where < 0) {
|
||||||
somethingLeftAbove = true;
|
somethingLeftAbove = true;
|
||||||
}
|
}
|
||||||
if (didSomething) {
|
|
||||||
break; // break from doTargets loop, but not from documents loop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!didSomething) {
|
if (!didSomething) {
|
||||||
if (somethingLeftAbove) {
|
if (somethingLeftAbove) {
|
||||||
// console.log("scrolling UP because everything on this screen has been done 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 done but there's more below");
|
// console.log("scrolling because everything on this screen has been clicked but there's more below 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");
|
// console.log("scrolling because we're not to the bottom yet 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) {
|
||||||
this.idleSince = Date.now();
|
this.idleSince = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!this.idleSince) {
|
if (!this.idleSince) {
|
||||||
this.idleSince = Date.now();
|
this.idleSince = Date.now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
start : function() {
|
|
||||||
var that = this;
|
|
||||||
this.intervalId = setInterval(function() {
|
|
||||||
that.intervalFunc()
|
|
||||||
}, 250);
|
|
||||||
},
|
|
||||||
|
|
||||||
isFinished : function() {
|
|
||||||
if (this.idleSince != null) {
|
|
||||||
var idleTimeMs = Date.now() - this.idleSince;
|
|
||||||
if (idleTimeMs / 1000 > this.IDLE_TIMEOUT_SEC) {
|
|
||||||
clearInterval(this.intervalId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
aboveBelowOrOnScreen : function(elem) {
|
aboveBelowOrOnScreen : function(elem) {
|
||||||
var eTop = elem.getBoundingClientRect().top;
|
var eTop = elem.getBoundingClientRect().top;
|
||||||
if (eTop < window.scrollY) {
|
if (eTop < window.scrollY) {
|
||||||
|
@ -163,6 +148,23 @@ var umbraBehavior = {
|
||||||
this.idleSince = null;
|
this.idleSince = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
start : function() {
|
||||||
|
var that = this;
|
||||||
|
this.intervalId = setInterval(function() {
|
||||||
|
that.intervalFunc()
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
|
||||||
|
isFinished : function() {
|
||||||
|
if (this.idleSince != null) {
|
||||||
|
var idleTimeMs = Date.now() - this.idleSince;
|
||||||
|
if (idleTimeMs / 1000 > this.IDLE_TIMEOUT_SEC) {
|
||||||
|
clearInterval(this.intervalId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
// end umbraBehavior definition
|
// end umbraBehavior definition
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue