PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 11.0.2
Jetpack – WP Security, Backup, Speed, & Growth v11.0.2
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 14.4.2 All 500 releases
jetpack / modules / photon / photon.js
photon.js
58 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 function recalculate() {
3 if ( this.complete ) {
4 // Support for lazy loading: if there is a lazy-src attribute and it's value
5 // is not the same as the current src we should wait until the image load event
6 var lazySrc = this.getAttribute( 'data-lazy-src' );
7 if ( lazySrc && this.src !== lazySrc ) {
8 this.addEventListener( 'onload', recalculate );
9 return;
10 }
11
12 // Copying CSS width/height into element attributes.
13 var width = this.width;
14 var height = this.height;
15 if ( width && width > 0 && height && height > 0 ) {
16 this.setAttribute( 'width', width );
17 this.setAttribute( 'height', height );
18
19 reset_for_retina( this );
20 }
21 } else {
22 this.addEventListener( 'onload', recalculate );
23 return;
24 }
25 }
26
27 /**
28 * For images lacking explicit dimensions and needing them, try to add them.
29 */
30 var restore_dims = function () {
31 var elements = document.querySelectorAll( 'img[data-recalc-dims]' );
32 for ( var i = 0; i < elements.length; i++ ) {
33 recalculate.call( elements[ i ] );
34 }
35 },
36 /**
37 * Modify given image's markup so that devicepx-jetpack.js will act on the image and it won't be reprocessed by this script.
38 */
39 reset_for_retina = function ( img ) {
40 img.removeAttribute( 'data-recalc-dims' );
41 img.removeAttribute( 'scale' );
42 };
43
44 /**
45 * Check both when page loads, and when IS is triggered.
46 */
47 if ( typeof window !== 'undefined' && typeof document !== 'undefined' ) {
48 // `DOMContentLoaded` may fire before the script has a chance to run
49 if ( document.readyState === 'loading' ) {
50 document.addEventListener( 'DOMContentLoaded', restore_dims );
51 } else {
52 restore_dims();
53 }
54 }
55
56 document.body.addEventListener( 'is.post-load', restore_dims );
57 } )();
58