Skip to content

Commit

Permalink
Properly calculate target element dimensions for other placements and…
Browse files Browse the repository at this point in the history
… not just default auto.
  • Loading branch information
pivica committed Jun 22, 2022
1 parent 57ca809 commit 853c1ac
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions js/offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@
return;
}

if (!this.$element.hasClass('in')) {
this.$element.css('visiblity', 'hidden !important').addClass('in')
}

var horizontal = $(window).width() / this.$element.width();
var vertical = $(window).height() / this.$element.height();
Expand All @@ -135,10 +132,6 @@
}

this.placement = horizontal >= vertical ? ab('left', 'right') : ab('top', 'bottom');

if (this.$element.css('visibility') === 'hidden !important') {
this.$element.removeClass('in').css('visiblity', '');
}
};

OffCanvas.prototype.opposite = function (placement) {
Expand Down Expand Up @@ -243,8 +236,16 @@

this.state = 'slide-in';
this.$element.css('width', '');
// Show the element so we can properly calculate needed dimensions.
if (!this.$element.hasClass('in')) {
this.$element.css('visiblity', 'hidden !important').addClass('in');
}
this.calcPlacement();
this.setWidth();
// Hide the element after all needed calculations.
if (this.$element.css('visibility') === 'hidden !important') {
this.$element.removeClass('in').css('visiblity', '');
}

var elements = this.getCanvasElements();
var placement = this.placement;
Expand Down

0 comments on commit 853c1ac

Please sign in to comment.