Support » Plugin: HD Quiz » How to add bottom “Previous Question” on Paginate mode

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    This is an upcoming feature actually 🙂

    However, if you add the following code to your theme’s function.php file, you will almost get this with perfect functionality. The only thing this won’t currently do is auto-scroll to the first visible question when you select the “back” button.

    
    function hdq_nattapongae1()
    { ?>
    
    <script>
    setTimeout(function(){
    	hdq_create_prev_buttons();
    	jQuery(".hdq_quiz").on("click", ".hdq_prev_button", function(){
    		hdq_prev_click()
    	})
    }, 2000)
    function hdq_create_prev_buttons(){
    	let data = '<div class="hdq_prev_button hdq_button" style = "margin-right: 1rem">BACK</div>';
    	let hdq_pagination_areas = document.getElementsByClassName("hdq_next_button");
    	for(let i = 1; i < hdq_pagination_areas.length; i++){
    		hdq_pagination_areas[i].insertAdjacentHTML("beforebegin", data);
    	}
    }
    
    function hdq_prev_click(){
    	jQuery(".hdq_question:visible").first().addClass("hdq_break");
    	jQuery(".hdq_break").prev(".hdq_jPaginate").addClass("hdq_break_prev_2");
    	let hdq_prev_p = jQuery(".hdq_break_prev_2").prevAll(".hdq_jPaginate").first();
    	if (typeof hdq_prev_p[0] != "undefined") {
    		jQuery(hdq_prev_p).addClass("hdq_break_prev");	
    	} else {
    		jQuery(".hdq_question:nth-child(2)").addClass("hdq_break_prev");
    	}
    	jQuery(".hdq_question").hide();
    	jQuery(".hdq_break_prev").nextUntil(".hdq_jPaginate").show();
    	jQuery(".hdq_break").removeClass("hdq_break");
    	jQuery(".hdq_break_prev").removeClass("hdq_break_prev");
    	jQuery(".hdq_break_prev_2").removeClass("hdq_break_prev_2");
    	jPage = parseInt(jPage - 1);
    }
    </script>
    
    <?php }
    add_action("hdq_before", "hdq_nattapongae1");
    

    The above code essentially does two things. First, it creates a new “BACK” button next to each “NEXT” button except the first (you can’t go back id you’re already on the first page after all!). Second, it adds in logic to figure out which questions to hide and show. It’s a little dirty but gets the job done in my own testing.

    Please let me know if you need further help with this

    • This reply was modified 1 month, 3 weeks ago by Harmonic Design. Reason: modified code to remove backquotes since I forgot this uses markup

    @harmonic_design

    Thank You.

    Now i get its.

    see pic below;
    https://drive.google.com/open?id=1HpxNJ1FAM_olLfgA_-XU-HHjMQ9mk4vs

    Let test;
    https://quiz.engineer-tutor.com/catc-math-1

    I waiting your upcoming feature ^^. Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.