diff --git a/common/static/images/arrow-left.png b/common/static/images/arrow-left.png new file mode 100644 index 0000000000..94ed6404aa Binary files /dev/null and b/common/static/images/arrow-left.png differ diff --git a/common/static/images/arrow-right.png b/common/static/images/arrow-right.png new file mode 100644 index 0000000000..333796a5f3 Binary files /dev/null and b/common/static/images/arrow-right.png differ 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 7c5e5ded73..6b4c2939f5 100644 --- a/common/static/js/capa/drag_and_drop/config_parser.js +++ b/common/static/js/capa/drag_and_drop/config_parser.js @@ -13,7 +13,7 @@ define(['logme'], function (logme) { returnStatus = true; state.config = { - 'imageDir': '/static/' + imageDir + '/images/', + 'imageDir': '/static/' + imageDir + '/images', 'draggable': [], 'target': '' }; diff --git a/common/static/js/capa/drag_and_drop/container.js b/common/static/js/capa/drag_and_drop/container.js index d9e7f51fc8..7fa922ba43 100644 --- a/common/static/js/capa/drag_and_drop/container.js +++ b/common/static/js/capa/drag_and_drop/container.js @@ -8,7 +8,17 @@ define(['logme'], function (logme) { return Container; function Container(state) { + state.containerEl = $( + '
' + ); + $('#inputtype_' + state.problemId).before(state.containerEl); } }); diff --git a/common/static/js/capa/drag_and_drop/draggables.js b/common/static/js/capa/drag_and_drop/draggables.js index c291422fee..daf9c0ee02 100644 --- a/common/static/js/capa/drag_and_drop/draggables.js +++ b/common/static/js/capa/drag_and_drop/draggables.js @@ -4,11 +4,42 @@ // See https://edx-wiki.atlassian.net/wiki/display/LMS/Integration+of+Require+JS+into+the+system (function (requirejs, require, define) { -define([], function () { +define(['logme'], function (logme) { return Draggables; function Draggables(state) { - state.draggables = 1; + (function (i) { + while (i < state.config.draggable.length) { + processDraggable(state.config.draggable[i]); + i += 1; + } + }(0)); + + function processDraggable(obj) { + var draggableContainerEl; + + logme(obj); + + draggableContainerEl = $( + '
' + ); + + if (obj.icon.length > 0) { + draggableContainerEl.append( + $('') + ); + } + + draggableContainerEl.appendTo(state.sliderEl); + } + } }); diff --git a/common/static/js/capa/drag_and_drop/main.js b/common/static/js/capa/drag_and_drop/main.js index 2745374950..2d4fa07cd0 100644 --- a/common/static/js/capa/drag_and_drop/main.js +++ b/common/static/js/capa/drag_and_drop/main.js @@ -5,8 +5,8 @@ (function (requirejs, require, define) { define( - ['logme', 'state', 'config_parser', 'target', 'draggables'], - function (logme, State, configParser, Target, Draggables) { + ['logme', 'state', 'config_parser', 'container', 'target', 'scroller', 'draggables'], + function (logme, State, configParser, Container, Target, Scroller, Draggables) { return Main; function Main() { @@ -17,6 +17,14 @@ define( function processProblem(index, value) { var problemId, imageDir, config, state; + if ($(value).attr('data-problem-processed') === 'true') { + // This problem was already processed by us before, so we will + // skip it. + + return; + } + $(value).attr('data-problem-processed', 'true'); + problemId = $(value).attr('data-plain-id'); if (typeof problemId !== 'string') { logme('ERROR: Could not find the ID of the problem DOM element.'); @@ -24,7 +32,7 @@ define( return; } - imageDir = $(value).attr('data-plain-id'); + imageDir = $(value).attr('data-course-folder'); if (typeof imageDir !== 'string') { logme('ERROR: Could not find the name of the image directory.'); @@ -50,7 +58,7 @@ define( Container(state); Target(state); - // Scroller(state); + Scroller(state); Draggables(state); logme(state); diff --git a/common/static/js/capa/drag_and_drop/scroller.js b/common/static/js/capa/drag_and_drop/scroller.js new file mode 100644 index 0000000000..451d15907c --- /dev/null +++ b/common/static/js/capa/drag_and_drop/scroller.js @@ -0,0 +1,99 @@ +// Wrapper for RequireJS. It will make the standard requirejs(), require(), and +// define() functions from Require JS available inside the anonymous function. +// +// See https://edx-wiki.atlassian.net/wiki/display/LMS/Integration+of+Require+JS+into+the+system +(function (requirejs, require, define) { + +define(['logme'], function (logme) { + return Scroller; + + function Scroller(state) { + var parentEl, moveLeftEl, showEl, moveRightEL, + moveRightEl_leftMargin; + + parentEl = $( + '
' + ); + + moveLeftEl = $( + '
' + ); + moveLeftEl.appendTo(parentEl); + + moveLeftEl.click(function () { + state.showElLeftMargin -= 100; + state.sliderEl.animate({ + 'margin-left': state.showElLeftMargin + 'px' + }); + }); + + showEl = $( + '
' + ); + showEl.appendTo(parentEl); + + state.showElLeftMargin = 0; + + state.sliderEl = $( + '
' + ); + state.sliderEl.appendTo(showEl); + + moveRightEl = $( + '
' + ); + moveRightEl.appendTo(parentEl); + + moveRightEl.click(function () { + state.showElLeftMargin += 100; + state.sliderEl.animate({ + 'margin-left': state.showElLeftMargin + 'px' + }); + }); + + parentEl.appendTo(state.containerEl); + } +}); + +// End of wrapper for RequireJS. As you can see, we are passing +// namespaced Require JS variables to an anonymous function. Within +// it, you can use the standard requirejs(), require(), and define() +// functions as if they were in the global namespace. +}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) diff --git a/common/static/js/capa/drag_and_drop/target.js b/common/static/js/capa/drag_and_drop/target.js index eaf4ffa731..486a6264e7 100644 --- a/common/static/js/capa/drag_and_drop/target.js +++ b/common/static/js/capa/drag_and_drop/target.js @@ -4,11 +4,50 @@ // See https://edx-wiki.atlassian.net/wiki/display/LMS/Integration+of+Require+JS+into+the+system (function (requirejs, require, define) { -define([], function () { +define(['logme'], function (logme) { return Target; function Target(state) { - state.target = 1; + var targetImgSrc, targetElContainer, mouseMoveDiv; + + targetImgSrc = state.config.imageDir + '/' + state.config.target; + + targetElContainer = $( + '
' + ); + + state.targetEl = $( + '' + ); + state.targetEl.appendTo(targetElContainer); + + state.targetEl.mousemove( + function (event) { + mouseMoveDiv.html( + '[' + event.offsetX + ', ' + event.offsetY + ']' + ); + } + ); + + mouseMoveDiv = $( + '
[0, 0]
' + ); + mouseMoveDiv.appendTo(targetElContainer); + + targetElContainer.appendTo(state.containerEl); } }); diff --git a/rakefile b/rakefile index 53d7381dd7..fa0293b900 100644 --- a/rakefile +++ b/rakefile @@ -53,7 +53,7 @@ default_options = { task :predjango do sh("find . -type f -name *.pyc -delete") - sh('pip install -q --upgrade --no-deps -r local-requirements.txt') + # sh('pip install -q --upgrade --no-deps -r local-requirements.txt') end task :clean_test_files do