PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2
Jetpack – WP Security, Backup, Speed, & Growth v6.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / photon / photon.js
photon.js
56 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* jshint onevar: false */
2
3 (function($){
4 /**
5 * For images lacking explicit dimensions and needing them, try to add them.
6 */
7 var restore_dims = function() {
8 $( 'img[data-recalc-dims]' ).each( function recalc() {
9 var $this = $( this );
10 if ( this.complete ) {
11
12 // Support for lazy loading: if there is a lazy-src
13 // attribute and it's value is not the same as the current src we
14 // should wait until the image load event
15 if ( $this.data( 'lazy-src' ) && $this.attr( 'src' ) !== $this.data( 'lazy-src' ) ) {
16 $this.load( recalc );
17 return;
18 }
19
20 var width = this.width,
21 height = this.height;
22
23 if ( width && width > 0 && height && height > 0 ) {
24 $this.attr( {
25 width: width,
26 height: height
27 } );
28
29 reset_for_retina( this );
30 }
31 }
32 else {
33 $this.load( recalc );
34 }
35 } );
36 },
37
38 /**
39 * Modify given image's markup so that devicepx-jetpack.js will act on the image and it won't be reprocessed by this script.
40 */
41 reset_for_retina = function( img ) {
42 $( img ).removeAttr( 'data-recalc-dims' ).removeAttr( 'scale' );
43 };
44
45 /**
46 * Check both when page loads, and when IS is triggered.
47 */
48 $( document ).ready( restore_dims );
49
50 if ( 'on' in $.fn ) {
51 $( document.body ).on( 'post-load', restore_dims );
52 } else {
53 $( document ).delegate( 'body', 'post-load', restore_dims );
54 }
55 })(jQuery);
56