Skip to content

Commit

Permalink
Fix bug caused by menu clone (fixes #484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minstel committed Jun 10, 2018
1 parent 38ac65d commit cce8a6d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions js/offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if (this.options.autohide && !this.options.modal) {
var eventName = (navigator.userAgent.match(/(iPad|iPhone)/i) === null) ? 'click' : 'touchstart'
$(document).on('click touchstart', $.proxy(this.autohide, this))
}
}

// Backdrop is added to dropdown on it's open, if device is touchable (or desctop FF, https://github.com/twbs/bootstrap/issues/13748)
// and dropdown is not inside .navbar-nav. So we remove it
Expand All @@ -49,7 +49,7 @@
this.options.disableScrolling = this.options.disablescrolling
delete this.options.disablescrolling
}

if (this.options.toggle) this.toggle()
}

Expand All @@ -59,7 +59,9 @@
autohide: true,
recalc: true,
disableScrolling: true,
modal: false
modal: false,
backdrop: false,
exclude: null
}

OffCanvas.prototype.setWidth = function () {
Expand Down Expand Up @@ -379,9 +381,10 @@
}

OffCanvas.prototype.autohide = function (e) {
if ($(e.target).closest(this.$element).length === 0) this.hide()
var target = $(e.target);
if (!target.hasClass('dropdown-backdrop') && $(e.target).closest(this.$element).length === 0) this.hide()
var $target = $(e.target);
var doHide = !$target.hasClass('dropdown-backdrop') && $target.closest(this.$element).length === 0;

if (doHide) this.hide()
}

// OFFCANVAS PLUGIN DEFINITION
Expand All @@ -395,6 +398,10 @@
var data = $this.data('bs.offcanvas')
var options = $.extend({}, OffCanvas.DEFAULTS, $this.data(), typeof option === 'object' && option)

//In case if user does smth like $('.navmenu-fixed-left').offcanvas('hide'),
//thus selecting also menu clone (that can cause issues)
if ($this.hasClass('offcanvas-clone')) return

if (!data) $this.data('bs.offcanvas', (data = new OffCanvas(this, options)))
if (typeof option === 'string') data[option]()
})
Expand Down

0 comments on commit cce8a6d

Please sign in to comment.