Moodle

Quiz javascript dependance

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: 1.6
  • Fix Version/s: None
  • Component/s: Quiz
  • Labels:
    None
  • Environment:
    All
  • Affected Branches:
    MOODLE_16_STABLE

Description

not really a bug as such but quizzes are dependent on Javascript support.

I've started to tackle this. Included here is code to make the latest cvs build as of

13:50 23rd March 2005 GMT a bit less dependent.

Problem - On multipage quizes the form requires javascripted links to navigate between questions.

Solution - replace the links with an accessible select box.

/****** function in /mod/quiz/locallib.php ***********/

function quiz_print_navigation_panel($questions, $questionsperpage, $navigation) {

global $QUIZ_QTYPES;

$numberinglayout = array();

$nextqnumber = 1;

foreach ($questions as $question) {

if ($qnumberinc = $QUIZ_QTYPES[$question->qtype]

->actual_number_of_questions($question)) { $numberinglayout[] = $nextqnumber; $nextqnumber += $qnumberinc; }

}

if ($nextqnumber - $qnumberinc <= $questionsperpage) { /// The total number of questions does not exceed the maximum /// number of allowed questions per page so... return 0; }

/// else - Navigation menu will be printed!

///////////////////////////////////////////////

/// Determine the layout of the navigation menu

///////////////////////////////////////////////

if (1 == $questionsperpage) { /// The simple case: $pagelinkagelayout = $pagenavigationlayout = $numberinglayout; } else {

/// More complicated:

$pagenavigationlayout = array();

$pagelinkagelayout = array($currentpagestart = 1);

foreach ($numberinglayout as $questionnumber) {

if ($questionnumber - $currentpagestart >= $questionsperpage) {

$pagenavigationlayout[] = $currentpagestart

.'-'. ($questionnumber - 1);

if ($currentpagestart < $navigation

&& $navigation < $questionnumber) { // $navigation is out of sync so adjust for robustness $navigation = $currentpagestart; }

$pagelinkagelayout[] = $currentpagestart = $questionnumber;

}

}

$pagenavigationlayout[] = $currentpagestart .'-'. ($nextqnumber - 1);

if ($currentpagestart < $navigation) { // $firstquestion is out of sync so adjust it for robustness... $navigation = $currentpagestart; }

}

foreach ($pagelinkagelayout as $key => $link) {

if ($link < $navigation) { $previouspagelink = $link; } else if ($link == $navigation) { $currentnavigationtitle = $pagenavigationlayout[$key]; } else {

$endpagelink = $link;

if (false == isset($nextpagelink)) { $nextpagelink = $link; }

}

}

$nav_str = '<label>After saving';

$nav_str .= '<select name=navigation title=select a destination after you submit this form.>';

$nav_str .= '<option value=0>Exit Quiz</option>';

if (isset($previouspagelink)) { $nav_str .= '<option value='.$previouspagelink.' '.(!isset($nextpagelink) ? 'selected=selected':'').'>'.get_string('previous').'</option>'; }

if (isset($nextpagelink)) { $nav_str .= '<option value='.$nextpagelink.' '.'selected=selected>'.get_string('next').'</option>'; }

foreach ($pagelinkagelayout as $key => $link) { $nav_str .= '<option value='.$link.'>Question '.$pagenavigationlayout[$key].'</option>'; }

$nav_str .= '</select></label>';

echo $nav_str;

return $navigation;

}

/****************/

Issue - in the javascripted version it was perfectly ok to have the links display across the top and bottom of the question. However, as this is a form element we can only logically display one of them (otherwise the value of the upper one won't matter because it'll be overwritten by the bottom one on submission). The second call to quiz_print_navigation_panel in quiz_print_quiz_questions (locallib.php ~1055) should be removed.

The quiz_print_navigation_panel has to be called before the question is printed and thus the select box ends up being displayed above the question when really it ought to be displayed next to the submit button.

To this end I've made a second version of quiz_print_navigation_panel which returns a 2 index array consisting of [0] => $navigation and [1]=>$nav_select_box and DOES NOT print out the select box. This allows me to hold the nav element until later where I echo it next to the submit box.

In this version the final two lines of the new version of quiz_print_navigation_panel should be replaced with

//don't echo out the $nav_str

return array($navigation, $nav_str

This in turn effects quiz_print_quiz_questions.....

// first call ~1004

list($navigation, $nav_widget) = quiz_print_navigation_panel($questions,

$quiz->questionsperpage, $navigation);

//we now have the navigation select box stored in $nav_widget

......

/*

~1046 we remove the second call to print the navigation as before and replace it as follows

*/

if($navigation)

{ echo $nav_widget; //print list of nav options. }

else

{ echo <input type=\hidden\ name=\navigation\ value='0' />\n; //save == exit }

This code removes the javascript dependence for pagination of a quiz. Tested with 1 q per page, 2 q per page and unlimited q per page.

Obviously, the quiz module is still highly dependent on JS but I'll continue to work to remove this if it's approved.

My apologies if this doesn't format properly. It's my first post here and if it's not clear what I mean I'll post the full files.

Gav

Issue Links

Activity

Hide
Martin Dougiamas added a comment -

From Gustav Delius (gwd2 at york.ac.uk) Thursday, 24 March 2005, 04:17 AM:

I think a smaller solution will be sufficient: make the next and previous links into buttons. The same should be done on all paging bars in Moodle. I'll post this in a new feature request.

I don't think the links to pages should be replaced by a drop-down menu. This would be less convenient for the large majority who do have javascript enabled browsers.

From Gustav Delius (gwd2 at york.ac.uk) Thursday, 24 March 2005, 04:22 AM:

I just noticed that most other paging bars in Moodle do not actually need to submit forms so they could stay as links. But for the quiz attempt page buttons would be better.

From Govsan (gavin at designiscentral.com) Thursday, 24 March 2005, 05:52 PM:

>I don't think the links to pages should be replaced by a drop-down menu. This would be less convenient for the large majority who do have javascript enabled browsers

True, but this is inaccessible.

http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-scripts

At the very least there should be a scriptless fallback. I'm aware that the quiz module still needs JS to work but these other dependencies could be removed as well.

>next and previous links into buttons

IMHO this would cause other problems. Firstly, it means you can only navigate one step in either direction. The can be very slow and frustrating. You're on question 20 and you've just realised you made a mistake on question 5....

Second. That give the user a choice of 3 submit buttons. Certainly with the current solution I occasionally found myself exiting the quiz accidentally because I clicked 'save my answers' instead of moving to the next question.

Show
Martin Dougiamas added a comment - From Gustav Delius (gwd2 at york.ac.uk) Thursday, 24 March 2005, 04:17 AM: I think a smaller solution will be sufficient: make the next and previous links into buttons. The same should be done on all paging bars in Moodle. I'll post this in a new feature request. I don't think the links to pages should be replaced by a drop-down menu. This would be less convenient for the large majority who do have javascript enabled browsers. From Gustav Delius (gwd2 at york.ac.uk) Thursday, 24 March 2005, 04:22 AM: I just noticed that most other paging bars in Moodle do not actually need to submit forms so they could stay as links. But for the quiz attempt page buttons would be better. From Govsan (gavin at designiscentral.com) Thursday, 24 March 2005, 05:52 PM: >I don't think the links to pages should be replaced by a drop-down menu. This would be less convenient for the large majority who do have javascript enabled browsers True, but this is inaccessible. http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-scripts At the very least there should be a scriptless fallback. I'm aware that the quiz module still needs JS to work but these other dependencies could be removed as well. >next and previous links into buttons IMHO this would cause other problems. Firstly, it means you can only navigate one step in either direction. The can be very slow and frustrating. You're on question 20 and you've just realised you made a mistake on question 5.... Second. That give the user a choice of 3 submit buttons. Certainly with the current solution I occasionally found myself exiting the quiz accidentally because I clicked 'save my answers' instead of moving to the next question.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: