diff --git a/dist/js/bootstrap.offcanvas.js b/dist/js/bootstrap.offcanvas.js index c6c60f8..3a68ccf 100644 --- a/dist/js/bootstrap.offcanvas.js +++ b/dist/js/bootstrap.offcanvas.js @@ -168,42 +168,44 @@ target = this.element.attr('data-target') ? this.element.attr('data-target') : false; if (target) { this.target = $(target); - if (this.target.length && !this.target.hasClass('js-offcanvas-done')) { + if (this.target.length) { + if (!this.target.hasClass('js-offcanvas-done')) { + this.location = this.target.hasClass("navbar-offcanvas-right") ? "right" : "left"; + this.target.addClass(this._transformSupported() ? "offcanvas-transform js-offcanvas-done" : "offcanvas-position js-offcanvas-done"); + this.target.data('offcanvas', this); + this.target.on('transitionend', (function(_this) { + return function() { + if (_this.target.is(':not(.in)')) { + return _this.target.height(''); + } + }; + })(this)); + $(document).on("click", this._documentClicked); + if (this.target.hasClass('navbar-offcanvas-touch')) { + t = new OffcanvasTouch(this.element, this.target, this.location, this); + } + this.target.find(".dropdown-toggle").each(function() { + var d; + return d = new OffcanvasDropdown(this); + }); + this.target.on('offcanvas.toggle', (function(_this) { + return function(e) { + return _this._clicked(e); + }; + })(this)); + this.target.on('offcanvas.close', (function(_this) { + return function(e) { + return _this._close(e); + }; + })(this)); + this.target.on('offcanvas.open', (function(_this) { + return function(e) { + return _this._open(e); + }; + })(this)); + } this.element.addClass('js-offcanvas-has-events'); - this.location = this.target.hasClass("navbar-offcanvas-right") ? "right" : "left"; - this.target.addClass(this._transformSupported() ? "offcanvas-transform js-offcanvas-done" : "offcanvas-position js-offcanvas-done"); - this.target.data('offcanvas', this); this.element.on("click", this._clicked); - this.target.on('transitionend', (function(_this) { - return function() { - if (_this.target.is(':not(.in)')) { - return _this.target.height(''); - } - }; - })(this)); - $(document).on("click", this._documentClicked); - if (this.target.hasClass('navbar-offcanvas-touch')) { - t = new OffcanvasTouch(this.element, this.target, this.location, this); - } - this.target.find(".dropdown-toggle").each(function() { - var d; - return d = new OffcanvasDropdown(this); - }); - this.target.on('offcanvas.toggle', (function(_this) { - return function(e) { - return _this._clicked(e); - }; - })(this)); - this.target.on('offcanvas.close', (function(_this) { - return function(e) { - return _this._close(e); - }; - })(this)); - this.target.on('offcanvas.open', (function(_this) { - return function(e) { - return _this._open(e); - }; - })(this)); } } else { console.warn('Offcanvas: `data-target` attribute must be present.'); diff --git a/dist/js/bootstrap.offcanvas.min.js b/dist/js/bootstrap.offcanvas.min.js index 413b72e..293cc48 100644 --- a/dist/js/bootstrap.offcanvas.min.js +++ b/dist/js/bootstrap.offcanvas.min.js @@ -21,4 +21,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -(function(){var a=function(a,b){return function(){return a.apply(b,arguments)}};!function(b,c){var d,e,f;e=function(){function c(c){this.element=c,this._clickEvent=a(this._clickEvent,this),this.element=b(this.element),this.nav=this.element.closest(".nav"),this.dropdown=this.element.parent().find(".dropdown-menu"),this.element.on("click",this._clickEvent),this.nav.closest(".navbar-offcanvas").on("click",function(a){return function(){if(a.dropdown.is(".shown"))return a.dropdown.removeClass("shown").closest(".open").removeClass("open")}}(this))}return c.prototype._clickEvent=function(a){return this.dropdown.hasClass("shown")||a.preventDefault(),a.stopPropagation(),b(".dropdown-toggle").not(this.element).closest(".open").removeClass("open").find(".dropdown-menu").removeClass("shown"),this.dropdown.toggleClass("shown"),this.element.parent().toggleClass("open")},c}(),f=function(){function d(c,d,e,f){this.button=c,this.element=d,this.location=e,this.offcanvas=f,this._getFade=a(this._getFade,this),this._getCss=a(this._getCss,this),this._touchEnd=a(this._touchEnd,this),this._touchMove=a(this._touchMove,this),this._touchStart=a(this._touchStart,this),this.endThreshold=130,this.startThreshold=this.element.hasClass("navbar-offcanvas-right")?b("body").outerWidth()-60:20,this.maxStartThreshold=this.element.hasClass("navbar-offcanvas-right")?b("body").outerWidth()-20:60,this.currentX=0,this.fade=!!this.element.hasClass("navbar-offcanvas-fade"),b(document).on("touchstart",this._touchStart),b(document).on("touchmove",this._touchMove),b(document).on("touchend",this._touchEnd)}return d.prototype._touchStart=function(a){if(this.startX=a.originalEvent.touches[0].pageX,this.element.is(".in"))return this.element.height(b(c).outerHeight())},d.prototype._touchMove=function(a){var c;if(b(a.target).parents(".navbar-offcanvas").length>0)return!0;if(this.startX>this.startThreshold&&this.startX0||(d=!1,e=a.originalEvent.changedTouches[0].pageX,Math.abs(e)!==this.startX?(c=this.element.hasClass("navbar-offcanvas-right")?Math.abs(e)>this.endThreshold+50:ethis.endThreshold&&this.startX>this.startThreshold&&this.startX0)return!0;if(this.startX>this.startThreshold&&this.startX0||(d=!1,e=a.originalEvent.changedTouches[0].pageX,Math.abs(e)!==this.startX?(c=this.element.hasClass("navbar-offcanvas-right")?Math.abs(e)>this.endThreshold+50:ethis.endThreshold&&this.startX>this.startThreshold&&this.startX + if @target.is ':not(.in)' + @target.height '' - # Remove then height on transition end - @target.on 'transitionend', => - if @target.is ':not(.in)' - @target.height '' + # Click event on document + $(document).on "click", @_documentClicked - # Click event on document - $(document).on "click", @_documentClicked + # Should touch be added to this target + if @target.hasClass 'navbar-offcanvas-touch' + # Create touch class + t = new OffcanvasTouch @element, @target, @location, @ - # Should touch be added to this target - if @target.hasClass 'navbar-offcanvas-touch' - # Create touch class - t = new OffcanvasTouch @element, @target, @location, @ + # Get all dropdown menu links and create a class for them + @target.find(".dropdown-toggle").each -> + d = new OffcanvasDropdown @ - # Get all dropdown menu links and create a class for them - @target.find(".dropdown-toggle").each -> - d = new OffcanvasDropdown @ + # Listen for a triggered event + @target.on 'offcanvas.toggle', (e) => + @_clicked e - # Listen for a triggered event - @target.on 'offcanvas.toggle', (e) => - @_clicked e + @target.on 'offcanvas.close', (e) => + @_close e - @target.on 'offcanvas.close', (e) => - @_close e + @target.on 'offcanvas.open', (e) => + @_open e - @target.on 'offcanvas.open', (e) => - @_open e + # Add class to element to say it already has events + @element.addClass 'js-offcanvas-has-events' + + # Click event on element + @element.on "click", @_clicked else # Just log a warning console.warn 'Offcanvas: `data-target` attribute must be present.'