MDL-79863 qtype_ordering: qtype/ordering update to latest version of JQuery (11.1) and add mouse-punch to handle drag-drop events on touchscreens

This commit is contained in:
Gordon Bateson
2024-04-04 10:59:17 +08:00
committed by Mathew May
parent 6d7355d4b7
commit a07a45df81
5 changed files with 19 additions and 175 deletions
File diff suppressed because one or more lines are too long
+4 -18
View File
File diff suppressed because one or more lines are too long
+4
View File
@@ -29,3 +29,7 @@ Further information
For more information, tutorials and online discussion forums, please visit:
http://moodlereader.org/
This plugin uses JQuery framework and plugins:
http://jqueryui.com/sortable/
http://touchpunch.furf.com/
+2 -44
View File
@@ -94,6 +94,7 @@ class qtype_ordering_renderer extends qtype_renderer {
if ($readonly==false) {
$result .= html_writer::tag('script', '', array('type'=>'text/javascript', 'src'=>$CFG->wwwroot.'/question/type/ordering/js/jquery.js'));
$result .= html_writer::tag('script', '', array('type'=>'text/javascript', 'src'=>$CFG->wwwroot.'/question/type/ordering/js/jquery-ui.js'));
$result .= html_writer::tag('script', '', array('type'=>'text/javascript', 'src'=>$CFG->wwwroot.'/question/type/ordering/js/jquery.ui.touch-punch.js'));
}
$style = "\n";
@@ -153,7 +154,7 @@ class qtype_ordering_renderer extends qtype_renderer {
if (count($answerids)) {
$result .= html_writer::start_tag('div', array('class' => 'ablock'));
$result .= html_writer::start_tag('div', array('class' => 'answer'));
$result .= html_writer::start_tag('ul', array('class' => 'boxy', 'id' => $sortable_id));
$result .= html_writer::start_tag('ul', array('class' => 'boxy', 'id' => $sortable_id));
// generate ordering items
foreach ($answerids as $position => $answerid) {
@@ -189,49 +190,6 @@ class qtype_ordering_renderer extends qtype_renderer {
$result .= html_writer::tag('div', '', array('style' => 'clear:both;'));
}
if ($readonly==false) {
$script = "\n";
$script .= "//<![CDATA[\n";
if ($addScript) {
$addScript = false; // only add these functions once
$script .= "function orderingTouchHandler(evt) {\n";
$script .= " var touchEvt = evt.changedTouches[0];\n";
$script .= " switch (evt.type) {\n";
$script .= " case 'touchstart': var type = 'mousedown'; break;\n";
$script .= " case 'touchmove': var type = 'mousemove'; break;\n";
$script .= " case 'touchend': var type = 'mouseup'; break;\n";
$script .= " default: return;\n";
$script .= " }\n";
$script .= " var mouseEvt = document.createEvent('MouseEvent');\n";
$script .= " // initMouseEvent(type, canBubble, cancelable, view, clickCount, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget)\n";
$script .= " mouseEvt.initMouseEvent(type, true, true, window, 1, touchEvt.screenX, touchEvt.screenY, touchEvt.clientX, touchEvt.clientY, false, false, false, false, 0, null);\n";
$script .= " touchEvt.target.dispatchEvent(mouseEvt);\n";
$script .= " evt.preventDefault();\n";
$script .= "}\n";
$script .= "function orderingTouchHandlers(sortableid) {\n";
$script .= " var obj = document.getElementById(sortableid);\n";
$script .= " if (obj) {\n";
$script .= " for (var i=0; i<obj.childNodes.length; i++) {\n";
$script .= " obj.childNodes.item(i).addEventListener('touchstart', orderingTouchHandler, false);\n";
$script .= " obj.childNodes.item(i).addEventListener('touchmove', orderingTouchHandler, false);\n";
$script .= " obj.childNodes.item(i).addEventListener('touchend', orderingTouchHandler, false);\n";
$script .= " obj.childNodes.item(i).addEventListener('touchcancel', orderingTouchHandler, false);\n";
$script .= " }\n";
$script .= " obj = null;\n";
$script .= " } else {\n";
$script .= " // try again in 1/2 a second - shouldn't be necessary !!\n";
$script .= " setTimeout(new Function('orderingTouchHandlers(".'"'."'+sortableid+'".'"'.")'), 500);\n";
$script .= " }\n";
$script .= "}\n";
}
$script .= "if (document.body.ontouchstart) {\n";
$script .= " orderingTouchHandlers('$sortable_id');\n";
$script .= "}\n";
$script .= "//]]>\n";
$result .= html_writer::tag('script', $script, array('type' => 'text/javascript'));
}
return $result;
}
+2 -2
View File
@@ -30,6 +30,6 @@ defined('MOODLE_INTERNAL') || die();
$plugin->cron = 0;
$plugin->component = 'qtype_ordering';
$plugin->maturity = MATURITY_STABLE; // ALPHA=50, BETA=100, RC=150, STABLE=200
$plugin->release = '2014-07-26 (02)';
$plugin->version = 2014072602;
$plugin->release = '2014-11-30 (03)';
$plugin->version = 2014113003;
$plugin->requires = 2010112400; // Moodle 2.0