@@ -57,25 +57,27 @@ window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndex
5757
5858 if ( $ . fn . cacheImages . defaults . indexedDbStatus === true ) {
5959 callbackFunction . call ( thisElem , i , img ) ; // This is the structure to use for our callbacks
60+ if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB already ready' ) ; }
6061 return ;
6162 }
6263
6364 var intervalCount = 0 ,
6465 thisInterval = setInterval ( function ( ) {
6566 intervalCount ++ ;
6667 if ( $ . fn . cacheImages . defaults . indexedDbStatus === true ) {
67- if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB ready to use' ) ; }
68+ if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB ready to use' , 'indexedDB took ' + ( intervalCount * 50 ) + 'ms to conenct' ) ; }
6869 callbackFunction . call ( thisElem , i , img ) ; // This is the structure to use for our callbacks
6970 clearInterval ( thisInterval ) ; return ;
7071 }
71- if ( intervalCount >= 41 ) { if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB did not load' ) ; } clearInterval ( thisInterval ) ; return ; } // only run for 2 seconds max
72+ if ( intervalCount >= 41 ) { // only run for 2 seconds max - if it isn't available then there are other issues at play
73+ if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB did not load' ) ; }
74+ clearInterval ( thisInterval ) ;
75+ return ;
76+ }
7277
7378 if ( $ . fn . cacheImages . defaults . debug ) { console . log ( 'indexedDB not yet available' ) ; }
7479 } , 50 ) ;
75-
76- // if( $.fn.cacheImages.defaults.ready === false ){}
77- // setTimeout(function(){ return 10; }, 1500);
78- return $ . fn . cacheImages . defaults . indexedDbStatus ;
80+ return ;
7981 } ;
8082 /*
8183 * Saves the encoded image data into the storage tool for the provided key
@@ -90,7 +92,7 @@ window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndex
9092 if ( typeof callbackFunction === 'function' ) {
9193 callbackFunction . call ( thisElem , key , encodedString ) ; // This is the structure to use for our callbacks
9294 }
93- } ;
95+ }
9496 request . onerror = function ( e ) {
9597 self . cacheImagesConfig . fail . call ( this ) ;
9698 self . cacheImagesConfig . always . call ( this ) ;
@@ -104,7 +106,9 @@ window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndex
104106 var tmp = window . cacheImagesDb . transaction ( "offlineImages" , 'readonly' ) . objectStore ( "offlineImages" ) . get ( key ) ;
105107 tmp . onsuccess = function ( e ) {
106108 encodedString = '' ;
107- if ( typeof e . target . result !== 'undefined' && typeof e . target . result . image === 'string' ) { encodedString = e . target . result . image ; }
109+ if ( typeof e . target . result !== 'undefined' && typeof e . target . result . image === 'string' ) {
110+ encodedString = e . target . result . image ;
111+ }
108112
109113 if ( typeof callbackFunction === 'function' ) {
110114 callbackFunction . call ( thisElem , key , encodedString ) ; // This is the structure to use for our callbacks
@@ -134,10 +138,8 @@ window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndex
134138 if ( / ^ d a t a : i m a g e / . test ( $ . fn . cacheImages . defaults . defaultImage ) === true ) {
135139 image = $ . fn . cacheImages . defaults . defaultImage ; // this is an encoded string
136140 } else {
137- tempKey = storagePrefix + ':' + this . cacheImagesConfig . defaultImage ;
138- if ( window . localStorage . getItem ( tempKey ) != null ) {
139- return window . localStorage . getItem ( tempKey ) ; // Default URL was already cached
140- }
141+ $ . fn . cacheImages . Output ( $ . fn . cacheImages . defaults . defaultImage , storagePrefix , callbackFunction ) ; // pass the callback through
142+ return ;
141143 }
142144 }
143145
@@ -146,29 +148,14 @@ window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndex
146148 }
147149 }
148150
149-
150- // if( window.localStorage.getItem( tempKey ) != null ){
151- // return window.localStorage.getItem( tempKey ); // Image exists in the cache
152- // }else{
153- //
154- // if( /^data:image/.test( $.fn.cacheImages.defaults.defaultImage ) === true ){
155- // return this.cacheImagesConfig.defaultImage; // this is an encoded string
156- // }
157- //
158- // tempKey = storagePrefix + ':' + this.cacheImagesConfig.defaultImage;
159- // if( window.localStorage.getItem( tempKey ) != null ){
160- // return window.localStorage.getItem( tempKey ); // Default URL was already cached
161- // }
162- // }
163-
164151 return null ; // Neither the image or the cached version existsed
165152 } ;
166153 /*
167154 * Will remove all of the cached images from their localStorage
168155 */
169156 $ . fn . cacheImages . drop = function ( storagePrefix ) {
170157 var dropKeys = [ ] , // Store the keys we need to drop here
171- debug = true ;
158+ debug = false ;
172159 if ( typeof storagePrefix === 'undefined' ) { storagePrefix = $ . fn . cacheImages . defaults . storagePrefix ; }
173160
174161 var request = window . cacheImagesDb . transaction ( "offlineImages" , "readonly" ) . objectStore ( "offlineImages" ) . openCursor ( ) ;
0 commit comments