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

Added public reposition method and escCloseAll option #8

Closed
wants to merge 3 commits 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
51 changes: 31 additions & 20 deletions jquery.bpopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
id = prefix + w.data('bPopup') + '__';
close();
};

$popup.reposition = function() {
reposition();
}

return $popup.each(function() {
if ($(this).data('bPopup')) return; //POPUP already exists?
Expand Down Expand Up @@ -131,6 +135,25 @@

return false; // Prevent default
}
function reposition() {
inside = insideWindow();
if(inside){
clearTimeout(debounce);
debounce = setTimeout(function(){
calPosition();
$popup
.dequeue()
.each(function() {
if(fixedPosStyle) {
$(this).css({ 'left': hPos, 'top': vPos });
}
else {
$(this).animate({ 'left': o.follow[0] ? getLeft(true) : 'auto', 'top': o.follow[1] ? getTop(true) : 'auto' }, o.followSpeed, o.followEasing);
}
});
}, 50);
}
}
//Eksperimental
function recenter(content){
var _width = content.width(), _height = content.height(), css = {};
Expand Down Expand Up @@ -163,7 +186,7 @@
}
function bindEvents() {
w.data('bPopup', popups);
$popup.delegate('.bClose, .' + o.closeClass, 'click.'+id, close); // legacy, still supporting the close class bClose
$popup.on('click', '.bClose, .' + o.closeClass, close); // legacy, still supporting the close class bClose

if (o.modalClose) {
$('.b-modal.'+id).css('cursor', 'pointer').bind('click', close);
Expand All @@ -179,29 +202,16 @@
.animate({ 'left': o.follow[0] ? getLeft(!fixedPosStyle) : 'auto', 'top': o.follow[1] ? getTop(!fixedPosStyle) : 'auto' }, o.followSpeed, o.followEasing);
}
}).bind('resize.'+id, function() {
inside = insideWindow();
if(inside){
clearTimeout(debounce);
debounce = setTimeout(function(){
calPosition();
$popup
.dequeue()
.each(function() {
if(fixedPosStyle) {
$(this).css({ 'left': hPos, 'top': vPos });
}
else {
$(this).animate({ 'left': o.follow[0] ? getLeft(true) : 'auto', 'top': o.follow[1] ? getTop(true) : 'auto' }, o.followSpeed, o.followEasing);
}
});
}, 50);
}
reposition();
});
}
if (o.escClose) {
d.bind('keydown.'+id, function(e) {
if (e.which == 27) { //escape
close();
var topZIndex = o.zIndex + $(window).data('bPopup') + 1;
if (o.escCloseAll || $popup.css("zIndex") == topZIndex) {
close();
}
}
});
}
Expand All @@ -213,7 +223,7 @@
$('.b-modal.'+id).unbind('click');
d.unbind('keydown.'+id);
w.unbind('.'+id).data('bPopup', (w.data('bPopup')-1 > 0) ? w.data('bPopup')-1 : null);
$popup.undelegate('.bClose, .' + o.closeClass, 'click.'+id, close).data('bPopup', null);
$popup.off('click', '.bClose, .' + o.closeClass).data('bPopup', null);
}
function doTransition(open) {
switch (o.transition) {
Expand Down Expand Up @@ -293,6 +303,7 @@
, contentContainer: false
, easing: 'swing'
, escClose: true
, escCloseAll: true
, follow: [true, true] // x, y
, followEasing: 'swing'
, followSpeed: 500
Expand Down