Skip to content

Commit d6c1048

Browse files
committed
Updated the demo to include a showing whats cached
1 parent 7bda9e2 commit d6c1048

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

demo.html

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2-
<html>
1+
<!DOCTYPE html>
2+
<html lang="en">
33
<head>
44
<title>jQuery Cache Images v1.0 Plug-in Demo</title>
5-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"><!-- please don't add "maximum-scale=1" here. It's bad for accessibility. -->
8+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
69

710
<script type="text/javascript" src="assets/jquery-1.9.1.js"></script>
811
<script type="text/javascript" src="jquery.cacheImages.js"></script>
@@ -14,18 +17,18 @@ <h1>jQuery Cache Images v1.0 Plug-in</h1>
1417

1518
<p>Use the following buttons to perform some basic checks on the cache</p>
1619
<p>
17-
<button id="cacheLoadAdd">Display all cached images</button>
18-
<button id="cacheStats">Cache Stats</button>
20+
<button id="cacheLoadAll">Display all cached images</button>
1921
<button id="dropCache">Empty the Cache</button>
2022
</p>
21-
<div id="statWindow" style="text-align: center;"></div>
23+
<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>
2225

2326
<p>Images are kept in browser's Local Storage as a base64 encoded string. </p>
2427

25-
<ul id="DemoImages">
26-
<li><img src="assets/x-all-the-things.png" /></li>
27-
<li><img src="assets/cat.gif" /></li>
28-
<li><img src="assets/warhol.jpg" /></li>
28+
<div id="DemoImages">
29+
<img src="assets/x-all-the-things.png" />
30+
<img src="assets/cat.gif" />
31+
<img src="assets/warhol.jpg" />
2932
</ul>
3033

3134

@@ -47,11 +50,37 @@ <h2>Flickr Test</h2>
4750
$(function(){
4851
// $('#flickrTest').cacheImages({debug: true});
4952
$(document).on('click','#dropCache', function(){ cacheImagesDrop(); });
53+
$(document).on('click','#cacheLoadAll', function(){ cacheImagesShowAll( $('#statWindow') ); });
5054
});
5155

56+
/*
57+
* Grab all of the images and display them inside the container
58+
*/
59+
60+
var cacheKeys = []; // Store the keys we need to drop here
5261
var cacheImagesShowAll = function( container ){
53-
54-
}
62+
var cacheKeys = []; // Store the keys we need to drop here
63+
// Lets get our loop on
64+
for (i = 0; i < window.localStorage.length; i++) {
65+
if( window.localStorage.key(i).substr( 0, window.cacheImagesConfig.storagePrefix.length + 1 ) !== window.cacheImagesConfig.storagePrefix + ':' ){ continue; } // Does not match our prefix?
66+
67+
cacheKeys.push( window.localStorage.key(i) ); // Droping the keys here re-indexes the localStorage so that the offset in our loop is wrong
68+
}
69+
70+
if( cacheKeys.length === 0 ){
71+
if( window.cacheImagesConfig.debug ){ console.log( 'No Images to Drop' ); }
72+
return true;
73+
}
74+
75+
// Show the images we found
76+
for( i = 0; i < cacheKeys.length; i++ ){
77+
// if( $('#' + cacheKeys[i] ).length > 0 ){ continue; }
78+
79+
container.append( $('<img />').prop( 'src', window.localStorage.getItem( cacheKeys[i] ) ).width('25%') );
80+
}
81+
82+
return true;
83+
};
5584
</script>
5685
</body>
5786
</html>

0 commit comments

Comments
 (0)