Skip to content

Commit acb645c

Browse files
authored
Merge pull request #483 from cloudinary/uat
2.7.5-rc-3
2 parents 477f22f + dda25c9 commit acb645c

39 files changed

+1435
-245
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"jQuery": "readonly",
88
"$": "readonly",
99
"CLDN": "readonly",
10+
"CLDLB": "readonly",
1011
"CLD_GLOBAL_TRANSFORMATIONS": "readonly",
1112
"samplePlayer": "readonly",
1213
"CLDCACHE": "readonly"

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.4
1+
2.7.5-rc-3

css/cloudinary.css

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

css/src/components/_ui.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@
198198
align-self: center;
199199
padding: 0 0.45rem;
200200
cursor: pointer;
201-
position: absolute;
202-
right: 0;
203201
}
204202

205203
&-title {
@@ -318,16 +316,23 @@
318316
}
319317

320318
&-group {
319+
.cld-group .cld-group {
320+
padding-left: 4px;
321+
}
321322

322323
hr {
323324
border-top: 1px solid $color-light-grey;
324325
margin: 1.5rem 0;
325326
clear: both;
326327
}
327328

329+
.cld-group .cld-group hr {
330+
display: none;
331+
}
332+
328333
&-heading {
329334
display: flex;
330-
335+
justify-content: space-between;
331336
h3 {
332337
font-size: 0.9rem;
333338

js/cloudinary.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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '4f54b160de748912ea5ea5d8ce80f326');

js/lazy-load.js

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

js/src/components/ui.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ const UI = {
1717
const triggers = context.querySelectorAll( '[data-bind-trigger]' );
1818
const masters = context.querySelectorAll( '[data-master]' );
1919
const files = context.querySelectorAll( '[data-file]' );
20+
const autoSuffix = context.querySelectorAll( '[data-auto-suffix]' );
2021
const self = this;
2122
const compilerDebounce = {};
2223

2324
// Bind on offs.
2425
OnOff.bind( masters );
25-
26+
autoSuffix.forEach( ( input ) => this._autoSuffix( input ) );
2627
triggers.forEach( ( input ) => this._trigger( input ) );
2728
toggles.forEach( ( toggle ) => this._toggle( toggle ) );
2829
conditions.forEach( ( condition ) => this._bind( condition ) );
@@ -48,6 +49,30 @@ const UI = {
4849
// Start cache manager.
4950
CacheManage.init( context );
5051
},
52+
_autoSuffix( input ) {
53+
const suffixes = input.dataset.autoSuffix;
54+
let defaultSuffix = '';
55+
const valid = [ ...suffixes.split( ';' ) ].map( ( suffix ) => {
56+
if ( 0 === suffix.indexOf( '*' ) ) {
57+
defaultSuffix = suffix.replace( '*', '' );
58+
return defaultSuffix;
59+
}
60+
return suffix;
61+
} );
62+
input.addEventListener( 'change', () => {
63+
const value = input.value.replace( ' ', '' );
64+
const number = value.replace( /[^0-9]/g, '' );
65+
const type = value.replace( /[0-9]/g, '' ).toLowerCase();
66+
if ( number ) {
67+
if ( -1 === valid.indexOf( type ) ) {
68+
input.value = number + defaultSuffix;
69+
} else {
70+
input.value = number + type;
71+
}
72+
}
73+
} );
74+
input.dispatchEvent( new Event( 'change' ) );
75+
},
5176
_files( file, compilerDebounce ) {
5277
const parent = file.dataset.parent;
5378
if ( ! parent ) {

js/src/lazy-load.js

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
const LazyLoad = {
2+
density: window.devicePixelRatio ? window.devicePixelRatio : 'auto',
3+
images: [],
4+
debounce: null,
5+
config: CLDLB ? CLDLB : {},
6+
lazyThreshold: 0,
7+
_init() {
8+
this._calcThreshold();
9+
[ ...document.images ].forEach( ( image ) => {
10+
if ( ! image.dataset.src ) {
11+
return;
12+
}
13+
image.originalWidth = image.dataset.width;
14+
this.images.push( image );
15+
} );
16+
17+
// Resize handler.
18+
window.addEventListener( 'resize', ( ev ) => {
19+
this._debounceBuild();
20+
} );
21+
window.addEventListener( 'scroll', ( ev ) => {
22+
this._debounceBuild();
23+
} );
24+
// Build images.
25+
this._build();
26+
},
27+
_calcThreshold() {
28+
const number = this.config.lazy_threshold.replace( /[^0-9]/g, '' );
29+
const type = this.config.lazy_threshold
30+
.replace( /[0-9]/g, '' )
31+
.toLowerCase();
32+
let unit = 0;
33+
switch ( type ) {
34+
case 'em':
35+
unit =
36+
parseFloat( getComputedStyle( document.body ).fontSize ) *
37+
number;
38+
break;
39+
case 'rem':
40+
unit =
41+
parseFloat(
42+
getComputedStyle( document.documentElement ).fontSize
43+
) * number;
44+
break;
45+
case 'vh':
46+
unit = ( window.innerHeight / number ) * 100;
47+
break;
48+
default:
49+
unit = number;
50+
}
51+
this.lazyThreshold = window.innerHeight + parseInt( unit, 10 );
52+
},
53+
_debounceBuild() {
54+
if ( this.debounce ) {
55+
clearTimeout( this.debounce );
56+
}
57+
this.debounce = setTimeout( () => {
58+
this._build();
59+
}, 100 );
60+
},
61+
_getDensity() {
62+
const maxDensity = CLDLB.dpr ? CLDLB.dpr.replace( 'X', '' ) : 'off';
63+
if ( 'off' === maxDensity ) {
64+
return 1;
65+
}
66+
let deviceDensity = this.density;
67+
if (
68+
! CLDLB.dpr_precise &&
69+
'auto' !== maxDensity &&
70+
'auto' !== deviceDensity
71+
) {
72+
deviceDensity =
73+
deviceDensity > Math.ceil( maxDensity )
74+
? maxDensity
75+
: deviceDensity;
76+
} else if ( 'auto' === CLDLB.dpr && 'auto' !== deviceDensity ) {
77+
deviceDensity = 'auto';
78+
}
79+
80+
return deviceDensity;
81+
},
82+
_build() {
83+
this.images.forEach( ( image ) => {
84+
this.buildSize( image );
85+
} );
86+
},
87+
_shouldRebuild( image ) {
88+
const width = this.scaleSize(
89+
image.originalWidth,
90+
image.width,
91+
this.config.pixel_step
92+
);
93+
const rect = image.getBoundingClientRect();
94+
const density = 'auto' !== this.density ? this._getDensity() : 1;
95+
return (
96+
rect.top < this.lazyThreshold &&
97+
( width > image.naturalWidth / density || ! image.cld_loaded )
98+
);
99+
},
100+
_shouldPlacehold( image ) {
101+
const width = this.scaleSize(
102+
image.originalWidth,
103+
image.width,
104+
this.config.pixel_step
105+
);
106+
const rect = image.getBoundingClientRect();
107+
const density = 'auto' !== this.density ? this._getDensity() : 1;
108+
return (
109+
! image.cld_loaded &&
110+
rect.top < this.lazyThreshold * 2 &&
111+
( width > image.naturalWidth / density || ! image.cld_placehold )
112+
);
113+
},
114+
getResponsiveSteps( image ) {
115+
const steps = Math.ceil(
116+
image.dataset.breakpoints
117+
? image.originalWidth / image.dataset.breakpoints
118+
: this.responsiveStep
119+
);
120+
return steps;
121+
},
122+
getQuality() {
123+
let quality = 'q_auto';
124+
switch (
125+
navigator && navigator.connection
126+
? navigator.connection.effectiveType
127+
: 'none'
128+
) {
129+
case 'none':
130+
break;
131+
case '4g':
132+
quality = 'q_auto:good';
133+
break;
134+
case '3g':
135+
quality = 'q_auto:eco';
136+
break;
137+
case '2g':
138+
case 'slow-2g':
139+
quality = 'q_auto:low';
140+
break;
141+
default:
142+
quality = 'q_auto:best';
143+
break;
144+
}
145+
return quality;
146+
},
147+
scaleSize( original, newSize, responsiveStep ) {
148+
const diff = Math.floor( ( original - newSize ) / responsiveStep );
149+
let scaledSize = original - responsiveStep * diff;
150+
if ( scaledSize > original ) {
151+
scaledSize = original;
152+
} else if ( this.config.max_width < scaledSize ) {
153+
scaledSize = original;
154+
}
155+
return scaledSize;
156+
},
157+
buildSize( image ) {
158+
if ( this._shouldRebuild( image ) ) {
159+
if ( image.dataset.srcset ) {
160+
image.srcset = image.dataset.srcset;
161+
} else {
162+
image.src = this.getSizeURL( image );
163+
}
164+
} else if ( this._shouldPlacehold( image ) ) {
165+
image.src = this.getPlaceholderURL( image );
166+
}
167+
},
168+
getSizeURL( image ) {
169+
image.cld_loaded = true;
170+
if ( image.dataset.srcset ) {
171+
image.srcset = image.dataset.srcset;
172+
delete image.dataset.srcset;
173+
return '';
174+
}
175+
const width = this.scaleSize(
176+
image.originalWidth,
177+
image.width,
178+
this.config.pixel_step
179+
);
180+
const density = this._getDensity();
181+
let newSize = '';
182+
if ( width ) {
183+
newSize += 'w_' + width;
184+
if ( 1 !== density ) {
185+
newSize += ',dpr_' + density;
186+
}
187+
}
188+
return image.dataset.src
189+
.replace( '--size--', newSize )
190+
.replace( /q_auto(?!:)/gi, this.getQuality() );
191+
},
192+
getPlaceholderURL( image ) {
193+
image.cld_placehold = true;
194+
return image.dataset.placeholder.replace( '/--size--', '/' );
195+
},
196+
};
197+
// Init.
198+
window.addEventListener( 'load', () => {
199+
LazyLoad._init();
200+
} );

js/wp-color-picker-alpha.min.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)