Skip to content

Commit 74493e8

Browse files
author
Amr Wagdy
committed
Feat: Possibility to not replace URL to single image - T6606
1 parent a75df1f commit 74493e8

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

Diff for: README-BLUR-HASH.md

+6
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ It is recommended to prevent page layout jumping. The parameter is used to calcu
485485

486486
To see the full cloudimage documentation [click here](https://docs.cloudimage.io/go/cloudimage-documentation)
487487

488+
### ci-do-not-replace-url (or data-ci-do-not-replace-url)
489+
490+
###### Type: **Boolean** | _optional_ | Default: **false**
491+
492+
If set to true, the plugin will only add query parameters to the provided image source URL.
493+
488494
### ci-not-lazy (or data-ci-not-lazy)
489495

490496
###### Type: **Bool**

Diff for: README-PLAIN.md

+6
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ adds possibility to use fixed height or width and change dynamically other dimen
471471
**NOTE:** if size is not set, the plugin uses a special algorithm to
472472
detect the width of image container and set the image size accordingly. This is the recommended way of using the Cloudimage Responsive plugin.
473473

474+
### ci-do-not-replace-url (or data-ci-do-not-replace-url)
475+
476+
###### Type: **Boolean** | _optional_ | Default: **false**
477+
478+
If set to true, the plugin will only add query parameters to the provided image source URL.
479+
474480
### ci-not-lazy (or data-ci-not-lazy)
475481

476482
###### Type: **Bool**

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ It is recommended to set this parameter to prevent page layout jumping. It is us
492492

493493
To see the full Cloudimage documentation, [click here](https://docs.cloudimage.io/go/cloudimage-documentation).
494494

495+
### ci-do-not-replace-url (or data-ci-do-not-replace-url)
496+
497+
###### Type: **Boolean** | _optional_ | Default: **false**
498+
499+
If set to true, the plugin will only add query parameters to the provided image source URL.
500+
495501
### ci-not-lazy (or data-ci-not-lazy)
496502

497503
###### Type: **Bool**

Diff for: README_v6.md

+6
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ It is recommended to prevent page layout jumping. The parameter is used to calcu
391391

392392
To see the full cloudimage documentation [click here](https://docs.cloudimage.io/go/cloudimage-documentation)
393393

394+
### ci-do-not-replace-url (or data-ci-do-not-replace-url)
395+
396+
###### Type: **Boolean** | _optional_ | Default: **false**
397+
398+
If set to true, the plugin will only add query parameters to the provided image source URL.
399+
394400
## <a name="lazy_loading"></a> Lazy Loading
395401

396402
Lazy loading is not included into js-cloudimage-responsive by default. If you [enable lazy loading](#lazy_loading_config) in the configuration, you need to add an additional library.

Diff for: examples/low-preview/src/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ <h2 class="content-text">
9090
</a>
9191
</div>
9292
<div class="sea-coast container">
93-
<img id="hero-section-image" ci-params="ci_info=1" ci-src="Main+image.jpg?vh=a1983b" alt="sea-coast" />
93+
<img
94+
id="hero-section-image"
95+
ci-params="ci_info=1"
96+
ci-src="Main+image.jpg?vh=a1983b"
97+
alt="sea-coast"
98+
/>
9499
<div class="image-size-wrapper">
95100
<p class="text">
96101
<span><span id="hero-section-image-size"></span> px</span>

Diff for: src/common/ci.utils.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const getCommonImageProps = (image) => ({
2424
isLazyCanceled: (attr(image, 'ci-not-lazy') !== null || attr(image, 'data-ci-not-lazy') !== null) || undefined,
2525
preserveSize: (attr(image, 'ci-preserve-size') !== null || attr(image, 'data-preserve-size') !== null) || undefined,
2626
imgNodeWidth: attr(image, 'width'),
27-
imgNodeHeight: attr(image, 'height')
27+
imgNodeHeight: attr(image, 'height'),
28+
doNotReplaceImageUrl: isTrue(image, 'ci-do-not-replace-url')
2829
});
2930

3031
export const getParams = (params) => {
@@ -82,7 +83,8 @@ export const getImageProps = (image, imgSelector) => {
8283
...getCommonImageProps(image),
8384
imgNodeSRC: attr(image, imgSelector) || undefined
8485
};
85-
const params = {
86+
87+
const params = {
8688
...getParamsFromURL(props.imgNodeSRC || ''),
8789
...props.params
8890
};
@@ -118,6 +120,13 @@ const getURLWithoutQueryParams = (url = '') => url.split('?')[0];
118120

119121
const attr = (element, attribute) => element.getAttribute(attribute);
120122

123+
const isTrue = (element, attribute) => {
124+
const imgProp = attr(element, attribute);
125+
const imgDataProp = attr(element, `data-${attribute}`);
126+
127+
return (imgProp !== null && imgProp !== 'false') || (imgDataProp !== null && imgDataProp !== 'false');
128+
};
129+
121130
export const addClass = (elem, className) => {
122131
if (!(elem.className.indexOf(className) > -1)) {
123132
elem.className += ' ' + className;

0 commit comments

Comments
 (0)