|
124 | 124 | /* |
125 | 125 | * Retreive the encoded string from local storage, passes the value to the callback function |
126 | 126 | */ |
127 | | - $.fn.cacheImages.Output = function( url, callbackFunction, storagePrefix ){ |
| 127 | + $.fn.cacheImages.Output = function( url, callbackFunction, storagePrefix, secondTry ){ |
128 | 128 | if( typeof storagePrefix === 'undefined' || typeof storagePrefix === 'null' ){ storagePrefix = $.fn.cacheImages.defaults.storagePrefix; } |
| 129 | + if( typeof secondTry !== 'boolean' ){ secondTry = false; } |
129 | 130 | var tempKey = storagePrefix + ':' + url, |
130 | 131 | thisElem = this; |
131 | 132 |
|
132 | 133 | var request = window.cacheImagesDb.transaction("offlineImages", "readonly").objectStore("offlineImages").get( tempKey ); |
133 | 134 | request.onsuccess = function(e) { |
134 | 135 | var image = ''; |
135 | | - if( typeof e.target.result !== 'undefined' && typeof e.target.result.image === 'string' && /^data:image/.test( e.target.result.image ) === true ){ |
| 136 | + |
| 137 | + // Lets try out this image |
| 138 | + if( typeof e.target.result !== 'undefined' && typeof e.target.result.image === 'string' ){ |
136 | 139 | image = e.target.result.image; |
| 140 | + if( $.fn.cacheImages.testOutput( image, true ) == false ){ |
| 141 | + delete image; // reset the variable to trigger default |
| 142 | + if( secondTry == false ){ |
| 143 | + // - Force Fetch the URL again |
| 144 | + // - Output the new Image |
| 145 | + $('body').append( |
| 146 | + $('<img style="display: none;" />') |
| 147 | + .addClass('cacheImagesRemove') |
| 148 | + .cacheImages({ |
| 149 | + url: url, |
| 150 | + forceSave: true, |
| 151 | + storagePrefix: storagePrefix, |
| 152 | + done: function( image ){ |
| 153 | + if( typeof callbackFunction == 'function' ){ |
| 154 | + $.fn.cacheImages.Output( url, callbackFunction, storagePrefix, true ); |
| 155 | + } |
| 156 | + } |
| 157 | + }) |
| 158 | + ); |
| 159 | + return; |
| 160 | + } |
| 161 | + } |
137 | 162 | } |
138 | 163 |
|
139 | | - if( image == '' ){ |
140 | | - if( /^data:image/.test( $.fn.cacheImages.defaults.defaultImage ) === true ){ |
| 164 | + |
| 165 | + |
| 166 | + // |
| 167 | + // Try to grab the default image |
| 168 | + if( $.fn.cacheImages.testOutput( image, true ) == false ){ |
| 169 | + if( $.fn.cacheImages.defaults.debug ){ console.log( 'FV.cacheImage.Output: Failed to load image ' + url ); } |
| 170 | + if( $.fn.cacheImages.testOutput( $.fn.cacheImages.defaults.defaultImage, true ) ){ |
141 | 171 | image = $.fn.cacheImages.defaults.defaultImage; // this is an encoded string |
142 | 172 | }else{ |
143 | 173 | $.fn.cacheImages.Output( $.fn.cacheImages.defaults.defaultImage, callbackFunction, storagePrefix ); // pass the callback through |
|
0 commit comments