diff --git a/question/type/ddimageortext/amd/build/question.min.js b/question/type/ddimageortext/amd/build/question.min.js
index a18f67b79c6..caedf312120 100644
--- a/question/type/ddimageortext/amd/build/question.min.js
+++ b/question/type/ddimageortext/amd/build/question.min.js
@@ -1 +1 @@
-define(["jquery","core/dragdrop","core/key_codes"],function(a,b,c){"use strict";function d(a,b,c){this.containerId=a,M.util.js_pending("qtype_ddimageortext-init-"+this.containerId),this.places=c,this.allImagesLoaded=!1,this.imageLoadingTimeoutId=null,b&&this.getRoot().addClass("qtype_ddimageortext-readonly");var d=this;this.getNotYetLoadedImages().one("load",function(){d.waitForAllImagesToBeLoaded()}),this.waitForAllImagesToBeLoaded()}d.prototype.waitForAllImagesToBeLoaded=function(){var a=this;if(!this.allImagesLoaded){if(null!==this.imageLoadingTimeoutId&&clearTimeout(this.imageLoadingTimeoutId),this.getNotYetLoadedImages().length>0)return void(this.imageLoadingTimeoutId=setTimeout(function(){a.waitForAllImagesToBeLoaded()},100));this.allImagesLoaded=!0,a.setupQuestion()}},d.prototype.getNotYetLoadedImages=function(){var a=this;return this.getRoot().find(".ddarea img").not(function(b,c){return a.imageIsLoaded(c)})},d.prototype.imageIsLoaded=function(a){return a.complete&&0!==a.naturalHeight},d.prototype.setupQuestion=function(){this.resizeAllDragsAndDrops(),this.cloneDrags(),this.positionDragsAndDrops(),M.util.js_complete("qtype_ddimageortext-init-"+this.containerId)},d.prototype.resizeAllDragsAndDrops=function(){var a=this;this.getRoot().find(".draghomes > div").each(function(b){a.resizeAllDragsAndDropsInGroup(b+1)})},d.prototype.resizeAllDragsAndDropsInGroup=function(b){var c=this.getRoot(),d=c.find(".dragitemgroup"+b+" .draghome"),e=0,f=0;d.each(function(a,b){e=Math.max(e,Math.ceil(b.offsetWidth)),f=Math.max(f,Math.ceil(b.offsetHeight))}),e+=10,f+=10,d.each(function(b,c){var d=Math.round((e-c.offsetWidth)/2),g=Math.floor((f-c.offsetHeight)/2);a(c).css({"padding-left":d+"px","padding-right":e-c.offsetWidth-d+"px","padding-top":g+"px","padding-bottom":f-c.offsetHeight-g+"px"})});for(var g in this.places)if(this.places.hasOwnProperty(g)){var h=this.places[g],i=h.text;parseInt(h.group)===b&&(""===i&&(i=M.util.get_string("blank","qtype_ddimageortext")),c.find(".dropzones").append('
'+i+"
"),c.find(".dropzone.place"+g).width(e-2).height(f-2))}},d.prototype.cloneDrags=function(){var b=this;this.getRoot().find(".ddarea .draghome").each(function(c,d){b.cloneDragsForOneChoice(a(d))})},d.prototype.cloneDragsForOneChoice=function(a){if(a.hasClass("infinite"))for(var b=this.noOfDropsInGroup(this.getGroup(a)),c=0;c1;)c--,d=this.getUnplacedChoice(a,c);return d},d.prototype.animateTo=function(a,b){var c=a.offset(),d=b.offset();a.addClass("beingdragged"),a.animate({left:parseInt(a.css("left"))+d.left-c.left,top:parseInt(a.css("top"))+d.top-c.top},{duration:"fast",done:function(){a.removeClass("beingdragged"),a.offset(d)}})},d.prototype.isPointInDrop=function(a,b,c){var d=c.offset();return a>=d.left&&a=d.top&&b0)return void(this.imageLoadingTimeoutId=setTimeout(function(){a.waitForAllImagesToBeLoaded()},100));this.allImagesLoaded=!0,a.setupQuestion()}},d.prototype.getNotYetLoadedImages=function(){var a=this;return this.getRoot().find(".ddarea img").not(function(b,c){return a.imageIsLoaded(c)})},d.prototype.imageIsLoaded=function(a){return a.complete&&0!==a.naturalHeight},d.prototype.setupQuestion=function(){this.resizeAllDragsAndDrops(),this.cloneDrags(),this.positionDragsAndDrops(),M.util.js_complete("qtype_ddimageortext-init-"+this.containerId)},d.prototype.resizeAllDragsAndDrops=function(){var b=this;this.getRoot().find(".draghomes > div").each(function(c,d){b.resizeAllDragsAndDropsInGroup(b.getClassnameNumericSuffix(a(d),"dragitemgroup"))})},d.prototype.resizeAllDragsAndDropsInGroup=function(b){var c=this.getRoot(),d=c.find(".dragitemgroup"+b+" .draghome"),e=0,f=0;d.each(function(a,b){e=Math.max(e,Math.ceil(b.offsetWidth)),f=Math.max(f,Math.ceil(b.offsetHeight))}),e+=10,f+=10,d.each(function(b,c){var d=Math.round((e-c.offsetWidth)/2),g=Math.floor((f-c.offsetHeight)/2);a(c).css({"padding-left":d+"px","padding-right":e-c.offsetWidth-d+"px","padding-top":g+"px","padding-bottom":f-c.offsetHeight-g+"px"})});for(var g in this.places)if(this.places.hasOwnProperty(g)){var h=this.places[g],i=h.text;parseInt(h.group)===b&&(""===i&&(i=M.util.get_string("blank","qtype_ddimageortext")),c.find(".dropzones").append(''+i+"
"),c.find(".dropzone.place"+g).width(e-2).height(f-2))}},d.prototype.cloneDrags=function(){var b=this;this.getRoot().find(".ddarea .draghome").each(function(c,d){b.cloneDragsForOneChoice(a(d))})},d.prototype.cloneDragsForOneChoice=function(a){if(a.hasClass("infinite"))for(var b=this.noOfDropsInGroup(this.getGroup(a)),c=0;c1;)c--,d=this.getUnplacedChoice(a,c);return d},d.prototype.animateTo=function(a,b){var c=a.offset(),d=b.offset();a.addClass("beingdragged"),a.animate({left:parseInt(a.css("left"))+d.left-c.left,top:parseInt(a.css("top"))+d.top-c.top},{duration:"fast",done:function(){a.removeClass("beingdragged"),a.offset(d)}})},d.prototype.isPointInDrop=function(a,b,c){var d=c.offset();return a>=d.left&&a=d.top&&b div').each(function(i) {
- thisQ.resizeAllDragsAndDropsInGroup(i + 1);
+ this.getRoot().find('.draghomes > div').each(function(i, node) {
+ thisQ.resizeAllDragsAndDropsInGroup(
+ thisQ.getClassnameNumericSuffix($(node), 'dragitemgroup'));
});
};
diff --git a/question/type/ddwtos/amd/build/ddwtos.min.js b/question/type/ddwtos/amd/build/ddwtos.min.js
index 388b76148ec..d85282069dc 100644
--- a/question/type/ddwtos/amd/build/ddwtos.min.js
+++ b/question/type/ddwtos/amd/build/ddwtos.min.js
@@ -1 +1 @@
-define(["jquery","core/dragdrop","core/key_codes"],function(a,b,c){"use strict";function d(a,b){this.containerId=a,b&&this.getRoot().addClass("qtype_ddwtos-readonly"),this.resizeAllDragsAndDrops(),this.cloneDrags(),this.positionDrags()}d.prototype.resizeAllDragsAndDrops=function(){var a=this;this.getRoot().find(".answercontainer > div").each(function(b){a.resizeAllDragsAndDropsInGroup(b+1)})},d.prototype.resizeAllDragsAndDropsInGroup=function(a){var b=this,c=this.getRoot().find(".draggrouphomes"+a+" span.draghome"),d=0,e=0;c.each(function(a,b){d=Math.max(d,Math.ceil(b.offsetWidth)),e=Math.max(e,Math.ceil(0+b.offsetHeight))}),d+=8,e+=2,c.each(function(a,c){b.setElementSize(c,d,e)}),this.getRoot().find("span.drop.group"+a).each(function(a,c){b.setElementSize(c,d,e)})},d.prototype.setElementSize=function(b,c,d){a(b).width(c).height(d).css("lineHeight",d+"px")},d.prototype.cloneDrags=function(){var b=this;this.getRoot().find("span.draghome").each(function(c,d){b.cloneDragsForOneChoice(a(d))})},d.prototype.cloneDragsForOneChoice=function(a){if(a.hasClass("infinite"))for(var b=this.noOfDropsInGroup(this.getGroup(a)),c=0;c1;)c--,d=this.getUnplacedChoice(a,c);return d},d.prototype.animateTo=function(a,b){var c=a.offset(),d=b.offset();a.addClass("beingdragged"),a.animate({left:parseInt(a.css("left"))+d.left-c.left,top:parseInt(a.css("top"))+d.top-c.top},{duration:"fast",done:function(){a.removeClass("beingdragged"),a.offset(d)}})},d.prototype.isPointInDrop=function(a,b,c){var d=c.offset();return a>=d.left&&a=d.top&&b div").each(function(c,d){b.resizeAllDragsAndDropsInGroup(b.getClassnameNumericSuffix(a(d),"draggrouphomes"))})},d.prototype.resizeAllDragsAndDropsInGroup=function(a){var b=this,c=this.getRoot().find(".draggrouphomes"+a+" span.draghome"),d=0,e=0;c.each(function(a,b){d=Math.max(d,Math.ceil(b.offsetWidth)),e=Math.max(e,Math.ceil(0+b.offsetHeight))}),d+=8,e+=2,c.each(function(a,c){b.setElementSize(c,d,e)}),this.getRoot().find("span.drop.group"+a).each(function(a,c){b.setElementSize(c,d,e)})},d.prototype.setElementSize=function(b,c,d){a(b).width(c).height(d).css("lineHeight",d+"px")},d.prototype.cloneDrags=function(){var b=this;this.getRoot().find("span.draghome").each(function(c,d){b.cloneDragsForOneChoice(a(d))})},d.prototype.cloneDragsForOneChoice=function(a){if(a.hasClass("infinite"))for(var b=this.noOfDropsInGroup(this.getGroup(a)),c=0;c1;)c--,d=this.getUnplacedChoice(a,c);return d},d.prototype.animateTo=function(a,b){var c=a.offset(),d=b.offset();a.addClass("beingdragged"),a.animate({left:parseInt(a.css("left"))+d.left-c.left,top:parseInt(a.css("top"))+d.top-c.top},{duration:"fast",done:function(){a.removeClass("beingdragged"),a.offset(d)}})},d.prototype.isPointInDrop=function(a,b,c){var d=c.offset();return a>=d.left&&a=d.top&&b div').each(function(i) {
- thisQ.resizeAllDragsAndDropsInGroup(i + 1);
+ this.getRoot().find('.answercontainer > div').each(function(i, node) {
+ thisQ.resizeAllDragsAndDropsInGroup(
+ thisQ.getClassnameNumericSuffix($(node), 'draggrouphomes'));
});
};
diff --git a/question/type/ddwtos/tests/behat/preview.feature b/question/type/ddwtos/tests/behat/preview.feature
index 33740931e5b..fe4a9138b3a 100644
--- a/question/type/ddwtos/tests/behat/preview.feature
+++ b/question/type/ddwtos/tests/behat/preview.feature
@@ -63,3 +63,19 @@ Feature: Preview a drag-drop into text question
Then the state of "The" question is shown as "Incorrect"
And I should see "Mark 0.00 out of 1.00"
And I switch to the main window
+
+ @javascript
+ Scenario: Preview a question that uses strange group numbers using the keyboard.
+ Given the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | ddwtos | Funny groups | oddgroups |
+ And I reload the page
+ When I click on "Preview" "link" in the "Funny groups" "table_row"
+ And I switch to "questionpreview" window
+ And I type " " into space "1" in the drag and drop onto image question
+ And I type " " into space "2" in the drag and drop onto image question
+ And I type " " into space "3" in the drag and drop onto image question
+ And I press "Submit and finish"
+ Then the state of "The" question is shown as "Correct"
+ And I should see "Mark 1.00 out of 1.00"
+ And I switch to the main window
diff --git a/question/type/ddwtos/tests/helper.php b/question/type/ddwtos/tests/helper.php
index 5554b2cf84e..ade05700c5f 100644
--- a/question/type/ddwtos/tests/helper.php
+++ b/question/type/ddwtos/tests/helper.php
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
*/
class qtype_ddwtos_test_helper extends question_test_helper {
public function get_test_questions() {
- return array('fox', 'maths');
+ return array('fox', 'maths', 'oddgroups');
}
/**
@@ -75,7 +75,9 @@ class qtype_ddwtos_test_helper extends question_test_helper {
}
/**
- * @return stdClass date to create a ddwtos question.
+ * This is a simple question with choices in three groups.
+ *
+ * @return stdClass data to create a ddwtos question.
*/
public function get_ddwtos_question_form_data_fox() {
$fromform = new stdClass();
@@ -99,6 +101,33 @@ class qtype_ddwtos_test_helper extends question_test_helper {
return $fromform;
}
+ /**
+ * Similar to the 'fox' example above, but using different, non-continuous group numbers.
+ *
+ * @return stdClass data to create a ddwtos question.
+ */
+ public function get_ddwtos_question_form_data_oddgroups() {
+ $fromform = new stdClass();
+
+ $fromform->name = 'Drag-and-drop words with strange groups';
+ $fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
+ $fromform->defaultmark = 1.0;
+ $fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
+ $fromform->choices = array(
+ array('answer' => 'quick', 'choicegroup' => '5'),
+ array('answer' => 'fox', 'choicegroup' => '7'),
+ array('answer' => 'lazy', 'choicegroup' => '3'),
+ array('answer' => 'slow', 'choicegroup' => '5'),
+ array('answer' => 'dog', 'choicegroup' => '7'),
+ array('answer' => 'assiduous', 'choicegroup' => '3'),
+ );
+ test_question_maker::set_standard_combined_feedback_form_data($fromform);
+ $fromform->shownumcorrect = 0;
+ $fromform->penalty = 0.3333333;
+
+ return $fromform;
+ }
+
/**
* @return qtype_ddwtos_question
*/