| 1 |
/** |
| 2 |
* Returns object with background image styles for Row and Column. |
| 3 |
* |
| 4 |
* @param {Object} attributes - block attributes. |
| 5 |
* |
| 6 |
* @return {Object} Styles object. |
| 7 |
*/ |
| 8 |
export default function getBackgroundStyles(attributes) { |
| 9 |
const { |
| 10 |
awb_image: image, |
| 11 |
awb_imageBackgroundSize: imageBackgroundSize, |
| 12 |
awb_imageBackgroundPosition: imageBackgroundPosition, |
| 13 |
} = attributes; |
| 14 |
|
| 15 |
const styles = {}; |
| 16 |
|
| 17 |
styles['> .nk-awb .jarallax-img'] = { |
| 18 |
'object-fit': undefined, |
| 19 |
'object-position': undefined, |
| 20 |
'background-repeat': undefined, |
| 21 |
'background-position': undefined, |
| 22 |
|
| 23 |
// Remove unused fallback styles. |
| 24 |
'font-family': undefined, |
| 25 |
}; |
| 26 |
|
| 27 |
// <img> tag with object-fit style |
| 28 |
if (image) { |
| 29 |
if (imageBackgroundSize !== 'pattern') { |
| 30 |
if (imageBackgroundSize) { |
| 31 |
styles['> .nk-awb .jarallax-img']['object-fit'] = |
| 32 |
imageBackgroundSize; |
| 33 |
} |
| 34 |
if (imageBackgroundPosition) { |
| 35 |
styles['> .nk-awb .jarallax-img']['object-position'] = |
| 36 |
imageBackgroundPosition; |
| 37 |
} |
| 38 |
|
| 39 |
// background image with pattern size |
| 40 |
} else { |
| 41 |
if (imageBackgroundSize) { |
| 42 |
styles['> .nk-awb .jarallax-img']['background-repeat'] = |
| 43 |
'repeat'; |
| 44 |
} |
| 45 |
if (imageBackgroundSize) { |
| 46 |
styles['> .nk-awb .jarallax-img']['background-position'] = |
| 47 |
imageBackgroundPosition; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return styles; |
| 53 |
} |
| 54 |
|