Skip to content

Commit e7e6810

Browse files
authored
Merge pull request #28 from scaleflex/T8076-feat-possibility-to-change-ci-src
T8076 feat possibility to change ci src
2 parents c9291aa + a6a7a32 commit e7e6810

26 files changed

+538
-13
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Types of changes:
2525
- ...
2626

2727
-------------
28+
## 4.9.1 - 2022-08-15
29+
### Fixed
30+
- `updateImage` method when image doesn't have low-preivew.
31+
32+
## 4.9.0 - 2022-08-11
33+
### Added
34+
- Possibility to change ci-src and process image.
35+
2836
## 4.8.13 - 2022-08-05
2937
### Fixed
3038
- Undefined hostname when adding relative src

Diff for: README-BLUR-HASH.md

+75
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ powered by [Cloudimage](https://www.cloudimage.io/)
8181
* [Step 3: Implement](#implement)
8282
* [Step 4: Prevent seeing broken images](#prevent_styles)
8383
* [Configuration](#configuration)
84+
* [Methods](#methods)
8485
* [Image properties](#image_properties)
8586
* [Lazy loading](#lazy_loading)
8687
* [Process dynamically loaded images](#dynamically-loaded)
@@ -125,6 +126,7 @@ In order to use Cloudimage responsive plugins on your single-page application, p
125126
<summary>Angular</summary>
126127
<a href="https://github.com/scaleflex/ng-cloudimage-responsive">Angular Cloudimage Responsive (Low Quality Preview)</a><br/>
127128
</details>
129+
128130
## <a name="requirements"/> Requirements
129131

130132
### Cloudimage account
@@ -397,8 +399,81 @@ If width and height attributes are NOT set, image container size will be detecte
397399
*Note*: If only width or height attributes is set, ratio is going to be taken from ci-ratio image attribute
398400

399401

402+
## <a name="methods"></a> methods
403+
404+
#### `updateImage`
405+
406+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
407+
408+
arguments:
409+
410+
`imgNode: HTMLElement` The image node to be updated.<br/>
411+
`newSrc: String` The new image src.<br/>
412+
`options: Object` Options that you need to add on the image, All the <a href="#image_properties">image properties</a> can be added in options.
413+
414+
Example:
415+
416+
```js
417+
const image = document.getElementById('cloudimage-image-example');
418+
const options = { 'ci-params': 'grey=1', alt: 'dress' };
419+
420+
window.ciResponsive.updateImage(image, 'dresses-img.jpg', options);
421+
```
422+
beside using this method to update image src or options. you can use it to for background images.
423+
424+
Example:
425+
```js
426+
const bgImage = document.getElementById('cloudimage-bg-example');
427+
const options = { 'ci-params': 'grey=1', alt: 'house' };
428+
429+
window.ciResponsive.updateImage(bgImage, 'house-img.jpg', options);
430+
```
431+
432+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-yzp7yz"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
433+
434+
#### `addImage`
435+
436+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
437+
438+
arguments:
439+
440+
`imgNode: HTMLElement` The image node to be added.<br/>
441+
442+
<u>Supported version: +v4.9.0</u>
443+
444+
Example:
445+
446+
```js
447+
const image = document.createElement('img');
448+
449+
image.setAttribute('ci-src', 'dresses-img.jpg');
450+
image.setAttribute('ci-params', 'gery=1');
451+
452+
document.body.appendChild(image);
453+
window.ciResponsive.addImage(image);
454+
```
455+
beside using this method to update image src or options. you can use it to for background images.
456+
457+
Example:
458+
459+
```js
460+
const bgImage = document.createElement('section');
461+
const paragraph = document.createElement('p');
462+
463+
bgImage.setAttribute('ci-bg-url', 'house-img.jpg');
464+
bgImage.setAttribute('ci-params', 'gery=1');
465+
466+
paragraph.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a nulla dictum';
467+
468+
bgImage.appendChild(paragraph);
469+
document.body.appendChild(bgImage);
470+
window.ciResponsive.addImage(bgImage);
471+
```
472+
473+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-8mk13l"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
400474
## <a name="image_properties"></a> Image properties
401475

476+
402477
Cloudimage responsive plugin will make image on your page responsive if you replace the `src` with `ci-src` attribute in the `<img>` tag:
403478

404479
### ci-src

Diff for: README-PLAIN.md

+74-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Cloudimage, contact us at
7676
* [Step 3: Implement](#implement)
7777
* [Step 4: Prevent seeing broken images](#prevent_styles)
7878
* [Configuration](#configuration)
79+
* [Methods](#methods)
7980
* [Image properties](#image_properties)
8081
* [Lazy loading](#lazy_loading)
8182
* [Process dynamically loaded images](#dynamically-loaded)
@@ -381,7 +382,7 @@ Breakpoints shortcuts to use in image size property, can be overwridden.
381382

382383
If width and height attributes are set:
383384

384-
**use** - width & height attributes values will be used to calculate image size (according to user's DPR) and **ratio**.
385+
**use** - width & height attributes values will be used to calculate image size (according to user's DPR) and **ratio**.
385386

386387
**take-ratio** - width & height attributes values will be used only to calculate **ratio**.
387388

@@ -390,6 +391,78 @@ If width and height attributes are set:
390391
If width and height attributes are NOT set, image container size will be detected to calculate result image size (according to user's DPR)
391392

392393
*Note*: If only width or height attributes is set, ratio is going to be taken from ci-ratio image attribute
394+
## <a name="methods"></a> methods
395+
396+
#### `updateImage`
397+
398+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
399+
400+
arguments:
401+
402+
`imgNode: HTMLElement` The image node to be updated.<br/>
403+
`newSrc: String` The new image src.<br/>
404+
`options: Object` Options that you need to add on the image, All the <a href="#image_properties">image properties</a> can be added in options.
405+
406+
Example:
407+
408+
```js
409+
const image = document.getElementById('cloudimage-image-example');
410+
const options = { 'ci-params': 'grey=1', alt: 'dress' };
411+
412+
window.ciResponsive.updateImage(image, 'dresses-img.jpg', options);
413+
```
414+
beside using this method to update image src or options. you can use it to for background images.
415+
416+
Example:
417+
```js
418+
const bgImage = document.getElementById('cloudimage-bg-example');
419+
const options = { 'ci-params': 'grey=1', alt: 'house' };
420+
421+
window.ciResponsive.updateImage(bgImage, 'house-img.jpg', options);
422+
```
423+
424+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-vgnpdk"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
425+
426+
#### `addImage`
427+
428+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
429+
430+
arguments:
431+
432+
`imgNode: HTMLElement` The image node to be added.<br/>
433+
434+
<u>Supported version: +v4.9.0</u>
435+
436+
Example:
437+
438+
```js
439+
const image = document.createElement('img');
440+
441+
image.setAttribute('ci-src', 'dresses-img.jpg');
442+
image.setAttribute('ci-params', 'gery=1');
443+
444+
document.body.appendChild(image);
445+
window.ciResponsive.addImage(image);
446+
```
447+
beside using this method to update image src or options. you can use it to for background images.
448+
449+
Example:
450+
451+
```js
452+
const bgImage = document.createElement('section');
453+
const paragraph = document.createElement('p');
454+
455+
bgImage.setAttribute('ci-bg-url', 'house-img.jpg');
456+
bgImage.setAttribute('ci-params', 'gery=1');
457+
458+
paragraph.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a nulla dictum';
459+
460+
bgImage.appendChild(paragraph);
461+
document.body.appendChild(bgImage);
462+
window.ciResponsive.addImage(bgImage);
463+
```
464+
465+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-8mk13l"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
393466

394467
## <a name="image_properties"></a> Image properties
395468

Diff for: README.md

+76-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ you can check our all-in-one Digital Asset Management solution
7676
* [Step 2: Initialize](#initialize)
7777
* [Step 3: Implement](#implement)
7878
* [Configuration](#configuration)
79+
* [Methods](#methods)
7980
* [Image properties](#image_properties)
8081
* [Lazy loading](#lazy_loading)
8182
* [Process dynamically loaded images](#dynamically-loaded)
@@ -308,7 +309,7 @@ Multiple params can be applied, separated by "```&```" e.g. wat_scale=35&wat_gra
308309
}
309310
```
310311

311-
#### alternative syntax
312+
#### alternative syntax
312313

313314
###### Type: **Object**
314315

@@ -396,11 +397,11 @@ Breakpoints shortcuts to use in image size property, can be overridden.
396397

397398
### imageSizeAttributes
398399

399-
###### Type: **String** | possible values: 'use', 'ignore', 'take-ratio' | Default: **'use'**
400+
###### Type: **String** | possible values: 'use', 'ignore', 'take-ratio' | Default: **'use'**
400401

401402
If width and height attributes are set:
402403

403-
**use** - width & height attributes values will be used to calculate image size (according to user's DPR) and **ratio**.
404+
**use** - width & height attributes values will be used to calculate image size (according to user's DPR) and **ratio**.
404405

405406
**take-ratio** - width & height attributes values will be used only to calculate **ratio**.
406407

@@ -410,6 +411,78 @@ If width and height attributes are NOT set, image container size will be detecte
410411

411412
*Note*: If only width or height attributes is set, ratio is going to be taken from ci-ratio image attribute
412413

414+
## <a name="methods"></a> methods
415+
416+
#### `updateImage`
417+
418+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
419+
420+
arguments:
421+
422+
`imgNode: HTMLElement` The image node to be updated.<br/>
423+
`newSrc: String` The new image src.<br/>
424+
`options: Object` Options that you need to add on the image, All the <a href="#image_properties">image properties</a> can be added in options.
425+
426+
Example:
427+
428+
```js
429+
const image = document.getElementById('cloudimage-image-example');
430+
const options = { 'ci-params': 'grey=1', alt: 'dress' };
431+
432+
window.ciResponsive.updateImage(image, 'dresses-img.jpg', options);
433+
```
434+
beside using this method to update image src or options. you can use it to for background images.
435+
436+
Example:
437+
```js
438+
const bgImage = document.getElementById('cloudimage-bg-example');
439+
const options = { 'ci-params': 'grey=1', alt: 'house' };
440+
441+
window.ciResponsive.updateImage(bgImage, 'house-img.jpg', options);
442+
```
443+
444+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-cnm8z9"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
445+
446+
#### `addImage`
447+
448+
<u>Type:</u> `function updateImage(newSrc, imgNode, options)`
449+
450+
arguments:
451+
452+
`imgNode: HTMLElement` The image node to be added.<br/>
453+
454+
<u>Supported version: +v4.9.0</u>
455+
456+
Example:
457+
458+
```js
459+
const image = document.createElement('img');
460+
461+
image.setAttribute('ci-src', 'dresses-img.jpg');
462+
image.setAttribute('ci-params', 'gery=1');
463+
464+
document.body.appendChild(image);
465+
window.ciResponsive.addImage(image);
466+
```
467+
beside using this method to update image src or options. you can use it to for background images.
468+
469+
Example:
470+
471+
```js
472+
const bgImage = document.createElement('section');
473+
const paragraph = document.createElement('p');
474+
475+
bgImage.setAttribute('ci-bg-url', 'house-img.jpg');
476+
bgImage.setAttribute('ci-params', 'gery=1');
477+
478+
paragraph.innerHTML = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a nulla dictum';
479+
480+
bgImage.appendChild(paragraph);
481+
document.body.appendChild(bgImage);
482+
window.ciResponsive.addImage(bgImage);
483+
```
484+
485+
<a href="https://codesandbox.io/s/js-cloudimage-responsive-example-8mk13l"><img src="https://codesandbox.io/static/img/play-codesandbox.svg" alt="edit in codesandbox"/></a>
413486
## <a name="image_properties"></a> Image properties
414487

415488
The Cloudimage responsive plugin will make an image on your page responsive if you replace the `src` with a `ci-src` attribute in the `<img>` tag:

Diff for: build/blur-hash/js-cloudimage-responsive.min.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/blur-hash/js-cloudimage-responsive.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/low-preview/js-cloudimage-responsive.min.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*!
2+
*
3+
* js-cloudimage-responsive v4.9.0 with low quality image placeholder technique
4+
* https://github.com/scaleflex/js-cloudimage-responsive
5+
*
6+
* Copyright (c) 2022 scaleflex
7+
* Released under the MIT license
8+
*
9+
* Date: 2022-08-15T20:33:53.648Z
10+
*
11+
*/img[ci-src]{opacity:0}div.ci-image-wrapper{display:block;width:100%;overflow:hidden;position:relative}img.ci-image{display:block;width:100%;padding:0!important;position:absolute;top:0;left:0;height:auto}img.ci-image-loaded{opacity:1}img.ci-image-ratio.ci-image-preview{height:100%}.ci-bg,.ci-bg>*{position:relative}.ci-bg:before{content:"";position:absolute;top:0;bottom:0;right:0;left:0;background:inherit;filter:blur(0);transition:filter .4s ease-in-out}.ci-bg.ci-bg-animation:before{filter:blur(10px)}

Diff for: build/low-preview/js-cloudimage-responsive.min.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/low-preview/js-cloudimage-responsive.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/plain/js-cloudimage-responsive.min.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/plain/js-cloudimage-responsive.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/wp/js-cloudimage-responsive.min.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/wp/js-cloudimage-responsive.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: config/blur-hash/webpack-build.config.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const TerserPlugin = require('terser-webpack-plugin');
23
const webpack = require('webpack');
34
const pkg = require('../../package');
45
const isDist = process.env.NODE_ENV === 'dist';
@@ -28,14 +29,20 @@ module.exports = {
2829
use: "babel-loader",
2930
exclude: /node_modules/
3031
},
31-
{
32+
{
3233
test: /\.css$/,
3334
use: ["style-loader", "css-loader"]
3435
}
3536
]
3637
},
38+
optimization: {
39+
minimizer: [new TerserPlugin({ extractComments: false })],
40+
},
3741
plugins: [
38-
new webpack.BannerPlugin(banner),
42+
new webpack.BannerPlugin({
43+
banner,
44+
entryOnly: true
45+
}),
3946
],
4047
resolve: {
4148
extensions: [".js", ".jsx"]

Diff for: config/low-preview/webpack-build.config.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const webpack = require('webpack');
33
const pkg = require('../../package');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
55
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
6+
const TerserPlugin = require('terser-webpack-plugin');
67
const isDist = process.env.NODE_ENV === 'dist';
78

89
const now = new Date();
@@ -44,9 +45,7 @@ module.exports = {
4445
optimization: {
4546
minimizer: [
4647
new CssMinimizerPlugin(),
47-
new UglifyJsPlugin({
48-
include: /\.min\.js$/
49-
})
48+
new TerserPlugin({ extractComments: false })
5049
],
5150
},
5251
resolve: {

Diff for: config/plain/webpack-build.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const TerserPlugin = require('terser-webpack-plugin');
23
const webpack = require('webpack');
34
const pkg = require('../../package');
45
const isDist = process.env.NODE_ENV === 'dist';
@@ -34,6 +35,9 @@ module.exports = {
3435
}
3536
]
3637
},
38+
optimization: {
39+
minimizer: [new TerserPlugin({ extractComments: false })],
40+
},
3741
plugins: [
3842
new webpack.BannerPlugin(banner),
3943
],

0 commit comments

Comments
 (0)