@glitchr/stickyjs 1.0.34 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/package.json +1 -1
- package/src/css/index.css +0 -0
- package/src/index.js +8 -0
- package/src/js/sticky.js +14 -15
package/README.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/css/index.css
CHANGED
|
File without changes
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
import $ from 'jquery';
|
|
2
|
+
|
|
3
|
+
// Modern browser: use passive event listeners where appropriate for better performance
|
|
4
|
+
jQuery.event.special.touchstart = { setup: function( _, ns, handle ) { this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
5
|
+
jQuery.event.special.touchmove = { setup: function( _, ns, handle ) { this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
6
|
+
jQuery.event.special.wheel = { setup: function( _, ns, handle ) { this.addEventListener("wheel", handle, { passive: true }); } };
|
|
7
|
+
jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addEventListener("mousewheel", handle, { passive: true }); } };
|
|
8
|
+
|
|
1
9
|
import './js/sticky.js';
|
|
2
10
|
import './css/index.css';
|
package/src/js/sticky.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
// Modern browser: use passive event listeners where appropriate for better performance
|
|
2
|
-
jQuery.event.special.touchstart = { setup: function( _, ns, handle ) { this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
3
|
-
jQuery.event.special.touchmove = { setup: function( _, ns, handle ) { this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
4
|
-
jQuery.event.special.wheel = { setup: function( _, ns, handle ) { this.addEventListener("wheel", handle, { passive: true }); } };
|
|
5
|
-
jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addEventListener("mousewheel", handle, { passive: true }); } };
|
|
6
|
-
|
|
7
|
-
// Sticky.js
|
|
8
1
|
(function(namespace) {
|
|
9
2
|
|
|
3
|
+
var replaceHashFlag = false;
|
|
4
|
+
|
|
10
5
|
namespace.replaceHash = function(newHash, triggerHashChange = true, skipIfEmptyIdentifier = true) {
|
|
11
6
|
|
|
7
|
+
replaceHashFlag = true;
|
|
12
8
|
var oldHash = location.hash;
|
|
13
9
|
var oldURL = location.origin+location.pathname+location.hash;
|
|
14
10
|
var oldHashElement = $(oldHash);
|
|
@@ -35,10 +31,11 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
35
31
|
|
|
36
32
|
var state = Object.assign({}, history.state, {href: newURL});
|
|
37
33
|
history.replaceState(state, '', newURL);
|
|
38
|
-
|
|
34
|
+
|
|
39
35
|
if(triggerHashChange)
|
|
40
36
|
dispatchEvent(new HashChangeEvent("hashchange", {oldURL:oldURL, newURL:newURL}));
|
|
41
37
|
|
|
38
|
+
replaceHashFlag = false;
|
|
42
39
|
return true;
|
|
43
40
|
}
|
|
44
41
|
|
|
@@ -693,9 +690,9 @@ $.fn.serializeObject = function () {
|
|
|
693
690
|
easing = dict["easing"] ?? "swing";
|
|
694
691
|
debounce = dict["debounce"] ?? 0;
|
|
695
692
|
|
|
696
|
-
duration = 1000*
|
|
697
|
-
durationX = 1000*
|
|
698
|
-
durationY = 1000*
|
|
693
|
+
duration = 1000*Sticky.parseDuration(dict["duration"] ?? 0);
|
|
694
|
+
durationX = 1000*Sticky.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
|
|
695
|
+
durationY = 1000*Sticky.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
|
|
699
696
|
|
|
700
697
|
if(speed) {
|
|
701
698
|
|
|
@@ -732,7 +729,7 @@ $.fn.serializeObject = function () {
|
|
|
732
729
|
} else {
|
|
733
730
|
|
|
734
731
|
$(el).animate({scrollTop: scrollTop}, durationY, easing,
|
|
735
|
-
() => $(el).animate({scrollLeft: scrollLeft}, durationX, easing,
|
|
732
|
+
() => $(el).animate({scrollLeft: scrollLeft}, durationX, easing, Sticky.debounce(callbackWrapper, debounce))
|
|
736
733
|
);
|
|
737
734
|
}
|
|
738
735
|
|
|
@@ -1147,13 +1144,15 @@ $.fn.serializeObject = function () {
|
|
|
1147
1144
|
var el = elAll.filter(function() {
|
|
1148
1145
|
|
|
1149
1146
|
if(this === $(Settings.identifier)) return false;
|
|
1150
|
-
|
|
1147
|
+
if($(this).hasClass("sticky-headlines-skip")) return false;
|
|
1148
|
+
return this.getBoundingClientRect().top + this.scrollHeight > 0;
|
|
1151
1149
|
});
|
|
1152
1150
|
|
|
1153
1151
|
var currentHashEl = $(window.location.hash)[0];
|
|
1154
1152
|
var atTop = $(window).scrollTop() < 2;
|
|
1155
1153
|
var atBottom = $(window).scrollTop() + $(window).height() - $(document).height() > -2;
|
|
1156
1154
|
|
|
1155
|
+
$(currentHashEl).addClass("highlight");
|
|
1157
1156
|
if((el.length == 0 && !atTop) || (!elAll.has(currentHashEl) && atBottom)) currentHash = window.location.hash;
|
|
1158
1157
|
else {
|
|
1159
1158
|
|
|
@@ -1177,7 +1176,7 @@ $.fn.serializeObject = function () {
|
|
|
1177
1176
|
}
|
|
1178
1177
|
|
|
1179
1178
|
window.replaceHash(hash, false, false);
|
|
1180
|
-
dispatchEvent(new HashChangeEvent("hashchange"))
|
|
1179
|
+
dispatchEvent(new HashChangeEvent("hashchange")); // doing it manually to avoid snapping
|
|
1181
1180
|
}
|
|
1182
1181
|
|
|
1183
1182
|
currentHash = hash;
|
|
@@ -1816,7 +1815,7 @@ $.fn.serializeObject = function () {
|
|
|
1816
1815
|
|
|
1817
1816
|
Sticky.onLoad();
|
|
1818
1817
|
$(window).trigger("scroll.sticky");
|
|
1819
|
-
$(window).on("hashchange", (e) => Sticky.reset());
|
|
1818
|
+
// $(window).on("hashchange", (e) => Sticky.reset());
|
|
1820
1819
|
});
|
|
1821
1820
|
|
|
1822
1821
|
return Sticky;
|