From 07e07b842a1ed2b73729cf78c6348b445ce3db13 Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 13:21:24 +0300 Subject: [PATCH 01/11] Added beforeOpen and beforeClose callbacks Added beforeOpen and beforeClose callbacks --- jquery.bpopup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 1586abe..fcc59f0 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -104,6 +104,7 @@ }; function open(){ + triggerCall(o.beforeOpen); // MODAL OVERLAY if (o.modal) { $('
') @@ -130,6 +131,7 @@ }; function close() { + triggerCall(o.beforeClose); if (o.modal) { $('.b-modal.'+$popup.data('id')) .fadeTo(o.speed, 0, function() { @@ -358,7 +360,9 @@ , modal: true , modalClose: true , modalColor: '#000' + , beforeClose: false , onClose: false + , beforeOpen: false , onOpen: false , opacity: 0.7 , position: ['auto', 'auto'] // x, y, From 595b9e99eee9558e105328402b8acbe8918e9b91 Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 13:24:34 +0300 Subject: [PATCH 02/11] Updated minified version Updated minified version --- jquery.bpopup.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.min.js b/jquery.bpopup.min.js index bbc4f72..31ffa91 100644 --- a/jquery.bpopup.min.js +++ b/jquery.bpopup.min.js @@ -4,4 +4,4 @@ * @demo: http://dinbror.dk/bpopup * @version: 0.11.0.min ================================================================================*/ - (function(c){c.fn.bPopup=function(A,E){function L(){a.contentContainer=c(a.contentContainer||b);switch(a.content){case "iframe":var d=c('");d.appendTo(a.contentContainer);t=b.outerHeight(!0);u=b.outerWidth(!0);B();d.attr("src",a.loadUrl);l(a.loadCallback);break;case "image":B();c("").load(function(){l(a.loadCallback);F(c(this))}).attr("src",a.loadUrl).hide().appendTo(a.contentContainer);break;default:B(),c('
').load(a.loadUrl,a.loadData,function(d,b,e){l(a.loadCallback,b);F(c(this))}).hide().appendTo(a.contentContainer)}}function B(){a.modal&&c('
').css({backgroundColor:a.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:a.zIndex+v}).appendTo(a.appendTo).fadeTo(a.speed,a.opacity);C();b.data("bPopup",a).data("id",e).css({left:"slideIn"==a.transition||"slideBack"==a.transition?"slideBack"==a.transition?f.scrollLeft()+w:-1*(x+u):m(!(!a.follow[0]&&n||g)),position:a.positionStyle||"absolute",top:"slideDown"==a.transition||"slideUp"==a.transition?"slideUp"==a.transition?f.scrollTop()+y:z+-1*t:p(!(!a.follow[1]&&q||g)),"z-index":a.zIndex+v+1}).each(function(){a.appending&&c(this).appendTo(a.appendTo)});G(!0)}function r(){a.modal&&c(".b-modal."+b.data("id")).fadeTo(a.speed,0,function(){c(this).remove()});a.scrollBar||c("html").css("overflow","auto");c(".b-modal."+e).unbind("click");f.unbind("keydown."+e);k.unbind("."+e).data("bPopup",0=b.height()&&(f.height=b.height());c>=b.width()&&(f.width=b.width());t=b.outerHeight(!0);u=b.outerWidth(!0);C();a.contentContainer.css({height:"auto",width:"auto"});f.left=m(!(!a.follow[0]&&n||g));f.top=p(!(!a.follow[1]&&q||g));b.animate(f,250,function(){d.show();h=D()})}function M(){k.data("bPopup",v);b.delegate(".bClose, ."+a.closeClass,"click."+e,r);a.modalClose&&c(".b-modal."+e).css("cursor","pointer").bind("click",r);N||!a.follow[0]&&!a.follow[1]||k.bind("scroll."+e,function(){if(h.x||h.y){var d={};h.x&&(d.left=a.follow[0]?m(!g):"auto");h.y&&(d.top=a.follow[1]?p(!g):"auto");b.dequeue().animate(d,a.followSpeed,a.followEasing)}}).bind("resize."+e,function(){I()});a.escClose&&f.bind("keydown."+e,function(a){27==a.which&&r()})}function G(d){function c(e){b.css({display:"block",opacity:1}).animate(e,a.speed,a.easing,function(){K(d)})}switch(d?a.transition:a.transitionClose||a.transition){case "slideIn":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()-(u||b.outerWidth(!0))-200});break;case "slideBack":c({left:d?m(!(!a.follow[0]&&n||g)):f.scrollLeft()+w+200});break;case "slideDown":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()-(t||b.outerHeight(!0))-200});break;case "slideUp":c({top:d?p(!(!a.follow[1]&&q||g)):f.scrollTop()+y+200});break;default:b.stop().fadeTo(a.speed,d?1:0,function(){K(d)})}}function K(d){d?(M(),l(E),a.autoClose&&(H=setTimeout(r,a.autoClose))):(b.hide(),l(a.onClose),a.loadUrl&&(a.contentContainer.empty(),b.css({height:"auto",width:"auto"})))}function m(a){return a?x+f.scrollLeft():x}function p(a){return a?z+f.scrollTop():z}function l(a,e){c.isFunction(a)&&a.call(b,e)}function C(){z=q?a.position[1]:Math.max(0,(y-b.outerHeight(!0))/2-a.amsl);x=n?a.position[0]:(w-b.outerWidth(!0))/2;h=D()}function D(){return{x:w>b.outerWidth(!0),y:y>b.outerHeight(!0)}}c.isFunction(A)&&(E=A,A=null);var a=c.extend({},c.fn.bPopup.defaults,A);a.scrollBar||c("html").css("overflow","hidden");var b=this,f=c(document),k=c(window),y=k.height(),w=k.width(),N=/OS 6(_\d)+/i.test(navigator.userAgent),v=0,e,h,q,n,g,z,x,t,u,J,H;b.close=function(){r()};b.reposition=function(a){I(a)};return b.each(function(){c(this).data("bPopup")||(l(a.onOpen),v=(k.data("bPopup")||0)+1,e="__b-popup"+v+"__",q="auto"!==a.position[1],n="auto"!==a.position[0],g="fixed"===a.positionStyle,t=b.outerHeight(!0),u=b.outerWidth(!0),a.loadUrl?L():B())})};c.fn.bPopup.defaults={amsl:50,appending:!0,appendTo:"body",autoClose:!1,closeClass:"b-close",content:"ajax",contentContainer:!1,easing:"swing",escClose:!0,follow:[!0,!0],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:!1,loadData:!1,loadUrl:!1,modal:!0,modalClose:!0,modalColor:"#000",onClose:!1,onOpen:!1,opacity:.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:!0,speed:250,transition:"fadeIn",transitionClose:!1,zIndex:9997}})(jQuery); +(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){triggerCall(o.beforeOpen);if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",beforeClose:false,onClose:false,beforeOpen:false,onOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); From d779179a18fc13fd8f4305e2f04a5a6508212845 Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 14:01:09 +0300 Subject: [PATCH 03/11] Added afterOpen callback Added afterOpen callback --- jquery.bpopup.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index fcc59f0..ec63983 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -18,6 +18,10 @@ // OPTIONS var o = $.extend({}, $.fn.bPopup.defaults, options); + + if(o.afterOpen !== false){ + callback = o.afterOpen; + } // HIDE SCROLLBAR? if (!o.scrollBar) @@ -104,7 +108,6 @@ }; function open(){ - triggerCall(o.beforeOpen); // MODAL OVERLAY if (o.modal) { $('
') @@ -127,11 +130,10 @@ $(this).appendTo(o.appendTo); } }); - doTransition(true); + doTransition(true); }; function close() { - triggerCall(o.beforeClose); if (o.modal) { $('.b-modal.'+$popup.data('id')) .fadeTo(o.speed, 0, function() { @@ -294,6 +296,7 @@ autoCloseTO = setTimeout(close, o.autoClose); } } else { + triggerCall(o.beforeClose); $popup.hide(); triggerCall(o.onClose); if (o.loadUrl) { @@ -360,10 +363,10 @@ , modal: true , modalClose: true , modalColor: '#000' - , beforeClose: false , onClose: false - , beforeOpen: false + , beforeClose: false , onOpen: false + , afterOpen: false , opacity: 0.7 , position: ['auto', 'auto'] // x, y, , positionStyle: 'absolute'// absolute or fixed From 7a85997dcdfc6d66e0f63ca5e4817e7a4e55905f Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 14:02:48 +0300 Subject: [PATCH 04/11] Updated minified version Updated minified version --- jquery.bpopup.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.min.js b/jquery.bpopup.min.js index 31ffa91..9fa51af 100644 --- a/jquery.bpopup.min.js +++ b/jquery.bpopup.min.js @@ -4,4 +4,4 @@ * @demo: http://dinbror.dk/bpopup * @version: 0.11.0.min ================================================================================*/ -(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){triggerCall(o.beforeOpen);if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",beforeClose:false,onClose:false,beforeOpen:false,onOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); +(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{triggerCall(o.beforeClose);$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); From f2da193abde4e74085fe6666d8173562dbe1178e Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 14:07:31 +0300 Subject: [PATCH 05/11] Fixed beforeClose callback Fixed beforeClose callback --- jquery.bpopup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index ec63983..5356c54 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -134,6 +134,9 @@ }; function close() { + + triggerCall(o.beforeClose); + if (o.modal) { $('.b-modal.'+$popup.data('id')) .fadeTo(o.speed, 0, function() { @@ -296,7 +299,6 @@ autoCloseTO = setTimeout(close, o.autoClose); } } else { - triggerCall(o.beforeClose); $popup.hide(); triggerCall(o.onClose); if (o.loadUrl) { From 3e326be156aebf28bcf3ccf1f693fccc8f3f578f Mon Sep 17 00:00:00 2001 From: kouts Date: Thu, 11 Jun 2015 14:08:47 +0300 Subject: [PATCH 06/11] Updated minified version --- jquery.bpopup.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.min.js b/jquery.bpopup.min.js index 9fa51af..7131b96 100644 --- a/jquery.bpopup.min.js +++ b/jquery.bpopup.min.js @@ -4,4 +4,4 @@ * @demo: http://dinbror.dk/bpopup * @version: 0.11.0.min ================================================================================*/ -(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{triggerCall(o.beforeClose);$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); +(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); From 28948d4cda7a5c06dfe21a836e1a830b8bb875e0 Mon Sep 17 00:00:00 2001 From: kouts Date: Fri, 3 Jul 2015 01:39:04 +0300 Subject: [PATCH 07/11] Added autoOpen option Added autoOpen option (default false) --- jquery.bpopup.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index 5356c54..fd56309 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -57,6 +57,10 @@ $popup.close = function() { close(); }; + + $popup.open = function(){ + open(); + } $popup.reposition = function(animateSpeed) { reposition(animateSpeed); @@ -73,7 +77,10 @@ function init() { triggerCall(o.onOpen); popups = ($w.data('bPopup') || 0) + 1, id = prefix + popups + '__',fixedVPos = o.position[1] !== 'auto', fixedHPos = o.position[0] !== 'auto', fixedPosStyle = o.positionStyle === 'fixed', height = $popup.outerHeight(true), width = $popup.outerWidth(true); - o.loadUrl ? createContent() : open(); + if(o.autoOpen){ + o.loadUrl ? createContent() : open(); + } + // o.loadUrl ? createContent() : open(); }; function createContent() { @@ -349,6 +356,7 @@ amsl: 50 , appending: true , appendTo: 'body' + , autoOpen: false , autoClose: false , closeClass: 'b-close' , content: 'ajax' // ajax, iframe or image From eb57683f1cecbd64b708d7a68e09f3dd92a9fd5c Mon Sep 17 00:00:00 2001 From: kouts Date: Fri, 3 Jul 2015 01:40:32 +0300 Subject: [PATCH 08/11] Added autoOpen option Added autoOpen option (default false) --- jquery.bpopup.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.min.js b/jquery.bpopup.min.js index 7131b96..52d4ef1 100644 --- a/jquery.bpopup.min.js +++ b/jquery.bpopup.min.js @@ -4,4 +4,4 @@ * @demo: http://dinbror.dk/bpopup * @version: 0.11.0.min ================================================================================*/ -(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);o.loadUrl?createContent():open();}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); +(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.open=function(){open();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);if(o.autoOpen){o.loadUrl?createContent():open();}}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoOpen:false,autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); From b46d1970914143d28c0800a0309a4558c09db218 Mon Sep 17 00:00:00 2001 From: kouts Date: Wed, 15 Mar 2017 13:21:10 +0200 Subject: [PATCH 09/11] Fixed positionContainer option Removed positionContainer.offset().left from calcPosition method --- jquery.bpopup.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index fd56309..e0de164 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -1,3 +1,4 @@ +/* bpopup_fix_2.js */ /*=================================================================================================================== * @name: bPopup * @type: jQuery @@ -61,7 +62,11 @@ $popup.open = function(){ open(); } - + + $popup.destroy = function(){ + destroy(); + } + $popup.reposition = function(animateSpeed) { reposition(animateSpeed); }; @@ -117,10 +122,15 @@ function open(){ // MODAL OVERLAY if (o.modal) { - $('
') - .css({backgroundColor: o.modalColor, position: 'fixed', top: 0, right:0, bottom:0, left: 0, opacity: 0, zIndex: o.zIndex + popups}) - .appendTo(o.appendTo) - .fadeTo(o.speed, o.opacity); + if($('div.b-modal.'+id).length){ + // console.log('b-modal exists'); + // Do nothing - b-modal (overlay) already exists + }else{ + $('
') + .css({backgroundColor: o.modalColor, position: 'fixed', top: 0, right:0, bottom:0, left: 0, opacity: 0, zIndex: o.zIndex + popups}) + .appendTo(o.appendTo) + .fadeTo(o.speed, o.opacity); + } } // POPUP @@ -158,6 +168,14 @@ return false; // Prevent default }; + + function destroy(){ + if (o.modal) { + $('.b-modal.'+$popup.data('id')).remove(); + } + unbindEvents(); + $popup.remove(); + }; function reposition(animateSpeed){ wH = windowHeight(); @@ -328,9 +346,13 @@ }; function calcPosition(){ - vPos = fixedVPos ? o.position[1] : Math.max(0, ((wH- $popup.outerHeight(true)) / 2) - o.amsl) - , hPos = fixedHPos ? o.position[0] : (wW - $popup.outerWidth(true)) / 2 - , inside = insideWindow(); + vPos = fixedVPos ? o.position[1] : Math.max(0, ((wH- $popup.outerHeight(true)) / 2) - o.amsl); + if(o.positionContainer != null){ + hPos = fixedHPos ? o.position[0] : (o.positionContainer.outerWidth() - $popup.outerWidth(true)) / 2; + }else{ + hPos = fixedHPos ? o.position[0] : (wW - $popup.outerWidth(true)) / 2; + } + inside = insideWindow(); }; function insideWindow(){ @@ -385,5 +407,6 @@ , transition: 'fadeIn' //transitions: fadeIn, slideDown, slideIn, slideBack , transitionClose: false , zIndex: 9997 // popup gets z-index 9999, modal overlay 9998 + , positionContainer:null }; })(jQuery); From 5ce27b8faf189c6f87ffadf5fcaf2bbafb715118 Mon Sep 17 00:00:00 2001 From: kouts Date: Wed, 15 Mar 2017 13:22:29 +0200 Subject: [PATCH 10/11] Updated title to fix_3 Updated title to fix_3 --- jquery.bpopup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.js b/jquery.bpopup.js index e0de164..68056fb 100644 --- a/jquery.bpopup.js +++ b/jquery.bpopup.js @@ -1,4 +1,4 @@ -/* bpopup_fix_2.js */ +/* bpopup_fix_3.js */ /*=================================================================================================================== * @name: bPopup * @type: jQuery From e250d9e1d1bddec5a15d12cce3455d692d22a33d Mon Sep 17 00:00:00 2001 From: kouts Date: Wed, 15 Mar 2017 13:23:47 +0200 Subject: [PATCH 11/11] Update jquery.bpopup.min.js --- jquery.bpopup.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.bpopup.min.js b/jquery.bpopup.min.js index 52d4ef1..6418e0c 100644 --- a/jquery.bpopup.min.js +++ b/jquery.bpopup.min.js @@ -4,4 +4,4 @@ * @demo: http://dinbror.dk/bpopup * @version: 0.11.0.min ================================================================================*/ -(function($){$.fn.bPopup=function(options,callback){if($.isFunction(options)){callback=options;options=null;}var o=$.extend({},$.fn.bPopup.defaults,options);if(o.afterOpen!==false){callback=o.afterOpen;}if(!o.scrollBar){$("html").css("overflow","hidden");}var $popup=this,d=$(document),w=window,$w=$(w),wH=windowHeight(),wW=windowWidth(),prefix="__b-popup",isIOS6X=(/OS 6(_\d)+/i).test(navigator.userAgent),buffer=200,popups=0,id,inside,fixedVPos,fixedHPos,fixedPosStyle,vPos,hPos,height,width,debounce,autoCloseTO;$popup.close=function(){close();};$popup.open=function(){open();};$popup.reposition=function(animateSpeed){reposition(animateSpeed);};return $popup.each(function(){if($(this).data("bPopup")){return;}init();});function init(){triggerCall(o.onOpen);popups=($w.data("bPopup")||0)+1,id=prefix+popups+"__",fixedVPos=o.position[1]!=="auto",fixedHPos=o.position[0]!=="auto",fixedPosStyle=o.positionStyle==="fixed",height=$popup.outerHeight(true),width=$popup.outerWidth(true);if(o.autoOpen){o.loadUrl?createContent():open();}}function createContent(){o.contentContainer=$(o.contentContainer||$popup);switch(o.content){case ("iframe"):var iframe=$('");iframe.appendTo(o.contentContainer);height=$popup.outerHeight(true);width=$popup.outerWidth(true);open();iframe.attr("src",o.loadUrl);triggerCall(o.loadCallback);break;case ("image"):open();$("").load(function(){triggerCall(o.loadCallback);recenter($(this));}).attr("src",o.loadUrl).hide().appendTo(o.contentContainer);break;default:open();$('
').load(o.loadUrl,o.loadData,function(response,status,xhr){triggerCall(o.loadCallback,status);recenter($(this));}).hide().appendTo(o.contentContainer);break;}}function open(){if(o.modal){$('
').css({backgroundColor:o.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:o.zIndex+popups}).appendTo(o.appendTo).fadeTo(o.speed,o.opacity);}calcPosition();$popup.data("bPopup",o).data("id",id).css({"left":o.transition=="slideIn"||o.transition=="slideBack"?(o.transition=="slideBack"?d.scrollLeft()+wW:(hPos+width)*-1):getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),"position":o.positionStyle||"absolute","top":o.transition=="slideDown"||o.transition=="slideUp"?(o.transition=="slideUp"?d.scrollTop()+wH:vPos+height*-1):getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)),"z-index":o.zIndex+popups+1}).each(function(){if(o.appending){$(this).appendTo(o.appendTo);}});doTransition(true);}function close(){triggerCall(o.beforeClose);if(o.modal){$(".b-modal."+$popup.data("id")).fadeTo(o.speed,0,function(){$(this).remove();});}unbindEvents();clearTimeout(autoCloseTO);doTransition();return false;}function reposition(animateSpeed){wH=windowHeight();wW=windowWidth();inside=insideWindow();if(inside.x||inside.y){clearTimeout(debounce);debounce=setTimeout(function(){calcPosition();animateSpeed=animateSpeed||o.followSpeed;var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(true):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(true):"auto";}$popup.dequeue().each(function(){if(fixedPosStyle){$(this).css({"left":hPos,"top":vPos});}else{$(this).animate(css,animateSpeed,o.followEasing);}});},50);}}function recenter(content){var _width=content.width(),_height=content.height(),css={};o.contentContainer.css({height:_height,width:_width});if(_height>=$popup.height()){css.height=$popup.height();}if(_width>=$popup.width()){css.width=$popup.width();}height=$popup.outerHeight(true),width=$popup.outerWidth(true);calcPosition();o.contentContainer.css({height:"auto",width:"auto"});css.left=getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)),css.top=getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle));$popup.animate(css,250,function(){content.show();inside=insideWindow();});}function bindEvents(){$w.data("bPopup",popups);$popup.delegate(".bClose, ."+o.closeClass,"click."+id,close);if(o.modalClose){$(".b-modal."+id).css("cursor","pointer").bind("click",close);}if(!isIOS6X&&(o.follow[0]||o.follow[1])){$w.bind("scroll."+id,function(){if(inside.x||inside.y){var css={};if(inside.x){css.left=o.follow[0]?getLeftPos(!fixedPosStyle):"auto";}if(inside.y){css.top=o.follow[1]?getTopPos(!fixedPosStyle):"auto";}$popup.dequeue().animate(css,o.followSpeed,o.followEasing);}}).bind("resize."+id,function(){reposition();});}if(o.escClose){d.bind("keydown."+id,function(e){if(e.which==27){close();}});}}function unbindEvents(){if(!o.scrollBar){$("html").css("overflow","auto");}$(".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);}function doTransition(open){switch(open?o.transition:o.transitionClose||o.transition){case"slideIn":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()-(width||$popup.outerWidth(true))-buffer});break;case"slideBack":animate({left:open?getLeftPos(!(!o.follow[0]&&fixedHPos||fixedPosStyle)):d.scrollLeft()+wW+buffer});break;case"slideDown":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()-(height||$popup.outerHeight(true))-buffer});break;case"slideUp":animate({top:open?getTopPos(!(!o.follow[1]&&fixedVPos||fixedPosStyle)):d.scrollTop()+wH+buffer});break;default:$popup.stop().fadeTo(o.speed,open?1:0,function(){onCompleteCallback(open);});}function animate(css){$popup.css({display:"block",opacity:1}).animate(css,o.speed,o.easing,function(){onCompleteCallback(open);});}}function onCompleteCallback(open){if(open){bindEvents();triggerCall(callback);if(o.autoClose){autoCloseTO=setTimeout(close,o.autoClose);}}else{$popup.hide();triggerCall(o.onClose);if(o.loadUrl){o.contentContainer.empty();$popup.css({height:"auto",width:"auto"});}}}function getLeftPos(includeScroll){return includeScroll?hPos+d.scrollLeft():hPos;}function getTopPos(includeScroll){return includeScroll?vPos+d.scrollTop():vPos;}function triggerCall(func,arg){$.isFunction(func)&&func.call($popup,arg);}function calcPosition(){vPos=fixedVPos?o.position[1]:Math.max(0,((wH-$popup.outerHeight(true))/2)-o.amsl),hPos=fixedHPos?o.position[0]:(wW-$popup.outerWidth(true))/2,inside=insideWindow();}function insideWindow(){return{x:wW>$popup.outerWidth(true),y:wH>$popup.outerHeight(true)};}function windowHeight(){return $w.height();}function windowWidth(){return $w.width();}};$.fn.bPopup.defaults={amsl:50,appending:true,appendTo:"body",autoOpen:false,autoClose:false,closeClass:"b-close",content:"ajax",contentContainer:false,easing:"swing",escClose:true,follow:[true,true],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:false,loadData:false,loadUrl:false,modal:true,modalClose:true,modalColor:"#000",onClose:false,beforeClose:false,onOpen:false,afterOpen:false,opacity:0.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:true,speed:250,transition:"fadeIn",transitionClose:false,zIndex:9997};})(jQuery); +!function(o){"use strict";o.fn.bPopup=function(t,n){function e(){w(y.onOpen),M=(L.data("bPopup")||0)+1,T=E+M+"__",x="auto"!==y.position[1],P="auto"!==y.position[0],U="fixed"===y.positionStyle,I=H.outerHeight(!0),S=H.outerWidth(!0),y.autoOpen&&(y.loadUrl?i():a())}function i(){switch(y.contentContainer=o(y.contentContainer||H),y.content){case"iframe":var t=o('");t.appendTo(y.contentContainer),I=H.outerHeight(!0),S=H.outerWidth(!0),a(),t.attr("src",y.loadUrl),w(y.loadCallback);break;case"image":a(),o("").load(function(){w(y.loadCallback),r(o(this))}).attr("src",y.loadUrl).hide().appendTo(y.contentContainer);break;default:a(),o('
').load(y.loadUrl,y.loadData,function(t,n){w(y.loadCallback,n),r(o(this))}).hide().appendTo(y.contentContainer)}}function a(){y.modal&&(o("div.b-modal."+T).length||o('
').css({backgroundColor:y.modalColor,position:"fixed",top:0,right:0,bottom:0,left:0,opacity:0,zIndex:y.zIndex+M}).appendTo(y.appendTo).fadeTo(y.speed,y.opacity)),m(),H.data("bPopup",y).data("id",T).css({left:"slideIn"==y.transition||"slideBack"==y.transition?"slideBack"==y.transition?_.scrollLeft()+A:-1*(W+S):h(!(!y.follow[0]&&P||U)),position:y.positionStyle||"absolute",top:"slideDown"==y.transition||"slideUp"==y.transition?"slideUp"==y.transition?_.scrollTop()+j:O+-1*I:b(!(!y.follow[1]&&x||U)),"z-index":y.zIndex+M+1}).each(function(){y.appending&&o(this).appendTo(y.appendTo)}),p(!0)}function l(){return w(y.beforeClose),y.modal&&o(".b-modal."+H.data("id")).fadeTo(y.speed,0,function(){o(this).remove()}),u(),clearTimeout(B),p(),!1}function s(){y.modal&&o(".b-modal."+H.data("id")).remove(),u(),H.remove()}function d(t){j=g(),A=k(),v=C(),(v.x||v.y)&&(clearTimeout(z),z=setTimeout(function(){m(),t=t||y.followSpeed;var n={};v.x&&(n.left=y.follow[0]?h(!0):"auto"),v.y&&(n.top=y.follow[1]?b(!0):"auto"),H.dequeue().each(function(){U?o(this).css({left:W,top:O}):o(this).animate(n,t,y.followEasing)})},50))}function r(o){var t=o.width(),n=o.height(),e={};y.contentContainer.css({height:n,width:t}),n>=H.height()&&(e.height=H.height()),t>=H.width()&&(e.width=H.width()),I=H.outerHeight(!0),S=H.outerWidth(!0),m(),y.contentContainer.css({height:"auto",width:"auto"}),e.left=h(!(!y.follow[0]&&P||U)),e.top=b(!(!y.follow[1]&&x||U)),H.animate(e,250,function(){o.show(),v=C()})}function c(){L.data("bPopup",M),H.delegate(".bClose, ."+y.closeClass,"click."+T,l),y.modalClose&&o(".b-modal."+T).css("cursor","pointer").bind("click",l),q||!y.follow[0]&&!y.follow[1]||L.bind("scroll."+T,function(){if(v.x||v.y){var o={};v.x&&(o.left=y.follow[0]?h(!U):"auto"),v.y&&(o.top=y.follow[1]?b(!U):"auto"),H.dequeue().animate(o,y.followSpeed,y.followEasing)}}).bind("resize."+T,function(){d()}),y.escClose&&_.bind("keydown."+T,function(o){27==o.which&&l()})}function u(){y.scrollBar||o("html").css("overflow","auto"),o(".b-modal."+T).unbind("click"),_.unbind("keydown."+T),L.unbind("."+T).data("bPopup",L.data("bPopup")-1>0?L.data("bPopup")-1:null),H.undelegate(".bClose, ."+y.closeClass,"click."+T,l).data("bPopup",null)}function p(o){function t(t){H.css({display:"block",opacity:1}).animate(t,y.speed,y.easing,function(){f(o)})}switch(o?y.transition:y.transitionClose||y.transition){case"slideIn":t({left:o?h(!(!y.follow[0]&&P||U)):_.scrollLeft()-(S||H.outerWidth(!0))-F});break;case"slideBack":t({left:o?h(!(!y.follow[0]&&P||U)):_.scrollLeft()+A+F});break;case"slideDown":t({top:o?b(!(!y.follow[1]&&x||U)):_.scrollTop()-(I||H.outerHeight(!0))-F});break;case"slideUp":t({top:o?b(!(!y.follow[1]&&x||U)):_.scrollTop()+j+F});break;default:H.stop().fadeTo(y.speed,o?1:0,function(){f(o)})}}function f(o){o?(c(),w(n),y.autoClose&&(B=setTimeout(l,y.autoClose))):(H.hide(),w(y.onClose),y.loadUrl&&(y.contentContainer.empty(),H.css({height:"auto",width:"auto"})))}function h(o){return o?W+_.scrollLeft():W}function b(o){return o?O+_.scrollTop():O}function w(t,n){o.isFunction(t)&&t.call(H,n)}function m(){O=x?y.position[1]:Math.max(0,(j-H.outerHeight(!0))/2-y.amsl),W=null!=y.positionContainer?P?y.position[0]:(y.positionContainer.outerWidth()-H.outerWidth(!0))/2:P?y.position[0]:(A-H.outerWidth(!0))/2,v=C()}function C(){return{x:A>H.outerWidth(!0),y:j>H.outerHeight(!0)}}function g(){return L.height()}function k(){return L.width()}o.isFunction(t)&&(n=t,t=null);var y=o.extend({},o.fn.bPopup.defaults,t);y.afterOpen!==!1&&(n=y.afterOpen),y.scrollBar||o("html").css("overflow","hidden");var T,v,x,P,U,O,W,I,S,z,B,H=this,_=o(document),D=window,L=o(D),j=g(),A=k(),E="__b-popup",q=/OS 6(_\d)+/i.test(navigator.userAgent),F=200,M=0;return H.close=function(){l()},H.open=function(){a()},H.destroy=function(){s()},H.reposition=function(o){d(o)},H.each(function(){o(this).data("bPopup")||e()})},o.fn.bPopup.defaults={amsl:50,appending:!0,appendTo:"body",autoOpen:!1,autoClose:!1,closeClass:"b-close",content:"ajax",contentContainer:!1,easing:"swing",escClose:!0,follow:[!0,!0],followEasing:"swing",followSpeed:500,iframeAttr:'scrolling="no" frameborder="0"',loadCallback:!1,loadData:!1,loadUrl:!1,modal:!0,modalClose:!0,modalColor:"#000",onClose:!1,beforeClose:!1,onOpen:!1,afterOpen:!1,opacity:.7,position:["auto","auto"],positionStyle:"absolute",scrollBar:!0,speed:250,transition:"fadeIn",transitionClose:!1,zIndex:9997,positionContainer:null}}(jQuery);