@glitchr/transparent 1.0.55 → 1.0.57
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 +110 -81
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": {},
|
|
@@ -314,7 +315,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
314
315
|
responseText = responseText.outerHTML;
|
|
315
316
|
|
|
316
317
|
var array = JSON.parse(sessionStorage.getItem('transparent')) || [];
|
|
317
|
-
if(
|
|
318
|
+
if (!array.includes(uuid)) {
|
|
318
319
|
|
|
319
320
|
array.push(uuid);
|
|
320
321
|
while(array.length > Settings["response_limit"])
|
|
@@ -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);
|
|
@@ -864,7 +873,6 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
864
873
|
}.bind(this), active.delay);
|
|
865
874
|
}
|
|
866
875
|
|
|
867
|
-
|
|
868
876
|
Transparent.replaceCanvases = function(dom) {
|
|
869
877
|
|
|
870
878
|
// Extract existing canvas to avoid redrawing them.. (time consuming)
|
|
@@ -952,69 +960,73 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
952
960
|
Transparent.userScroll = function(el = undefined) { return $(el === undefined ? document.documentElement : el).closestScrollable().prop("user-scroll") ?? true; }
|
|
953
961
|
Transparent.scrollTo = function(dict, el = window, callback = function() {})
|
|
954
962
|
{
|
|
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
|
-
}
|
|
963
|
+
setTimeout(function() {
|
|
995
964
|
|
|
996
|
-
|
|
965
|
+
el = $(el).length ? $(el)[0] : window;
|
|
966
|
+
if (el === window )
|
|
967
|
+
el = document.documentElement;
|
|
968
|
+
if (el === document)
|
|
969
|
+
el = document.documentElement;
|
|
970
|
+
|
|
971
|
+
var maxScrollX = $(el).prop("scrollWidth") - Math.round($(el).prop("clientWidth"));
|
|
972
|
+
if (maxScrollX == 0) maxScrollX = Math.round($(el).prop("clientWidth"));
|
|
973
|
+
var maxScrollY = $(el).prop("scrollHeight") - Math.round($(el).prop("clientHeight"));
|
|
974
|
+
if (maxScrollY == 0) maxScrollY = Math.round($(el).prop("clientHeight"));
|
|
975
|
+
|
|
976
|
+
scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
|
|
977
|
+
scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
|
|
978
|
+
|
|
979
|
+
speed = parseFloat(dict["speed"] ?? 0);
|
|
980
|
+
easing = dict["easing"] ?? "swing";
|
|
981
|
+
debounce = dict["debounce"] ?? 0;
|
|
982
|
+
|
|
983
|
+
duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
|
|
984
|
+
durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
|
|
985
|
+
durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
|
|
986
|
+
|
|
987
|
+
if(speed) {
|
|
988
|
+
|
|
989
|
+
var currentScrollX = $(el)[0].scrollLeft;
|
|
990
|
+
if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
|
|
991
|
+
distanceX = Math.abs(scrollLeft - currentScrollX);
|
|
992
|
+
else // Going back to 0 position
|
|
993
|
+
distanceX = currentScrollX;
|
|
994
|
+
|
|
995
|
+
var currentScrollY = $(el)[0].scrollTop;
|
|
996
|
+
if(currentScrollY <= scrollTop || scrollTop == 0) // Going to the right
|
|
997
|
+
distanceY = Math.abs(scrollTop - currentScrollY);
|
|
998
|
+
else // Going back to 0 position
|
|
999
|
+
distanceY = currentScrollY;
|
|
1000
|
+
|
|
1001
|
+
durationX = speed ? 1000*distanceX/speed : durationX;
|
|
1002
|
+
durationY = speed ? 1000*distanceY/speed : durationY;
|
|
1003
|
+
duration = durationX+durationY;
|
|
1004
|
+
}
|
|
997
1005
|
|
|
998
|
-
|
|
999
|
-
callback();
|
|
1006
|
+
var callbackWrapper = function() {
|
|
1000
1007
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1008
|
+
el.dispatchEvent(new Event('scroll'));
|
|
1009
|
+
callback();
|
|
1003
1010
|
|
|
1004
|
-
|
|
1011
|
+
$(el).prop("user-scroll", true);
|
|
1012
|
+
};
|
|
1005
1013
|
|
|
1006
|
-
|
|
1007
|
-
el.dispatchEvent(new Event('scroll'));
|
|
1008
|
-
callback();
|
|
1014
|
+
if(duration == 0) {
|
|
1009
1015
|
|
|
1010
|
-
|
|
1016
|
+
el.scrollTo(scrollLeft, scrollTop);
|
|
1017
|
+
el.dispatchEvent(new Event('scroll'));
|
|
1018
|
+
callback();
|
|
1011
1019
|
|
|
1012
|
-
|
|
1020
|
+
$(el).prop("user-scroll", true);
|
|
1013
1021
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1022
|
+
} else {
|
|
1023
|
+
|
|
1024
|
+
$(el).stop(true).animate({scrollTop: scrollTop}, durationY, easing,
|
|
1025
|
+
() => $(el).stop(true).animate({scrollLeft: scrollLeft}, durationX, easing, Transparent.debounce(callbackWrapper, debounce))
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
}.bind(this), 1);
|
|
1018
1030
|
|
|
1019
1031
|
return this;
|
|
1020
1032
|
}
|
|
@@ -1201,6 +1213,14 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1201
1213
|
window.previousLocation = window.location.toString();
|
|
1202
1214
|
if(callback === null) callback = function() {};
|
|
1203
1215
|
|
|
1216
|
+
$(Transparent.html).data("autoscroll-prevent", false);
|
|
1217
|
+
$(Transparent.html).off("wheel.autoscroll DOMMouseScroll.autoscroll mousewheel.autoscroll touchstart.autoscroll");
|
|
1218
|
+
$(Transparent.html).on("wheel.autoscroll DOMMouseScroll.autoscroll mousewheel.autoscroll touchstart.autoscroll", function(e) {
|
|
1219
|
+
|
|
1220
|
+
$(this).prop("user-scroll", true);
|
|
1221
|
+
$(this).stop();
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1204
1224
|
activeInRemainingTime = activeInRemainingTime - (Date.now() - activeInTime);
|
|
1205
1225
|
setTimeout(function() {
|
|
1206
1226
|
|
|
@@ -1357,7 +1377,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1357
1377
|
|
|
1358
1378
|
Transparent.remToPixel = function(rem) { return parseFloat(rem) * parseFloat(getComputedStyle(document.documentElement).fontSize); }
|
|
1359
1379
|
Transparent.emToPixel = function(em, el) { return parseFloat(em ) * parseFloat(getComputedStyle(el.parentElement).fontSize); }
|
|
1360
|
-
Transparent.percentToPixel = function(p , el) { return parseFloat(p ) * el.outerWidth(); }
|
|
1380
|
+
Transparent.percentToPixel = function(p , el) { return parseFloat(p ) * $(el).outerWidth(); }
|
|
1361
1381
|
Transparent.parseToPixel = function(str, el) {
|
|
1362
1382
|
|
|
1363
1383
|
if(str === undefined) return undefined;
|
|
@@ -1393,26 +1413,30 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1393
1413
|
|
|
1394
1414
|
Transparent.scrollToHash = function(hash = window.location.hash, options = {}, callback = function() {}, el = window)
|
|
1395
1415
|
{
|
|
1396
|
-
|
|
1416
|
+
setTimeout(function() {
|
|
1397
1417
|
|
|
1398
|
-
if (
|
|
1399
|
-
hash = '#' + hash;
|
|
1418
|
+
if (hash !== "") {
|
|
1400
1419
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1420
|
+
if ((''+hash).charAt(0) !== '#')
|
|
1421
|
+
hash = '#' + hash;
|
|
1403
1422
|
|
|
1404
|
-
var
|
|
1405
|
-
|
|
1423
|
+
var hashElement = $(hash)[0] ?? undefined;
|
|
1424
|
+
if (hashElement !== undefined) {
|
|
1406
1425
|
|
|
1407
|
-
|
|
1408
|
-
|
|
1426
|
+
var scrollTop = hashElement.getBoundingClientRect().top + document.documentElement.scrollTop - Transparent.getScrollPadding().top;
|
|
1427
|
+
var scrollLeft = hashElement.getBoundingClientRect().left + document.documentElement.scrollLeft - Transparent.getScrollPadding().left;
|
|
1409
1428
|
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1429
|
+
options = Object.assign({duration: Settings["smoothscroll_duration"], speed: Settings["smoothscroll_speed"]}, options, {left:scrollLeft, top:scrollTop});
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
var bottomReach = document.body.scrollHeight - (window.scrollY + window.innerHeight) < 1;
|
|
1433
|
+
var bottomOverflow = scrollTop > window.scrollY + window.innerHeight;
|
|
1434
|
+
}
|
|
1413
1435
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1436
|
+
if(hash === "" || (bottomReach && bottomOverflow)) callback({}, el);
|
|
1437
|
+
else Transparent.scrollTo(options, el, callback);
|
|
1438
|
+
|
|
1439
|
+
}.bind(this), 1); // minimal delay to ensure the element is rendered
|
|
1416
1440
|
|
|
1417
1441
|
return this;
|
|
1418
1442
|
}
|
|
@@ -1447,7 +1471,10 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1447
1471
|
|
|
1448
1472
|
// Determine link
|
|
1449
1473
|
const link = Transparent.findLink(e);
|
|
1450
|
-
if
|
|
1474
|
+
if (link == null) {
|
|
1475
|
+
e.preventDefault();
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1451
1478
|
|
|
1452
1479
|
dispatchEvent(new CustomEvent('transparent:link', {link:link}));
|
|
1453
1480
|
|
|
@@ -1510,7 +1537,9 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1510
1537
|
// Simple wildcard support: * matches any sequence of characters
|
|
1511
1538
|
let pattern = exception.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
1512
1539
|
let regex = new RegExp('^' + pattern + '$');
|
|
1513
|
-
if (regex.test(url.pathname))
|
|
1540
|
+
if (regex.test(url.pathname)) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1514
1543
|
}
|
|
1515
1544
|
}
|
|
1516
1545
|
|
|
@@ -1534,7 +1563,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1534
1563
|
Transparent.scrollToHash(url.hash ?? "", {easing:Settings["smoothscroll_easing"], duration:Settings["smoothscroll_duration"], speed:Settings["smoothscroll_speed"]}, function() {
|
|
1535
1564
|
|
|
1536
1565
|
if (e.target != undefined && $(e.target).data("skip-hash") != true)
|
|
1537
|
-
window.
|
|
1566
|
+
window.location.hash = url.hash;
|
|
1538
1567
|
|
|
1539
1568
|
}, $(e.target).closestScrollable());
|
|
1540
1569
|
|