close selctor, more button, more

This commit is contained in:
Barbara Miller 2017-10-04 19:55:43 -07:00
parent dabbdef88b
commit e4bea7590e
2 changed files with 128 additions and 85 deletions

View file

@ -52,8 +52,11 @@
closeSelector: .pmf-artist-modal__close-btn closeSelector: .pmf-artist-modal__close-btn
- -
url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$' url_regex: '^https?://(?:www\.)?huffingtonpost\.com/.*$'
behavior_js_template: huffpostslides.js behavior_js_template: umbraBehavior.js.j2
request_idle_timeout_sec: 10 default_parameters:
actions:
- selector: .slideshow
- selector: .slideshow-overlay__container__left__nav__next
- -
url_regex: '^https?://(?:www\.)?brooklynmuseum\.org/exhibitions/.*$' url_regex: '^https?://(?:www\.)?brooklynmuseum\.org/exhibitions/.*$'
behavior_js_template: simpleclicks.js.j2 behavior_js_template: simpleclicks.js.j2
@ -156,5 +159,7 @@
request_idle_timeout_sec: 10 request_idle_timeout_sec: 10
- # default fallback behavior - # default fallback behavior
url_regex: '^.*$' url_regex: '^.*$'
request_idle_timeout_sec: 10 behavior_js_template: umbraBehavior.js.j2
behavior_js_template: default.js default_parameters:
actions:
- selector: button.sc-button-play, button.playButton, div.soundItem

View file

@ -1,5 +1,5 @@
/* /*
* brozzler/js-templates/umbrabehavior.js.j2 - a library for umbra/brozzler behaviors * brozzler/js-templates/umbrabehavior.js.j2 - a generalized umbra/brozzler behavior
* *
* Copyright (C) 2017 Internet Archive * Copyright (C) 2017 Internet Archive
* *
@ -24,108 +24,146 @@ var umbraBehavior = {
intervalId : null, intervalId : null,
state : null, state : null,
// actions : [{'selector': 'div.teaser, li.pager__item a'}], actions : [{'selector': 'div.teaser, li.pager__item a'}],
actions : {{actions|json}}, //actions : {{actions|json}},
k : 0,
intervalFunc: function() { intervalFunc: function() {
if (!this.state) { if (!this.state) {
this.state = this.actions.length === 1 ? "simple" : "fancy"; this.state = this.actions.length === 1 ? "simple" : "fancy";
} else if (this.actions.length === k + 1) {
// last action always uses simple block
this.state = "simple";
} }
for (var k = 0; k < this.actions.length; k++) {
var selector = this.actions[k].selector; var k = this.k;
var action = this.actions[k].do ? this.actions[k].do : 'click'; var selector = this.actions[k].selector;
var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null; var action = this.actions[k].do ? this.actions[k].do : 'click';
var limit = this.actions[k].limit ? this.actions[k].limit : 0; var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null;
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
continue; // need to figure out more about how to end more complex actions...
} // var limit = this.actions[k].limit ? this.actions[k].limit : 0;
if (limit && !(this.actions[k].alreadyDone)) { // if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
this.actions[k].alreadyDone = []; // continue;
// }
// if (limit && !(this.actions[k].alreadyDone)) {
// this.actions[k].alreadyDone = [];
// }
if (this.state === "fancy") {
var moreButton = document.querySelectorAll(selector);
if (moreButton.length > 0) {
console.log("clicking more button");
this.doTarget(moreButton[0],action);
this.k++; // use next action at next run of interval function
return;
} }
if (this.state === "simple") { if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
var didSomething = false; window.scrollBy(0, 200);
var somethingLeftBelow = false; this.idleSince = null;
var somethingLeftAbove = false; return;
}
var iframes = document.querySelectorAll("iframe"); if (this.idleSince === null) {
var documents = Array(iframes.length + 1); console.log("nothing to do at the moment, might be waiting for something to load, setting this.idleSince=Date.now()");
documents[0] = document; this.idleSince = Date.now();
return;
iframesLength = iframes.length; } else {
for (var i = 0; i < iframesLength; i++) { if ((Date.now() - this.idleSince) > 9000) {
documents[i+1] = iframes[i].contentWindow.document; console.log("finished loading-thumbs, it appears we have reached the bottom");
this.state = "clicking-first-thumb";
this.idleSince = null;
} }
return;
}
}
documentsLength = documents.length; if (this.state === "simple") {
for (var j = 0; j < documentsLength; j++) { var didSomething = false;
var somethingLeftBelow = false;
var somethingLeftAbove = false;
if (closeSelector) { var iframes = document.querySelectorAll("iframe");
var closeTargets = documents[j].querySelectorAll(closeSelector); var documents = Array(iframes.length + 1);
if (closeTargets != []) { documents[0] = document;
for ( var i = 0; i < closeTargets.length; i++) {
this.doTarget(closeTargets[i], 'click'); iframesLength = iframes.length;
didSomething = true; for (var i = 0; i < iframesLength; i++) {
break; // break from closeTargets loop documents[i+1] = iframes[i].contentWindow.document;
} }
documentsLength = documents.length;
for (var j = 0; j < documentsLength; j++) {
if (closeSelector) {
var closeTargets = documents[j].querySelectorAll(closeSelector);
if (closeTargets != []) {
for ( var i = 0; i < closeTargets.length; i++) {
this.doTarget(closeTargets[i], 'click');
didSomething = true;
break; // break from closeTargets loop
} }
} }
}
var doTargets = documents[j].querySelectorAll(selector); var doTargets = documents[j].querySelectorAll(selector);
if (doTargets == []) { if (doTargets == []) {
continue;
}
doTargetsLength = doTargets.length;
for ( var i = 0; i < doTargetsLength; i++) {
// if using limits...
// if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
// break;
// }
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
continue; continue;
} }
if (!this.isVisible(doTargets[i])) {
doTargetsLength = doTargets.length; continue;
for ( var i = 0; i < doTargetsLength; i++) {
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
break;
}
if (this.alreadyDone.indexOf(doTargets[i]) > -1) {
continue;
}
if (!this.isVisible(doTargets[i])) {
continue;
}
var where = this.aboveBelowOrOnScreen(doTargets[i]);
if (where == 0) {
this.doTarget(doTargets[i], action);
if (this.actions[k].alreadyDone) {
this.actions[k].alreadyDone.push(doTargets[i]);
}
didSomething = true;
break; // break from doTargets loop, but not from documents loop
} else if (where > 0) {
somethingLeftBelow = true;
} else if (where < 0) {
somethingLeftAbove = true;
}
} }
} var where = this.aboveBelowOrOnScreen(doTargets[i]);
if (!didSomething) { if (where == 0) {
if (somethingLeftAbove) { this.doTarget(doTargets[i], action);
// console.log("scrolling UP because everything on this screen has been clicked but we missed something above"); // if (this.actions[k].alreadyDone) {
window.scrollBy(0, -500); // this.actions[k].alreadyDone.push(doTargets[i]);
this.idleSince = null; // }
} else if (somethingLeftBelow) { didSomething = true;
// console.log("scrolling because everything on this screen has been clicked but there's more below document.body.clientHeight=" break; // break from doTargets loop, but not from documents loop
// + document.body.clientHeight); } else if (where > 0) {
window.scrollBy(0, 200); somethingLeftBelow = true;
this.idleSince = null; } else if (where < 0) {
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) { somethingLeftAbove = true;
// console.log("scrolling because we're not to the bottom yet document.body.clientHeight="
// + document.body.clientHeight);
window.scrollBy(0, 200);
this.idleSince = null;
} else if (this.idleSince == null) {
this.idleSince = Date.now();
} }
} }
} }
if (!this.idleSince) { if (!didSomething) {
this.idleSince = Date.now(); if (somethingLeftAbove) {
// console.log("scrolling UP because everything on this screen has been clicked but we missed something above");
window.scrollBy(0, -500);
this.idleSince = null;
} else if (somethingLeftBelow) {
// 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);
this.idleSince = null;
} else if (window.scrollY + window.innerHeight < document.documentElement.scrollHeight) {
// console.log("scrolling because we're not to the bottom yet document.body.clientHeight="
// + document.body.clientHeight);
window.scrollBy(0, 200);
this.idleSince = null;
} else if (this.idleSince == null) {
this.idleSince = Date.now();
}
} }
} }
if (!this.idleSince) {
this.idleSince = Date.now();
}
}, },
aboveBelowOrOnScreen : function(elem) { aboveBelowOrOnScreen : function(elem) {