@searchspring/snap-toolbox
Advanced tools
Comparing version 0.38.1 to 0.39.0
@@ -10,2 +10,3 @@ export declare type Target = { | ||
autoRetarget?: boolean; | ||
clickRetarget?: boolean | string; | ||
[any: string]: unknown; | ||
@@ -12,0 +13,0 @@ }; |
@@ -37,28 +37,37 @@ "use strict"; | ||
this.targets.forEach(function (target) { | ||
var timeoutTime = 100; | ||
var checker = function () { | ||
// lets not just keep trying forever - this waits roughly 12 seconds before giving up. | ||
if (timeoutTime < 2000) { | ||
// increase the time till next check | ||
timeoutTime = timeoutTime + 200; | ||
_this.retarget(); | ||
setTimeout(checker, timeoutTime); | ||
} | ||
else { | ||
// timed out, lets unhide the target | ||
target.hideTarget && _this.unhideTarget(target.selector); | ||
} | ||
}; | ||
// add click event to restart retargeting check | ||
if (target.clickRetarget) { | ||
var clickElems = []; | ||
if (typeof target.clickRetarget == 'boolean') { | ||
clickElems.push(_this.document); | ||
} | ||
else { | ||
clickElems = Array.from(_this.document.querySelectorAll(target.clickRetarget)); | ||
} | ||
clickElems.map(function (elem) { | ||
elem.addEventListener('click', function () { | ||
timeoutTime = 100; | ||
checker(); | ||
}); | ||
}); | ||
} | ||
if (target.autoRetarget) { | ||
var timeoutTime_1 = 100; | ||
var checker_1 = function () { | ||
//lets not just keep trying forever - this waits roughly 12 seconds before giving up. | ||
if (timeoutTime_1 < 2000) { | ||
//increase the time till next check | ||
timeoutTime_1 = timeoutTime_1 + 200; | ||
var elems = _this.domQuery(target.selector); | ||
//did we find any targets? | ||
if (elems && elems.length) { | ||
_this.retarget(); | ||
target.hideTarget && _this.unhideTarget(target.selector); | ||
} | ||
else { | ||
//try again soon | ||
setTimeout(checker_1, timeoutTime_1); | ||
} | ||
} | ||
else { | ||
//timed out, lets unhide the target | ||
target.hideTarget && _this.unhideTarget(target.selector); | ||
} | ||
}; | ||
checker_1(); | ||
// do initial retargeting check | ||
checker(); | ||
} | ||
else if (/complete|loaded/.test(_this.document.readyState)) { | ||
else if (/complete|interactive|loaded/.test(_this.document.readyState)) { | ||
// DOMContent has loaded - unhide targets | ||
@@ -84,5 +93,3 @@ target.hideTarget && _this.unhideTarget(target.selector); | ||
// hide targets before found | ||
if (target.hideTarget) { | ||
_this.hideTarget(target.selector); | ||
} | ||
target.hideTarget && _this.hideTarget(target.selector); | ||
var elems = _this.domQuery(target.selector).filter(function (elem) { | ||
@@ -94,3 +101,3 @@ if (!globallyTargetedElems.find(function (e) { return e == elem; }) && !_this.targetedElems.find(function (e) { return e == elem; })) { | ||
// unhide retarget attempts | ||
_this.unhideTarget(target.selector); | ||
target.hideTarget && _this.unhideTarget(target.selector); | ||
} | ||
@@ -126,3 +133,3 @@ }); | ||
// unhide target | ||
_this.unhideTarget(target.selector); | ||
target.hideTarget && _this.unhideTarget(target.selector); | ||
}); | ||
@@ -129,0 +136,0 @@ if (errors.length) { |
@@ -10,2 +10,3 @@ export declare type Target = { | ||
autoRetarget?: boolean; | ||
clickRetarget?: boolean | string; | ||
[any: string]: unknown; | ||
@@ -12,0 +13,0 @@ }; |
@@ -33,28 +33,37 @@ let globallyTargetedElems = []; | ||
this.targets.forEach((target) => { | ||
let timeoutTime = 100; | ||
const checker = () => { | ||
// lets not just keep trying forever - this waits roughly 12 seconds before giving up. | ||
if (timeoutTime < 2000) { | ||
// increase the time till next check | ||
timeoutTime = timeoutTime + 200; | ||
this.retarget(); | ||
setTimeout(checker, timeoutTime); | ||
} | ||
else { | ||
// timed out, lets unhide the target | ||
target.hideTarget && this.unhideTarget(target.selector); | ||
} | ||
}; | ||
// add click event to restart retargeting check | ||
if (target.clickRetarget) { | ||
let clickElems = []; | ||
if (typeof target.clickRetarget == 'boolean') { | ||
clickElems.push(this.document); | ||
} | ||
else { | ||
clickElems = Array.from(this.document.querySelectorAll(target.clickRetarget)); | ||
} | ||
clickElems.map((elem) => { | ||
elem.addEventListener('click', () => { | ||
timeoutTime = 100; | ||
checker(); | ||
}); | ||
}); | ||
} | ||
if (target.autoRetarget) { | ||
let timeoutTime = 100; | ||
const checker = () => { | ||
//lets not just keep trying forever - this waits roughly 12 seconds before giving up. | ||
if (timeoutTime < 2000) { | ||
//increase the time till next check | ||
timeoutTime = timeoutTime + 200; | ||
const elems = this.domQuery(target.selector); | ||
//did we find any targets? | ||
if (elems && elems.length) { | ||
this.retarget(); | ||
target.hideTarget && this.unhideTarget(target.selector); | ||
} | ||
else { | ||
//try again soon | ||
setTimeout(checker, timeoutTime); | ||
} | ||
} | ||
else { | ||
//timed out, lets unhide the target | ||
target.hideTarget && this.unhideTarget(target.selector); | ||
} | ||
}; | ||
// do initial retargeting check | ||
checker(); | ||
} | ||
else if (/complete|loaded/.test(this.document.readyState)) { | ||
else if (/complete|interactive|loaded/.test(this.document.readyState)) { | ||
// DOMContent has loaded - unhide targets | ||
@@ -78,5 +87,3 @@ target.hideTarget && this.unhideTarget(target.selector); | ||
// hide targets before found | ||
if (target.hideTarget) { | ||
this.hideTarget(target.selector); | ||
} | ||
target.hideTarget && this.hideTarget(target.selector); | ||
const elems = this.domQuery(target.selector).filter((elem) => { | ||
@@ -88,3 +95,3 @@ if (!globallyTargetedElems.find((e) => e == elem) && !this.targetedElems.find((e) => e == elem)) { | ||
// unhide retarget attempts | ||
this.unhideTarget(target.selector); | ||
target.hideTarget && this.unhideTarget(target.selector); | ||
} | ||
@@ -118,3 +125,3 @@ }); | ||
// unhide target | ||
this.unhideTarget(target.selector); | ||
target.hideTarget && this.unhideTarget(target.selector); | ||
}); | ||
@@ -121,0 +128,0 @@ if (errors.length) { |
{ | ||
"name": "@searchspring/snap-toolbox", | ||
"version": "0.38.1", | ||
"version": "0.39.0", | ||
"description": "Snap Toolbox", | ||
@@ -26,3 +26,3 @@ "main": "dist/cjs/index.js", | ||
], | ||
"gitHead": "c7f130f994a310eb4fefc9806ea102194981bed0" | ||
"gitHead": "008ac73f9ffd82bbcf9036ae8cc9cad33dc7fb5a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
58840
1168