PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.3.0
GenerateBlocks v1.3.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / utils / get-background-image / index.js
generateblocks / src / utils / get-background-image Last commit date
index.js 5 years ago
index.js
74 lines
1 import hexToRGBA from '../hex-to-rgba';
2
3 import {
4 applyFilters,
5 } from '@wordpress/hooks';
6
7 export default function getBackgroundImageCSS( type, props ) {
8 const {
9 attributes,
10 } = props;
11
12 const {
13 backgroundColor,
14 backgroundColorOpacity,
15 bgImage,
16 gradient,
17 bgOptions,
18 gradientColorOne,
19 gradientColorOneOpacity,
20 gradientColorTwo,
21 gradientColorTwoOpacity,
22 gradientColorStopOne,
23 gradientColorStopTwo,
24 gradientDirection,
25 } = attributes;
26
27 let gradientValue = '';
28
29 if ( gradient ) {
30 let gradientColorStopOneValue = '',
31 gradientColorStopTwoValue = '';
32
33 const gradientColorOneValue = hexToRGBA( gradientColorOne, gradientColorOneOpacity );
34 const gradientColorTwoValue = hexToRGBA( gradientColorTwo, gradientColorTwoOpacity );
35
36 if ( gradientColorOne && '' !== gradientColorStopOne ) {
37 gradientColorStopOneValue = ' ' + gradientColorStopOne + '%';
38 }
39
40 if ( gradientColorTwo && '' !== gradientColorStopTwo ) {
41 gradientColorStopTwoValue = ' ' + gradientColorStopTwo + '%';
42 }
43
44 gradientValue = 'linear-gradient(' + gradientDirection + 'deg, ' + gradientColorOneValue + gradientColorStopOneValue + ', ' + gradientColorTwoValue + gradientColorStopTwoValue + ')';
45 }
46
47 if ( 'gradient' === type ) {
48 return gradientValue;
49 }
50
51 let backgroundImage = false;
52
53 const backgroundColorValue = hexToRGBA( backgroundColor, backgroundColorOpacity );
54
55 if ( !! bgImage ) {
56 let url = bgImage.image.url;
57
58 url = applyFilters( 'generateblocks.editor.bgImageURL', url, props );
59
60 if ( 'element' === bgOptions.selector && ( backgroundColorValue || gradient ) && 'undefined' !== typeof bgOptions.overlay && bgOptions.overlay ) {
61 // Old background image overlays mixed with our gradients.
62 if ( gradient ) {
63 backgroundImage = gradientValue + ', url(' + url + ')';
64 } else if ( backgroundColorValue ) {
65 backgroundImage = 'linear-gradient(0deg, ' + backgroundColorValue + ', ' + backgroundColorValue + '), url(' + url + ')';
66 }
67 } else {
68 backgroundImage = 'url(' + url + ')';
69 }
70 }
71
72 return backgroundImage;
73 }
74