MDL-79871 qtype_ordering: Move existing modules into class

Part of: MDL-79863
- Taken the existing module and done the bare minimum to make it work within one class that gets called.
This commit is contained in:
Mathew May
2024-04-04 15:26:44 +08:00
parent 416ffeed36
commit d70277d050
7 changed files with 48 additions and 71 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-3
View File
@@ -1,3 +0,0 @@
define("qtype_ordering/reorder",["jquery","qtype_ordering/drag_reorder"],(function($,DragReorder){return{init:function(sortableid,responseid){new DragReorder({list:"ul#"+sortableid,item:"li.sortableitem",proxyHtml:'<div class="que ordering dragproxy"><ul class="%%LIST_CLASS_NAME%%"><li class="%%ITEM_CLASS_NAME%% item-moving">%%ITEM_HTML%%</li></ul></div>',itemMovingClass:"current-drop",idGetter:function(item){return $(item).attr("id")},nameGetter:function(item){return $(item).text},reorderStart:function(){},reorderEnd:function(){},reorderDone:function(list,item,newOrder){$("input#"+responseid)[0].value=newOrder.join(",")}})}}}));
//# sourceMappingURL=reorder.min.js.map
@@ -1 +0,0 @@
{"version":3,"file":"reorder.min.js","sources":["../src/reorder.js"],"sourcesContent":["define(['jquery', 'qtype_ordering/drag_reorder'], function($, DragReorder) {\n return {\n /**\n * Initialise one ordering question.\n *\n * @param {String} sortableid id of ul for this question.\n * @param {String} responseid id of hidden field for this question.\n */\n init: function(sortableid, responseid) {\n new DragReorder({\n list: 'ul#' + sortableid,\n item: 'li.sortableitem',\n proxyHtml: '<div class=\"que ordering dragproxy\">' +\n '<ul class=\"%%LIST_CLASS_NAME%%\"><li class=\"%%ITEM_CLASS_NAME%% item-moving\">' +\n '%%ITEM_HTML%%</li></ul></div>',\n itemMovingClass: \"current-drop\",\n idGetter: function(item) {\n return $(item).attr('id');\n },\n nameGetter: function(item) {\n return $(item).text;\n },\n reorderStart: function() {\n // Do nothing.\n },\n reorderEnd: function() {\n // Do nothing.\n },\n reorderDone: function(list, item, newOrder) {\n $('input#' + responseid)[0].value = newOrder.join(',');\n }\n });\n }\n };\n});\n"],"names":["define","$","DragReorder","init","sortableid","responseid","list","item","proxyHtml","itemMovingClass","idGetter","attr","nameGetter","text","reorderStart","reorderEnd","reorderDone","newOrder","value","join"],"mappings":"AAAAA,gCAAO,CAAC,SAAU,gCAAgC,SAASC,EAAGC,mBACnD,CAOHC,KAAM,SAASC,WAAYC,gBACnBH,YAAY,CACZI,KAAM,MAAQF,WACdG,KAAM,kBACNC,UAAW,gJAGXC,gBAAiB,eACjBC,SAAU,SAASH,aACJN,EAAEM,MAAMI,KAAK,OAE5BC,WAAY,SAASL,aACNN,EAAEM,MAAMM,MAEvBC,aAAc,aAGdC,WAAY,aAGZC,YAAa,SAASV,KAAMC,KAAMU,UAC9BhB,EAAE,SAAWI,YAAY,GAAGa,MAAQD,SAASE,KAAK"}
+45 -19
View File
@@ -24,19 +24,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* @module qtype_ordering/drag_reorder
*/
define([
'jquery',
'core/dragdrop',
'core/key_codes'
], function(
$,
drag,
keys
) {
'use strict';
import $ from 'jquery';
import drag from 'core/dragdrop';
import keys from 'core/key_codes';
export default class DragReorder {
/**
* Constructor.
*
@@ -104,7 +98,7 @@ define([
*
* @param {Object} config As above.
*/
return function(config) {
constructor(config) {
var dragStart = null, // Information about when and where the drag started.
originalOrder = null, // Array of ids.
itemDragging = null, // Item being moved by dragging (jQuery object).
@@ -169,7 +163,7 @@ define([
offsetValue = -20;
window.console.log("For midY(proxy) < midY(closestItem) offset is: " + offsetValue);
}
if (midY(proxy) + offsetValue < midY(closestItem)) {
if (midY(proxy) + offsetValue < midY(closestItem)) {
itemDragging.insertBefore(closestItem);
} else {
itemDragging.insertAfter(closestItem);
@@ -304,9 +298,9 @@ define([
*/
var getCurrentOrder = function() {
return (itemDragging || itemMoving).closest(config.list).find(config.item).map(
function(index, item) {
return config.idGetter(item);
}).get();
function(index, item) {
return config.idGetter(item);
}).get();
};
/**
@@ -345,5 +339,37 @@ define([
// Make the items tabbable.
$(config.itemInPage).attr('tabindex', '0');
};
});
}
/**
* Initialise one ordering question.
*
* @param {String} sortableid id of ul for this question.
* @param {String} responseid id of hidden field for this question.
*/
static init(sortableid, responseid) {
new DragReorder({
list: 'ul#' + sortableid,
item: 'li.sortableitem',
proxyHtml: '<div class="que ordering dragproxy">' +
'<ul class="%%LIST_CLASS_NAME%%"><li class="%%ITEM_CLASS_NAME%% item-moving">' +
'%%ITEM_HTML%%</li></ul></div>',
itemMovingClass: "current-drop",
idGetter: function(item) {
return $(item).attr('id');
},
nameGetter: function(item) {
return $(item).text;
},
reorderStart: function() {
// Do nothing.
},
reorderEnd: function() {
// Do nothing.
},
reorderDone: function(list, item, newOrder) {
$('input#' + responseid)[0].value = newOrder.join(',');
}
});
}
}
-35
View File
@@ -1,35 +0,0 @@
define(['jquery', 'qtype_ordering/drag_reorder'], function($, DragReorder) {
return {
/**
* Initialise one ordering question.
*
* @param {String} sortableid id of ul for this question.
* @param {String} responseid id of hidden field for this question.
*/
init: function(sortableid, responseid) {
new DragReorder({
list: 'ul#' + sortableid,
item: 'li.sortableitem',
proxyHtml: '<div class="que ordering dragproxy">' +
'<ul class="%%LIST_CLASS_NAME%%"><li class="%%ITEM_CLASS_NAME%% item-moving">' +
'%%ITEM_HTML%%</li></ul></div>',
itemMovingClass: "current-drop",
idGetter: function(item) {
return $(item).attr('id');
},
nameGetter: function(item) {
return $(item).text;
},
reorderStart: function() {
// Do nothing.
},
reorderEnd: function() {
// Do nothing.
},
reorderDone: function(list, item, newOrder) {
$('input#' + responseid)[0].value = newOrder.join(',');
}
});
}
};
});
+1 -1
View File
@@ -104,7 +104,7 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
} else {
$sortableitem = 'sortableitem';
$params = array($sortableid, $responseid);
$this->page->requires->js_call_amd('qtype_ordering/reorder', 'init', $params);
$this->page->requires->js_call_amd('qtype_ordering/drag_reorder', 'init', $params);
}
$result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));