<div class="efl-survey efl-survey--page-notification" data-behavior="efl-survey">
<div class="efl-survey__header">
<canvas id="efl-survey__header--icon" width="60" height="60"></canvas>
<button class="efl-survey__close" aria-label="close quiz notification"></button>
</div>
<div class="efl-survey__quiz">
<div class="efl-survey__quiz--steps step1">
<a class="heading" href="#bundled-learning-promo">Take our quick and easy quiz</a>
<p class="copy">Earn a trophy by completing 7 questions related to this article </p>
</div>
<div class="efl-survey__quiz--steps step2 hidden">
<h4>Well done, you’ve done this Quiz</h4>
</div>
</div>
</div>
No notes defined.
/* No context defined. */
import { gsap } from 'gsap';
import { ScrollToPlugin } from 'gsap/ScrollToPlugin';
import { Rive, Fit, Layout } from '@rive-app/canvas';
import { findPos } from '../efl-filter-bar/efl-filter-bar';
export default parentElement => {
const surveyUsefulYesCta = parentElement.querySelector('.survey-useful-yes');
const surveyUsefulNoCta = parentElement.querySelector('.survey-useful-no');
const surveyPractiseYesCta = parentElement.querySelector(
'.survey-practise-yes'
);
const surveyPractiseNoCta = parentElement.querySelector(
'.survey-practise-no'
);
const surveyNotNeededCta = parentElement.querySelector('.survey-not-needed');
const surveyComplicatedCta = parentElement.querySelector(
'.survey-complicated'
);
const surveyNotUsefulCta = parentElement.querySelector('.survey-not-useful');
const surveyOtherReasonCta = parentElement.querySelector(
'.survey-other-reason'
);
const surveySubmitReasonCta = parentElement.querySelector(
'.survey-submit-reason'
);
const textArea = parentElement.querySelector('textarea');
const characterCount = parentElement.querySelector('.character-count');
const surveClearTextCta = parentElement.querySelector('.clear-text');
const closeBtn = parentElement.querySelector('.efl-survey__close');
const quizNotification = parentElement.classList.contains(
'efl-survey--page-notification'
);
const surveyHeading = parentElement.querySelector('.heading');
const bundleQuiz = document.querySelector('.bundled-learning-promo.quiz');
const { fanid, surveyPageId } = parentElement.dataset;
let surveyData;
const questionJson = [];
// Rive
const surveyCanvas = parentElement.querySelector('#efl-survey__header--icon');
const lyout = new Layout({
fit: Fit.Cover,
});
const MOBILE_BREAKPOINT = 820;
gsap.registerPlugin(ScrollToPlugin);
async function updateSurveyDetailsCallback() {
const url = `/Personalise/UpdateUserSurvey`;
// eslint-disable-next-line compat/compat
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0',
},
body: surveyData,
});
return response.json();
}
function updateSurveyDetails() {
try {
// isAjaxRuning = true;
updateSurveyDetailsCallback().then(response => {
if (response) {
console.log(response);
}
});
} catch (e) {
throw new Error('Unable to update survey details ::', e);
}
}
const swithScreen = screen => {
const allSteps = parentElement.querySelectorAll(
'.efl-survey__questions--steps'
);
const activeStep = parentElement.querySelector(`.${screen}`);
allSteps.forEach(steps => {
steps.classList.add('hidden');
});
activeStep.classList.remove('hidden');
surveyData = `{
"id": "${fanid}",
"surveyPages": [{
"surveyPageId": "${surveyPageId}",
"questions": ${JSON.stringify(questionJson)}
}]
}`;
};
const firstStepJson = e => {
const { questionId } = e.target.closest(
'.efl-survey__questions--steps'
).dataset;
const { answerId } = e.target.dataset;
const answer = e.target.innerText;
const question = `{
"questionId": "${questionId}",
"answerId": "${answerId}",
"answer": "${answer}"
}`;
questionJson[0] = JSON.parse(question);
};
const secondStepJson = e => {
const { questionId } = e.target.closest(
'.efl-survey__questions--steps'
).dataset;
const { answerId } = e.target.dataset;
const answer = e.target.innerText;
const question = `{
"questionId": "${questionId}",
"answerId": "${answerId}",
"answer": "${answer}"
}`;
questionJson[1] = JSON.parse(question);
};
const otherReasonJson = () => {
const { questionId } = surveyOtherReasonCta.closest(
'.efl-survey__questions--steps'
).dataset;
const { answerId } = surveyOtherReasonCta.dataset;
const answer = textArea.value;
const question = `{
"questionId": "${questionId}",
"answerId": "${answerId}",
"answer": "${answer}"
}`;
questionJson[1] = JSON.parse(question);
};
const linkScrollTo = e => {
if (bundleQuiz) {
if (window.innerWidth <= MOBILE_BREAKPOINT) {
e.preventDefault();
const jumpTo = document.querySelector('.jump-to-section');
const jumpToHeader = document.querySelector('.jump-to-section--header');
const quizPos = findPos(bundleQuiz);
const offsetVal = 310;
if (jumpTo.ariaExpanded === 'true') {
gsap.to(window, {
duration: 5,
scrollTo: {
y:
quizPos -
offsetVal -
jumpToHeader.offsetHeight +
jumpTo.offsetHeight,
},
ease: 'power2',
});
} else {
gsap.to(window, {
duration: 5,
scrollTo: { y: quizPos - offsetVal - jumpToHeader.offsetHeight },
ease: 'power2',
});
}
} else {
gsap.to(window, {
duration: 5,
scrollTo: { y: bundleQuiz.offsetTop },
ease: 'power2',
});
}
}
};
closeBtn.addEventListener('click', e => {
e.preventDefault();
parentElement.classList.add('hidden');
});
if (!quizNotification) {
const riveAnimation = new Rive({
src: '/assets/example-content/efl-survey.riv',
canvas: surveyCanvas,
layout: lyout,
onLoad: () => {
riveAnimation.resizeDrawingSurfaceToCanvas();
},
});
riveAnimation.play('Survey load');
riveAnimation.play('Survey pulse');
surveySubmitReasonCta.setAttribute('aria-disabled', 'true');
characterCount.innerHTML = textArea.value.length;
surveyUsefulYesCta.addEventListener('click', e => {
e.preventDefault();
firstStepJson(e);
swithScreen('step2');
});
surveyPractiseYesCta.addEventListener('click', e => {
e.preventDefault();
secondStepJson(e);
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Survey load');
riveAnimation.stop('Survey pulse');
riveAnimation.play('Complete');
riveAnimation.play('Complete loop');
});
surveyPractiseNoCta.addEventListener('click', e => {
e.preventDefault();
secondStepJson(e);
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Survey load');
riveAnimation.stop('Survey pulse');
riveAnimation.play('Complete');
riveAnimation.play('Complete loop');
});
surveyUsefulNoCta.addEventListener('click', e => {
e.preventDefault();
firstStepJson(e);
swithScreen('step4');
riveAnimation.stop('Survey load');
riveAnimation.stop('Survey pulse');
riveAnimation.play('Negative');
riveAnimation.play('Negative pulse');
});
surveyNotNeededCta.addEventListener('click', e => {
e.preventDefault();
secondStepJson(e);
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Negative');
riveAnimation.stop('Negative pulse');
riveAnimation.play('Complete red');
riveAnimation.play('Complete loop red');
});
surveyComplicatedCta.addEventListener('click', e => {
e.preventDefault();
secondStepJson(e);
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Negative');
riveAnimation.stop('Negative pulse');
riveAnimation.play('Complete red');
riveAnimation.play('Complete loop red');
});
surveyNotUsefulCta.addEventListener('click', e => {
e.preventDefault();
secondStepJson(e);
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Negative');
riveAnimation.stop('Negative pulse');
riveAnimation.play('Complete red');
riveAnimation.play('Complete loop red');
});
surveyOtherReasonCta.addEventListener('click', e => {
e.preventDefault();
swithScreen('step5');
});
surveClearTextCta.addEventListener('click', e => {
e.preventDefault();
textArea.value = '';
characterCount.innerHTML = '0';
surveySubmitReasonCta.setAttribute('aria-disabled', 'true');
});
textArea.addEventListener('keyup', e => {
characterCount.innerHTML = e.target.value.length;
// Disable button on empty text
if (e.target.value.length > 0) {
surveySubmitReasonCta.setAttribute('aria-disabled', 'false');
} else {
surveySubmitReasonCta.setAttribute('aria-disabled', 'true');
}
});
surveySubmitReasonCta.addEventListener('click', e => {
e.preventDefault();
otherReasonJson();
swithScreen('step3');
updateSurveyDetails();
riveAnimation.stop('Negative');
riveAnimation.stop('Negative pulse');
riveAnimation.play('Complete red');
riveAnimation.play('Complete loop red');
});
} else {
const notificationAnimation = new Rive({
src: '/assets/example-content/quiz_notification.riv',
canvas: surveyCanvas,
layout: lyout,
onLoad: () => {
notificationAnimation.resizeDrawingSurfaceToCanvas();
},
});
const completeAnimation = new Rive({
src: '/assets/example-content/quiz_complete.riv',
canvas: surveyCanvas,
layout: lyout,
onLoad: () => {
completeAnimation.resizeDrawingSurfaceToCanvas();
},
});
const activeStep = parentElement.querySelector('.step1');
if (activeStep.classList.contains('hidden')) {
completeAnimation.play('Loop');
} else {
notificationAnimation.play('Active');
}
surveyHeading.addEventListener('click', e => {
e.preventDefault();
if (!bundleQuiz) {
return;
}
linkScrollTo(e);
});
}
};
.efl-survey {
display: flex;
width: 100%;
min-width: 31.2rem;
background-color: $white;
border-radius: 0.8rem;
border: 0.1rem solid $grey-light;
padding: 2.4rem;
flex-direction: column;
max-height: initial;
transition: max-height 0.3s ease-in-out;
margin: 0 auto;
&__header {
display: flex;
justify-content: space-between;
margin-bottom: 1.4rem;
align-items: flex-start;
canvas {
width: 4rem;
height: 4rem;
margin-left: -1rem;
margin-top: -1rem;
}
&--icon {
width: 4rem;
height: 4rem;
}
button {
display: flex;
justify-content: center;
align-items: center;
border: none;
cursor: pointer;
background-color: transparent;
color: $blue;
padding: 0;
&:hover {
background-color: $grey-light;
}
&::after {
content: '';
display: block;
width: 1.4rem;
height: 1.4rem;
background: url('./assets/images/close.svg') no-repeat center;
background-size: contain;
}
}
}
&__questions {
font-family: $ef-font;
&--steps {
.steps-no {
font-size: 1.4rem;
line-height: 1.4rem;
color: $color-interface-light;
margin-bottom: 0.2rem;
}
h4 {
@extend .efl-heading-4;
font-size: 2rem;
line-height: 2.4rem;
font-weight: 700;
margin-bottom: 1.6rem;
color: $blue;
}
.cta {
background-color: transparent;
color: $blue;
border-radius: 4px;
font-size: 1.8rem;
line-height: 2.4rem;
min-height: 4.2rem;
border: 2px solid $light-blue;
text-transform: initial;
margin-bottom: 0.8rem;
&:hover {
background-color: $color-interface-light;
color: $white;
border-color: $color-interface-light;
}
&:last-of-type {
margin-bottom: 0;
}
&.survey-submit-reason {
background-color: $red;
color: white;
border-color: $red;
&:hover {
background-color: $color-interface-light;
color: $white;
border-color: $color-interface-light;
}
&[aria-disabled='true'] {
cursor: unset;
background-color: $grey-light;
border-color: $grey-light;
color: $white;
}
}
}
textarea {
width: 100%;
min-height: 11.4rem;
border-color: $light-blue;
padding: 1.3rem 1.6rem;
margin-bottom: 0.8rem;
font-size: 1.8rem;
line-height: 2.4rem;
color: $blue;
resize: none;
&::placeholder {
font-size: 1.8rem;
line-height: 2.4rem;
color: $color-interface-light;
}
&:focus {
border: $black;
}
}
.survey-reason-note {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin-bottom: 1.6rem;
font-size: 1.6rem;
line-height: 2.4rem;
letter-spacing: -0.01em;
color: $color-interface-light;
a {
color: $color-interface-light;
text-decoration: underline;
}
p {
margin-bottom: 0;
}
}
}
}
&--page-notification {
.efl-survey__header {
margin-bottom: 0.8rem;
}
.efl-survey__header canvas {
width: 6rem;
height: 6rem;
margin-left: -1rem;
margin-top: -1rem;
}
.efl-survey__quiz {
font-family: $ef-font;
.efl-survey__quiz--steps {
h4 {
@extend .efl-heading-5;
font-size: 2rem;
margin-bottom: 0.2rem;
}
a {
@extend .efl-heading-5;
color: $blue;
text-decoration: none;
font-size: 2rem;
margin-bottom: 0.2rem;
}
.copy {
@extend .efl-p-medium;
color: #5b6885;
letter-spacing: 0.02em;
}
}
}
}
@media screen and (max-width: 819px) {
display: flex;
margin-bottom: 2.4rem;
}
}
.jump-to-section--container {
@media screen and (max-width: 819px) {
.efl-survey {
display: flex;
}
}
&.expanded {
&:not(.sticky) {
.efl-survey {
display: flex;
}
}
}
&.sticky {
&:not(.expanded) {
.efl-survey {
display: none;
}
}
}
}
.efl-column-layout--two {
.efl-column-layout__col:last-of-type {
@media screen and (max-width: 819px) {
.efl-survey {
display: none;
}
}
}
}
<div class="efl-survey efl-survey--page-notification" data-behavior="efl-survey">
<div class="efl-survey__header">
<canvas id="efl-survey__header--icon" width="60" height="60"></canvas>
<button class="efl-survey__close" aria-label="close quiz notification"></button>
</div>
<div class="efl-survey__quiz">
<div class="efl-survey__quiz--steps step1">
<a class="heading" href="#bundled-learning-promo">Take our quick and easy quiz</a>
<p class="copy">Earn a trophy by completing 7 questions related to this article </p>
</div>
<div class="efl-survey__quiz--steps step2 hidden">
<h4>Well done, you’ve done this Quiz</h4>
</div>
</div>
</div>