diff --git a/common/static/js/capa/drag_and_drop/config_parser.js b/common/static/js/capa/drag_and_drop/config_parser.js index b154a81826..536430101d 100644 --- a/common/static/js/capa/drag_and_drop/config_parser.js +++ b/common/static/js/capa/drag_and_drop/config_parser.js @@ -163,10 +163,15 @@ define(['logme'], function (logme) { if (!attrIsString(obj, 'icon')) { return false; } + if (!attrIsString(obj, 'label')) { return false; } + if (!attrIsBoolean(obj, 'can_reuse', false)) { + return false; + } + state.config.draggables.push(obj); return true; @@ -197,7 +202,11 @@ define(['logme'], function (logme) { } function attrIsString(obj, attr) { - if (typeof obj[attr] !== 'string') { + if (obj.hasOwnProperty(attr) === false) { + logme('ERROR: Attribute "obj.' + attr + '" is not present.'); + + return false; + } else if (typeof obj[attr] !== 'string') { logme('ERROR: Attribute "obj.' + attr + '" is not a string.'); return false; @@ -209,6 +218,12 @@ define(['logme'], function (logme) { function attrIsInteger(obj, attr) { var tempInt; + if (obj.hasOwnProperty(attr) === false) { + logme('ERROR: Attribute "obj.' + attr + '" is not present.'); + + return false; + } + tempInt = parseInt(obj[attr], 10); if (isFinite(tempInt) === false) { @@ -221,6 +236,34 @@ define(['logme'], function (logme) { return true; } + + function attrIsBoolean(obj, attr, defaultVal) { + if (obj.hasOwnProperty(attr) === false) { + if (defaultVal === undefined) { + logme('ERROR: Attribute "obj.' + attr + '" is not present.'); + + return false; + } else { + obj[attr] = defaultVal; + + return true; + } + } + + if (obj[attr] === '') { + obj[attr] = defaultVal; + } else if ((obj[attr] === 'false') || (obj[attr] === false)) { + obj[attr] = false; + } else if ((obj[attr] === 'true') || (obj[attr] === true)) { + obj[attr] = true; + } else { + logme('ERROR: Attribute "obj.' + attr + '" is not a boolean.'); + + return false; + } + + return true; + } }); // End of wrapper for RequireJS. As you can see, we are passing diff --git a/common/static/js/capa/drag_and_drop/draggables.js b/common/static/js/capa/drag_and_drop/draggables.js index a78d336879..add445ebb0 100644 --- a/common/static/js/capa/drag_and_drop/draggables.js +++ b/common/static/js/capa/drag_and_drop/draggables.js @@ -195,6 +195,13 @@ define(['logme', 'update_input'], function (logme, updateInput) { var draggableObj; draggableObj = { + 'id': obj.id, + + 'isReusable': obj.can_reuse, + + 'x': -1, + 'y': -1, + 'zIndex': objIndex, 'oldZIndex': objIndex, 'labelEl': null, @@ -373,12 +380,15 @@ define(['logme', 'update_input'], function (logme, updateInput) { 'top', 50 - draggableObj.iconHeightSmall * 0.5 ); + + draggableObj.hasLoaded = true; } else { // If no icon and no label, don't create a draggable. return; } } + // Attach events to "iconEl". draggableObj.iconEl.mousedown(function (event) { draggableObj.mouseDown.call(draggableObj, event); }); @@ -389,6 +399,7 @@ define(['logme', 'update_input'], function (logme, updateInput) { draggableObj.mouseMove.call(draggableObj, event); }); + // Attach events to "containerEl". draggableObj.containerEl.mousedown(function (event) { draggableObj.mouseDown.call(draggableObj, event); }); @@ -399,16 +410,7 @@ define(['logme', 'update_input'], function (logme, updateInput) { draggableObj.mouseMove.call(draggableObj, event); }); - draggableObj.id = obj.id; - draggableObj.x = -1; - draggableObj.y = -1; - state.numDraggablesInSlider += 1; - - if (obj.icon.length === 0) { - draggableObj.hasLoaded = true; - } - state.draggables.push(draggableObj); } diff --git a/common/static/js/capa/drag_and_drop/main.js b/common/static/js/capa/drag_and_drop/main.js index 900ea34e15..7eb4f5101e 100644 --- a/common/static/js/capa/drag_and_drop/main.js +++ b/common/static/js/capa/drag_and_drop/main.js @@ -70,6 +70,10 @@ define( if (updateInput.check(state) === false) { updateInput.update(state); } + + setTimeout(function () { + logme('state.draggables', state.draggables); + }, 500); }()); } });