Plugin Directory

Changeset 1013273


Ignore:
Timestamp:
10/24/2014 09:27:54 AM (11 years ago)
Author:
bypr.nils
Message:

fixed issue where images would load too late when no absolute width and height was given and refresh on scroll was off

Location:
smart-image-loader/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • smart-image-loader/trunk/readme.txt

    r1013263 r1013273  
    3737= 0.3.9 =
    3838* fixed bug where some images would not load on older android versions (2.x)
     39* fixed issue where images would load too late when no absolute width and height was given and refresh on scroll was off
    3940
    4041= 0.3.8 =
  • smart-image-loader/trunk/smart_image_loader.js

    r1013263 r1013273  
    196196
    197197
     198    has_absolute_size = function( img )
     199    {
     200        return typeof img.width == "string" && img.width.match(/^\d+$/) && typeof img.height == "string" && img.height.match(/^\d+$/);
     201    },
     202
     203
    198204    refresh_data = function( $elements, update_view )
    199205    {
     
    330336
    331337        requestAnimationFrame(function () {
    332             refresh_data( $wrapped_images, true );
     338
     339            // sometimes the one frame is not enough so we will refresh_data again on load
     340            if ( !has_absolute_size(wrapping_image) )
     341            {
     342                refresh_data( $wrapped_images, true );
     343            }
    333344        });
    334345
     
    362373
    363374                    images_loaded = i+1;
     375
     376                    // has the document layout changed after the source has been inserted?
     377                    if ( !has_absolute_size(e.target) )
     378                    {
     379                        refresh_data( $wrapped_images, true );
     380                    }
    364381
    365382                    if ( images_loaded == images_to_load && typeof on_all_visible_load_callback == 'function' )
  • smart-image-loader/trunk/smart_image_loader.min.js

    r1013263 r1013273  
    1 jQuery(function(N){var af=window.sil_options||{selector:"img",cleanup:true,responsive_touch:true,emulate_inertia:true,emulate_rubberband:true,meat:100,refresh_resize:true,refresh_scroll:false,enhanced_accuracy:false,lazy_load_at:1024,fade:false,placeholder:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"};
    2 var ae=document,T=window,G=N(ae),Z,A,z,u,i,E,P,h,M,o,l,k,r,a,j,f,H,n,C,Y,I,D,ab,ag,ac,q=/(iPad|iPhone|iPod)/g.test(navigator.userAgent),x=!!(T.matchMedia&&T.matchMedia("(max-device-width: "+af.lazy_load_at+"px)").matches),U=function(){var w=T,d="inner";
    3 if(!("innerWidth" in T)){d="client";w=ae.documentElement||ae.body;}return{width:w[d+"Width"],height:w[d+"Height"]};},V=function(d,w){if(window.getComputedStyle){return document.defaultView.getComputedStyle(d,null)[w];
    4 }if(d.currentStyle){return d.currentStyle[w];}},J=function(){return I!==Y;},c=function(){return ab!==D;},aa=function(){return ac!==ag;},Q=function(ap){var w,aq,ak,ai,al,d,am,aj,ar,ao,an;
    5 if(ap.nodeType&&ap.nodeType==1){w=ap;}else{if(this.nodeType&&this.nodeType==1){w=this;}}aq=N(w);ak=aq.data("offsetTop");ai=aq.data("offsetLeft");al=aq.data("width");
    6 d=aq.data("height");element_visibile=aq.data("visibility");am=ak+d>M-af.meat;ao=ai+al>o-af.meat;aj=ak<M+P+af.meat;ar=ai<o+E+af.meat;return am&&ao&&aj&&ar&&element_visibile;
    7 },W=function(d){var w,ai;if(d.nodeType&&d.nodeType==1){w=d;}else{if(this.nodeType&&this.nodeType==1){w=this;}}ai=N(w).attr("src");return ai==af.placeholder||ai==i;
    8 },e=function(d,w){d=d||A||N("body").find("noscript").prev(af.selector);d.each(function(){var aj=N(this);aj.data({offsetTop:aj.offset().top,offsetLeft:aj.offset().left,width:aj.width(),height:aj.height(),visibility:V(this,"display")!="none"&&V(this,"visibility")!="hidden"&&V(this,"opacity")!="0"});
    9 });h=N(ae).height();if(w){var ai=x?null:v;O(ai,true);}},F=function(){var d,w,ai;T.scrollBy(0,Math.floor(f/2));f*=0.95;d=h<=P+M+1;w=(M===0);ai=d||w;H=false;
    10 if(Math.abs(f)>2&&!r&&!ai){H=true;}else{if(ai&&af.emulate_rubberband){b(f);}}},b=function(ai){n=ai;var aj=ai<0?1:-1,w=Math.min(Math.abs(ai),T.innerHeight/10)*aj,d=Math.abs(ai*3);
    11 d=Math.min(d,200);d=Math.max(d,125);ae.body.style.webkitTransition="all "+d/1000*0.5+"s cubic-bezier(0.3, 0.6, 0.6, 1)";ae.documentElement.style.backgroundColor="lightgrey";
    12 T.requestAnimationFrame(function(){ae.body.style.webkitTransform="translate3d(0px, "+w+"px, 0px)";});T.setTimeout(function(){ae.body.style.webkitTransition="all "+d/1000*2+"s cubic-bezier(0.5, 0.03, 0.5, 1)";
    13 T.requestAnimationFrame(function(){ae.body.style.webkitTransform="translate3d(0px, 0px, 0px)";});},d*0.5);T.setTimeout(function(){ae.body.style.webkitTransform="";
    14 ae.body.style.webkitTransition="";ae.documentElement.style.backgroundColor="";n=false;},d*2.5);},R=function(ai,w,ak){Z=N(ai);var d=Z.attr("data-sil"),aj=u.filter('[data-sil="'+d+'"]');
    15 if(typeof w=="function"){Z.on("load",w);}if(af.fade&&ak){Z.data({opacity:Z.css("opacity")}).css({opacity:"0"});Z.on("load",function(){N(this).fadeTo(500,N(this).data("opacity"));
    16 });}Z.attr("src",aj.attr("title"));requestAnimationFrame(function(){e(A,true);});if(af.cleanup){aj.parent("span").remove();}},O=function(ak,aj){var ai=A.filter(Q),d=ai.length,w=0;
    17 if(d===0&&typeof ak=="function"){ak();}else{ai.each(function(al,am){R(am,function(an){K(an);w=al+1;if(w==d&&typeof ak=="function"){ak();}},aj);A=A.map(function(){if(this!==am){return this;
    18 }});});}},v=function(){A.each(function(){var d=this;R(d,K);A=A.map(function(){if(this!==d){return this;}});});},K=function(d){C=A.length>0?false:true;if(C){G.trigger("sil_load");
    19 }},ad=function(){e(A,true);},B=function(d){d.preventDefault();D=d;},y=function(){j=0;f=0;l=false;k=false;r=true;H=false;},ah=function(){l=false;k=false;
    20 r=false;if(af.emulate_inertia){H=true;}},S=function(d){Y=d;},t=function(d){ag=d;},s=function(){if(!q){window.requestAnimationFrame(X);}},p=function(){h=G.height();
    21 if(q){T.requestAnimationFrame(X);}},m=function(){N(T).on("resize",t);N(T).on("load",p);G.on("scroll",S);if(af.responsive_touch&&q){G.on("touchmove",B);
    22 G.on("touchend",ah);G.on("touchstart",y);}G.ready(s);},g=function(){N(T).off("resize",t);G.off("scroll",S);if(af.responsive_touch&&q){G.off("touchmove",B);
    23 G.off("touchend",ah);G.off("touchstart",y);}},L=function(ai){if(J()){M=G.scrollTop();o=G.scrollLeft();if(af.refresh_scroll){e(A);}if(x){O(null,true);}I=Y;
    24 }if(c()){var w=D.originalEvent.layerX-o;var d=D.originalEvent.layerY-M;j=f=0;if(l&&l!==w){j=l-w;}if(k&&k!==d){f=k-d;}l=w;k=d;T.scrollBy(j,f);ab=D;}if(aa()){E=U().width;
    25 P=U().height;e(A);if(af.refresh_resize){e(A);}if(x){O(null,true);}ac=ag;}if(H){F();}if(!C||H||n){T.requestAnimationFrame(L);}else{g();}},X=function(){z=N("html, body");
    26 u=N("body").find("noscript[data-sil]");A=N(af.selector+"[data-sil]");E=U().width;P=U().height;i=ae.location.protocol+"//"+ae.location.host+"/";M=G.scrollTop();
    27 o=G.scrollLeft();h=G.height();H=false;n=false;C=A.length>0?false:true;window.sil_refresh=ad;e(A);if(x){O();}else{O(v);}L();};rf_poly();m();});function rf_poly(){var b=0;
     1jQuery(function(N){var ag=window.sil_options||{selector:"img",cleanup:true,responsive_touch:true,emulate_inertia:true,emulate_rubberband:true,meat:100,refresh_resize:true,refresh_scroll:false,enhanced_accuracy:false,lazy_load_at:1024,fade:false,placeholder:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"};
     2var af=document,U=window,G=N(af),aa,A,z,u,i,E,Q,h,M,o,l,k,r,a,j,f,H,n,C,Z,I,D,ac,ah,ad,q=/(iPad|iPhone|iPod)/g.test(navigator.userAgent),x=!!(U.matchMedia&&U.matchMedia("(max-device-width: "+ag.lazy_load_at+"px)").matches),V=function(){var w=U,d="inner";
     3if(!("innerWidth" in U)){d="client";w=af.documentElement||af.body;}return{width:w[d+"Width"],height:w[d+"Height"]};},W=function(d,w){if(window.getComputedStyle){return document.defaultView.getComputedStyle(d,null)[w];
     4}if(d.currentStyle){return d.currentStyle[w];}},J=function(){return I!==Z;},c=function(){return ac!==D;},ab=function(){return ad!==ah;},R=function(aq){var w,ar,al,aj,am,d,an,ak,at,ap,ao;
     5if(aq.nodeType&&aq.nodeType==1){w=aq;}else{if(this.nodeType&&this.nodeType==1){w=this;}}ar=N(w);al=ar.data("offsetTop");aj=ar.data("offsetLeft");am=ar.data("width");
     6d=ar.data("height");element_visibile=ar.data("visibility");an=al+d>M-ag.meat;ap=aj+am>o-ag.meat;ak=al<M+Q+ag.meat;at=aj<o+E+ag.meat;return an&&ap&&ak&&at&&element_visibile;
     7},X=function(d){var w,aj;if(d.nodeType&&d.nodeType==1){w=d;}else{if(this.nodeType&&this.nodeType==1){w=this;}}aj=N(w).attr("src");return aj==ag.placeholder||aj==i;
     8},O=function(d){return typeof d.width=="string"&&d.width.match(/^\d+$/)&&typeof d.height=="string"&&d.height.match(/^\d+$/);},e=function(d,w){d=d||A||N("body").find("noscript").prev(ag.selector);
     9d.each(function(){var ak=N(this);ak.data({offsetTop:ak.offset().top,offsetLeft:ak.offset().left,width:ak.width(),height:ak.height(),visibility:W(this,"display")!="none"&&W(this,"visibility")!="hidden"&&W(this,"opacity")!="0"});
     10});h=N(af).height();if(w){var aj=x?null:v;P(aj,true);}},F=function(){var d,w,aj;U.scrollBy(0,Math.floor(f/2));f*=0.95;d=h<=Q+M+1;w=(M===0);aj=d||w;H=false;
     11if(Math.abs(f)>2&&!r&&!aj){H=true;}else{if(aj&&ag.emulate_rubberband){b(f);}}},b=function(aj){n=aj;var ak=aj<0?1:-1,w=Math.min(Math.abs(aj),U.innerHeight/10)*ak,d=Math.abs(aj*3);
     12d=Math.min(d,200);d=Math.max(d,125);af.body.style.webkitTransition="all "+d/1000*0.5+"s cubic-bezier(0.3, 0.6, 0.6, 1)";af.documentElement.style.backgroundColor="lightgrey";
     13U.requestAnimationFrame(function(){af.body.style.webkitTransform="translate3d(0px, "+w+"px, 0px)";});U.setTimeout(function(){af.body.style.webkitTransition="all "+d/1000*2+"s cubic-bezier(0.5, 0.03, 0.5, 1)";
     14U.requestAnimationFrame(function(){af.body.style.webkitTransform="translate3d(0px, 0px, 0px)";});},d*0.5);U.setTimeout(function(){af.body.style.webkitTransform="";
     15af.body.style.webkitTransition="";af.documentElement.style.backgroundColor="";n=false;},d*2.5);},S=function(aj,w,al){aa=N(aj);var d=aa.attr("data-sil"),ak=u.filter('[data-sil="'+d+'"]');
     16if(typeof w=="function"){aa.on("load",w);}if(ag.fade&&al){aa.data({opacity:aa.css("opacity")}).css({opacity:"0"});aa.on("load",function(){N(this).fadeTo(500,N(this).data("opacity"));
     17});}aa.attr("src",ak.attr("title"));requestAnimationFrame(function(){if(!O(aj)){e(A,true);}});if(ag.cleanup){ak.parent("span").remove();}},P=function(al,ak){var aj=A.filter(R),d=aj.length,w=0;
     18if(d===0&&typeof al=="function"){al();}else{aj.each(function(am,an){S(an,function(ao){K(ao);w=am+1;if(!O(ao.target)){e(A,true);}if(w==d&&typeof al=="function"){al();
     19}},ak);A=A.map(function(){if(this!==an){return this;}});});}},v=function(){A.each(function(){var d=this;S(d,K);A=A.map(function(){if(this!==d){return this;
     20}});});},K=function(d){C=A.length>0?false:true;if(C){G.trigger("sil_load");}},ae=function(){e(A,true);},B=function(d){d.preventDefault();D=d;},y=function(){j=0;
     21f=0;l=false;k=false;r=true;H=false;},ai=function(){l=false;k=false;r=false;if(ag.emulate_inertia){H=true;}},T=function(d){Z=d;},t=function(d){ah=d;},s=function(){if(!q){window.requestAnimationFrame(Y);
     22}},p=function(){h=G.height();if(q){U.requestAnimationFrame(Y);}},m=function(){N(U).on("resize",t);N(U).on("load",p);G.on("scroll",T);if(ag.responsive_touch&&q){G.on("touchmove",B);
     23G.on("touchend",ai);G.on("touchstart",y);}G.ready(s);},g=function(){N(U).off("resize",t);G.off("scroll",T);if(ag.responsive_touch&&q){G.off("touchmove",B);
     24G.off("touchend",ai);G.off("touchstart",y);}},L=function(aj){if(J()){M=G.scrollTop();o=G.scrollLeft();if(ag.refresh_scroll){e(A);}if(x){P(null,true);}I=Z;
     25}if(c()){var w=D.originalEvent.layerX-o;var d=D.originalEvent.layerY-M;j=f=0;if(l&&l!==w){j=l-w;}if(k&&k!==d){f=k-d;}l=w;k=d;U.scrollBy(j,f);ac=D;}if(ab()){E=V().width;
     26Q=V().height;e(A);if(ag.refresh_resize){e(A);}if(x){P(null,true);}ad=ah;}if(H){F();}if(!C||H||n){U.requestAnimationFrame(L);}else{g();}},Y=function(){z=N("html, body");
     27u=N("body").find("noscript[data-sil]");A=N(ag.selector+"[data-sil]");E=V().width;Q=V().height;i=af.location.protocol+"//"+af.location.host+"/";M=G.scrollTop();
     28o=G.scrollLeft();h=G.height();H=false;n=false;C=A.length>0?false:true;window.sil_refresh=ae;e(A);if(x){P();}else{P(v);}L();};rf_poly();m();});function rf_poly(){var b=0;
    2829var c=["webkit","moz"];for(var a=0;a<c.length&&!window.requestAnimationFrame;++a){window.requestAnimationFrame=window[c[a]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[c[a]+"CancelAnimationFrame"]||window[c[a]+"CancelRequestAnimationFrame"];
    2930}if(!window.requestAnimationFrame){window.requestAnimationFrame=function(h,e){var d=new Date().getTime();var f=Math.max(0,16-(d-b));var g=window.setTimeout(function(){h(d+f);
Note: See TracChangeset for help on using the changeset viewer.