/
jquery.imageCache.js
49 lines (46 loc) · 1.25 KB
/
jquery.imageCache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* jQuery Image Cache
*
* Load images from browser local storage
*
* @author Dumitru Glavan
* @link http://dumitruglavan.com
* @version 1.0
* @requires jQuery v1.3.2 or later
*
* Examples and documentation at: http://dumitruglavan.com/jquery-image-cache-plugin-cache-images-in-browsers-local-storage/
* Official jQuery plugin page: http://plugins.jquery.com/project/jquery-image-cache
* Find source on GitHub: https://github.com/doomhz/jQuery-Image-Cache
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
;(function ($) {
$.fn.imageCache = function (options) {
this.config = {
base64ImageEncoderPath: 'get_image.php?id='
};
$.extend(this.config, options);
var self = this;
var $self = $(this);
$(document).ready(function () {
$(self).each(function (i, img) {
var src = $(img).attr('src') || $(img).attr('data-src');
if (localStorage) {
var localSrc = localStorage[src];
if (localSrc) {
$(img).attr('src', localSrc);
} else {
$.get(self.config.base64ImageEncoderPath + src, function (data) {
localStorage[src] = data;
$(img).attr('src', data);
});
}
}
});
});
return this;
}
})(jQuery);