|
10 | 10 | * @requires jQuery v1.7 or later |
11 | 11 | * |
12 | 12 | * Official jQuery plugin page: |
13 | | - * Find source on GitHub: https://github.com/FreshVine/jQuery-cache-image |
| 13 | + * Find source on GitHub: https://github.com/FreshVine/jQuery-cache-images |
14 | 14 | * |
15 | 15 | * Dual licensed under the MIT and GPL licenses: |
16 | 16 | * http://www.opensource.org/licenses/mit-license.php |
|
72 | 72 | } |
73 | 73 | if( typeof imgType === 'undefined' || localSrcEncoded === 'pending' ){ |
74 | 74 | // This is either not an image, or the URL is already being processed somewhere else |
75 | | - self.cacheImagesConfig.fail.call( $this ); |
76 | | - self.cacheImagesConfig.always.call( $this ); |
| 75 | + self.cacheImagesConfig.fail.call( this ); |
| 76 | + self.cacheImagesConfig.always.call( this ); |
77 | 77 | return; // stop running |
78 | 78 | } |
79 | 79 |
|
|
84 | 84 | if( self.cacheImagesConfig.encodeOnCanvas && imgType !== 'gif' ){ // For some reason animated gifs do not correctly encode on the canvas |
85 | 85 | $this.load(function () { |
86 | 86 | newSrc = $.fn.cacheImages.base64EncodeCanvas( img ); // Process the image |
87 | | - $.fn.cacheImages.set( $this, key, newSrc ); // Save the media |
| 87 | + $.fn.cacheImages.set( this, key, newSrc ); // Save the media |
88 | 88 | if( src.substring(0,5) === 'data:' ){ |
89 | | - $this.prop('src', newSrc ); |
90 | | - if( $this.is('.cacheImagesRemove') ){ |
91 | | - $this.remove(); |
| 89 | + this.prop('src', newSrc ); |
| 90 | + if( this.is('.cacheImagesRemove') ){ |
| 91 | + this.remove(); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | }); |
95 | 95 | } |
96 | 96 | else{ |
97 | | - var xhr = new XMLHttpRequest(); |
| 97 | + var xhr = new XMLHttpRequest(), |
| 98 | + thisElem = this; |
98 | 99 | xhr.open('GET', src, true); |
99 | 100 | xhr.responseType = 'arraybuffer'; // Cannot use the jQuery ajax method until it support this response type |
100 | 101 | xhr.onload = function( e ){ |
|
103 | 104 | newSrc = 'data:image/' + imgType + ';base64,' + $.fn.cacheImages.base64EncodeResponse( this.response ); |
104 | 105 | } |
105 | 106 |
|
106 | | - $.fn.cacheImages.set( $this, key, newSrc, function( key, encodedString ){ |
| 107 | + $.fn.cacheImages.set( thisElem, key, newSrc, function( key, encodedString ){ |
107 | 108 | // Default processing of the response |
108 | 109 | if( encodedString.length !== 0 && encodedString !== 'data:image/' + imgType + ';base64,'){ // it appended image data |
109 | | - this.prop('src', newSrc ); |
| 110 | + this.prop('src', encodedString ); |
110 | 111 | if( this.is('.cacheImagesRemove') ){ |
111 | 112 | this.remove(); |
112 | 113 | } |
|
0 commit comments