diff --git a/common/static/js/capa/drag_and_drop/draggables.js b/common/static/js/capa/drag_and_drop/draggables.js index 72d424c7af..87081a78f8 100644 --- a/common/static/js/capa/drag_and_drop/draggables.js +++ b/common/static/js/capa/drag_and_drop/draggables.js @@ -63,6 +63,8 @@ define(['logme', 'update_input'], function (logme, updateInput) { var draggableObj, obj; draggableObj = { + 'uniqueId': /* this.uniqueId */ this.state.getUniqueId(), // Is newly set. + 'originalConfigObj': this.originalConfigObj, 'stateDraggablesIndex': /* this.stateDraggablesIndex */ null, // Will be set. @@ -379,6 +381,8 @@ define(['logme', 'update_input'], function (logme, updateInput) { var draggableObj; draggableObj = { + 'uniqueId': state.getUniqueId(), + 'originalConfigObj': obj, 'stateDraggablesIndex': null, @@ -768,7 +772,7 @@ define(['logme', 'update_input'], function (logme, updateInput) { if ( (this.state.config.onePerTarget === true) && (target.draggableList.length === 1) && - (target.draggableList[0].id !== this.id) + (target.draggableList[0].uniqueId !== this.uniqueId) ) { continue; } diff --git a/common/static/js/capa/drag_and_drop/state.js b/common/static/js/capa/drag_and_drop/state.js index d99b90872f..d0ea6b65ef 100644 --- a/common/static/js/capa/drag_and_drop/state.js +++ b/common/static/js/capa/drag_and_drop/state.js @@ -26,9 +26,33 @@ define([], function () { 'targets': [], - 'updateArrowOpacity': null + 'updateArrowOpacity': null, + + 'uniqueId': 0, + 'salt': makeSalt(), + + 'getUniqueId': getUniqueId }; } + + function getUniqueId() { + this.uniqueId += 1; + + return this.salt + '_' + this.uniqueId.toFixed(0); + } + + function makeSalt() { + var text, possible, i; + + text = ''; + possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + + for(i = 0; i < 5; i += 1) { + text += possible.charAt(Math.floor(Math.random() * possible.length)); + } + + return text; + } }); // End of wrapper for RequireJS. As you can see, we are passing diff --git a/common/static/js/capa/drag_and_drop/targets.js b/common/static/js/capa/drag_and_drop/targets.js index 2d1c8b8326..e56020aac6 100644 --- a/common/static/js/capa/drag_and_drop/targets.js +++ b/common/static/js/capa/drag_and_drop/targets.js @@ -15,7 +15,7 @@ define(['logme'], function (logme) { c1 += 1; } }(0)); - } // function Targets(state) { + } function processTarget(state, obj) { var targetEl, borderCss, numTextEl, targetObj; @@ -36,7 +36,6 @@ define(['logme'], function (logme) { 'left: ' + obj.x + 'px; ' + borderCss + '" ' + - 'data-target-id="' + obj.id + '" ' + '>' ); targetEl.appendTo(state.baseImageEl.parent());