add closeSelector feature

This commit is contained in:
Barbara Miller 2017-09-12 15:27:59 -07:00
parent 5126e37139
commit dd18d07ccd

View File

@ -24,6 +24,7 @@ var umbraBehavior = {
intervalId : null,
state : null,
// actions : [{'selector': 'div.teaser, li.pager__item a'}],
actions : {{actions|json}},
intervalFunc: function() {
@ -33,6 +34,7 @@ var umbraBehavior = {
for (var k = 0; k < this.actions.length; k++) {
var selector = this.actions[k].selector;
var action = this.actions[k].do ? this.actions[k].do : 'click';
var closeSelector = this.actions[k].closeSelector ? this.actions[k].closeSelector : null;
var limit = this.actions[k].limit ? this.actions[k].limit : 0;
if (limit && this.actions[k].alreadyDone && this.actions[k].alreadyDone.length >= limit) {
continue;
@ -58,6 +60,17 @@ var umbraBehavior = {
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);
if (doTargets == []) {
continue;
@ -101,7 +114,7 @@ var umbraBehavior = {
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);
// + document.body.clientHeight);
window.scrollBy(0, 200);
this.idleSince = null;
} else if (this.idleSince == null) {