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

Add toggle functionality. #130

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion demo/assets/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var addEvent = function addEvent(element, eventName, func) {
};

addEvent(document.getElementById('open-left'), 'click', function(){
snapper.open('left');
snapper.toggle('left');
});

/* Prevent Safari opening links when viewing as a Mobile App */
Expand Down
36 changes: 26 additions & 10 deletions snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
cache.animatingInterval = setInterval(function() {
utils.dispatchEvent('animating');
}, 1);

utils.events.addEvent(settings.element, utils.transitionCallback(), action.translate.easeCallback);
action.translate.x(n);
}
Expand All @@ -219,15 +219,15 @@
if( (settings.disable==='left' && n>0) ||
(settings.disable==='right' && n<0)
){ return; }

if( !settings.hyperextensible ){
if( n===settings.maxPosition || n>settings.maxPosition ){
n=settings.maxPosition;
} else if( n===settings.minPosition || n<settings.minPosition ){
n=settings.minPosition;
}
}

n = parseInt(n, 10);
if(isNaN(n)){
n = 0;
Expand Down Expand Up @@ -261,25 +261,25 @@
// No drag on ignored elements
var target = e.target ? e.target : e.srcElement,
ignoreParent = utils.parentUntil(target, 'data-snap-ignore');

if (ignoreParent) {
utils.dispatchEvent('ignore');
return;
}


if(settings.dragger){
var dragParent = utils.parentUntil(target, settings.dragger);

// Only use dragger if we're in a closed state
if( !dragParent &&
(cache.translation !== settings.minPosition &&
if( !dragParent &&
(cache.translation !== settings.minPosition &&
cache.translation !== settings.maxPosition
)){
return;
}
}

utils.dispatchEvent('start');
settings.element.style[cache.vendor+'Transition'] = '';
cache.isDragging = true;
Expand Down Expand Up @@ -498,6 +498,19 @@
utils.dispatchEvent('close');
action.translate.easeTo(0);
};

this.toggle = function(side) {
var state = this.state().state;
if (state === 'left' || state === 'right'){
this.close();
}
else{
this.open(side);
}
};



this.expand = function(side){
var to = win.innerWidth || doc.documentElement.clientWidth;

Expand Down Expand Up @@ -552,6 +565,9 @@
info: cache.simpleStates
};
};



init(userOpts);
};
if ((typeof module !== 'undefined') && module.exports) {
Expand Down