From a5a580bc1dbd595a1f9752f310a70df28a8b673b Mon Sep 17 00:00:00 2001 From: Martin Gotink Date: Thu, 2 May 2013 11:44:04 +0200 Subject: [PATCH 1/3] expose a reposition method to allow manual repositioning --- jquery.bpopup.js | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 38fd689..5a3a223 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -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? @@ -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 = {}; @@ -179,23 +202,7 @@ .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) { From 4f8c1a84ebfc2f9ef3a41df46ca2af0989bef7d8 Mon Sep 17 00:00:00 2001 From: Martin Gotink Date: Thu, 2 May 2013 11:54:14 +0200 Subject: [PATCH 2/3] Added escCloseAll option to control if all popups or only the topmost popup should be closed after pressing esc --- jquery.bpopup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 5a3a223..69ef51e 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -208,7 +208,10 @@ 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(); + } } }); } @@ -300,6 +303,7 @@ , contentContainer: false , easing: 'swing' , escClose: true + , escCloseAll: true , follow: [true, true] // x, y , followEasing: 'swing' , followSpeed: 500 From dc741b235df3ce2c92fc0306cf491905113cc54f Mon Sep 17 00:00:00 2001 From: Martin Gotink Date: Fri, 28 Jun 2013 09:03:55 +0200 Subject: [PATCH 3/3] Fix issue with (un)binding events --- jquery.bpopup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 69ef51e..6079608 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -186,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); @@ -223,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) {