Skip to content

Commit a9cda51

Browse files
committed
Create a utility method
1 parent 8b9a3cd commit a9cda51

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

js/inline-loader.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '007ec7db37693c504126');
1+
<?php return array('dependencies' => array(), 'version' => 'ddf62970fa28de856098');

js/inline-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lazy-load.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '55e7765755171c4d412c');
1+
<?php return array('dependencies' => array(), 'version' => '763fff6b35eade3cc6d2');

js/lazy-load.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/inline-loader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { roundToHalf } from './utils';
2+
13
const CloudinaryLoader = {
24
deviceDensity: window.devicePixelRatio ? window.devicePixelRatio : 'auto',
35
density: null,
@@ -154,7 +156,7 @@ const CloudinaryLoader = {
154156

155157
// Round to nearest 0.5 to reduce URL variations
156158
if ( 'auto' !== deviceDensity ) {
157-
deviceDensity = Math.round( deviceDensity * 2 ) / 2;
159+
deviceDensity = roundToHalf( deviceDensity );
158160
}
159161

160162
if (
@@ -164,7 +166,7 @@ const CloudinaryLoader = {
164166
maxDensity = parseFloat( maxDensity );
165167

166168
// Round maxDensity to nearest 0.5 to maintain consistency
167-
maxDensity = Math.round( maxDensity * 2 ) / 2;
169+
maxDensity = roundToHalf( maxDensity );
168170
deviceDensity =
169171
deviceDensity > Math.ceil( maxDensity )
170172
? maxDensity

src/js/lazy-load.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { roundToHalf } from './utils';
2+
13
const LazyLoad = {
24
deviceDensity: window.devicePixelRatio ? window.devicePixelRatio : 'auto',
35
density: null,
@@ -76,7 +78,7 @@ const LazyLoad = {
7678

7779
// Round to nearest 0.5 to reduce URL variations
7880
if ( 'auto' !== deviceDensity ) {
79-
deviceDensity = Math.round( deviceDensity * 2 ) / 2;
81+
deviceDensity = roundToHalf( deviceDensity );
8082
}
8183

8284
if (
@@ -85,7 +87,7 @@ const LazyLoad = {
8587
) {
8688
maxDensity = parseFloat( maxDensity );
8789
// Round maxDensity to nearest 0.5 to maintain consistency
88-
maxDensity = Math.round( maxDensity * 2 ) / 2;
90+
maxDensity = roundToHalf( maxDensity );
8991
deviceDensity =
9092
deviceDensity > Math.ceil( maxDensity )
9193
? maxDensity

0 commit comments

Comments
 (0)