Skip to content

Commit

Permalink
Breaking: Moved background images into their own divs (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Jul 28, 2022
1 parent 147e32f commit 1a8a9b6
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 34 deletions.
4 changes: 1 addition & 3 deletions js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class Theme extends Backbone.Controller {
onPostRender(view) {
const viewModel = view.model;
const theme = viewModel.get('_vanilla');
if (!theme) return;
const model = new Backbone.Model(theme);
const el = view.$el;

if (!theme) return;

switch (viewModel.get('_type')) {
case 'page':
new ThemePageView({ model, el });
Expand Down
29 changes: 17 additions & 12 deletions js/themePageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ export default class ThemePageView extends ThemeView {

const $header = this.$('.page__header');

this.addHeaderBackgroundLayer($header);
this.setHeaderBackgroundImage(header, $header);
this.setHeaderBackgroundStyles(header, $header);
this.setHeaderMinimumHeight(header, $header);
}

addHeaderBackgroundLayer($header) {
if ($header.find(' > .background').length) return;
this.$headerBackground = $('<div class="background" aria-hidden="true"></div>')
.prependTo($header);
}

setHeaderBackgroundImage(config, $header) {
const backgroundImages = config._backgroundImage;

Expand All @@ -40,27 +47,25 @@ export default class ThemePageView extends ThemeView {
}

if (backgroundImage) {
$header
.addClass('has-bg-image')
$header.addClass('has-bg-image');
this.$headerBackground
.css('background-image', 'url(' + backgroundImage + ')');
return;
}

$header
.removeClass('has-bg-image')
.css('background-image', '');
$header.removeClass('has-bg-image');
this.$headerBackground.css('background-image', '');
}

setHeaderBackgroundStyles(config, $header) {
const styles = config._backgroundStyles;

if (!styles) return;

$header.css({
'background-repeat': styles._backgroundRepeat,
'background-size': styles._backgroundSize,
'background-position': styles._backgroundPosition
});
this.$headerBackground
.css({
'background-repeat': styles._backgroundRepeat,
'background-size': styles._backgroundSize,
'background-position': styles._backgroundPosition
});
}

setHeaderMinimumHeight(config, $header) {
Expand Down
32 changes: 19 additions & 13 deletions js/themeView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Adapt from 'core/js/adapt';
import device from 'core/js/device';

export default class ThemeView extends Backbone.View {

Expand All @@ -25,6 +26,7 @@ export default class ThemeView extends Backbone.View {

setStyles() {
this.setClasses();
this.addBackgroundLayer();
this.setBackgroundImage();
this.setBackgroundStyles();
this.setMinimumHeight();
Expand All @@ -36,14 +38,20 @@ export default class ThemeView extends Backbone.View {
this.$el.addClass(this.className());
}

addBackgroundLayer() {
if (this.$el.find(' > .background').length) return;
this.$background = $('<div class="background" aria-hidden="true"></div>')
.prependTo(this.$el);
}

setBackgroundImage() {
const backgroundImages = this.model.get('_backgroundImage');

if (!backgroundImages) return;

let backgroundImage;

switch (Adapt.device.screenSize) {
switch (device.screenSize) {
case 'large':
backgroundImage = backgroundImages._large;
break;
Expand All @@ -55,27 +63,25 @@ export default class ThemeView extends Backbone.View {
}

if (backgroundImage) {
this.$el
.addClass('has-bg-image')
this.$el.addClass('has-bg-image');
this.$background
.css('background-image', 'url(' + backgroundImage + ')');
return;
}

this.$el
.removeClass('has-bg-image')
.css('background-image', '');
this.$el.removeClass('has-bg-image');
this.$background.css('background-image', '');
}

setBackgroundStyles() {
const styles = this.model.get('_backgroundStyles');

if (!styles) return;

this.$el.css({
'background-repeat': styles._backgroundRepeat,
'background-size': styles._backgroundSize,
'background-position': styles._backgroundPosition
});
this.$background
.css({
'background-repeat': styles._backgroundRepeat,
'background-size': styles._backgroundSize,
'background-position': styles._backgroundPosition
});
}

setMinimumHeight() {
Expand Down
13 changes: 12 additions & 1 deletion less/core/article.less
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
.article {
&.has-bg-image {
position: relative;

&.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__inner {
position: relative;
}

&__header-inner {
.l-container-padding(@article-header-padding-ver, @article-header-padding-hoz);
}
Expand Down
10 changes: 9 additions & 1 deletion less/core/block.less
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
.block {
&.has-bg-image {
position: relative;

&.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__inner {
position: relative;
.l-container-padding(@block-padding-ver, @block-padding-hoz);
}

Expand Down
24 changes: 22 additions & 2 deletions less/core/page.less
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
.page {
position: relative;
max-width: inherit;
.l-container-padding(@page-padding-ver, @page-padding-hoz);

&.has-bg-image {
&.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__header.has-bg-image {
&__inner {
position: relative;
}

&__header {
position: relative;
}

&__header.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__header-inner {
position: relative;
.l-container-padding(@page-header-padding-ver, @page-header-padding-hoz);
}

Expand Down
24 changes: 22 additions & 2 deletions less/plugins/adapt-contrib-boxmenu/boxMenu.less
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
.boxmenu {
position: relative;
max-width: inherit;
.l-container-padding(@menu-padding-ver, @menu-padding-hoz);

&.has-bg-image {
&.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__header.has-bg-image {
&__inner {
position: relative;
}

&__header {
position: relative;
}

&__header.has-bg-image > .background {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: center top;
}

&__header-inner {
position: relative;
.l-container-padding(@menu-header-padding-ver, @menu-header-padding-hoz);
}

Expand Down

0 comments on commit 1a8a9b6

Please sign in to comment.