@@ -18,10 +18,10 @@ <h1>jQuery Cache Images v1.0 Plug-in</h1>
1818 < p > Use the following buttons to perform some basic checks on the cache</ p >
1919 < p >
2020 < button id ="cacheLoadAll "> Display all cached images</ button >
21+ < button onclick ="$('#statWindow').html(''); "> Empty Display</ button >
2122 < button id ="dropCache "> Empty the Cache</ button >
2223 </ p >
2324 < div id ="statWindow " style ="text-align: center; border: 5px solid; min-height: 40px; "> </ div >
24- < div style ="text-align: right; "> < button onclick ="$('#statWindow').html(''); "> Empty Display</ button > </ div >
2525
2626 < p > Images are kept in browser's Local Storage as a base64 encoded string. </ p >
2727
@@ -35,7 +35,6 @@ <h1>jQuery Cache Images v1.0 Plug-in</h1>
3535 < h2 > Flickr Test</ h2 >
3636 < div >
3737 Here is a dynamic example where we will fetch a bunch of images from Flickr, dynamically insert them into the page, and they all get cached.
38- < pre > </ pre >
3938 < br />
4039 < button id ="FlickrTest "> Load Some Flickr Images</ button >
4140 </ div >
@@ -52,7 +51,23 @@ <h2>Flickr Test</h2>
5251 $ ( document ) . on ( 'click' , '#dropCache' , function ( ) { cacheImagesDrop ( ) ; } ) ;
5352 $ ( document ) . on ( 'click' , '#cacheLoadAll' , function ( ) { cacheImagesShowAll ( $ ( '#statWindow' ) ) ; } ) ;
5453 $ ( document ) . on ( 'click' , '#FlickrTest' , function ( ) {
55-
54+ var jxhr = $ . ajax ( 'http://api.flickr.com/services/feeds/photos_public.gne?tags=paris,church&lang=en-us&format=json' ,
55+ { type : 'get' ,
56+ dataType : 'jsonp' ,
57+ jsonpCallback : 'jsonFlickrFeed' ,
58+ data : { 'tags' : 'goat,pasture' ,
59+ 'lang' : 'en-us' ,
60+ 'format' : 'json' } ,
61+ } )
62+ . done ( function ( data , textStatus , jqXHR ) {
63+ var items = [ ] ;
64+
65+ $ . each ( data . items , function ( key , photo ) {
66+ // cacheImageFetchURL( photo.media.m ); // Cache the image for later use
67+
68+ $ ( '#flickrTest' ) . append ( $ ( '<img />' ) . cacheImages ( { url : photo . media . m } ) ) ; // Using the caching immediately
69+ } ) ;
70+ } ) ;
5671 } ) ;
5772 } ) ;
5873
@@ -78,6 +93,8 @@ <h2>Flickr Test</h2>
7893 // Show the images we found
7994 for ( i = 0 ; i < cacheKeys . length ; i ++ ) {
8095 // if( $('#' + cacheKeys[i] ).length > 0 ){ continue; }
96+ if ( window . localStorage . getItem ( cacheKeys [ i ] ) === 'pending' ) { continue ; }
97+ if ( window . localStorage . getItem ( cacheKeys [ i ] ) === 'error' ) { continue ; }
8198
8299 container . append ( $ ( '<img />' ) . prop ( 'src' , window . localStorage . getItem ( cacheKeys [ i ] ) ) . width ( '25%' ) ) ;
83100 }
0 commit comments