Browse files

Fix iframe autosize for Webkit

  • Loading branch information...
1 parent 590bb90 commit e25352c3bf19028bde60c0fce87d29f08a357d73 @fancyapps committed Feb 19, 2012
Showing with 13 additions and 9 deletions.
  1. +10 −6 source/jquery.fancybox.js
  2. +3 −3 source/jquery.fancybox.pack.js
View
16 source/jquery.fancybox.js
@@ -387,7 +387,7 @@
// Unbind the keyboard / clicking actions
unbindEvents: function () {
if (F.wrap) {
- F.wrap.unbind('.fb');
+ F.wrap.unbind('.fb');
}
D.unbind('.fb');
@@ -798,7 +798,7 @@
F.showLoading();
- content.data('ready', false).bind('load', function() {
+ content.data('ready', false).appendTo(F.inner).bind('load', function() {
var iframe = $(this), height;
try {
@@ -813,6 +813,7 @@
}
if (iframe.data('ready') === false) {
+
F.hideLoading();
if (height) {
@@ -824,10 +825,10 @@
iframe.data('ready', true);
} else if (height) {
- F.update();
+ F.update();
}
- }).appendTo(F.inner).attr('src', current.href);
+ }).attr('src', current.href);
return;
@@ -857,7 +858,7 @@
F.bindEvents();
F._preloadImages();
- F.transitions[ F.isOpened ? F.current.nextMethod : F.current.openMethod ]();
+ F.transitions[ F.isOpened ? F.current.nextMethod : F.current.openMethod ]();
},
_setDimension: function () {
@@ -1160,7 +1161,9 @@
F.outer.add(F.inner).width('auto').height('auto');
- wrap.css(startPos).show().animate(endPos, {
+ wrap.css(startPos).show();
+
+ wrap.animate(endPos, {
duration: current.openSpeed,
easing: current.openEasing,
step: this.step,
@@ -1169,6 +1172,7 @@
} else {
wrap.css($.extend({}, dim, F._getPosition()));
+
if (current.openEffect === 'fade') {
wrap.fadeIn(current.openSpeed, F._afterZoomIn);
View
6 source/jquery.fancybox.pack.js
@@ -17,16 +17,16 @@ a._afterLoad()};a.imgPreload.onerror=function(){this.onload=this.onerror=null;a.
1;g<=Math.min(c.preload,d-1);g++)if(f=b[(c.index+g)%d],f=e(f).attr("href")||f)(new Image).src=f},_afterLoad:function(){a.hideLoading();!a.coming||!1===a.trigger("afterLoad",a.current)?a.coming=!1:(a.isOpened?(e(".fancybox-item").remove(),a.wrap.stop(!0).removeClass("fancybox-opened"),a.inner.css("overflow","hidden"),a.transitions[a.current.prevMethod]()):(e(".fancybox-wrap").stop().trigger("onReset").remove(),a.trigger("afterClose")),a.unbindEvents(),a.isOpen=!1,a.current=a.coming,a.coming=null,a.wrap=
e(a.current.tpl.wrap).addClass("fancybox-"+(s?"mobile":"desktop")+" fancybox-tmp "+a.current.wrapCSS).appendTo("body"),a.outer=e(".fancybox-outer",a.wrap).css("padding",a.current.padding+"px"),a.inner=e(".fancybox-inner",a.wrap),a._setContent())},_setContent:function(){var b,c,d=a.current,f=d.type;switch(f){case "inline":case "ajax":case "html":b=d.content;b instanceof e&&(b=b.show().detach(),b.parent().hasClass("fancybox-inner")&&b.parents(".fancybox-wrap").trigger("onReset").remove(),e(a.wrap).bind("onReset",
function(){b.appendTo("body").hide()}));d.autoSize&&(c=e('<div class="fancybox-tmp '+a.current.wrapCSS+'"></div>').appendTo("body").append(b),d.width=c.width(),d.height=c.height(),c.width(a.current.width),c.height()>d.height&&(c.width(d.width+1),d.width=c.width(),d.height=c.height()),b=c.contents().detach(),c.remove());break;case "image":b=d.tpl.image.replace("{href}",d.href);d.aspectRatio=!0;break;case "swf":b=d.tpl.swf.replace(/\{width\}/g,d.width).replace(/\{height\}/g,d.height).replace(/\{href\}/g,
-d.href)}if("iframe"===f){b=e(d.tpl.iframe.replace("{rnd}",(new Date).getTime())).attr("scrolling",d.scrolling);d.scrolling="auto";if(d.autoSize){b.width(d.width);a.showLoading();b.data("ready",!1).bind("load",function(){var b=e(this),c;try{this.contentWindow.document.location&&(c=b.contents().find("body").height()+12,b.height(c))}catch(f){d.autoSize=!1}!1===b.data("ready")?(a.hideLoading(),c&&(a.current.height=c),a._beforeShow(),b.data("ready",!0)):c&&a.update()}).appendTo(a.inner).attr("src",d.href);
+d.href)}if("iframe"===f){b=e(d.tpl.iframe.replace("{rnd}",(new Date).getTime())).attr("scrolling",d.scrolling);d.scrolling="auto";if(d.autoSize){b.width(d.width);a.showLoading();b.data("ready",!1).appendTo(a.inner).bind("load",function(){var b=e(this),c;try{this.contentWindow.document.location&&(c=b.contents().find("body").height()+12,b.height(c))}catch(f){d.autoSize=!1}!1===b.data("ready")?(a.hideLoading(),c&&(a.current.height=c),a._beforeShow(),b.data("ready",!0)):c&&a.update()}).attr("src",d.href);
return}b.attr("src",d.href)}else if("image"===f||"swf"===f)d.autoSize=!1,d.scrolling="visible";a.inner.append(b);a._beforeShow()},_beforeShow:function(){a.trigger("beforeShow");a._setDimension();a.wrap.hide().removeClass("fancybox-tmp");a.bindEvents();a._preloadImages();a.transitions[a.isOpened?a.current.nextMethod:a.current.openMethod]()},_setDimension:function(){var b=a.wrap,c=a.outer,d=a.inner,f=a.current,g=a.getViewport(),k=f.margin,h=2*f.padding,i=f.width,j=f.height,o=f.maxWidth,l=f.maxHeight,
p=f.minWidth,m=f.minHeight,n;g.w-=k[1]+k[3];g.h-=k[0]+k[2];-1<i.toString().indexOf("%")&&(i=(g.w-h)*parseFloat(i)/100);-1<j.toString().indexOf("%")&&(j=(g.h-h)*parseFloat(j)/100);k=i/j;i+=h;j+=h;f.fitToView&&(o=Math.min(g.w,o),l=Math.min(g.h,l));f.aspectRatio?(i>o&&(i=o,j=(i-h)/k+h),j>l&&(j=l,i=(j-h)*k+h),i<p&&(i=p,j=(i-h)/k+h),j<m&&(j=m,i=(j-h)*k+h)):(i=Math.max(p,Math.min(i,o)),j=Math.max(m,Math.min(j,l)));i=Math.round(i);j=Math.round(j);e(b.add(c).add(d)).width("auto").height("auto");d.width(i-
h).height(j-h);b.width(i);n=b.height();if(i>o||n>l)for(;(i>o||n>l)&&i>p&&n>m;)j-=10,f.aspectRatio?(i=Math.round((j-h)*k+h),i<p&&(i=p,j=(i-h)/k+h)):i-=10,d.width(i-h).height(j-h),b.width(i),n=b.height();f.dim={width:i,height:n};f.canGrow=f.autoSize&&j>m&&j<l;f.canShrink=!1;f.canExpand=!1;if(i-h<f.width||j-h<f.height)f.canExpand=!0;else if((i>g.w||n>g.h)&&i>p&&j>m)f.canShrink=!0;b=n-h;a.innerSpace=b-d.height();a.outerSpace=b-c.height()},_getPosition:function(b){var c=a.current,d=a.getViewport(),f=c.margin,
e=a.wrap.width()+f[1]+f[3],k=a.wrap.height()+f[0]+f[2],h={position:"absolute",top:f[0]+d.y,left:f[3]+d.x};if(c.fixed&&(!b||!1===b[0])&&k<=d.h&&e<=d.w)h={position:"fixed",top:f[0],left:f[3]};h.top=Math.ceil(Math.max(h.top,h.top+(d.h-k)*c.topRatio))+"px";h.left=Math.ceil(Math.max(h.left,h.left+0.5*(d.w-e)))+"px";return h},_afterZoomIn:function(){var b=a.current,c=b.scrolling;a.isOpen=a.isOpened=!0;a.wrap.addClass("fancybox-opened").css("overflow","visible");a.update();a.inner.css("overflow","yes"===
c?"scroll":"no"===c?"hidden":c);if(b.closeClick||b.nextClick)a.inner.css("cursor","pointer").bind("click.fb",b.nextClick?a.next:a.close);b.closeBtn&&e(b.tpl.closeBtn).appendTo(a.outer).bind("click.fb",a.close);b.arrows&&1<a.group.length&&((b.loop||0<b.index)&&e(b.tpl.prev).appendTo(a.inner).bind("click.fb",a.prev),(b.loop||b.index<a.group.length-1)&&e(b.tpl.next).appendTo(a.inner).bind("click.fb",a.next));a.trigger("afterShow");a.opts.autoPlay&&!a.player.isActive&&(a.opts.autoPlay=!1,a.play())},_afterZoomOut:function(){a.trigger("afterClose");
a.wrap.trigger("onReset").remove();e.extend(a,{group:{},opts:{},current:null,isActive:!1,isOpened:!1,isOpen:!1,wrap:null,outer:null,inner:null})}});a.transitions={getOrigPosition:function(){var b=a.current,c=b.element,d=b.padding,f=e(b.orig),g={},k=50,h=50;!f.length&&b.isDom&&e(c).is(":visible")&&(f=e(c).find("img:first"),f.length||(f=e(c)));f.length?(g=f.offset(),f.is("img")&&(k=f.outerWidth(),h=f.outerHeight())):(b=a.getViewport(),g.top=b.y+0.5*(b.h-h),g.left=b.x+0.5*(b.w-k));return g={top:Math.ceil(g.top-
d)+"px",left:Math.ceil(g.left-d)+"px",width:Math.ceil(k+2*d)+"px",height:Math.ceil(h+2*d)+"px"}},step:function(b,c){var d,e,g;if("width"===c.prop||"height"===c.prop)e=g=Math.ceil(b-2*a.current.padding),"height"===c.prop&&(d=(b-c.start)/(c.end-c.start),c.start>c.end&&(d=1-d),e-=a.innerSpace*d,g-=a.outerSpace*d),a.inner[c.prop](e),a.outer[c.prop](g)},zoomIn:function(){var b=a.wrap,c=a.current,d,f;d=c.dim;"elastic"===c.openEffect?(f=e.extend({},d,a._getPosition(!0)),delete f.position,d=this.getOrigPosition(),
-c.openOpacity&&(d.opacity=0,f.opacity=1),a.outer.add(a.inner).width("auto").height("auto"),b.css(d).show().animate(f,{duration:c.openSpeed,easing:c.openEasing,step:this.step,complete:a._afterZoomIn})):(b.css(e.extend({},d,a._getPosition())),"fade"===c.openEffect?b.fadeIn(c.openSpeed,a._afterZoomIn):(b.show(),a._afterZoomIn()))},zoomOut:function(){var b=a.wrap,c=a.current,d;"elastic"===c.closeEffect?("fixed"===b.css("position")&&b.css(a._getPosition(!0)),d=this.getOrigPosition(),c.closeOpacity&&(d.opacity=
-0),b.animate(d,{duration:c.closeSpeed,easing:c.closeEasing,step:this.step,complete:a._afterZoomOut})):b.fadeOut("fade"===c.closeEffect?c.closeSpeed:0,a._afterZoomOut)},changeIn:function(){var b=a.wrap,c=a.current,d;"elastic"===c.nextEffect?(d=a._getPosition(!0),d.opacity=0,d.top=parseInt(d.top,10)-200+"px",b.css(d).show().animate({opacity:1,top:"+=200px"},{duration:c.nextSpeed,easing:c.nextEasing,complete:a._afterZoomIn})):(b.css(a._getPosition()),"fade"===c.nextEffect?b.hide().fadeIn(c.nextSpeed,
+c.openOpacity&&(d.opacity=0,f.opacity=1),a.outer.add(a.inner).width("auto").height("auto"),b.css(d).show(),b.animate(f,{duration:c.openSpeed,easing:c.openEasing,step:this.step,complete:a._afterZoomIn})):(b.css(e.extend({},d,a._getPosition())),"fade"===c.openEffect?b.fadeIn(c.openSpeed,a._afterZoomIn):(b.show(),a._afterZoomIn()))},zoomOut:function(){var b=a.wrap,c=a.current,d;"elastic"===c.closeEffect?("fixed"===b.css("position")&&b.css(a._getPosition(!0)),d=this.getOrigPosition(),c.closeOpacity&&
+(d.opacity=0),b.animate(d,{duration:c.closeSpeed,easing:c.closeEasing,step:this.step,complete:a._afterZoomOut})):b.fadeOut("fade"===c.closeEffect?c.closeSpeed:0,a._afterZoomOut)},changeIn:function(){var b=a.wrap,c=a.current,d;"elastic"===c.nextEffect?(d=a._getPosition(!0),d.opacity=0,d.top=parseInt(d.top,10)-200+"px",b.css(d).show().animate({opacity:1,top:"+=200px"},{duration:c.nextSpeed,easing:c.nextEasing,complete:a._afterZoomIn})):(b.css(a._getPosition()),"fade"===c.nextEffect?b.hide().fadeIn(c.nextSpeed,
a._afterZoomIn):(b.show(),a._afterZoomIn()))},changeOut:function(){var b=a.wrap,c=a.current,d=function(){e(this).trigger("onReset").remove()};b.removeClass("fancybox-opened");"elastic"===c.prevEffect?b.animate({opacity:0,top:"+=200px"},{duration:c.prevSpeed,easing:c.prevEasing,complete:d}):b.fadeOut("fade"===c.prevEffect?c.prevSpeed:0,d)}};a.helpers.overlay={overlay:null,update:function(){var a,c;this.overlay.width(0).height(0);e.browser.msie?(a=Math.max(m.documentElement.scrollWidth,m.body.scrollWidth),
c=Math.max(m.documentElement.offsetWidth,m.body.offsetWidth),a=a<c?l.width():a):a=q.width();this.overlay.width(a).height(q.height())},beforeShow:function(b){this.overlay||(b=e.extend(!0,{speedIn:"fast",closeClick:!0,opacity:1,css:{background:"black"}},b),this.overlay=e('<div id="fancybox-overlay"></div>').css(b.css).appendTo("body"),this.update(),b.closeClick&&this.overlay.bind("click.fb",a.close),l.bind("resize.fb",e.proxy(this.update,this)),this.overlay.fadeTo(b.speedIn,b.opacity))},onUpdate:function(){this.update()},
afterClose:function(a){this.overlay&&this.overlay.fadeOut(a.speedOut||0,function(){e(this).remove()});this.overlay=null}};a.helpers.title={beforeShow:function(b){var c;if(c=a.current.title)c=e('<div class="fancybox-title fancybox-title-'+b.type+'-wrap">'+c+"</div>").appendTo("body"),"float"===b.type&&(c.width(c.width()),c.wrapInner('<span class="child"></span>'),a.current.margin[2]+=Math.abs(parseInt(c.css("margin-bottom"),10))),c.appendTo("over"===b.type?a.inner:"outside"===b.type?a.wrap:a.outer)}};

0 comments on commit e25352c

Please sign in to comment.