diff --git a/question/type/ordering/amd/build/drag_reorder.min.js b/question/type/ordering/amd/build/drag_reorder.min.js index 81322853d77..7515c910637 100644 --- a/question/type/ordering/amd/build/drag_reorder.min.js +++ b/question/type/ordering/amd/build/drag_reorder.min.js @@ -1 +1,2 @@ -define(["jquery",require.specified("core/dragdrop")?"core/dragdrop":"qtype_ordering/dragdrop",require.specified("core/key_codes")?"core/key_codes":"qtype_ordering/key_codes"],function(a,b,c){return function(d){var e=null,f=null,g=null,h=null,i=null,j=function(c,h){e={time:(new Date).getTime(),x:h.x,y:h.y},g=a(c.currentTarget).closest(d.itemInPage),"undefined"!=typeof d.reorderStart&&d.reorderStart(g.closest(d.list),g),f=s(),i=a(d.proxyHtml.replace("%%ITEM_HTML%%",g.html()).replace("%%ITEM_CLASS_NAME%%",g.attr("class"))),a(document.body).append(i),i.css("position","absolute"),i.css(g.offset()),i.width(g.outerWidth()),i.height(g.outerHeight()),g.addClass(d.itemMovingClass),l(g),b.start(c,i,k,n)},k=function(){var b=g.closest(d.list),c=null,e=null;b.find(d.item).each(function(b,d){var f=r(d,i);(null===c||fnew Date().getTime()-e.time&&10>Math.abs(e.x-a)&&10>Math.abs(e.y-b)){g[0].focus()}j.remove();j=null;g.removeClass(d.itemMovingClass);g=null;e=null},p=function(a,b){switch(a.keyCode){case c.space:case c.arrowRight:case c.arrowDown:a.preventDefault();a.stopPropagation();var d=b.next();if(d.length){d.insertBefore(b)}break;case c.arrowLeft:case c.arrowUp:a.preventDefault();a.stopPropagation();var e=b.prev();if(e.length){e.insertAfter(b)}break;}},q=function(a){return a.offset().left+a.outerWidth()/2},r=function(a){return a.offset().top+a.outerHeight()/2},s=function(b,c){var d=a(b),e=a(c),f=q(d)-q(e),g=r(d)-r(e);return Math.sqrt(f*f+g*g)},t=function(){return(g||h).closest(d.list).find(d.item).map(function(a,b){return d.idGetter(b)}).get()},u=function(a,b){return a.length===b.length&&a.every(function(a,c){return a===b[c]})};d.itemInPage=function combineSelectors(a,b){var c=[];a.split(",").forEach(function(a){b.split(",").forEach(function(b){c.push(a.trim()+" "+b.trim())})});return c.join(", ")}(d.list,d.item);a(d.list).on("mousedown touchstart",d.item,function(a){var c=b.prepare(a);if(c.start){l(a,c)}});a(d.list).on("keydown",d.item,function(b){h=a(b.currentTarget).closest(d.itemInPage);f=t();p(b,h);var c=t();if(!u(f,c)){d.reorderDone(h.closest(d.list),h,c)}});a(d.itemInPage).attr("tabindex","0")}}); +//# sourceMappingURL=drag_reorder.min.js.map diff --git a/question/type/ordering/amd/build/drag_reorder.min.js.map b/question/type/ordering/amd/build/drag_reorder.min.js.map new file mode 100644 index 00000000000..2a741689ad9 --- /dev/null +++ b/question/type/ordering/amd/build/drag_reorder.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/drag_reorder.js"],"names":["define","require","specified","$","drag","keys","config","dragStart","originalOrder","itemDragging","itemMoving","proxy","orderList","startDrag","event","details","list","time","Date","getTime","x","y","currentTarget","closest","itemInPage","reorderStart","getCurrentOrder","proxyHtml","replace","html","attr","document","body","append","css","offset","width","outerWidth","height","outerHeight","addClass","itemMovingClass","updateProxy","start","dragMove","dragEnd","closestItem","closestDistance","find","item","each","index","element","distance","distanceBetweenElements","midY","insertBefore","insertAfter","items","count","length","i","reorderEnd","newOrder","arrayEquals","reorderDone","Math","abs","focus","remove","removeClass","itemMovedByKeyboard","e","current","keyCode","space","arrowRight","arrowDown","preventDefault","stopPropagation","next","arrowLeft","arrowUp","prev","midX","jQuery","left","top","element1","element2","e1","e2","dx","dy","sqrt","map","idGetter","get","a1","a2","every","v","combineSelectors","outer","inner","combined","split","forEach","firstSelector","secondSelector","push","trim","join","on","prepare"],"mappings":"AA6BAA,OAAM,+BAAC,CACH,QADG,CAEHC,OAAO,CAACC,SAAR,CAAkB,eAAlB,EAAqC,eAArC,CAAuD,yBAFpD,CAGHD,OAAO,CAACC,SAAR,CAAkB,gBAAlB,EAAsC,gBAAtC,CAAyD,0BAHtD,CAAD,CAIH,SACCC,CADD,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AYA5D,CAAC,CAACG,CAAM,CAACkB,UAAR,CAAD,CAAqBM,IAArB,CAA0B,UAA1B,CAAsC,GAAtC,CACH,CACJ,CAlTK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Generic library to allow things in a vertical list to be re-ordered using drag and drop.\n *\n * To make a set of things draggable, create a new instance of this object passing the\n * necessary config, as explained in the comment on the constructor.\n *\n * @package qtype_ordering\n * @copyright 2018 The Open University\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module qtype_ordering/drag_reorder\n */\ndefine([\n 'jquery',\n require.specified('core/dragdrop') ? 'core/dragdrop' : 'qtype_ordering/dragdrop',\n require.specified('core/key_codes') ? 'core/key_codes' : 'qtype_ordering/key_codes'\n], function(\n $,\n drag,\n keys\n) {\n\n /**\n * Constructor.\n *\n * To make a list draggable, create a new instance of this object, passing the necessary config.\n * For example:\n * {\n * // Selector for the list (or lists) to be reordered.\n * list: 'ul.my-list',\n *\n * // Selector, relative to the list selector, for the items that can be moved.\n * item: '> li',\n *\n * // The user actually drags a proxy object, which is constructed from this string,\n * // and then added directly as a child of . The token %%ITEM_HTML%% is\n * // replaced with the innerHtml of the item being dragged. The token %%ITEM_CLASS_NAME%%\n * // is replaced with the class attribute of the item being dragged. Because of this,\n * // the styling of the contents of your list item needs to work for the proxy, as well as\n * // for items in place in the context of the list. Your CSS also needs to ensure\n * // that this proxy has position: absolute. You probably want other styles, like a\n * // drop shadow. Using class osep-itemmoving might be all you need to do.\n * proxyHtml: '
%%ITEM_HTML%%
,\n *\n * // While the proxy is being dragged, this class is added to the item being moved.\n * // You can probably use \"osep-itemmoving\" here.\n * itemMovingClass: \"osep-itemmoving\",\n *\n * // This is a callback which, when called with the DOM node for an item,\n * // returns the string that uniquely identifies each item.\n * // Therefore, the result of the drag action will be represented by the array\n * // obtained by calling this method on each item in the list in order.\n * idGetter: function(item) { return $(node).data('id'); },\n *\n * // This is a callback which, when called with the DOM node for an item,\n * // returns a string that is the name of the item.\n * nameGetter: function(item) { return $(node).text(); },\n *\n * // Function that will be called when a re-order starts (optional, can be not set).\n * // Useful if you need to save information about the initial state.\n * // This function should have two parameters. The first will be a\n * // jQuery object for the list that was reordered, the second will\n * // be the jQuery object for the item moved - which will not yet have been moved.\n * // Note, it is quite possible for reorderStart to be called with no\n * // subsequent call to reorderDone.\n * reorderStart: function($list, $item) { ... }\n *\n * // Function that will be called when a drag has finished, and the list\n * // has been reordered. This function should have three parameters. The first will be\n * // a jQuery object for the list that was reordered, the second will be the jQuery\n * // object for the item moved, and the third will be the new order, which is\n * // an array of ids obtained by calling idGetter on each item in the list in order.\n * // This callback will only be called in the new order is actually different from the old order.\n * reorderDone: function($list, $item, newOrder) { ... }\n *\n * // Function that is alwasy called when a re-order ends (optional, can be not set)\n * // whether or not the order has changed. Useful if you need to undo changes made\n * // in reorderStart, since reorderDone is only called if the new order is different\n * // from the original order.\n * reorderEnd: function($list, $item) { ... }\n * }\n *\n * There is a subtlety ( === hack?) that you can use. If you have items in your list that do not\n * have a drag handle, they they are considered to be placeholders in otherwise empty containers.\n * See how block_userlinks does it, if this seems like it might be useful. nameGetter should return\n * the container name for these items.\n *\n * @param config As above.\n */\n return function(config) {\n var dragStart = null, // Information about when and where the drag started.\n originalOrder = null, // Array of ids.\n itemDragging = null, // Item being moved by dragging (jQuery object).\n itemMoving = null, // Item being moved using the accessible modal (jQuery object).\n proxy = null, // Drag proxy (jQuery object).\n orderList = null; // Order list (jQuery object).\n\n var startDrag = function(event, details) {\n orderList = $(config.list);\n\n dragStart = {\n time: new Date().getTime(),\n x: details.x,\n y: details.y\n };\n\n itemDragging = $(event.currentTarget).closest(config.itemInPage);\n\n if (typeof config.reorderStart !== 'undefined') {\n config.reorderStart(itemDragging.closest(config.list), itemDragging);\n }\n\n originalOrder = getCurrentOrder();\n proxy = $(config.proxyHtml.replace('%%ITEM_HTML%%', itemDragging.html())\n .replace('%%ITEM_CLASS_NAME%%', itemDragging.attr('class'))\n .replace('%%LIST_CLASS_NAME%%', orderList.attr('class')));\n\n $(document.body).append(proxy);\n proxy.css('position', 'absolute');\n proxy.css(itemDragging.offset());\n proxy.width(itemDragging.outerWidth());\n proxy.height(itemDragging.outerHeight());\n itemDragging.addClass(config.itemMovingClass);\n updateProxy(itemDragging);\n\n // Start drag.\n drag.start(event, proxy, dragMove, dragEnd);\n\n };\n\n var dragMove = function() {\n var list = itemDragging.closest(config.list);\n var closestItem = null;\n var closestDistance = null;\n list.find(config.item).each(function (index, element) {\n var distance = distanceBetweenElements(element, proxy);\n if (closestItem === null || distance < closestDistance) {\n closestItem = $(element);\n closestDistance = distance;\n }\n });\n\n if (closestItem[0] === itemDragging[0]) {\n return;\n }\n if (midY(proxy) < midY(closestItem)) {\n itemDragging.insertBefore(closestItem);\n } else {\n itemDragging.insertAfter(closestItem);\n }\n updateProxy(itemDragging);\n };\n\n /**\n * Update proxy's position.\n * @param itemDragging\n */\n var updateProxy = function(itemDragging) {\n var list = itemDragging.closest('ol, ul');\n var items = list.find('li');\n var count = items.length;\n for (var i = 0; i < count; ++i) {\n //proxy.css('margin-left', '20p');\n if (itemDragging[0] === items[i]) {\n proxy.find('li').attr('value', i + 1);\n break;\n }\n }\n };\n\n /**\n * It outer and inner are two CSS selectors, which may contain commas,\n * then combine them safely. So combineSelectors('a, b', 'c, d')\n * gives 'a c, a d, b c, b d'.\n * @param outer\n * @param inner\n * @returns {string}\n */\n var combineSelectors = function(outer, inner) {\n var combined = [];\n outer.split(',').forEach(function(firstSelector) {\n inner.split(',').forEach(function(secondSelector) {\n combined.push(firstSelector.trim() + ' ' + secondSelector.trim());\n });\n });\n return combined.join(', ');\n };\n\n var dragEnd = function(x, y) {\n if (typeof config.reorderEnd !== 'undefined') {\n config.reorderEnd(itemDragging.closest(config.list), itemDragging);\n }\n\n var newOrder = getCurrentOrder();\n if (!arrayEquals(originalOrder, newOrder)) {\n // Order has changed, call the callback.\n config.reorderDone(itemDragging.closest(config.list), itemDragging, newOrder);\n\n } else if (new Date().getTime() - dragStart.time < 500 &&\n Math.abs(dragStart.x - x) < 10 && Math.abs(dragStart.y - y) < 10) {\n // This was really a click. Set the focus on the current item.\n itemDragging[0].focus();\n }\n proxy.remove();\n proxy = null;\n itemDragging.removeClass(config.itemMovingClass);\n itemDragging = null;\n dragStart = null;\n };\n\n /**\n * Items can be moved and placed using certain keys.\n * Tab for tabbing though and choose the item to be moved\n * space, arrow-right arrow-down for moving current element forewards.\n * arrow-right arrow-down for moving the current element backwards.\n * @param e, the event\n * @param item, the current moving item\n */\n var itemMovedByKeyboard = function (e, current) {\n switch (e.keyCode) {\n case keys.space:\n case keys.arrowRight:\n case keys.arrowDown:\n e.preventDefault();\n e.stopPropagation();\n var next = current.next();\n if (next.length) {\n next.insertBefore(current);\n }\n break;\n\n case keys.arrowLeft:\n case keys.arrowUp:\n e.preventDefault();\n e.stopPropagation();\n var prev = current.prev();\n if (prev.length) {\n prev.insertAfter(current);\n }\n break;\n }\n };\n\n /**\n * Get the x-position of the middle of the DOM node represented by the given jQuery object.\n * @param jQuery wrapping a DOM node.\n * @returns Number the x-coordinate of the middle (left plus half outerWidth).\n */\n var midX = function(jQuery) {\n return jQuery.offset().left + jQuery.outerWidth() / 2;\n };\n\n /**\n * Get the y-position of the middle of the DOM node represented by the given jQuery object.\n * @param jQuery wrapping a DOM node.\n * @returns Number the y-coordinate of the middle (top plus half outerHeight).\n */\n var midY = function(jQuery) {\n return jQuery.offset().top + jQuery.outerHeight() / 2;\n };\n\n /**\n * Calculate the distance between the centres of two elements.\n * @param element1 selector, element or jQuery.\n * @param element2 selector, element or jQuery.\n * @return number the distance in pixels.\n */\n var distanceBetweenElements = function(element1, element2) {\n var e1 = $(element1), e2 = $(element2);\n var dx = midX(e1) - midX(e2);\n var dy = midY(e1) - midY(e2);\n return Math.sqrt(dx * dx + dy * dy);\n };\n\n /**\n * Get the current order of the list containing itemDragging.\n * @returns Array of strings, the id of each element in order.\n */\n var getCurrentOrder = function() {\n return (itemDragging || itemMoving).closest(config.list).find(config.item).map(\n function(index, item) { return config.idGetter(item); }).get();\n };\n\n /**\n * Compare two arrays, which just contain simple values like ints or strings,\n * to see if they are equal.\n * @param a1 first array.\n * @param a2 second array.\n * @return boolean true if they both contain the same elements in the same order, else false.\n */\n var arrayEquals = function(a1, a2) {\n return a1.length === a2.length &&\n a1.every(function(v, i) { return v === a2[i]; });\n };\n config.itemInPage = combineSelectors(config.list, config.item);\n\n // AJAX for section drag and click-to-move.\n $(config.list).on('mousedown touchstart', config.item, function(event) {\n var details = drag.prepare(event);\n if (details.start) {\n startDrag(event, details);\n }\n });\n\n $(config.list).on('keydown', config.item, function(event) {\n itemMoving = $(event.currentTarget).closest(config.itemInPage);\n originalOrder = getCurrentOrder();\n itemMovedByKeyboard(event, itemMoving);\n var newOrder = getCurrentOrder();\n if (!arrayEquals(originalOrder, newOrder)) {\n // Order has changed, call the callback.\n config.reorderDone(itemMoving.closest(config.list), itemMoving, newOrder);\n }\n });\n\n // Make the items tabbable.\n $(config.itemInPage).attr('tabindex', '0');\n };\n});\n"],"file":"drag_reorder.min.js"} \ No newline at end of file diff --git a/question/type/ordering/amd/build/reorder.min.js b/question/type/ordering/amd/build/reorder.min.js index 1dd41656d5f..c9539a7d642 100644 --- a/question/type/ordering/amd/build/reorder.min.js +++ b/question/type/ordering/amd/build/reorder.min.js @@ -1 +1,2 @@ -define(["jquery","qtype_ordering/drag_reorder"],function(a,b){return{init:function(c,d){new b({list:"ul#"+c,item:"li.sortableitem",proxyHtml:'
  • %%ITEM_HTML%%
',itemMovingClass:"current-drop",idGetter:function(b){return a(b).attr("id")},nameGetter:function(b){return a(b).text},reorderStart:function(){},reorderEnd:function(){},reorderDone:function(b,c,e){a("input#"+d)[0].value=e.join(",")}})}}}); \ No newline at end of file +define ("qtype_ordering/reorder",["jquery","qtype_ordering/drag_reorder"],function(a,b){return{init:function init(c,d){new b({list:"ul#"+c,item:"li.sortableitem",proxyHtml:"
  • %%ITEM_HTML%%
",itemMovingClass:"current-drop",idGetter:function idGetter(b){return a(b).attr("id")},nameGetter:function nameGetter(b){return a(b).text},reorderStart:function reorderStart(){},reorderEnd:function reorderEnd(){},reorderDone:function reorderDone(b,c,e){a("input#"+d)[0].value=e.join(",")}})}}}); +//# sourceMappingURL=reorder.min.js.map diff --git a/question/type/ordering/amd/build/reorder.min.js.map b/question/type/ordering/amd/build/reorder.min.js.map new file mode 100644 index 00000000000..162006f6cb4 --- /dev/null +++ b/question/type/ordering/amd/build/reorder.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/reorder.js"],"names":["define","$","dragReorder","init","sortableid","responseid","list","item","proxyHtml","itemMovingClass","idGetter","attr","nameGetter","text","reorderStart","reorderEnd","reorderDone","newOrder","value","join"],"mappings":"AAAAA,OAAM,0BAAC,CAAC,QAAD,CAAW,6BAAX,CAAD,CAA4C,SAASC,CAAT,CAAYC,CAAZ,CAAyB,CACvE,MAAO,CAOHC,IAAI,CAAE,cAAUC,CAAV,CAAsBC,CAAtB,CAAkC,CACpC,GAAIH,CAAAA,CAAJ,CAAgB,CACZI,IAAI,CAAE,MAAQF,CADF,CAEZG,IAAI,CAAE,iBAFM,CAGZC,SAAS,sJAHG,CAMZC,eAAe,CAAE,cANL,CAOZC,QAAQ,CAAE,kBAAUH,CAAV,CAAgB,CAAE,MAAON,CAAAA,CAAC,CAACM,CAAD,CAAD,CAAQI,IAAR,CAAa,IAAb,CAAqB,CAP5C,CAQZC,UAAU,CAAE,oBAAUL,CAAV,CAAgB,CAAE,MAAON,CAAAA,CAAC,CAACM,CAAD,CAAD,CAAQM,IAAO,CARxC,CASZC,YAAY,CAAE,uBAAW,CAAE,CATf,CAUZC,UAAU,CAAE,qBAAW,CAAE,CAVb,CAWZC,WAAW,CAAE,qBAASV,CAAT,CAAeC,CAAf,CAAqBU,CAArB,CAA+B,CACxChB,CAAC,CAAC,SAAWI,CAAZ,CAAD,CAAyB,CAAzB,EAA4Ba,KAA5B,CAAoCD,CAAQ,CAACE,IAAT,CAAc,GAAd,CACvC,CAbW,CAAhB,CAeH,CAvBE,CAyBV,CA1BK,CAAN","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: '
' +\n '
  • ' +\n '%%ITEM_HTML%%
',\n itemMovingClass: \"current-drop\",\n idGetter: function (item) { return $(item).attr('id'); },\n nameGetter: function (item) { return $(item).text; },\n reorderStart: function() {},\n reorderEnd: function() {},\n reorderDone: function(list, item, newOrder) {\n $('input#' + responseid)[0].value = newOrder.join(',');\n }\n });\n }\n };\n});\n"],"file":"reorder.min.js"} \ No newline at end of file diff --git a/question/type/ordering/amd/src/drag_reorder.js b/question/type/ordering/amd/src/drag_reorder.js index 1612e8d56ab..cb3116015d7 100644 --- a/question/type/ordering/amd/src/drag_reorder.js +++ b/question/type/ordering/amd/src/drag_reorder.js @@ -109,9 +109,12 @@ define([ originalOrder = null, // Array of ids. itemDragging = null, // Item being moved by dragging (jQuery object). itemMoving = null, // Item being moved using the accessible modal (jQuery object). - proxy = null; // Drag proxy (jQuery object). + proxy = null, // Drag proxy (jQuery object). + orderList = null; // Order list (jQuery object). var startDrag = function(event, details) { + orderList = $(config.list); + dragStart = { time: new Date().getTime(), x: details.x, @@ -126,7 +129,8 @@ define([ originalOrder = getCurrentOrder(); proxy = $(config.proxyHtml.replace('%%ITEM_HTML%%', itemDragging.html()) - .replace('%%ITEM_CLASS_NAME%%', itemDragging.attr('class'))); + .replace('%%ITEM_CLASS_NAME%%', itemDragging.attr('class')) + .replace('%%LIST_CLASS_NAME%%', orderList.attr('class'))); $(document.body).append(proxy); proxy.css('position', 'absolute'); diff --git a/question/type/ordering/amd/src/reorder.js b/question/type/ordering/amd/src/reorder.js index 54faf685f3b..1066bb8e289 100644 --- a/question/type/ordering/amd/src/reorder.js +++ b/question/type/ordering/amd/src/reorder.js @@ -11,7 +11,7 @@ define(['jquery', 'qtype_ordering/drag_reorder'], function($, dragReorder) { list: 'ul#' + sortableid, item: 'li.sortableitem', proxyHtml: '
' + - '
  • ' + + '
    • ' + '%%ITEM_HTML%%
', itemMovingClass: "current-drop", idGetter: function (item) { return $(item).attr('id'); }, diff --git a/question/type/ordering/styles.css b/question/type/ordering/styles.css index 7ee5fc23300..342d3720263 100644 --- a/question/type/ordering/styles.css +++ b/question/type/ordering/styles.css @@ -34,6 +34,14 @@ box-shadow: 0 0 5px 5px rgba(255, 255, 150, 1); } +.que.ordering .sortablelist.numbering123 li, +.que.ordering .sortablelist.numberingabc li, +.que.ordering .sortablelist.numberingABCD li, +.que.ordering .sortablelist.numberingiii li, +.que.ordering .sortablelist.numberingIIII li { + margin-left: 26px; /* The margin is needed for the list-style-type in numberingxxx classes */ +} + .que.ordering .sortablelist.numberingnone li { list-style-type : none; margin-left: 0px; @@ -74,6 +82,8 @@ } .que.ordering.dragproxy .sortablelist li { margin: 0; + padding: 6px 0 6px 12px; + width: 100%; } .que.ordering.dragproxy .sortablelist li.horizontal { float: none;