Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for closing on click and edge slide in options. #10

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function Slideout(options) {
this._duration = parseInt(options.duration, 10) || 300;
this._tolerance = parseInt(options.tolerance, 10) || 70;
this._padding = parseInt(options.padding, 10) || 256;
this._closeOnClick = options.closeOnClick || false;
this._grabWidth = parseInt(options.grabWidth, 10) || 0;

// Init touch events
this._initTouchEvents();
Expand Down Expand Up @@ -154,14 +156,25 @@ Slideout.prototype._initTouchEvents = function() {
}
});

if (this._closeOnClick) {
/**
* Close menu when panel is clicked while open
*/
this.panel.addEventListener('click', function() {
if (self.isOpen) { self.close(); }
});
}

/**
* Resets values on touchstart
*/
this.panel.addEventListener(touch.start, function(eve) {
self._moved = false;
self._opening = false;
self._startOffsetX = eve.touches[0].pageX;
self._preventOpen = (!self.isOpen() && self.menu.clientWidth !== 0);

var offset = eve.touches[0].pageX;
self._startOffsetX = offset;
self._preventOpen = (!self.isOpen() && (self.menu.clientWidth !== 0 || (self._grabWidth && offset > self._grabWidth)));
});

/**
Expand Down