iamphill / Bootstrap-Offcanvas

:zap: Offcanvas menu built with Bootstrap
MIT License
366 stars 111 forks source link

Add jQuery plugin method. #66

Closed patorash closed 6 years ago

patorash commented 7 years ago

I want use Bootstrap-Offcanvas with turbolinks5. But Bootstrap-Offcanvas not working with turbolinks5. Because Bootstrap-Offcanvas execute only $(document).ready timing.

I add jQuery plugin method to Bootstrap-Offcanvas.

$.fn.bootstrapOffcanvas = ->
  elements = this
  elements.each -> new Offcanvas($(this))

How to use

$ ->
  $('[data-toggle="offcanvas"]').bootstrapOffcanvas()

How to use with turbolinks

document.addEventListener 'turbolinks:load', (event) ->
  $('[data-toggle="offcanvas"]').bootstrapOffcanvas()
document.addEventLitener 'turbolinks:beforeCache', (event) ->
  $("#js-bootstrap-offcanvas").trigger("offcanvas.close")
elfin-sbreuers commented 7 years ago

+1 for having a plugin version that can be used dynamically, e.g. in projects that use ember to build the html scaffold.

iamphill commented 6 years ago

This is now in master 👍 thanks @patorash