@glitchr/transparent 1.0.55 → 1.0.56
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/package.json +1 -1
- package/src/js/transparent.js +108 -78
package/package.json
CHANGED
package/src/js/transparent.js
CHANGED
|
@@ -26,6 +26,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
26
26
|
if(!newHash) newHash = "";
|
|
27
27
|
if (newHash !== "" && (''+newHash).charAt(0) !== '#')
|
|
28
28
|
newHash = '#' + newHash;
|
|
29
|
+
|
|
29
30
|
var newURL = location.origin+location.pathname+newHash;
|
|
30
31
|
var newHashElement = $(newHash);
|
|
31
32
|
|
|
@@ -161,7 +162,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
161
162
|
|
|
162
163
|
var Transparent = window.Transparent = {};
|
|
163
164
|
Transparent.version = '0.1.0';
|
|
164
|
-
|
|
165
|
+
|
|
165
166
|
var Settings = Transparent.settings = {
|
|
166
167
|
"headers": {},
|
|
167
168
|
"data": {},
|
|
@@ -442,11 +443,16 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
442
443
|
Transparent.addLayout();
|
|
443
444
|
Transparent.lazyLoad();
|
|
444
445
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
});
|
|
446
|
+
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
447
|
+
const scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
|
448
|
+
window.previousScroll = {top: scrollTop, left: scrollLeft};
|
|
449
449
|
|
|
450
|
+
if($(Transparent.html).hasClass(Transparent.state.FIRST)) {
|
|
451
|
+
Transparent.scrollToHash(location.hash, {}, function() {
|
|
452
|
+
Transparent.activeOut(() => Transparent.html.removeClass(Transparent.state.FIRST));
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
450
456
|
return this;
|
|
451
457
|
};
|
|
452
458
|
|
|
@@ -544,6 +550,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
544
550
|
var href = el.target.getAttribute("action");
|
|
545
551
|
if(!href) href = location.pathname + href;
|
|
546
552
|
|
|
553
|
+
|
|
547
554
|
if (href.startsWith("#")) href = location.pathname + href;
|
|
548
555
|
if (href.endsWith ("#")) href = href.slice(0, -1);
|
|
549
556
|
|
|
@@ -558,6 +565,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
558
565
|
|
|
559
566
|
if(!$(el).hasClass("skip-validation") && !form.checkValidity()) {
|
|
560
567
|
console.error("Invalid form submission.", el);
|
|
568
|
+
form.classList.add('was-validated');
|
|
561
569
|
return null;
|
|
562
570
|
}
|
|
563
571
|
|
|
@@ -603,6 +611,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
603
611
|
|
|
604
612
|
if(!$(el).hasClass("skip-validation") && !form.checkValidity()) {
|
|
605
613
|
console.error("Invalid form submission.", el);
|
|
614
|
+
form.classList.add('was-validated');
|
|
606
615
|
return null;
|
|
607
616
|
}
|
|
608
617
|
|
|
@@ -843,7 +852,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
843
852
|
Transparent.html.removeClass(Transparent.state.ACTIVEOUT);
|
|
844
853
|
if(Transparent.html.hasClass(Transparent.state.LOADING)) {
|
|
845
854
|
|
|
846
|
-
dispatchEvent(new Event('transparent:'+Transparent.state.
|
|
855
|
+
dispatchEvent(new Event('transparent:'+Transparent.state.LOADING));
|
|
847
856
|
|
|
848
857
|
Object.values(Transparent.state).forEach(e => Transparent.html.removeClass(e));
|
|
849
858
|
Transparent.html.addClass(Transparent.state.ROOT + " " + Transparent.state.READY);
|
|
@@ -952,69 +961,73 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
952
961
|
Transparent.userScroll = function(el = undefined) { return $(el === undefined ? document.documentElement : el).closestScrollable().prop("user-scroll") ?? true; }
|
|
953
962
|
Transparent.scrollTo = function(dict, el = window, callback = function() {})
|
|
954
963
|
{
|
|
955
|
-
|
|
956
|
-
if (el === window )
|
|
957
|
-
el = document.documentElement;
|
|
958
|
-
if (el === document)
|
|
959
|
-
el = document.documentElement;
|
|
960
|
-
|
|
961
|
-
var maxScrollX = $(el).prop("scrollWidth") - Math.round($(el).prop("clientWidth"));
|
|
962
|
-
if (maxScrollX == 0) maxScrollX = Math.round($(el).prop("clientWidth"));
|
|
963
|
-
var maxScrollY = $(el).prop("scrollHeight") - Math.round($(el).prop("clientHeight"));
|
|
964
|
-
if (maxScrollY == 0) maxScrollY = Math.round($(el).prop("clientHeight"));
|
|
965
|
-
|
|
966
|
-
scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
|
|
967
|
-
scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
|
|
968
|
-
|
|
969
|
-
speed = parseFloat(dict["speed"] ?? 0);
|
|
970
|
-
easing = dict["easing"] ?? "swing";
|
|
971
|
-
debounce = dict["debounce"] ?? 0;
|
|
972
|
-
|
|
973
|
-
duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
|
|
974
|
-
durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
|
|
975
|
-
durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
|
|
976
|
-
|
|
977
|
-
if(speed) {
|
|
978
|
-
|
|
979
|
-
var currentScrollX = $(el)[0].scrollLeft;
|
|
980
|
-
if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
|
|
981
|
-
distanceX = Math.abs(scrollLeft - currentScrollX);
|
|
982
|
-
else // Going back to 0 position
|
|
983
|
-
distanceX = currentScrollX;
|
|
984
|
-
|
|
985
|
-
var currentScrollY = $(el)[0].scrollTop;
|
|
986
|
-
if(currentScrollY <= scrollTop || scrollTop == 0) // Going to the right
|
|
987
|
-
distanceY = Math.abs(scrollTop - currentScrollY);
|
|
988
|
-
else // Going back to 0 position
|
|
989
|
-
distanceY = currentScrollY;
|
|
990
|
-
|
|
991
|
-
durationX = speed ? 1000*distanceX/speed : durationX;
|
|
992
|
-
durationY = speed ? 1000*distanceY/speed : durationY;
|
|
993
|
-
duration = durationX+durationY;
|
|
994
|
-
}
|
|
964
|
+
setTimeout(function() {
|
|
995
965
|
|
|
996
|
-
|
|
966
|
+
el = $(el).length ? $(el)[0] : window;
|
|
967
|
+
if (el === window )
|
|
968
|
+
el = document.documentElement;
|
|
969
|
+
if (el === document)
|
|
970
|
+
el = document.documentElement;
|
|
971
|
+
|
|
972
|
+
var maxScrollX = $(el).prop("scrollWidth") - Math.round($(el).prop("clientWidth"));
|
|
973
|
+
if (maxScrollX == 0) maxScrollX = Math.round($(el).prop("clientWidth"));
|
|
974
|
+
var maxScrollY = $(el).prop("scrollHeight") - Math.round($(el).prop("clientHeight"));
|
|
975
|
+
if (maxScrollY == 0) maxScrollY = Math.round($(el).prop("clientHeight"));
|
|
976
|
+
|
|
977
|
+
scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
|
|
978
|
+
scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
|
|
979
|
+
|
|
980
|
+
speed = parseFloat(dict["speed"] ?? 0);
|
|
981
|
+
easing = dict["easing"] ?? "swing";
|
|
982
|
+
debounce = dict["debounce"] ?? 0;
|
|
983
|
+
|
|
984
|
+
duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
|
|
985
|
+
durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
|
|
986
|
+
durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
|
|
987
|
+
|
|
988
|
+
if(speed) {
|
|
989
|
+
|
|
990
|
+
var currentScrollX = $(el)[0].scrollLeft;
|
|
991
|
+
if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
|
|
992
|
+
distanceX = Math.abs(scrollLeft - currentScrollX);
|
|
993
|
+
else // Going back to 0 position
|
|
994
|
+
distanceX = currentScrollX;
|
|
995
|
+
|
|
996
|
+
var currentScrollY = $(el)[0].scrollTop;
|
|
997
|
+
if(currentScrollY <= scrollTop || scrollTop == 0) // Going to the right
|
|
998
|
+
distanceY = Math.abs(scrollTop - currentScrollY);
|
|
999
|
+
else // Going back to 0 position
|
|
1000
|
+
distanceY = currentScrollY;
|
|
1001
|
+
|
|
1002
|
+
durationX = speed ? 1000*distanceX/speed : durationX;
|
|
1003
|
+
durationY = speed ? 1000*distanceY/speed : durationY;
|
|
1004
|
+
duration = durationX+durationY;
|
|
1005
|
+
}
|
|
997
1006
|
|
|
998
|
-
|
|
999
|
-
callback();
|
|
1007
|
+
var callbackWrapper = function() {
|
|
1000
1008
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1009
|
+
el.dispatchEvent(new Event('scroll'));
|
|
1010
|
+
callback();
|
|
1003
1011
|
|
|
1004
|
-
|
|
1012
|
+
$(el).prop("user-scroll", true);
|
|
1013
|
+
};
|
|
1005
1014
|
|
|
1006
|
-
|
|
1007
|
-
el.dispatchEvent(new Event('scroll'));
|
|
1008
|
-
callback();
|
|
1015
|
+
if(duration == 0) {
|
|
1009
1016
|
|
|
1010
|
-
|
|
1017
|
+
el.scrollTo(scrollLeft, scrollTop);
|
|
1018
|
+
el.dispatchEvent(new Event('scroll'));
|
|
1019
|
+
callback();
|
|
1011
1020
|
|
|
1012
|
-
|
|
1021
|
+
$(el).prop("user-scroll", true);
|
|
1013
1022
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1023
|
+
} else {
|
|
1024
|
+
|
|
1025
|
+
$(el).stop(true).animate({scrollTop: scrollTop}, durationY, easing,
|
|
1026
|
+
() => $(el).stop(true).animate({scrollLeft: scrollLeft}, durationX, easing, Transparent.debounce(callbackWrapper, debounce))
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
}.bind(this), 1);
|
|
1018
1031
|
|
|
1019
1032
|
return this;
|
|
1020
1033
|
}
|
|
@@ -1201,6 +1214,14 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1201
1214
|
window.previousLocation = window.location.toString();
|
|
1202
1215
|
if(callback === null) callback = function() {};
|
|
1203
1216
|
|
|
1217
|
+
$(Transparent.html).data("autoscroll-prevent", false);
|
|
1218
|
+
$(Transparent.html).off("wheel.autoscroll DOMMouseScroll.autoscroll mousewheel.autoscroll touchstart.autoscroll");
|
|
1219
|
+
$(Transparent.html).on("wheel.autoscroll DOMMouseScroll.autoscroll mousewheel.autoscroll touchstart.autoscroll", function(e) {
|
|
1220
|
+
|
|
1221
|
+
$(this).prop("user-scroll", true);
|
|
1222
|
+
$(this).stop();
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1204
1225
|
activeInRemainingTime = activeInRemainingTime - (Date.now() - activeInTime);
|
|
1205
1226
|
setTimeout(function() {
|
|
1206
1227
|
|
|
@@ -1393,26 +1414,30 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1393
1414
|
|
|
1394
1415
|
Transparent.scrollToHash = function(hash = window.location.hash, options = {}, callback = function() {}, el = window)
|
|
1395
1416
|
{
|
|
1396
|
-
|
|
1417
|
+
setTimeout(function() {
|
|
1397
1418
|
|
|
1398
|
-
if (
|
|
1399
|
-
hash = '#' + hash;
|
|
1419
|
+
if (hash !== "") {
|
|
1400
1420
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1421
|
+
if ((''+hash).charAt(0) !== '#')
|
|
1422
|
+
hash = '#' + hash;
|
|
1403
1423
|
|
|
1404
|
-
var
|
|
1405
|
-
|
|
1424
|
+
var hashElement = $(hash)[0] ?? undefined;
|
|
1425
|
+
if (hashElement !== undefined) {
|
|
1406
1426
|
|
|
1407
|
-
|
|
1408
|
-
|
|
1427
|
+
var scrollTop = hashElement.getBoundingClientRect().top + document.documentElement.scrollTop - Transparent.getScrollPadding().top;
|
|
1428
|
+
var scrollLeft = hashElement.getBoundingClientRect().left + document.documentElement.scrollLeft - Transparent.getScrollPadding().left;
|
|
1409
1429
|
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1430
|
+
options = Object.assign({duration: Settings["smoothscroll_duration"], speed: Settings["smoothscroll_speed"]}, options, {left:scrollLeft, top:scrollTop});
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
var bottomReach = document.body.scrollHeight - (window.scrollY + window.innerHeight) < 1;
|
|
1434
|
+
var bottomOverflow = scrollTop > window.scrollY + window.innerHeight;
|
|
1435
|
+
}
|
|
1413
1436
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1437
|
+
if(hash === "" || (bottomReach && bottomOverflow)) callback({}, el);
|
|
1438
|
+
else Transparent.scrollTo(options, el, callback);
|
|
1439
|
+
|
|
1440
|
+
}.bind(this), 1); // minimal delay to ensure the element is rendered
|
|
1416
1441
|
|
|
1417
1442
|
return this;
|
|
1418
1443
|
}
|
|
@@ -1447,7 +1472,10 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1447
1472
|
|
|
1448
1473
|
// Determine link
|
|
1449
1474
|
const link = Transparent.findLink(e);
|
|
1450
|
-
if
|
|
1475
|
+
if (link == null) {
|
|
1476
|
+
e.preventDefault();
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1451
1479
|
|
|
1452
1480
|
dispatchEvent(new CustomEvent('transparent:link', {link:link}));
|
|
1453
1481
|
|
|
@@ -1510,7 +1538,9 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1510
1538
|
// Simple wildcard support: * matches any sequence of characters
|
|
1511
1539
|
let pattern = exception.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
1512
1540
|
let regex = new RegExp('^' + pattern + '$');
|
|
1513
|
-
if (regex.test(url.pathname))
|
|
1541
|
+
if (regex.test(url.pathname)) {
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1514
1544
|
}
|
|
1515
1545
|
}
|
|
1516
1546
|
|
|
@@ -1534,7 +1564,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1534
1564
|
Transparent.scrollToHash(url.hash ?? "", {easing:Settings["smoothscroll_easing"], duration:Settings["smoothscroll_duration"], speed:Settings["smoothscroll_speed"]}, function() {
|
|
1535
1565
|
|
|
1536
1566
|
if (e.target != undefined && $(e.target).data("skip-hash") != true)
|
|
1537
|
-
window.
|
|
1567
|
+
window.location.hash = url.hash;
|
|
1538
1568
|
|
|
1539
1569
|
}, $(e.target).closestScrollable());
|
|
1540
1570
|
|