Skip to content

Commit

Permalink
#448 - Disposen js offcanvas on component dispose.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 17, 2024
1 parent 0d101f3 commit d7e779e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Money.Blazor.Host/wwwroot/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ window.Bootstrap = {
}
},
Offcanvas: {
Initialize: function(interop, container) {
Initialize: function (interop, container) {
let offcanvas = bootstrap.Offcanvas.getInstance(container);
if (!offcanvas) {
offcanvas = new bootstrap.Offcanvas(container);
Expand All @@ -44,15 +44,18 @@ window.Bootstrap = {
});
}
},
Show: function(container) {
Show: function (container) {
bootstrap.Offcanvas.getInstance(container).show()
},
Hide: function(container) {
Hide: function (container) {
bootstrap.Offcanvas.getInstance(container).hide();
},
Dispose: function (container) {
bootstrap.Offcanvas.getInstance(container).dispose();
}
},
Theme: {
Apply: function(theme) {
Apply: function (theme) {
document.documentElement.setAttribute("data-bs-theme", theme);
}
}
Expand All @@ -63,7 +66,7 @@ window.Network = {
function handler() {
interop.invokeMethodAsync("Network.StatusChanged", navigator.onLine);
}

window.addEventListener('online', handler);
window.addEventListener('offline', handler);

Expand Down Expand Up @@ -133,13 +136,13 @@ window.PullToRefresh = {
Initialize: function (interop) {
const container = document.body;
const listenerOptions = { passive: true };

const prerequisities = () => !document.querySelector(".modal.fade.show") && document.querySelector("nav.navbar-dark .navbar-collapse.collapse");

refreshClosure = (() => {
const treshold = 200;
const $ui = $(".refresher");

let _isActive = false;
let _startX;
let _startY;
Expand All @@ -151,7 +154,7 @@ window.PullToRefresh = {
_startY = 0;
_lastDeltaX = 0;
_lastDeltaY = 0;

if (document.scrollingElement.scrollTop === 0 && prerequisities()) {
_startX = Math.floor(e.touches[0].pageX);
_startY = Math.floor(e.touches[0].pageY);
Expand All @@ -175,19 +178,19 @@ window.PullToRefresh = {
if (_isActive && _lastDeltaY > treshold && _lastDeltaX < (treshold / 2) && prerequisities()) {
interop.invokeMethodAsync("PullToRefresh.Pulled");
}

$ui.removeClass("visible");
};

return { start, move, end };
})();

swipeClosure = (() => {
const tresholdX = 100;
const tresholdY = 100;
const $leftUi = $(".swipe-left");
const $rightUi = $(".swipe-right");

let _isActive = false;
let _startX;
let _startY;
Expand Down Expand Up @@ -215,15 +218,15 @@ window.PullToRefresh = {
_startY = 0;
_lastDeltaX = 0;
_lastDeltaY = 0;

if (prerequisities()) {
_startX = Math.floor(e.touches[0].pageX);
_startY = Math.floor(e.touches[0].pageY);
if (_startX < (tresholdX / 2)) {
_isActive = 1;
return;
}

if (window.innerWidth - _startX < (tresholdX / 2)) {
_isActive = 2;
return;
Expand Down Expand Up @@ -269,7 +272,7 @@ window.PullToRefresh = {
swapLeftIcon(false);
swapRightIcon(false);
};

const end = () => {
$leftUi.css("margin-left", 0);
$rightUi.css("margin-right", 0);
Expand Down

0 comments on commit d7e779e

Please sign in to comment.