<div class="recent-players-squad" data-behaviour="recent-players-squad-selection">
<div class="recent-players-squad__section">
<div class="recent-players-squad__label">SELECT SQUAD</div>
<div class="recent-players-squad__dropdown" role="button" aria-label="SELECT SQUAD">
<label for="recent-players-squad-select">
<select id="recent-players-squad-select" class="custom-select">
<option value="/components/preview/squad-page?sqd=CURRENT" selected>CURRENT</option>
<option value="/components/preview/squad-page?sqd=RECENT">RECENT</option>
</select>
</label>
</div>
</div>
</div>
No notes defined.
{
"recent-players-squad": [
{
"text": "CURRENT",
"value": "/components/preview/squad-page?sqd=CURRENT",
"default": true
},
{
"text": "RECENT",
"value": "/components/preview/squad-page?sqd=RECENT"
}
]
}
import customSelect from '../../behaviours/select/custom-select';
const MOBILE_BREAKPOINT = 800;
const recentPlayerSquadSelect = document.querySelector(
'[data-behaviour="recent-players-squad-selection"]'
);
if (window.innerWidth >= MOBILE_BREAKPOINT && recentPlayerSquadSelect) {
const recentPlayerSelectBox = document
.querySelector('.recent-players-squad')
.querySelector('.custom-select');
if (recentPlayerSelectBox) {
customSelect(recentPlayerSelectBox);
}
}
window.addEventListener('DOMContentLoaded', () => {
function getUrlParameters(parameter, staticURL, decode) {
const currLocation = staticURL.length ? staticURL : window.location.search;
if (!currLocation) {
return null;
}
const parArr = currLocation.split('?')[1].split('&');
const returnBool = true;
for (let i = 0; i < parArr.length; i++) {
const parr = parArr[i].split('=');
if (parr[0] === parameter) {
return decode ? decodeURIComponent(parr[1]) : parr[1];
}
}
if (!returnBool) {
return false;
}
return null;
}
function getStringValue(parameter, currLocation) {
if (!currLocation) {
return null;
}
const parArr = currLocation.split('?')[1].split('&');
const returnBool = true;
for (let i = 0; i < parArr.length; i++) {
const parr = parArr[i].split('=');
if (parr[0] === parameter) {
return parr[1];
}
}
if (!returnBool) {
return false;
}
return null;
}
const getDropdownIds = getUrlParameters('sqd', '');
const getSelectBoxID = document.querySelector('#recent-players-squad-select');
const getCurrentDropdown = document.querySelector('.select-styled');
if (getDropdownIds) {
getSelectBoxID.querySelectorAll('option').forEach(option => {
if (getStringValue('sqd', option.value) === getDropdownIds) {
option.setAttribute('selected', 'selected');
getCurrentDropdown.innerText = getDropdownIds;
getCurrentDropdown.setAttribute('rel', option.value);
} else {
option.removeAttribute('selected');
}
});
document.querySelectorAll('.select-options > li').forEach(option => {
option.removeAttribute('style');
if (
getStringValue('sqd', option.getAttribute('rel')) === getDropdownIds
) {
// eslint-disable-next-line no-param-reassign
option.style.display = 'none';
}
});
}
});
export default parentElement => {
const ENTER_KEY_CODE = 13;
// add data-behavior hero-carousel-with-squad-selection for styling settings.
const heroCarouselElement = document.querySelector(
'[data-behavior="hero-carousel"]'
);
const heroBannerElement = document.querySelector('.banner');
if (heroCarouselElement) {
heroCarouselElement.dataset.behavior = 'hero-carousel-with-squad-selection';
}
if (heroBannerElement) {
heroBannerElement.dataset.behavior = 'hero-carousel-with-squad-selection';
}
const resizeRecentPlayerBlock = () => {
const trayWidth = document.querySelector('.page-content__tray').clientWidth;
document.querySelector(
'.recent-players-squad'
).style.width = `${trayWidth}px`;
};
resizeRecentPlayerBlock();
if (window.innerWidth >= MOBILE_BREAKPOINT) {
const optionSelect = document.querySelectorAll('.select-options li');
const optionTimer = setInterval(() => {
if (optionSelect) {
parentElement.querySelectorAll('.select-options li').forEach(option => {
option.addEventListener('click', event => {
event.stopPropagation();
// const opt = `?sqd=${event.target.getAttribute('rel')}`;
// eslint-disable-next-line no-restricted-globals
location.href = `${location.origin}${event.target.getAttribute(
'rel'
)}`;
// console.log(event.target.getAttribute('rel'));
});
option.addEventListener('keydown', event => {
if (event.keyCode === ENTER_KEY_CODE) {
event.preventDefault();
// eslint-disable-next-line no-restricted-globals
location.href = `${location.origin}${event.target.getAttribute(
'rel'
)}`;
}
});
});
clearInterval(optionTimer);
}
}, 500);
document.addEventListener('click', event => {
event.stopPropagation();
});
} else {
parentElement
.querySelector('.custom-select')
.addEventListener('change', event => {
event.stopPropagation();
// const opt = `?sqd=${event.target.value}`;
// eslint-disable-next-line no-restricted-globals
location.href = `${location.origin}${event.target.value}`;
// console.log(`${event.target.value}`);
});
}
window.addEventListener('resize', () => resizeRecentPlayerBlock());
};
.recent-players-squad {
justify-content: center;
align-items: center;
flex-direction: column;
z-index: 99;
transition: all 0.4s ease-out 0s;
background-color: #d2d7e2;
border-radius: 1.2rem 1.2rem 0 0;
width: calc(100vw - 1.6rem);
transform: translate(-1.6rem, -4.4rem);
padding: 2.2rem 1.6rem;
height: 13.8rem;
&__section {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
&__label {
@include heading-m;
line-height: 3.4rem;
color: var(--brand-primary);
margin-bottom: 1.6rem;
}
&.fixed-selection {
.youth-team-selection__label {
display: none;
}
}
&__dropdown {
position: relative;
width: 100%;
&::after {
content: '';
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
right: 0;
top: 1px;
padding: 0 0 2px;
position: absolute;
pointer-events: none;
background: url('./assets/images/chevron.svg') no-repeat center center;
width: 3.8rem;
height: 3.7rem;
background-size: 0.8rem 1rem;
background-color: rgba(187, 193, 206, 0.3);
border-bottom: 1px solid rgba(187, 193, 206, 0.6);
}
}
select::-ms-expand {
display: none;
}
select {
font-family: $text-font;
font-size: 1.4rem;
line-height: 4.4rem;
color: $crest-blue;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
display: block;
width: 100%;
height: 3.8rem;
padding: 0 1.6rem;
background-color: $white;
-ms-word-break: normal;
word-break: normal;
border: 1px solid $grey;
box-sizing: border-box;
}
@media screen and (min-width: $mq-medium) {
display: flex;
height: 9.4rem;
flex-direction: row;
padding: 0.8rem 0;
width: calc(100vw - 5rem);
transform: translate(-11.8rem, -7.3rem);
label {
position: relative;
width: 100%;
height: 3.8rem;
display: block;
}
&__section {
flex-direction: row;
}
&__label {
margin-right: 2.4rem;
margin-bottom: 0;
}
&.fixed-selection {
.youth-team-selection__label {
display: block;
}
}
&__dropdown {
width: 29rem;
&::after {
content: '';
display: none;
}
}
.select-styled {
border: 1px solid $grey;
line-height: 3.8rem;
&::after {
width: 3.6rem;
height: 3.6rem;
border-bottom: 1px solid rgba(187, 193, 206, 0.6);
}
&.active::after {
border-bottom: none;
border-top: 1px solid rgba(187, 193, 206, 0.6);
}
}
.select-options {
border: 1px solid $grey;
border-top: 0;
}
.select-options li:nth-child(2) {
border-top: 0;
}
.select-options li:hover {
background: var(--brand-primary);
}
}
}
@media screen and (min-width: 820px) {
.page-content__tray {
top: -9.4rem !important;
}
}
:root [data-brand='legends'] {
.recent-players-squad {
&__label {
color: $color-interface-light;
}
}
}
<div class="recent-players-squad" data-behaviour="recent-players-squad-selection">
<div class="recent-players-squad__section">
<div class="recent-players-squad__label">SELECT SQUAD</div>
<div class="recent-players-squad__dropdown" role="button" aria-label="SELECT SQUAD">
<label for="recent-players-squad-select">
<select id="recent-players-squad-select" class="custom-select">
{{#each recent-players-squad}}
<option value="{{value}}" {{#if default}}selected{{/if}}>{{text}}</option>
{{/each}}
</select>
</label>
</div>
</div>
</div>