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

stayOpen and stayClose API #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ meny.open();

meny.close();

meny.stayOpen(); // always open, pass a boolean parameter 'false' to revert

meny.stayClose(); // always close, pass a boolean parameter 'false' to revert

meny.isOpen(); // true/false

meny.destroy(); // revert original DOM state, unbind events
Expand Down
41 changes: 39 additions & 2 deletions js/meny.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var Meny = {
touchMoveX = null,
touchMoveY = null,
isOpen = false,
_stayOpen = false,
_stayClose = false,
isMouseDown = false;

// Precalculated transform and style states
Expand Down Expand Up @@ -343,7 +345,7 @@ var Meny = {
* Expands the menu.
*/
function open() {
if( !isOpen ) {
if( !isOpen && !_stayClose ) {
isOpen = true;

Meny.addClass( dom.wrapper, 'meny-active' );
Expand Down Expand Up @@ -381,7 +383,7 @@ var Meny = {
* Collapses the menu.
*/
function close() {
if( isOpen ) {
if( isOpen && !_stayOpen ) {
isOpen = false;

Meny.removeClass( dom.wrapper, 'meny-active' );
Expand Down Expand Up @@ -604,6 +606,38 @@ var Meny = {
}
}

function stayOpen(state) {
if( typeof state !== 'undefined' ) {
_stayOpen = state;
}
else {
_stayOpen = true;
}

//revert stay close to false state
if( _stayClose ) {
_stayClose = false;
}

return true;
}

function stayClose(state) {
if( typeof state !== 'undefined' ) {
_stayClose = state;
}
else {
_stayClose = true;
}

//revert stay open to false state
if( _stayOpen ) {
_stayOpen = false;
}

return true;
}


/// API: ///////////////////////////////////

Expand All @@ -614,6 +648,9 @@ var Meny = {
close: close,
destroy: destroy,

stayOpen: stayOpen,
stayClose: stayClose,

isOpen: function() {
return isOpen;
},
Expand Down