mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-79863 qtype_ordering: Moodle.2x question/type/ordering use md5 instead of fraction field as id in ordering questions
This commit is contained in:
parent
05a43d9094
commit
20084542b5
@ -1,231 +0,0 @@
|
||||
<?php
|
||||
if (!isset($SAJAX_INCLUDED)) {
|
||||
|
||||
/*
|
||||
* GLOBALS AND DEFAULTS
|
||||
*
|
||||
*/
|
||||
$sajax_debug_mode = 0;
|
||||
$sajax_export_list = array();
|
||||
$sajax_request_type = "GET";
|
||||
$sajax_remote_uri = "";
|
||||
|
||||
/*
|
||||
* CODE
|
||||
*
|
||||
*/
|
||||
function sajax_init() {
|
||||
}
|
||||
|
||||
function sajax_get_my_uri() {
|
||||
global $REQUEST_URI;
|
||||
|
||||
return $REQUEST_URI;
|
||||
}
|
||||
|
||||
$sajax_remote_uri = sajax_get_my_uri();
|
||||
|
||||
function sajax_handle_client_request() {
|
||||
global $sajax_export_list;
|
||||
|
||||
$mode = "";
|
||||
|
||||
if (! empty($_GET["rs"]))
|
||||
$mode = "get";
|
||||
|
||||
if (!empty($_POST["rs"]))
|
||||
$mode = "post";
|
||||
|
||||
if (empty($mode))
|
||||
return;
|
||||
|
||||
if ($mode == "get") {
|
||||
// Bust cache in the head
|
||||
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
||||
// always modified
|
||||
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header ("Pragma: no-cache"); // HTTP/1.0
|
||||
$func_name = $_GET["rs"];
|
||||
if (! empty($_GET["rsargs"]))
|
||||
$args = $_GET["rsargs"];
|
||||
else
|
||||
$args = array();
|
||||
}
|
||||
else {
|
||||
$func_name = $_POST["rs"];
|
||||
if (! empty($_POST["rsargs"]))
|
||||
$args = $_POST["rsargs"];
|
||||
else
|
||||
$args = array();
|
||||
}
|
||||
|
||||
if (! in_array($func_name, $sajax_export_list))
|
||||
echo "-:$func_name not callable";
|
||||
else {
|
||||
echo "+:";
|
||||
$result = call_user_func_array($func_name, $args);
|
||||
echo $result;
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function sajax_get_common_js() {
|
||||
global $sajax_debug_mode;
|
||||
global $sajax_request_type;
|
||||
global $sajax_remote_uri;
|
||||
|
||||
$t = strtoupper($sajax_request_type);
|
||||
if ($t != "GET" && $t != "POST")
|
||||
return "// Invalid type: $t.. \n\n";
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
// remote scripting library
|
||||
// (c) copyright 2005 modernmethod, inc
|
||||
var sajax_debug_mode = <?php echo $sajax_debug_mode ? "true" : "false"; ?>;
|
||||
var sajax_request_type = "<?php echo $t; ?>";
|
||||
|
||||
function sajax_debug(text) {
|
||||
if (sajax_debug_mode)
|
||||
alert("RSD: " + text)
|
||||
}
|
||||
function sajax_init_object() {
|
||||
sajax_debug("sajax_init_object() called..")
|
||||
|
||||
var A;
|
||||
try {
|
||||
A=new ActiveXObject("Msxml2.XMLHTTP");
|
||||
} catch (e) {
|
||||
try {
|
||||
A=new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch (oc) {
|
||||
A=null;
|
||||
}
|
||||
}
|
||||
if(!A && typeof XMLHttpRequest != "undefined")
|
||||
A = new XMLHttpRequest();
|
||||
if (!A)
|
||||
sajax_debug("Could not create connection object.");
|
||||
return A;
|
||||
}
|
||||
function sajax_do_call(func_name, args) {
|
||||
var i, x, n;
|
||||
var uri;
|
||||
var post_data;
|
||||
|
||||
uri = "<?php echo $sajax_remote_uri; ?>";
|
||||
if (sajax_request_type == "GET") {
|
||||
if (uri.indexOf("?") == -1)
|
||||
uri = uri + "?rs=" + escape(func_name);
|
||||
else
|
||||
uri = uri + "&rs=" + escape(func_name);
|
||||
for (i = 0; i < args.length-1; i++)
|
||||
uri = uri + "&rsargs[]=" + escape(args[i]);
|
||||
uri = uri + "&rsrnd=" + new Date().getTime();
|
||||
post_data = null;
|
||||
} else {
|
||||
post_data = "rs=" + escape(func_name);
|
||||
for (i = 0; i < args.length-1; i++)
|
||||
post_data = post_data + "&rsargs[]=" + escape(args[i]);
|
||||
}
|
||||
|
||||
x = sajax_init_object();
|
||||
x.open(sajax_request_type, uri, true);
|
||||
if (sajax_request_type == "POST") {
|
||||
x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
|
||||
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
x.onreadystatechange = function() {
|
||||
if (x.readyState != 4)
|
||||
return;
|
||||
sajax_debug("received " + x.responseText);
|
||||
|
||||
var status;
|
||||
var data;
|
||||
status = x.responseText.charAt(0);
|
||||
data = x.responseText.substring(2);
|
||||
if (status == "-")
|
||||
alert("Error: " + data);
|
||||
else
|
||||
args[args.length-1](data);
|
||||
}
|
||||
x.send(post_data);
|
||||
sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
|
||||
sajax_debug(func_name + " waiting..");
|
||||
delete x;
|
||||
}
|
||||
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $html;
|
||||
}
|
||||
|
||||
function sajax_show_common_js() {
|
||||
echo sajax_get_common_js();
|
||||
}
|
||||
|
||||
// javascript escape a value
|
||||
function sajax_esc($val)
|
||||
{
|
||||
return str_replace('"', '\\\\"', $val);
|
||||
}
|
||||
|
||||
function sajax_get_one_stub($func_name) {
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
// wrapper for <?php echo $func_name; ?>
|
||||
|
||||
function x_<?php echo $func_name; ?>() {
|
||||
sajax_do_call("<?php echo $func_name; ?>",
|
||||
x_<?php echo $func_name; ?>.arguments);
|
||||
}
|
||||
|
||||
<?php
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $html;
|
||||
}
|
||||
|
||||
function sajax_show_one_stub($func_name) {
|
||||
echo sajax_get_one_stub($func_name);
|
||||
}
|
||||
|
||||
function sajax_export() {
|
||||
global $sajax_export_list;
|
||||
|
||||
$n = func_num_args();
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$sajax_export_list[] = func_get_arg($i);
|
||||
}
|
||||
}
|
||||
|
||||
$sajax_js_has_been_shown = 0;
|
||||
function sajax_get_javascript()
|
||||
{
|
||||
global $sajax_js_has_been_shown;
|
||||
global $sajax_export_list;
|
||||
|
||||
$html = "";
|
||||
if (! $sajax_js_has_been_shown) {
|
||||
$html .= sajax_get_common_js();
|
||||
$sajax_js_has_been_shown = 1;
|
||||
}
|
||||
foreach ($sajax_export_list as $func) {
|
||||
$html .= sajax_get_one_stub($func);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function sajax_show_javascript()
|
||||
{
|
||||
echo sajax_get_javascript();
|
||||
}
|
||||
|
||||
|
||||
$SAJAX_INCLUDED = 1;
|
||||
}
|
||||
?>
|
@ -1,112 +0,0 @@
|
||||
/**********************************************************
|
||||
Very minorly modified from the example by Tim Taylor
|
||||
http://tool-man.org/examples/sorting.html
|
||||
|
||||
Added Coordinate.prototype.inside( northwest, southeast );
|
||||
|
||||
**********************************************************/
|
||||
|
||||
var Coordinates = {
|
||||
ORIGIN : new Coordinate(0, 0),
|
||||
|
||||
northwestPosition : function(element) {
|
||||
var x = parseInt(element.style.left);
|
||||
var y = parseInt(element.style.top);
|
||||
|
||||
return new Coordinate(isNaN(x) ? 0 : x, isNaN(y) ? 0 : y);
|
||||
},
|
||||
|
||||
southeastPosition : function(element) {
|
||||
return Coordinates.northwestPosition(element).plus(
|
||||
new Coordinate(element.offsetWidth, element.offsetHeight));
|
||||
},
|
||||
|
||||
northwestOffset : function(element, isRecursive) {
|
||||
var offset = new Coordinate(element.offsetLeft, element.offsetTop);
|
||||
|
||||
if (!isRecursive) return offset;
|
||||
|
||||
var parent = element.offsetParent;
|
||||
while (parent) {
|
||||
offset = offset.plus(
|
||||
new Coordinate(parent.offsetLeft, parent.offsetTop));
|
||||
parent = parent.offsetParent;
|
||||
}
|
||||
return offset;
|
||||
},
|
||||
|
||||
southeastOffset : function(element, isRecursive) {
|
||||
return Coordinates.northwestOffset(element, isRecursive).plus(
|
||||
new Coordinate(element.offsetWidth, element.offsetHeight));
|
||||
},
|
||||
|
||||
fixEvent : function(event) {
|
||||
event.windowCoordinate = new Coordinate(event.clientX, event.clientY);
|
||||
}
|
||||
};
|
||||
|
||||
function Coordinate(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
Coordinate.prototype.toString = function() {
|
||||
return "(" + this.x + "," + this.y + ")";
|
||||
}
|
||||
|
||||
Coordinate.prototype.plus = function(that) {
|
||||
return new Coordinate(this.x + that.x, this.y + that.y);
|
||||
}
|
||||
|
||||
Coordinate.prototype.minus = function(that) {
|
||||
return new Coordinate(this.x - that.x, this.y - that.y);
|
||||
}
|
||||
|
||||
Coordinate.prototype.distance = function(that) {
|
||||
var deltaX = this.x - that.x;
|
||||
var deltaY = this.y - that.y;
|
||||
|
||||
return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
|
||||
}
|
||||
|
||||
Coordinate.prototype.max = function(that) {
|
||||
var x = Math.max(this.x, that.x);
|
||||
var y = Math.max(this.y, that.y);
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
|
||||
Coordinate.prototype.constrain = function(min, max) {
|
||||
if (min.x > max.x || min.y > max.y) return this;
|
||||
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
|
||||
if (min.x != null) x = Math.max(x, min.x);
|
||||
if (max.x != null) x = Math.min(x, max.x);
|
||||
if (min.y != null) y = Math.max(y, min.y);
|
||||
if (max.y != null) y = Math.min(y, max.y);
|
||||
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
|
||||
Coordinate.prototype.reposition = function(element) {
|
||||
element.style["top"] = this.y + "px";
|
||||
element.style["left"] = this.x + "px";
|
||||
}
|
||||
|
||||
Coordinate.prototype.equals = function(that) {
|
||||
if (this == that) return true;
|
||||
if (!that || that == null) return false;
|
||||
|
||||
return this.x == that.x && this.y == that.y;
|
||||
}
|
||||
|
||||
// returns true of this point is inside specified box
|
||||
Coordinate.prototype.inside = function(northwest, southeast) {
|
||||
if ((this.x >= northwest.x) && (this.x <= southeast.x) &&
|
||||
(this.y >= northwest.y) && (this.y <= southeast.y)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
/*
|
||||
* drag.js - click & drag DOM elements
|
||||
*
|
||||
* originally based on Youngpup's dom-drag.js, www.youngpup.net
|
||||
*/
|
||||
|
||||
/**********************************************************
|
||||
Further modified from the example by Tim Taylor
|
||||
http://tool-man.org/examples/sorting.html
|
||||
|
||||
Changed onMouseMove where it calls group.onDrag and then
|
||||
adjusts the offset for changes to the DOM. If the item
|
||||
being moved changed parents it would be off so changed to
|
||||
get the absolute offset (recursive northwestOffset).
|
||||
|
||||
**********************************************************/
|
||||
|
||||
var Drag = {
|
||||
BIG_Z_INDEX : 10000,
|
||||
group : null,
|
||||
isDragging : false,
|
||||
|
||||
makeDraggable : function(group) {
|
||||
group.handle = group;
|
||||
group.handle.group = group;
|
||||
|
||||
group.minX = null;
|
||||
group.minY = null;
|
||||
group.maxX = null;
|
||||
group.maxY = null;
|
||||
group.threshold = 0;
|
||||
group.thresholdY = 0;
|
||||
group.thresholdX = 0;
|
||||
|
||||
group.onDragStart = new Function();
|
||||
group.onDragEnd = new Function();
|
||||
group.onDrag = new Function();
|
||||
|
||||
// TODO: use element.prototype.myFunc
|
||||
group.setDragHandle = Drag.setDragHandle;
|
||||
group.setDragThreshold = Drag.setDragThreshold;
|
||||
group.setDragThresholdX = Drag.setDragThresholdX;
|
||||
group.setDragThresholdY = Drag.setDragThresholdY;
|
||||
group.constrain = Drag.constrain;
|
||||
group.constrainVertical = Drag.constrainVertical;
|
||||
group.constrainHorizontal = Drag.constrainHorizontal;
|
||||
|
||||
group.onmousedown = Drag.onMouseDown;
|
||||
},
|
||||
|
||||
constrainVertical : function() {
|
||||
var nwOffset = Coordinates.northwestOffset(this, true);
|
||||
this.minX = nwOffset.x;
|
||||
this.maxX = nwOffset.x;
|
||||
},
|
||||
|
||||
constrainHorizontal : function() {
|
||||
var nwOffset = Coordinates.northwestOffset(this, true);
|
||||
this.minY = nwOffset.y;
|
||||
this.maxY = nwOffset.y;
|
||||
},
|
||||
|
||||
constrain : function(nwPosition, sePosition) {
|
||||
this.minX = nwPosition.x;
|
||||
this.minY = nwPosition.y;
|
||||
this.maxX = sePosition.x;
|
||||
this.maxY = sePosition.y;
|
||||
},
|
||||
|
||||
setDragHandle : function(handle) {
|
||||
if (handle && handle != null)
|
||||
this.handle = handle;
|
||||
else
|
||||
this.handle = this;
|
||||
|
||||
this.handle.group = this;
|
||||
this.onmousedown = null;
|
||||
this.handle.onmousedown = Drag.onMouseDown;
|
||||
},
|
||||
|
||||
setDragThreshold : function(threshold) {
|
||||
if (isNaN(parseInt(threshold))) return;
|
||||
|
||||
this.threshold = threshold;
|
||||
},
|
||||
|
||||
setDragThresholdX : function(threshold) {
|
||||
if (isNaN(parseInt(threshold))) return;
|
||||
|
||||
this.thresholdX = threshold;
|
||||
},
|
||||
|
||||
setDragThresholdY : function(threshold) {
|
||||
if (isNaN(parseInt(threshold))) return;
|
||||
|
||||
this.thresholdY = threshold;
|
||||
},
|
||||
|
||||
onMouseDown : function(event) {
|
||||
event = Drag.fixEvent(event);
|
||||
Drag.group = this.group;
|
||||
|
||||
var group = this.group;
|
||||
var mouse = event.windowCoordinate;
|
||||
var nwOffset = Coordinates.northwestOffset(group, true);
|
||||
var nwPosition = Coordinates.northwestPosition(group);
|
||||
var sePosition = Coordinates.southeastPosition(group);
|
||||
var seOffset = Coordinates.southeastOffset(group, true);
|
||||
|
||||
group.originalOpacity = group.style.opacity;
|
||||
group.originalZIndex = group.style.zIndex;
|
||||
group.initialWindowCoordinate = mouse;
|
||||
// TODO: need a better name, but don't yet understand how it
|
||||
// participates in the magic while dragging
|
||||
group.dragCoordinate = mouse;
|
||||
|
||||
Drag.showStatus(mouse, nwPosition, sePosition, nwOffset, seOffset);
|
||||
|
||||
group.onDragStart(nwPosition, sePosition, nwOffset, seOffset);
|
||||
|
||||
// TODO: need better constraint API
|
||||
if (group.minX != null)
|
||||
group.minMouseX = mouse.x - nwPosition.x +
|
||||
group.minX - nwOffset.x;
|
||||
if (group.maxX != null)
|
||||
group.maxMouseX = group.minMouseX + group.maxX - group.minX;
|
||||
|
||||
if (group.minY != null)
|
||||
group.minMouseY = mouse.y - nwPosition.y +
|
||||
group.minY - nwOffset.y;
|
||||
if (group.maxY != null)
|
||||
group.maxMouseY = group.minMouseY + group.maxY - group.minY;
|
||||
|
||||
group.mouseMin = new Coordinate(group.minMouseX, group.minMouseY);
|
||||
group.mouseMax = new Coordinate(group.maxMouseX, group.maxMouseY);
|
||||
|
||||
document.onmousemove = Drag.onMouseMove;
|
||||
document.onmouseup = Drag.onMouseUp;
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
showStatus : function(mouse, nwPosition, sePosition, nwOffset, seOffset) {
|
||||
/*window.status =
|
||||
"mouse: " + mouse.toString() + " " +
|
||||
"NW pos: " + nwPosition.toString() + " " +
|
||||
"SE pos: " + sePosition.toString() + " " +
|
||||
"NW offset: " + nwOffset.toString() + " " +
|
||||
"SE offset: " + seOffset.toString();*/
|
||||
},
|
||||
|
||||
onMouseMove : function(event) {
|
||||
event = Drag.fixEvent(event);
|
||||
var group = Drag.group;
|
||||
var mouse = event.windowCoordinate;
|
||||
var nwOffset = Coordinates.northwestOffset(group, true);
|
||||
var nwPosition = Coordinates.northwestPosition(group);
|
||||
var sePosition = Coordinates.southeastPosition(group);
|
||||
var seOffset = Coordinates.southeastOffset(group, true);
|
||||
|
||||
Drag.showStatus(mouse, nwPosition, sePosition, nwOffset, seOffset);
|
||||
|
||||
if (!Drag.isDragging) {
|
||||
if (group.threshold > 0) {
|
||||
var distance = group.initialWindowCoordinate.distance(
|
||||
mouse);
|
||||
if (distance < group.threshold) return true;
|
||||
} else if (group.thresholdY > 0) {
|
||||
var deltaY = Math.abs(group.initialWindowCoordinate.y - mouse.y);
|
||||
if (deltaY < group.thresholdY) return true;
|
||||
} else if (group.thresholdX > 0) {
|
||||
var deltaX = Math.abs(group.initialWindowCoordinate.x - mouse.x);
|
||||
if (deltaX < group.thresholdX) return true;
|
||||
}
|
||||
|
||||
Drag.isDragging = true;
|
||||
group.style["zIndex"] = Drag.BIG_Z_INDEX;
|
||||
group.style["opacity"] = 0.75;
|
||||
}
|
||||
|
||||
// TODO: need better constraint API
|
||||
var adjusted = mouse.constrain(group.mouseMin, group.mouseMax);
|
||||
nwPosition = nwPosition.plus(adjusted.minus(group.dragCoordinate));
|
||||
nwPosition.reposition(group);
|
||||
group.dragCoordinate = adjusted;
|
||||
|
||||
// once dragging has started, the position of the group
|
||||
// relative to the mouse should stay fixed. They can get out
|
||||
// of sync if the DOM is manipulated while dragging, so we
|
||||
// correct the error here
|
||||
//
|
||||
// TODO: what we really want to do is find the offset from
|
||||
// our corner to the mouse coordinate and adjust to keep it
|
||||
// the same
|
||||
|
||||
// changed to be recursive/use absolute offset for corrections
|
||||
var offsetBefore = Coordinates.northwestOffset(group, true);
|
||||
group.onDrag(nwPosition, sePosition, nwOffset, seOffset);
|
||||
var offsetAfter = Coordinates.northwestOffset(group, true);
|
||||
|
||||
if (!offsetBefore.equals(offsetAfter)) {
|
||||
var errorDelta = offsetBefore.minus(offsetAfter);
|
||||
nwPosition = Coordinates.northwestPosition(group).plus(errorDelta);
|
||||
nwPosition.reposition(group);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
onMouseUp : function(event) {
|
||||
event = Drag.fixEvent(event);
|
||||
var group = Drag.group;
|
||||
|
||||
var mouse = event.windowCoordinate;
|
||||
var nwOffset = Coordinates.northwestOffset(group, true);
|
||||
var nwPosition = Coordinates.northwestPosition(group);
|
||||
var sePosition = Coordinates.southeastPosition(group);
|
||||
var seOffset = Coordinates.southeastOffset(group, true);
|
||||
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
group.onDragEnd(nwPosition, sePosition, nwOffset, seOffset);
|
||||
|
||||
if (Drag.isDragging) {
|
||||
// restoring zIndex before opacity avoids visual flicker in Firefox
|
||||
group.style["zIndex"] = group.originalZIndex;
|
||||
group.style["opacity"] = group.originalOpacity;
|
||||
}
|
||||
|
||||
Drag.group = null;
|
||||
Drag.isDragging = false;
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
fixEvent : function(event) {
|
||||
if (typeof event == 'undefined') event = window.event;
|
||||
Coordinates.fixEvent(event);
|
||||
|
||||
return event;
|
||||
}
|
||||
};
|
260
question/type/ordering/dd_files/dragdrop.js
vendored
260
question/type/ordering/dd_files/dragdrop.js
vendored
@ -1,260 +0,0 @@
|
||||
/**********************************************************
|
||||
Adapted from the sortable lists example by Tim Taylor
|
||||
http://tool-man.org/examples/sorting.html
|
||||
Modified by Tom Westcott : http://www.cyberdummy.co.uk
|
||||
**********************************************************/
|
||||
|
||||
var DragDrop = {
|
||||
firstContainer : null,
|
||||
lastContainer : null,
|
||||
parent_id : null,
|
||||
parent_group : null,
|
||||
makeListContainer : function(list, group) {
|
||||
// each container becomes a linked list node
|
||||
if (this.firstContainer == null) {
|
||||
this.firstContainer = this.lastContainer = list;
|
||||
list.previousContainer = null;
|
||||
list.nextContainer = null;
|
||||
} else {
|
||||
list.previousContainer = this.lastContainer;
|
||||
list.nextContainer = null;
|
||||
this.lastContainer.nextContainer = list;
|
||||
this.lastContainer = list;
|
||||
}
|
||||
|
||||
// these functions are called when an item is draged over
|
||||
// a container or out of a container bounds. onDragOut
|
||||
// is also called when the drag ends with an item having
|
||||
// been added to the container
|
||||
list.onDragOver = new Function();
|
||||
list.onDragOut = new Function();
|
||||
list.onDragDrop = new Function();
|
||||
list.group = group;
|
||||
|
||||
var items = list.getElementsByTagName( "li" );
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
DragDrop.makeItemDragable(items[i]);
|
||||
}
|
||||
},
|
||||
|
||||
serData : function ( group, theid ) {
|
||||
var container = DragDrop.firstContainer;
|
||||
var j = 0;
|
||||
var string = "";
|
||||
|
||||
while (container != null) {
|
||||
|
||||
if(theid != null && container.id != theid)
|
||||
{
|
||||
container = container.nextContainer;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(group != null && container.group != group)
|
||||
{
|
||||
container = container.nextContainer;
|
||||
continue;
|
||||
}
|
||||
|
||||
j ++;
|
||||
if(j > 1)
|
||||
{
|
||||
string += ":";
|
||||
}
|
||||
string += container.id;
|
||||
|
||||
var items = container.getElementsByTagName( "li" );
|
||||
string += "(";
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
if(i > 0)
|
||||
{
|
||||
string += ",";
|
||||
}
|
||||
string += items[i].id;
|
||||
}
|
||||
string += ")";
|
||||
|
||||
container = container.nextContainer;
|
||||
}
|
||||
return string;
|
||||
},
|
||||
|
||||
makeItemDragable : function(item) {
|
||||
Drag.makeDraggable(item);
|
||||
item.setDragThreshold(5);
|
||||
|
||||
// tracks if the item is currently outside all containers
|
||||
item.isOutside = false;
|
||||
|
||||
item.onDragStart = DragDrop.onDragStart;
|
||||
item.onDrag = DragDrop.onDrag;
|
||||
item.onDragEnd = DragDrop.onDragEnd;
|
||||
},
|
||||
|
||||
onDragStart : function(nwPosition, sePosition, nwOffset, seOffset) {
|
||||
// update all container bounds, since they may have changed
|
||||
// on a previous drag
|
||||
//
|
||||
// could be more smart about when to do this
|
||||
var container = DragDrop.firstContainer;
|
||||
while (container != null) {
|
||||
container.northwest = Coordinates.northwestOffset( container, true );
|
||||
container.southeast = Coordinates.southeastOffset( container, true );
|
||||
container = container.nextContainer;
|
||||
}
|
||||
|
||||
// item starts out over current parent
|
||||
this.parentNode.onDragOver();
|
||||
parent_id = this.parentNode.id;
|
||||
parent_group = this.parentNode.group;
|
||||
},
|
||||
|
||||
onDrag : function(nwPosition, sePosition, nwOffset, seOffset) {
|
||||
// check if we were nowhere
|
||||
if (this.isOutside) {
|
||||
// check each container to see if in its bounds
|
||||
var container = DragDrop.firstContainer;
|
||||
while (container != null) {
|
||||
|
||||
if ((nwOffset.inside( container.northwest, container.southeast ) ||
|
||||
seOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) {
|
||||
// we're inside this one
|
||||
container.onDragOver();
|
||||
this.isOutside = false;
|
||||
|
||||
// since isOutside was true, the current parent is a
|
||||
// temporary clone of some previous container node and
|
||||
// it needs to be removed from the document
|
||||
var tempParent = this.parentNode;
|
||||
tempParent.removeChild( this );
|
||||
container.appendChild( this );
|
||||
tempParent.parentNode.removeChild( tempParent );
|
||||
break;
|
||||
}
|
||||
container = container.nextContainer;
|
||||
}
|
||||
// we're still not inside the bounds of any container
|
||||
if (this.isOutside)
|
||||
return;
|
||||
|
||||
// check if we're outside our parent's bounds
|
||||
} else if (!(nwOffset.inside( this.parentNode.northwest, this.parentNode.southeast ) ||
|
||||
seOffset.inside( this.parentNode.northwest, this.parentNode.southeast ))) {
|
||||
|
||||
this.parentNode.onDragOut();
|
||||
this.isOutside = true;
|
||||
|
||||
// check if we're inside a new container's bounds
|
||||
var container = DragDrop.firstContainer;
|
||||
while (container != null) {
|
||||
if ((nwOffset.inside( container.northwest, container.southeast ) ||
|
||||
seOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) {
|
||||
// we're inside this one
|
||||
container.onDragOver();
|
||||
this.isOutside = false;
|
||||
this.parentNode.removeChild( this );
|
||||
container.appendChild( this );
|
||||
break;
|
||||
}
|
||||
container = container.nextContainer;
|
||||
}
|
||||
// if we're not in any container now, make a temporary clone of
|
||||
// the previous container node and add it to the document
|
||||
if (this.isOutside) {
|
||||
var tempParent = this.parentNode.cloneNode( false );
|
||||
this.parentNode.removeChild( this );
|
||||
tempParent.appendChild( this );
|
||||
// body puts a border or item at bottom of page if do not have this
|
||||
tempParent.style.border = 0;
|
||||
document.getElementsByTagName( "body" ).item(0).appendChild( tempParent );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if we get here, we're inside some container bounds, so we do
|
||||
// everything the original dragsort script did to swap us into the
|
||||
// correct position
|
||||
|
||||
var parent = this.parentNode;
|
||||
|
||||
var item = this;
|
||||
var next = DragUtils.nextItem(item);
|
||||
while (next != null && this.offsetTop >= next.offsetTop - 2) {
|
||||
var item = next;
|
||||
var next = DragUtils.nextItem(item);
|
||||
}
|
||||
if (this != item) {
|
||||
DragUtils.swap(this, next);
|
||||
return;
|
||||
}
|
||||
|
||||
var item = this;
|
||||
var previous = DragUtils.previousItem(item);
|
||||
while (previous != null && this.offsetTop <= previous.offsetTop + 2) {
|
||||
var item = previous;
|
||||
var previous = DragUtils.previousItem(item);
|
||||
}
|
||||
if (this != item) {
|
||||
DragUtils.swap(this, item);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
onDragEnd : function(nwPosition, sePosition, nwOffset, seOffset) {
|
||||
// if the drag ends and we're still outside all containers
|
||||
// it's time to remove ourselves from the document or add
|
||||
// to the trash bin
|
||||
if (this.isOutside) {
|
||||
var container = DragDrop.firstContainer;
|
||||
while (container != null) {
|
||||
if(container.id == parent_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
container = container.nextContainer;
|
||||
}
|
||||
this.isOutside = false;
|
||||
this.parentNode.removeChild( this );
|
||||
container.appendChild( this );
|
||||
this.style["top"] = "0px";
|
||||
this.style["left"] = "0px";
|
||||
//var container = DragDrop.firstContainer;
|
||||
//container.appendChild( this );
|
||||
return;
|
||||
}
|
||||
this.parentNode.onDragOut();
|
||||
this.parentNode.onDragDrop();
|
||||
this.style["top"] = "0px";
|
||||
this.style["left"] = "0px";
|
||||
}
|
||||
};
|
||||
|
||||
var DragUtils = {
|
||||
swap : function(item1, item2) {
|
||||
var parent = item1.parentNode;
|
||||
parent.removeChild(item1);
|
||||
parent.insertBefore(item1, item2);
|
||||
|
||||
item1.style["top"] = "0px";
|
||||
item1.style["left"] = "0px";
|
||||
},
|
||||
|
||||
nextItem : function(item) {
|
||||
var sibling = item.nextSibling;
|
||||
while (sibling != null) {
|
||||
if (sibling.nodeName == item.nodeName) return sibling;
|
||||
sibling = sibling.nextSibling;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
previousItem : function(item) {
|
||||
var sibling = item.previousSibling;
|
||||
while (sibling != null) {
|
||||
if (sibling.nodeName == item.nodeName) return sibling;
|
||||
sibling = sibling.previousSibling;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
ul.sortable li {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
ul.boxy {
|
||||
list-style-type: none;
|
||||
padding: 4px 4px 0 4px;
|
||||
margin: 0px;
|
||||
font-size: 13px;
|
||||
font-family: Arial, sans-serif;
|
||||
border: 1px solid #ccc;
|
||||
width: 360px;
|
||||
float: left;
|
||||
margin-left: 5px;
|
||||
}
|
||||
ul.boxy li {
|
||||
cursor: move;
|
||||
margin-bottom: 1px;
|
||||
padding: 8px 2px;
|
||||
border: 1px solid #CCC;
|
||||
background-color: #EEE;
|
||||
min-height: 20px;
|
||||
border-image: initial;
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
<?php
|
||||
if (empty($CFG->orderingquestiontypeflag)) {
|
||||
$CFG->orderingquestiontypeflag = 1;
|
||||
?>
|
||||
<link rel="stylesheet" href="<?php echo $CFG->wwwroot . "/question/type/ordering/"; ?>dd_files/lists.css" type="text/css">
|
||||
<script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot . "/question/type/ordering/"; ?>dd_files/coordinates.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot . "/question/type/ordering/"; ?>dd_files/drag.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="<?php echo $CFG->wwwroot . "/question/type/ordering/"; ?>dd_files/dragdrop.js"></script>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<script language="JavaScript" type="text/javascript"><!--
|
||||
function confirm(z)
|
||||
{
|
||||
window.status = 'Sajax version updated';
|
||||
}
|
||||
|
||||
function onDrop_<?php echo $question->id; ?>() {
|
||||
var data_<?php echo $question->id; ?> = DragDrop.serData('g_<?php echo $question->id; ?>');
|
||||
x_sajax_update(data_<?php echo $question->id; ?>, confirm);
|
||||
}
|
||||
|
||||
function onneedrun_<?php echo $question->id; ?>() {
|
||||
|
||||
var list_<?php echo $question->id; ?> = document.getElementById("ordering");
|
||||
DragDrop.makeListContainer( list_<?php echo $question->id; ?>, 'g_<?php echo $question->id; ?>' );
|
||||
list_<?php echo $question->id; ?>.onDragOver = function() { this.style["background"] = "#EEF"; };
|
||||
list_<?php echo $question->id; ?>.onDragOut = function() {this.style["background"] = "none"; };
|
||||
|
||||
}
|
||||
|
||||
function getSort_<?php echo $question->id; ?>()
|
||||
{
|
||||
<?php echo $question->name_prefix; ?> = document.getElementById("<?php echo $question->name_prefix; ?>");
|
||||
<?php echo $question->name_prefix; ?>.value = DragDrop.serData('g_<?php echo $question->id; ?>', null);
|
||||
}
|
||||
|
||||
function showValue_<?php echo $question->id; ?>()
|
||||
{
|
||||
<?php echo $question->name_prefix ?> = document.getElementById("<?php echo $question->name_prefix; ?>");
|
||||
alert(<?php echo $question->name_prefix; ?>.value);
|
||||
}
|
||||
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
function touchHandler(event)
|
||||
{
|
||||
var touches = event.changedTouches,
|
||||
first = touches[0],
|
||||
type = "";
|
||||
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case "touchstart":
|
||||
type = "mousedown";
|
||||
break;
|
||||
|
||||
case "touchmove":
|
||||
type="mousemove";
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
case "touchend":
|
||||
type="mouseup";
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
var simulatedEvent = document.createEvent("MouseEvent");
|
||||
|
||||
//initMouseEvent(type, canBubble, cancelable, view, clickCount, screenX, screenY, clientX, clientY,
|
||||
// ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget);
|
||||
|
||||
simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
|
||||
false, false, false, false, 0/*left*/, null);
|
||||
|
||||
first.target.dispatchEvent(simulatedEvent);
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function init() {
|
||||
for(i=0;i<document.getElementById("ordering").childNodes.length;i++) {
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchstart", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchmove", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchend", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchcancel", touchHandler, false);
|
||||
}
|
||||
|
||||
|
||||
var myInterval = window.setInterval(function (a,b) {
|
||||
function touchHandler(event)
|
||||
{
|
||||
var touches = event.changedTouches,
|
||||
first = touches[0],
|
||||
type = "";
|
||||
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case "touchstart":
|
||||
type = "mousedown";
|
||||
break;
|
||||
|
||||
case "touchmove":
|
||||
type="mousemove";
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
case "touchend":
|
||||
type="mouseup";
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
var simulatedEvent = document.createEvent("MouseEvent");
|
||||
|
||||
//initMouseEvent(type, canBubble, cancelable, view, clickCount, screenX, screenY, clientX, clientY,
|
||||
// ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget);
|
||||
|
||||
simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY,
|
||||
false, false, false, false, 0, null);
|
||||
|
||||
first.target.dispatchEvent(simulatedEvent);
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
for(i=0;i<document.getElementById("ordering").childNodes.length;i++) {
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchstart", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchmove", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchend", touchHandler, false);
|
||||
document.getElementById('ordering').childNodes.item(i).addEventListener("touchcancel", touchHandler, false);
|
||||
}
|
||||
},500);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class="qtext">
|
||||
<?php echo $questiontext; ?>
|
||||
</div>
|
||||
|
||||
<?php /*if ($image) { ?>
|
||||
<img class="qimage" src="<?php echo $image; ?>" alt="" />
|
||||
<?php }*/ ?><img class="qimage" src="type/ordering/icon.gif" alt="" />
|
||||
|
||||
<div class="ablock clearfix">
|
||||
<div class="prompt">
|
||||
<?php echo $answerprompt; ?>
|
||||
</div>
|
||||
|
||||
<div class="answer">
|
||||
<ul id="ordering" class="sortable boxy">
|
||||
<?php $row = 1; foreach ($anss as $answer) { ?>
|
||||
<li id="<?php echo $answer->id ?>" onMouseUp="getSort_<?php echo $question->id; ?>()"><?php echo $answer->text ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php if ($feedback) { ?>
|
||||
<div class="feedback">
|
||||
<?php echo $feedback ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<input type="hidden" name="<?php echo $question->name_prefix; ?>" id="<?php echo $question->name_prefix; ?>" value="" />
|
||||
|
||||
<?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?>
|
||||
</div>
|
||||
|
||||
<iframe frameborder="0" hspace="0" vspace="0" height="1" width="1" onload="onneedrun_<?php echo $question->id; ?>();getSort_<?php echo $question->id; ?>();"></iframe>
|
||||
|
||||
<script>init();</script>
|
Binary file not shown.
Before Width: | Height: | Size: 908 B |
Loading…
x
Reference in New Issue
Block a user