Fix matching draggable question

pull/4020/head
Angel Fernando Quiroz Campos 4 years ago
parent 01ec9c83be
commit 4b2a244e63
  1. 20
      assets/css/scss/_exercise.scss
  2. 3
      assets/js/exercise.js
  3. 22
      public/main/inc/lib/exercise.lib.php
  4. 112
      public/main/template/default/exercise/submit.js.html.twig

@ -154,4 +154,24 @@
} }
} }
} }
&.type-19 {
@apply mb-4;
.drag_question {
@apply relative;
.window {
@apply border rounded-md relative;
&.window_left_question {
@apply text-right p-3 pr-5;
}
&.window_right_question {
@apply p-3 pl-5;
}
}
}
}
} }

@ -7,4 +7,5 @@ import '../../public/main/inc/lib/javascript/epiclock/javascript/jquery.dateform
import '../../public/main/inc/lib/javascript/epiclock/javascript/jquery.epiclock.js'; import '../../public/main/inc/lib/javascript/epiclock/javascript/jquery.epiclock.js';
import '../../public/main/inc/lib/javascript/epiclock/renderers/minute/epiclock.minute.js'; import '../../public/main/inc/lib/javascript/epiclock/renderers/minute/epiclock.minute.js';
import './annotation' import './annotation'
import '../../public/main/inc/lib/javascript/hotspot/js/hotspot.js'; import '../../public/main/inc/lib/javascript/hotspot/js/hotspot.js';
import '../../public/main/inc/lib/javascript/d3/jquery.xcolor.js';

@ -1302,18 +1302,16 @@ HTML;
$s .= " $s .= "
<script> <script>
$(function() { $(function() {
$(window).on('load', function() { MatchingDraggable.instances['$questionId'].connect({
jsPlumb.connect({ source: 'window_$windowId',
source: 'window_$windowId', target: 'window_{$questionId}_{$selectedIndex}_answer',
target: 'window_{$questionId}_{$selectedIndex}_answer', endpoint: ['Dot', {radius: 12}],
endpoint: ['Blank', {radius: 15}], anchors: ['RightMiddle', 'LeftMiddle'],
anchors: ['RightMiddle', 'LeftMiddle'], paintStyle: {stroke: '#8A8888', strokeWidth: 8},
paintStyle: {strokeStyle: '#8A8888', lineWidth: 8}, connector: [
connector: [ MatchingDraggable.connectorType,
MatchingDraggable.connectorType, {curvines: MatchingDraggable.curviness}
{curvines: MatchingDraggable.curviness} ]
]
});
}); });
}); });
</script> </script>

@ -87,7 +87,12 @@ var MatchingDraggable = {
curviness: 0, curviness: 0,
connectorType: 'Straight', connectorType: 'Straight',
initialized: false, initialized: false,
instances: {},
init: function (questionId) { init: function (questionId) {
var instance = jsPlumb.getInstance();
MatchingDraggable.instances[questionId] = instance;
var windowQuestionSelector = '.window' + questionId + '_question', var windowQuestionSelector = '.window' + questionId + '_question',
countConnections = $(windowQuestionSelector).length, countConnections = $(windowQuestionSelector).length,
colorArray = [], colorArray = [],
@ -101,25 +106,17 @@ var MatchingDraggable = {
colorArrayDestination = $.xcolor.analogous("#51a351", 10); colorArrayDestination = $.xcolor.analogous("#51a351", 10);
} }
jsPlumb.importDefaults({ var scope = questionId + "_scope";
DragOptions: {cursor: 'pointer', zIndex: 2000},
PaintStyle: {strokeStyle: '#000'},
EndpointStyle: {strokeStyle: '#316b31'},
Endpoint: 'Rectangle',
Anchors: ['TopCenter', 'TopCenter']
});
var exampleDropOptions = { var exampleDropOptions = {
tolerance: 'touch', tolerance: 'touch'
hoverClass: 'dropHover',
activeClass: 'dragActive'
}; };
var destinationEndPoint = { var destinationEndPoint = {
endpoint: ["Dot", {radius: 15}], endpoint: ["Dot", {radius: 15}],
paintStyle: {fillStyle: MatchingDraggable.colorDestination}, paintStyle: {fill: MatchingDraggable.colorDestination},
isSource: false, isSource: false,
connectorStyle: {strokeStyle: MatchingDraggable.colorDestination, lineWidth: 8}, connectorStyle: {stroke: MatchingDraggable.colorDestination, strokeWidth: 8},
connector: [ connector: [
MatchingDraggable.connectorType, MatchingDraggable.connectorType,
{curviness: MatchingDraggable.curviness} {curviness: MatchingDraggable.curviness}
@ -127,9 +124,10 @@ var MatchingDraggable = {
maxConnections: 1000, maxConnections: 1000,
isTarget: true, isTarget: true,
dropOptions: exampleDropOptions, dropOptions: exampleDropOptions,
scope: scope,
beforeDrop: function (params) { beforeDrop: function (params) {
jsPlumb.select({source: params.sourceId}).each(function (connection) { instance.select({source: params.sourceId}).each(function (connection) {
jsPlumb.detach(connection); instance.detach(connection);
}); });
var selectId = params.sourceId + "_select"; var selectId = params.sourceId + "_select";
@ -146,65 +144,53 @@ var MatchingDraggable = {
} }
}; };
var count = 0; var sourceEndPoint = {
var sourceDestinationArray = []; endpoint: [
"Dot",
{radius: 15}
],
paintStyle: {
fill: MatchingDraggable.colorDestination
},
isSource: true,
connectorStyle: {
stroke: "#8a8888",
strokeWidth: 8
},
connector: [
MatchingDraggable.connectorType,
{curviness: MatchingDraggable.curviness}
],
maxConnections: 1,
isTarget: false,
dropOptions: exampleDropOptions,
scope: scope
};
$(windowQuestionSelector).each(function (index) { $(windowQuestionSelector).each(function (index) {
var windowId = $(this).attr("id"); var windowId = $(this).attr("id");
var scope = windowId + "scope"; sourceEndPoint.paintStyle.fill = colorArray[index].getHex();
var destinationColor = colorArray[count].getHex();
var sourceEndPoint = {
endpoint: [
"Dot",
{radius: 15}
],
paintStyle: {
fillStyle: destinationColor
},
isSource: true,
connectorStyle: {
strokeStyle: "#8a8888",
lineWidth: 8
},
connector: [
MatchingDraggable.connectorType,
{curviness: MatchingDraggable.curviness}
],
maxConnections: 1,
isTarget: false,
dropOptions: exampleDropOptions,
scope: scope
};
sourceDestinationArray[count + 1] = sourceEndPoint;
count++;
jsPlumb.addEndpoint( instance.addEndpoint(
windowId, windowId,
{ {
anchor: ['RightMiddle', 'RightMiddle', 'RightMiddle', 'RightMiddle'] anchor: ['RightMiddle', 'RightMiddle', 'RightMiddle', 'RightMiddle']
}, },
sourceEndPoint sourceEndPoint
); );
});
var destinationCount = 0; $(windowQuestionSelector).each(function (index) {
var windowDestinationId = $(this).attr("id");
$(windowQuestionSelector).each(function (index) { destinationEndPoint.paintStyle.fill = colorArrayDestination[index].getHex();
var windowDestinationId = $(this).attr("id");
destinationEndPoint.scope = scope; instance.addEndpoint(
destinationEndPoint.paintStyle.fillStyle = colorArrayDestination[destinationCount].getHex(); windowDestinationId + "_answer",
destinationCount++; {
anchors: ['LeftMiddle', 'LeftMiddle', 'LeftMiddle', 'LeftMiddle']
jsPlumb.addEndpoint( },
windowDestinationId + "_answer", destinationEndPoint
{ );
anchors: ['LeftMiddle', 'LeftMiddle', 'LeftMiddle', 'LeftMiddle']
},
destinationEndPoint
);
});
}); });
MatchingDraggable.attachBehaviour(); MatchingDraggable.attachBehaviour();
@ -218,8 +204,6 @@ var MatchingDraggable = {
jsPlumb.ready(function () { jsPlumb.ready(function () {
if ($(".drag_question").length > 0) { if ($(".drag_question").length > 0) {
MatchingDraggable.init();
$(document).scroll(function () { $(document).scroll(function () {
jsPlumb.repaintEverything(); jsPlumb.repaintEverything();
}); });

Loading…
Cancel
Save