Skip to content

Commit 872191a

Browse files
committed
Fix validateSelector method stopped working if a selector could not be validated
1 parent b109322 commit 872191a

File tree

9 files changed

+43
-16
lines changed

9 files changed

+43
-16
lines changed

changelog.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 3.0.1 (Hotfix release)
4+
5+
#### Bug Fixes
6+
- ScrollToSmooth stopped working in version 3.0.0 when the selector to be validated would fail
7+
38
### 3.0.0
49

510
#### Features

dist/scrolltosmooth.cjs.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,16 @@ var forEach = function forEach(arr, callback) {
603603

604604
var validateSelector = function validateSelector(selector) {
605605
var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : d;
606-
var valid = false; // Check if the target is a valid selector inside the scrollToSmooth container
606+
var valid = true; // Check if the target is a valid selector inside the scrollToSmooth container
607607

608-
if (typeof selector == 'string' && _$(selector, container) || isNodeOrElement(selector) && container.contains(selector)) {
609-
valid = true;
608+
try {
609+
if (typeof selector === 'string') {
610+
_$(selector, container);
611+
} else if (isNodeOrElement(selector) && container.contains(selector)) {
612+
selector;
613+
}
614+
} catch (e) {
615+
valid = false;
610616
}
611617

612618
return valid;
@@ -747,6 +753,7 @@ function getTargetElement(el) {
747753
return this.container;
748754
}
749755

756+
console.log(targetSelector, validateSelector(targetSelector, this.container));
750757
return validateSelector(targetSelector, this.container) ? _$(targetSelector, this.container) : null;
751758
}
752759
/**

dist/scrolltosmooth.esm.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,16 @@ var forEach = function forEach(arr, callback) {
599599

600600
var validateSelector = function validateSelector(selector) {
601601
var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : d;
602-
var valid = false; // Check if the target is a valid selector inside the scrollToSmooth container
602+
var valid = true; // Check if the target is a valid selector inside the scrollToSmooth container
603603

604-
if (typeof selector == 'string' && _$(selector, container) || isNodeOrElement(selector) && container.contains(selector)) {
605-
valid = true;
604+
try {
605+
if (typeof selector === 'string') {
606+
_$(selector, container);
607+
} else if (isNodeOrElement(selector) && container.contains(selector)) {
608+
selector;
609+
}
610+
} catch (e) {
611+
valid = false;
606612
}
607613

608614
return valid;
@@ -743,6 +749,7 @@ function getTargetElement(el) {
743749
return this.container;
744750
}
745751

752+
console.log(targetSelector, validateSelector(targetSelector, this.container));
746753
return validateSelector(targetSelector, this.container) ? _$(targetSelector, this.container) : null;
747754
}
748755
/**

dist/scrolltosmooth.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)