Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Added open event
Browse files Browse the repository at this point in the history
  • Loading branch information
iamphill committed Mar 28, 2016
1 parent d2598be commit bd6f68e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
36 changes: 36 additions & 0 deletions dist/js/bootstrap.offcanvas.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/bootstrap.offcanvas.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/coffee/bootstrap.offcanvas.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@

@target.on 'offcanvas.close', (e) =>
@_close e

@target.on 'offcanvas.open', (e) =>
@_open e
else
# Just log a warning
console.warn 'Offcanvas: `data-target` attribute must be present.'
Expand Down Expand Up @@ -237,8 +240,23 @@

@bodyOverflow()

_open: (e) =>
e.preventDefault()
return if @target.is '.in'

@_sendEventsBefore()

# Toggle in class
@target.addClass 'in'
@element.addClass 'is-open'

@_navbarHeight()

@bodyOverflow()

_close: (e) =>
e.preventDefault()
return if @target.is ':not(.in)'

@_sendEventsBefore()

Expand Down
8 changes: 6 additions & 2 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
assert.ok(!$("#js-bootstrap-offcanvas").hasClass("in"), "Off-Canvas should not be visible");
});

test("Close event hides offcanvas", function (assert) {
assert.expect(1);
test("Events to show & hide offcanvas", function (assert) {
assert.expect(2);
$("#js-bootstrap-offcanvas").trigger("offcanvas.open");

assert.ok($("#js-bootstrap-offcanvas").hasClass("in"), "Off-Canvas should be visible");

$("#js-bootstrap-offcanvas").trigger("offcanvas.close");

assert.ok(!$("#js-bootstrap-offcanvas").hasClass("in"), "Off-Canvas should not be visible");
Expand Down

0 comments on commit bd6f68e

Please sign in to comment.