// modify your data here var submitButtonName = 'Submit_Question'; var sectionData = [ { // section 1 startTime: 18*1000, // start time of the section, in milliseconds questionTime: [15*60*1000, 16*60*1000], // question will appear randomly in this time range (milliseconds) questions: [ // pool of questions in this section { // 1st question title: 'Q1_P1_Title', // name of question title question: 'Q1_P1' // name of question }, { // 2nd question title: 'Q2_P1_Title', question: 'Q2_P1' }, { // 3rd question title: 'Q3_P1_Title', question: 'Q3_P1' }, { // 4th question title: 'Q4_P1_Title', question: 'Q4_P1' } ] }, { // section 2 startTime: 15*60*1000, questionTime: [30*60*1000, 31*60*1000], questions: [ { // 1st question title: 'Q1_P2_Title', // name of question title question: 'Q1_P2' // name of question }, { // 2nd question title: 'Q2_P2_Title', question: 'Q2_P2' }, { // 3rd question title: 'Q3_P2_Title', question: 'Q3_P2' }, { // 4th question title: 'Q4_P2_Title', question: 'Q4_P2' } ] }, { // section 3 startTime: 30*60*1000, questionTime: [45*60*1000, 46*60*1000], questions: [ { // 1st question title: 'Q1_P3_Title', // name of question title question: 'Q1_P3' // name of question }, { // 2nd question title: 'Q2_P3_Title', question: 'Q2_P3' }, { // 3rd question title: 'Q3_P3_Title', question: 'Q3_P3' }, { // 4th question title: 'Q4_P3_Title', question: 'Q4_P3' } ] }, { // section 4 startTime: 45*60*1000, questionTime: [80000, 95000], questions: [ { // 1st question title: 'Q1_P4_Title', // name of question title question: 'Q1_P4' // name of question }, { // 2nd question title: 'Q2_P4_Title', question: 'Q2_P4' }, { // 3rd question title: 'Q3_P4_Title', question: 'Q3_P4' }, { // 4th question title: 'Q4_P4_Title', question: 'Q4_P4' } ] } ]; // don't touch code below function randomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } prez.mySubmitButtonName = submitButtonName; prez.mySections = sectionData; prez.mySectionIndex = -1; prez.myShowingQuestion = null; prez.myShowNextSection = function() { this.pause(false); this.myShowQuestion(false); if (this.mySectionIndex >= this.mySections.length - 1) return; ++this.mySectionIndex; this.myShowSection(); }; prez.myRestartSection = function() { this.pause(false); this.myShowQuestion(false); this.myShowSection(true); }; prez.myShowQuestion = function(show) { if (!this.myShowingQuestion) return; var images = this.myShowingQuestion.images; if (images) { for (var i = 0; i < images.length; ++i) { var imageObject = this.object(images[i]); if (show) imageObject.show(); else imageObject.hide(); } } if (show) { this.object(this.myShowingQuestion.title).show(); this.object(this.myShowingQuestion.question).show().clear(); this.object(this.mySubmitButtonName).show().node.style.transform = 'translateZ(0px)'; } else { this.object(this.myShowingQuestion.title).hide(); this.object(this.myShowingQuestion.question).hide(); this.object(this.mySubmitButtonName).hide(); this.myShowingQuestion = null; } }; prez.myShowSection = function(atSectionStart) { var sectionData = this.mySections[this.mySectionIndex]; if (!sectionData) return; if (atSectionStart) this.slideTime(sectionData.startTime); var questionTimeRange = sectionData.questionTime; this.myRandomQuestionTime = randomNumber(questionTimeRange[0], questionTimeRange[1]); this.myShowQuestionInTimer(sectionData.questions); }; prez.myShowQuestionInTimer = function(questionData) { if (this.myShowQuestionTimer) clearTimeout(this.myShowQuestionTimer); this.myShowQuestionTimer = setTimeout(function() { var randomQuestionIndex = randomNumber(0, questionData.length - 1); delete prez.myShowQuestionTimer; prez.myShowingQuestion = questionData[randomQuestionIndex]; prez.pause(true); prez.myShowQuestion(true); }, this.myRandomQuestionTime - this.slideTime()); }; // pause/resume timer if (!prez.myPauseAll) { prez.myPauseAll = prez.pauseAll; prez.pauseAll = function() { var pausing = this.allPaused(); var result = this.myPauseAll.apply(this, arguments); if (pausing != this.allPaused() && this.myShowQuestionTimer) { if (pausing) { // resume timer var sectionData = this.mySections[this.mySectionIndex]; if (sectionData) this.myShowQuestionInTimer(sectionData.questions); } else { // pause timer clearTimeout(this.myShowQuestionTimer); } } return result; }; } // start first section prez.myShowNextSection();