initShortcuts: function () {
let $this = this;
$(document).on('keyup', function (e) {
- let key = e.key.toLocaleUpperCase();
- if (key === ' ') {
- key = 'Space';
- }
-
- $('[aria-keyshortcuts="' + key + '"]').each(function () {
- if ($this.quiz.utils.isEnabled($(this))) {
- $(this).get(0).click();
- return true;
+ if($("textarea:focus,input:focus").length < 1) {
+ let key = e.key.toLocaleUpperCase();
+ if (key === ' ') {
+ key = 'Space';
}
- });
+
+ $('[aria-keyshortcuts="' + key + '"]').each(function () {
+ if ($this.quiz.utils.isEnabled($(this))) {
+ $(this).get(0).click();
+ return true;
+ }
+ });
+ }
});
},
}
this.intervalCountDown = 0;
this.runningManTimeout = 0;
this.timeline = null;
+ this.email = null;
this.scrollBarDropdown = null;
this.intro = new QuizScreenIntro(this);
initEvents: function () {
const $this = this;
+
// Réinitialiser les réponses
$(document).on("click", ".btn.reset", function () {
$this.resetForm();
// Cliquer sur le bouton suivant
$(document).on("click", ".active-screen.next .action", function () {
+
+ if($this.getActiveScreenType() === 'email') {
+ if(!$this.validateEmail($this.activeScreen.find("input").val())) {
+ alert('Please enter a correct format');
+ return false;
+ }
+ }
+
if (($this.currentQuestionAnswers.length === 0 && !parseInt($this.quiz.question.current().countdown_enable)) || (parseInt($this.quiz.question.current().countdown_enable) && $this.intervalCountDown !== 0 && $this.currentQuestionAnswers.length === 0)) {
alert('Please select at least one answer');
return false;
if ($(this).hasClass('validate')) {
let review = $this.sendUserAnswers();
// Si la revue instantanée est activée, on affiche les résultats
- if ($this.quiz.data.instantReview) {
+ if ($this.quiz.data.instantReview && !['country','email','text'].includes($this.getActiveScreenType()) ) {
$this.instantReview(review);
} else {
// Sinon, on passe directement à la question suivante
updateUserAnswers: function () {
const $this = this;
this.currentQuestionAnswers = []
- $(".active-screen form").find("input:checked").each(function () {
- $this.currentQuestionAnswers.push(parseInt($(this).val()));
- });
+
+ if(['country','email','text'].includes(this.getActiveScreenType())) {
+ this.currentQuestionAnswers = this.getActiveScreen().find(".answer-text").val()
+ } else {
+ $(".active-screen form").find("input:checked").each(function () {
+ $this.currentQuestionAnswers.push(parseInt($(this).val()));
+ });
+ }
},
/**
$this.quiz.match.start()
} else if($this.getActiveScreenType() === 'country') {
$this.quiz.countriesList.start()
+ } else if($this.getActiveScreenType() === 'email') {
+ $this.email = $this.activeScreen.find("input").val()
}
//
$this.currentQuestionAnswers = [];
$this.quiz.progressbar.update();
-
if (screen === 'outro') {
$this.outro.show();
}
+
$this.quiz.resize.resize();
});
},
this.quiz.draganddrop.reset();
} else if(type === 'match') {
this.quiz.match.reset();
+ } else {
+ this.getCurrentForm().find(".answer-text").val("")
}
},
resetCountdownBackground: function () {
document.documentElement.style.setProperty("--width-bg-countdown", "100%")
},
+
+ validateEmail: function(email) {
+ let re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
+ return re.test(email);
+ }
};
export default QuizScreens;