summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/photon/photon.js')
-rw-r--r--plugins/jetpack/modules/photon/photon.js40
1 files changed, 18 insertions, 22 deletions
diff --git a/plugins/jetpack/modules/photon/photon.js b/plugins/jetpack/modules/photon/photon.js
index f7d32dfc..f68daebc 100644
--- a/plugins/jetpack/modules/photon/photon.js
+++ b/plugins/jetpack/modules/photon/photon.js
@@ -1,11 +1,9 @@
-/* jshint onevar: false */
-
( function() {
function recalculate() {
if ( this.complete ) {
// Support for lazy loading: if there is a lazy-src attribute and it's value
// is not the same as the current src we should wait until the image load event
- var lazySrc = this.getAttribute('data-lazy-src');
+ var lazySrc = this.getAttribute( 'data-lazy-src' );
if ( lazySrc && this.src !== lazySrc ) {
this.addEventListener( 'onload', recalculate );
return;
@@ -15,35 +13,33 @@
var width = this.width;
var height = this.height;
if ( width && width > 0 && height && height > 0 ) {
- this.setAttribute('width', width);
- this.setAttribute('height', height);
+ this.setAttribute( 'width', width );
+ this.setAttribute( 'height', height );
reset_for_retina( this );
}
- }
- else {
+ } else {
this.addEventListener( 'onload', recalculate );
return;
}
}
-
+
/**
* For images lacking explicit dimensions and needing them, try to add them.
*/
var restore_dims = function() {
- var elements = document.querySelectorAll( 'img[data-recalc-dims]' );
- for (var i = 0; i < elements.length; i++) {
- recalculate.call( elements[i] );
- }
- },
-
- /**
- * Modify given image's markup so that devicepx-jetpack.js will act on the image and it won't be reprocessed by this script.
- */
- reset_for_retina = function( img ) {
- img.removeAttribute( 'data-recalc-dims' );
- img.removeAttribute( 'scale' );
- };
+ var elements = document.querySelectorAll( 'img[data-recalc-dims]' );
+ for ( var i = 0; i < elements.length; i++ ) {
+ recalculate.call( elements[ i ] );
+ }
+ },
+ /**
+ * Modify given image's markup so that devicepx-jetpack.js will act on the image and it won't be reprocessed by this script.
+ */
+ reset_for_retina = function( img ) {
+ img.removeAttribute( 'data-recalc-dims' );
+ img.removeAttribute( 'scale' );
+ };
/**
* Check both when page loads, and when IS is triggered.
@@ -56,6 +52,6 @@
restore_dims();
}
}
-
+
document.body.addEventListener( 'post-load', restore_dims );
} )();