mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 23:20:09 +01:00
MDL-79863 qtype_ordering: qtype/ordering ensure JQuery is high enough version to allow drag-and-drop when Quiz is in a popup window
This commit is contained in:
parent
07346a063b
commit
6571680f9a
4
question/type/ordering/jquery/jquery-ui.js
vendored
4
question/type/ordering/jquery/jquery-ui.js
vendored
File diff suppressed because one or more lines are too long
@ -47,19 +47,54 @@ class qtype_ordering extends question_type {
|
||||
* It also includes the jquery files required for this plugin
|
||||
*/
|
||||
public function find_standard_scripts() {
|
||||
global $PAGE;
|
||||
global $CFG, $PAGE;
|
||||
|
||||
// include "script.js" and/or "script.php" in the normal way
|
||||
parent::find_standard_scripts();
|
||||
|
||||
// include jquery files
|
||||
$version = '';
|
||||
$min_version = '1.11.0'; // Moodle 2.7
|
||||
$search = '/jquery-([0-9.]+)(\.min)?\.js$/';
|
||||
|
||||
// make sure jQuery version is high enough
|
||||
// (required if Quiz is in a popup window)
|
||||
// Moodle 2.5 has jQuery 1.9.1
|
||||
// Moodle 2.6 has jQuery 1.10.2
|
||||
// Moodle 2.7 has jQuery 1.11.0
|
||||
// Moodle 2.8 has jQuery 1.11.1
|
||||
// Moodle 2.9 has jQuery 1.11.1
|
||||
if (method_exists($PAGE->requires, 'jquery')) {
|
||||
// Moodle >= 2.5
|
||||
if ($version=='') {
|
||||
include($CFG->dirroot.'/lib/jquery/plugins.php');
|
||||
if (isset($plugins['jquery']['files'][0])) {
|
||||
if (preg_match($search, $plugins['jquery']['files'][0], $matches)) {
|
||||
$version = $matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($version=='') {
|
||||
$filename = $CFG->dirroot.'/lib/jquery/jquery*.js';
|
||||
foreach (glob($filename) as $filename) {
|
||||
if (preg_match($search, $filename, $matches)) {
|
||||
$version = $matches[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version_compare($version, $min_version) < 0) {
|
||||
$version = '';
|
||||
}
|
||||
}
|
||||
|
||||
// include jquery files
|
||||
if ($version) {
|
||||
// Moodle >= 2.7
|
||||
$PAGE->requires->jquery();
|
||||
$PAGE->requires->jquery_plugin('ui');
|
||||
$PAGE->requires->jquery_plugin('ui.touch-punch', 'qtype_ordering');
|
||||
} else {
|
||||
// Moodle <= 2.4
|
||||
// Moodle <= 2.6
|
||||
$jquery = '/question/type/' . $this->name().'/jquery';
|
||||
$PAGE->requires->js($jquery.'/jquery.js', true);
|
||||
$PAGE->requires->js($jquery.'/jquery-ui.js', true);
|
||||
|
@ -64,19 +64,22 @@ class qtype_ordering_renderer extends qtype_with_combined_feedback_renderer {
|
||||
} else {
|
||||
$script = "\n";
|
||||
$script .= "//<![CDATA[\n";
|
||||
$script .= "$(function() {\n";
|
||||
$script .= " $('#$sortable_id').sortable({\n";
|
||||
$script .= " update: function(event, ui) {\n";
|
||||
$script .= " var ItemsOrder = $(this).sortable('toArray').toString();\n";
|
||||
$script .= " $('#$response_id').attr('value', ItemsOrder);\n";
|
||||
$script .= " }\n";
|
||||
$script .= "if (window.$) {\n"; // $ is an alias for jQuery
|
||||
$script .= " $(function() {\n";
|
||||
$script .= " $('#$sortable_id').sortable({\n";
|
||||
$script .= " update: function(event, ui) {\n";
|
||||
$script .= " var ItemsOrder = $(this).sortable('toArray').toString();\n";
|
||||
$script .= " $('#$response_id').attr('value', ItemsOrder);\n";
|
||||
$script .= " },\n";
|
||||
$script .= " opacity: 0.6\n";
|
||||
$script .= " });\n";
|
||||
$script .= " $('#$sortable_id').disableSelection();\n";
|
||||
$script .= " });\n";
|
||||
$script .= " $('#$sortable_id').disableSelection();\n";
|
||||
$script .= "});\n";
|
||||
$script .= "$(document).ready(function() {\n";
|
||||
$script .= " var ItemsOrder = $('#$sortable_id').sortable('toArray').toString();\n";
|
||||
$script .= " $('#$response_id').attr('value', ItemsOrder);\n";
|
||||
$script .= "});\n";
|
||||
$script .= " $(document).ready(function() {\n";
|
||||
$script .= " var ItemsOrder = $('#$sortable_id').sortable('toArray').toString();\n";
|
||||
$script .= " $('#$response_id').attr('value', ItemsOrder);\n";
|
||||
$script .= " });\n";
|
||||
$script .= "}\n";
|
||||
$script .= "//]]>\n";
|
||||
$result .= html_writer::tag('script', $script, array('type' => 'text/javascript'));
|
||||
}
|
||||
|
@ -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 = '2015-02-05 (19)';
|
||||
$plugin->version = 2015020519;
|
||||
$plugin->release = '2015-02-15 (20)';
|
||||
$plugin->version = 2015021520;
|
||||
$plugin->requires = 2010112400; // Moodle 2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user