-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @module Banners | ||
* @description Adds banners to your site. | ||
*/ | ||
|
||
import * as GLOBALS from 'publicConfig/wp-settings'; | ||
import { bannerWrapper, bannerContent } from '../templates/banners'; | ||
|
||
const banners = { | ||
top: '', | ||
bottom: '', | ||
}; | ||
|
||
/** | ||
* Determines if the given banner should be displayed. | ||
* | ||
* @param {*} banner BigCommerce Banner object. | ||
* @return {boolean} True if banner should be displayed false otherwise. | ||
*/ | ||
const showBanner = (banner) => { | ||
const now = Math.round(new Date().getTime() / 1000); | ||
|
||
// check if banner is visible and not expired | ||
if (!banner.visible || (banner.date_type === 'custom' && now >= banner.date_to)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
const init = () => { | ||
if (!GLOBALS.BANNERS) { | ||
return; | ||
} | ||
|
||
// Loop through banners array | ||
GLOBALS.BANNERS.items.forEach((banner) => { | ||
if (!showBanner(banner)) { | ||
return; | ||
} | ||
|
||
// append banner to location | ||
banners[banner.location] += bannerContent(banner.content); | ||
}); | ||
|
||
const styles = `background-color: ${GLOBALS.BANNERS.bg_color}; color: ${GLOBALS.BANNERS.text_color};`; | ||
|
||
// insert "top" banners | ||
if (banners.top) { | ||
document.body.insertAdjacentHTML('afterbegin', bannerWrapper(styles, banners.top)); | ||
} | ||
|
||
// insert "bottom" banners | ||
if (banners.bottom) { | ||
document.body.insertAdjacentHTML('beforeend', bannerWrapper(styles, banners.bottom)); | ||
} | ||
}; | ||
|
||
export default init; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @module Banners | ||
* @description Clearinghouse for all banner scripts. | ||
*/ | ||
|
||
import banners from './banners'; | ||
|
||
const init = () => { | ||
banners(); | ||
}; | ||
|
||
export default init; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const bannerContent = content => ( | ||
`<div class="bc-banner">${content}</div>` | ||
); | ||
|
||
export const bannerWrapper = (styles = null, banners = null) => ( | ||
`<div class="bc-banners" style="${styles}">${banners}</div>` | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
@import "order-product-row"; | ||
@import "images"; | ||
@import "wish-lists"; | ||
@import "banner"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.bc-banners { | ||
padding: 0.78571em 0; | ||
text-align: center; | ||
|
||
p:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.bc-banner { | ||
margin: 0 auto; | ||
max-width: 85.71429em; | ||
width: 100%; | ||
} |