MDL-79863 qtype_ordering: qtype/ordering add AMD folder and files cor compatability with Moodle >= 2.9. Many thanks to Jakob Ackermann (github.com/jacac)

This commit is contained in:
Gordon Bateson 2018-01-17 08:12:54 +09:00 committed by Mathew May
parent c40caa6a09
commit 489c938b85
4 changed files with 226 additions and 0 deletions

View file

@ -0,0 +1 @@
!function(a){"function"==typeof define&&define.amd?define(["jquery","jqueryui"],a):a(window.jQuery)}(function(a){function b(a){var b=window.pageXOffset,c=window.pageYOffset,d=a.clientX,e=a.clientY;return 0===a.pageY&&Math.floor(e)>Math.floor(a.pageY)||0===a.pageX&&Math.floor(d)>Math.floor(a.pageX)?(d-=b,e-=c):(e<a.pageY-c||d<a.pageX-b)&&(d=a.pageX-b,e=a.pageY-c),{clientX:d,clientY:e}}function c(c,e){if(!(!d&&c.originalEvent.touches.length>1||d&&!c.isPrimary)){var f=d?c.originalEvent:c.originalEvent.changedTouches[0],g=document.createEvent("MouseEvents"),h=b(f);a(f.target).is("input")||a(f.target).is("textarea")?c.stopPropagation():c.preventDefault(),g.initMouseEvent(e,!0,!0,window,1,c.screenX||f.screenX,c.screenY||f.screenY,c.clientX||h.clientX,c.clientY||h.clientY,!1,!1,!1,!1,0,null),c.target.dispatchEvent(g)}}var d=window.navigator.pointerEnabled||window.navigator.msPointerEnabled;if(a.support.touch="ontouchend"in document||d,a.support.touch&&a.ui.mouse){var e,f=a.ui.mouse.prototype,g=f._mouseInit;f._touchStart=function(a){var b=this;e||!d&&!b._mouseCapture(a.originalEvent.changedTouches[0])||(e=!0,b._touchMoved=!1,c(a,"mouseover"),c(a,"mousemove"),c(a,"mousedown"))},f._touchMove=function(a){e&&(this._touchMoved=!0,c(a,"mousemove"))},f._touchEnd=function(a){e&&(c(a,"mouseup"),c(a,"mouseout"),this._touchMoved||c(a,"click"),e=!1)},f._mouseInit=function(){var b=this;b.element.on({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd"),pointerDown:a.proxy(b,"_touchStart"),pointerMove:a.proxy(b,"_touchMove"),pointerUp:a.proxy(b,"_touchEnd"),MSPointerDown:a.proxy(b,"_touchStart"),MSPointerMove:a.proxy(b,"_touchMove"),MSPointerUp:a.proxy(b,"_touchEnd")}),g.call(b)}}});

View file

@ -0,0 +1 @@
define(["jquery","jqueryui","qtype_ordering/jquery.ui.touch-punch-improved"],function(a){return{init:function(b,c,d,e){a("#"+b).sortable({axis:e,containment:a("#"+b),opacity:.6,update:function(){var b=a(this).sortable("toArray").toString();a("#"+c).attr("value",b)}})}}});

View file

@ -0,0 +1,207 @@
/*!
* jQuery UI Touch Punch Improved 0.3.1
*
*
* Copyright 2013, Chris Hutchinson <chris@brushd.com>
* Original jquery-ui-touch-punch Copyright 2011, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([ "jquery", "jqueryui" ], factory );
} else {
// Browser globals
factory( window.jQuery );
}
}(function ($) {
var pointerEnabled = window.navigator.pointerEnabled
|| window.navigator.msPointerEnabled;
// Detect touch support
$.support.touch = 'ontouchend' in document || pointerEnabled;
// Ignore browsers without touch support or mouse support
if (!$.support.touch || !$.ui.mouse) {
return;
}
var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
touchHandled;
// see http://stackoverflow.com/a/12714084/220825
function fixTouch(touch) {
var winPageX = window.pageXOffset,
winPageY = window.pageYOffset,
x = touch.clientX,
y = touch.clientY;
if (touch.pageY === 0 && Math.floor(y) > Math.floor(touch.pageY)
|| touch.pageX === 0 && Math.floor(x) > Math.floor(touch.pageX)) {
// iOS4 clientX/clientY have the value that should have been
// in pageX/pageY. While pageX/page/ have the value 0
x = x - winPageX;
y = y - winPageY;
} else if (y < (touch.pageY - winPageY) || x < (touch.pageX - winPageX)) {
// Some Android browsers have totally bogus values for clientX/Y
// when scrolling/zooming a page. Detectable since clientX/clientY
// should never be smaller than pageX/pageY minus page scroll
x = touch.pageX - winPageX;
y = touch.pageY - winPageY;
}
return {
clientX: x,
clientY: y
};
}
/**
* Simulate a mouse event based on a corresponding touch event
* @param {Object} event A touch event
* @param {String} simulatedType The corresponding mouse event
*/
function simulateMouseEvent (event, simulatedType) {
// Ignore multi-touch events
if ((!pointerEnabled && event.originalEvent.touches.length > 1) || (pointerEnabled && !event.isPrimary)) {
return;
}
var touch = pointerEnabled ? event.originalEvent : event.originalEvent.changedTouches[0],
simulatedEvent = document.createEvent('MouseEvents'),
coord = fixTouch(touch);
// Check if element is an input or a textarea
if ($(touch.target).is("input") || $(touch.target).is("textarea")) {
event.stopPropagation();
} else {
event.preventDefault();
}
// Initialize the simulated mouse event using the touch event's coordinates
simulatedEvent.initMouseEvent(
simulatedType, // type
true, // bubbles
true, // cancelable
window, // view
1, // detail
event.screenX || touch.screenX, // screenX
event.screenY || touch.screenY, // screenY
event.clientX || coord.clientX, // clientX
event.clientY || coord.clientY, // clientY
false, // ctrlKey
false, // altKey
false, // shiftKey
false, // metaKey
0, // button
null // relatedTarget
);
// Dispatch the simulated event to the target element
event.target.dispatchEvent(simulatedEvent);
}
/**
* Handle the jQuery UI widget's touchstart events
* @param {Object} event The widget element's touchstart event
*/
mouseProto._touchStart = function (event) {
var self = this;
// Ignore the event if another widget is already being handled
if (touchHandled || (!pointerEnabled && !self._mouseCapture(event.originalEvent.changedTouches[0]))) {
return;
}
// Set the flag to prevent other widgets from inheriting the touch event
touchHandled = true;
// Track movement to determine if interaction was a click
self._touchMoved = false;
// Simulate the mouseover event
simulateMouseEvent(event, 'mouseover');
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
// Simulate the mousedown event
simulateMouseEvent(event, 'mousedown');
};
/**
* Handle the jQuery UI widget's touchmove events
* @param {Object} event The document's touchmove event
*/
mouseProto._touchMove = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Interaction was not a click
this._touchMoved = true;
// Simulate the mousemove event
simulateMouseEvent(event, 'mousemove');
};
/**
* Handle the jQuery UI widget's touchend events
* @param {Object} event The document's touchend event
*/
mouseProto._touchEnd = function (event) {
// Ignore event if not handled
if (!touchHandled) {
return;
}
// Simulate the mouseup event
simulateMouseEvent(event, 'mouseup');
// Simulate the mouseout event
simulateMouseEvent(event, 'mouseout');
// If the touch interaction did not move, it should trigger a click
if (!this._touchMoved) {
// Simulate the click event
simulateMouseEvent(event, 'click');
}
// Unset the flag to allow other widgets to inherit the touch event
touchHandled = false;
};
/**
* A duck punch of the $.ui.mouse _mouseInit method to support touch events.
* This method extends the widget with bound touch event handlers that
* translate touch events to mouse events and pass them to the widget's
* original mouse event handling methods.
*/
mouseProto._mouseInit = function () {
var self = this;
self.element.on({
'touchstart': $.proxy(self, '_touchStart'),
'touchmove': $.proxy(self, '_touchMove'),
'touchend': $.proxy(self, '_touchEnd'),
'pointerDown': $.proxy(self, '_touchStart'),
'pointerMove': $.proxy(self, '_touchMove'),
'pointerUp': $.proxy(self, '_touchEnd'),
'MSPointerDown': $.proxy(self, '_touchStart'),
'MSPointerMove': $.proxy(self, '_touchMove'),
'MSPointerUp': $.proxy(self, '_touchEnd')
});
// Call the original $.ui.mouse init method
_mouseInit.call(self);
};
}));

View file

@ -0,0 +1,17 @@
define(['jquery', 'jqueryui', 'qtype_ordering/jquery.ui.touch-punch-improved'], function($) {
return {
init: function (sortableid, responseid, ablockid, axis) {
$('#' + sortableid).sortable({
axis : axis,
containment: $('#'+sortableid),
opacity : 0.6,
update : function () {
var ItemsOrder = $(this).sortable('toArray').toString();
$('#' + responseid).attr('value', ItemsOrder);
}
});
}
};
});