Skip to content

Commit

Permalink
Updates for 2.7.0 (#115)
Browse files Browse the repository at this point in the history
* Updates for 2.7.0

* Remove 14.x from node-version

* Add unit tests for waitForIntersection and "Don't activate when preview parameter doesn't match a recipe ID"
  • Loading branch information
allmywant authored Jan 9, 2025
1 parent 650ff7a commit 48eb1c2
Show file tree
Hide file tree
Showing 6 changed files with 3,117 additions and 1,893 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x]

steps:
- uses: actions/checkout@v1
Expand Down
36 changes: 36 additions & 0 deletions lib/mojito.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ Mojito = (function () {
previewRecipe = this.options.recipes[recipeId],
success = false;

// Disable test when preview parameter exists but doesn't match a recipe ID
if (recipeId && !previewRecipe) {
return false;
}

// If previewing, run recipe and return
if (previewRecipe != null) {
this.log('Forcing test [' + this.options.name + '][' + this.options.id + '] into recipe [' + previewRecipe.name + '][' + recipeId + ']');
Expand Down Expand Up @@ -724,6 +729,37 @@ Mojito = (function () {
domWatcher.observe(elements[i], watchOptions);
}
},
/**
* Run a callback when changes in the intersection of a target element with an ancestor element or with a top-level document's viewport
* @param element: dom element
* @param callback: callback function on change
* @param options: an optional object providing options plus an "once" option
* e.g. threshold, rootMargin, see https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
* once, run callback once or everytime the element is intersecting. default is true
*/
waitForIntersection: function (element, callback, options) {
options = options||{ once: true };
if (!('once' in options)) {
options.once = true;
}

var observer = new IntersectionObserver(function (entries, observer) {
var entry = entries[0];
if (!entry) {
return;
}

if (entry.isIntersecting) {
callback(entry);

if (options.once) {
observer.disconnect();
}
}
}, options);

observer.observe(element);
},
/**
* get user id (uuidv4)
*/
Expand Down
Loading

0 comments on commit 48eb1c2

Please sign in to comment.