diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/utils.py b/cms/djangoapps/contentstore/rest_api/v2/views/utils.py index 8a6fe461fdb7..740608c6ae77 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/utils.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/utils.py @@ -5,7 +5,7 @@ from rest_framework.generics import GenericAPIView from rest_framework import permissions from cms.djangoapps.contentstore.rest_api.v2.serializers.utils import NumericalInputValidationRequestSerializer -from xmodule.capa.inputtypes import preview_numeric_input +from xblocks_contrib.problem.capa.inputtypes import preview_numeric_input class NumericalInputValidationView(GenericAPIView): diff --git a/cms/envs/common.py b/cms/envs/common.py index f4f6fd8b9c9d..fc6556e5efd2 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -289,7 +289,6 @@ MAKO_TEMPLATE_DIRS_BASE.insert(3, COMMON_ROOT / 'static') MAKO_TEMPLATE_DIRS_BASE.append(CMS_ROOT / 'djangoapps' / 'pipeline_js' / 'templates') -MAKO_TEMPLATE_DIRS_BASE.append(XMODULE_ROOT / 'capa' / 'templates') def make_lms_template_path(settings): diff --git a/common/djangoapps/edxmako/services.py b/common/djangoapps/edxmako/services.py index d300e32cf75a..f3fb5bfe7ce1 100644 --- a/common/djangoapps/edxmako/services.py +++ b/common/djangoapps/edxmako/services.py @@ -54,7 +54,6 @@ def render_lms_template(self, template_file, dictionary): Templates which are in these dirs will only work with this function: edx-platform/lms/templates/ - edx-platform/xmodule/capa/templates/ openedx/features/course_experience/templates """ return render_to_string(template_file, dictionary, namespace=lms_mako_namespace) diff --git a/common/static/applets/capa/Protex.jar b/common/static/applets/capa/Protex.jar deleted file mode 100644 index 2c6a819ec5d1..000000000000 Binary files a/common/static/applets/capa/Protex.jar and /dev/null differ diff --git a/common/static/applets/capa/genex.jar b/common/static/applets/capa/genex.jar deleted file mode 100644 index 75f784b59245..000000000000 Binary files a/common/static/applets/capa/genex.jar and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX2E0-3D-balls.png b/common/static/images/capa/vsepr/AX2E0-3D-balls.png deleted file mode 100644 index 7595cf2a6c96..000000000000 Binary files a/common/static/images/capa/vsepr/AX2E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX2E1-3D-balls.png b/common/static/images/capa/vsepr/AX2E1-3D-balls.png deleted file mode 100644 index c8816feb114f..000000000000 Binary files a/common/static/images/capa/vsepr/AX2E1-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX2E2-3D-balls.png b/common/static/images/capa/vsepr/AX2E2-3D-balls.png deleted file mode 100644 index 00faa7e6beef..000000000000 Binary files a/common/static/images/capa/vsepr/AX2E2-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX2E3-3D-balls.png b/common/static/images/capa/vsepr/AX2E3-3D-balls.png deleted file mode 100644 index 4fb7022f8c03..000000000000 Binary files a/common/static/images/capa/vsepr/AX2E3-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX3E0-3D-balls.png b/common/static/images/capa/vsepr/AX3E0-3D-balls.png deleted file mode 100644 index eeff5b22a244..000000000000 Binary files a/common/static/images/capa/vsepr/AX3E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX3E1-3D-balls.png b/common/static/images/capa/vsepr/AX3E1-3D-balls.png deleted file mode 100644 index e5386bf0d79a..000000000000 Binary files a/common/static/images/capa/vsepr/AX3E1-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX3E2-3D-balls.png b/common/static/images/capa/vsepr/AX3E2-3D-balls.png deleted file mode 100644 index 185abaa4ea61..000000000000 Binary files a/common/static/images/capa/vsepr/AX3E2-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX4E0-3D-balls.png b/common/static/images/capa/vsepr/AX4E0-3D-balls.png deleted file mode 100644 index f690ad1f5a09..000000000000 Binary files a/common/static/images/capa/vsepr/AX4E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX4E1-3D-balls.png b/common/static/images/capa/vsepr/AX4E1-3D-balls.png deleted file mode 100644 index 1e940f7576c3..000000000000 Binary files a/common/static/images/capa/vsepr/AX4E1-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX4E2-3D-balls.png b/common/static/images/capa/vsepr/AX4E2-3D-balls.png deleted file mode 100644 index ec74eb90fc20..000000000000 Binary files a/common/static/images/capa/vsepr/AX4E2-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX5E1-3D-balls.png b/common/static/images/capa/vsepr/AX5E1-3D-balls.png deleted file mode 100644 index dc12dd9f749d..000000000000 Binary files a/common/static/images/capa/vsepr/AX5E1-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX5E2-3D-balls.png b/common/static/images/capa/vsepr/AX5E2-3D-balls.png deleted file mode 100644 index 38755c144de0..000000000000 Binary files a/common/static/images/capa/vsepr/AX5E2-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX6E0-3D-balls.png b/common/static/images/capa/vsepr/AX6E0-3D-balls.png deleted file mode 100644 index 775ffc46b981..000000000000 Binary files a/common/static/images/capa/vsepr/AX6E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX6E1-3D-balls.png b/common/static/images/capa/vsepr/AX6E1-3D-balls.png deleted file mode 100644 index 3e51b877c1b6..000000000000 Binary files a/common/static/images/capa/vsepr/AX6E1-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX7E0-3D-balls.png b/common/static/images/capa/vsepr/AX7E0-3D-balls.png deleted file mode 100644 index 95d7aebffd5f..000000000000 Binary files a/common/static/images/capa/vsepr/AX7E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX8E0-3D-balls.png b/common/static/images/capa/vsepr/AX8E0-3D-balls.png deleted file mode 100644 index 3a24f7794a88..000000000000 Binary files a/common/static/images/capa/vsepr/AX8E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/AX9E0-3D-balls.png b/common/static/images/capa/vsepr/AX9E0-3D-balls.png deleted file mode 100644 index b457f58eb5f0..000000000000 Binary files a/common/static/images/capa/vsepr/AX9E0-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Bent-3D-balls.png b/common/static/images/capa/vsepr/Bent-3D-balls.png deleted file mode 100644 index 71bb9526a89c..000000000000 Binary files a/common/static/images/capa/vsepr/Bent-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Linear-3D-balls.png b/common/static/images/capa/vsepr/Linear-3D-balls.png deleted file mode 100644 index af5f92c7b102..000000000000 Binary files a/common/static/images/capa/vsepr/Linear-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Linear-stick.png b/common/static/images/capa/vsepr/Linear-stick.png deleted file mode 100644 index e1306f9a0d31..000000000000 Binary files a/common/static/images/capa/vsepr/Linear-stick.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Octahedral-3D-balls.png b/common/static/images/capa/vsepr/Octahedral-3D-balls.png deleted file mode 100644 index 0032fe1ed31d..000000000000 Binary files a/common/static/images/capa/vsepr/Octahedral-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Octahedral-stick.png b/common/static/images/capa/vsepr/Octahedral-stick.png deleted file mode 100644 index 3d2b7ca5fd1e..000000000000 Binary files a/common/static/images/capa/vsepr/Octahedral-stick.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Pentagonal-bipyramidal-3D-balls.png b/common/static/images/capa/vsepr/Pentagonal-bipyramidal-3D-balls.png deleted file mode 100644 index 23e02daf25b3..000000000000 Binary files a/common/static/images/capa/vsepr/Pentagonal-bipyramidal-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Pentagonal-planar-3D-balls.png b/common/static/images/capa/vsepr/Pentagonal-planar-3D-balls.png deleted file mode 100644 index 0768ec750463..000000000000 Binary files a/common/static/images/capa/vsepr/Pentagonal-planar-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Pentagonal-pyramidal-3D-balls.png b/common/static/images/capa/vsepr/Pentagonal-pyramidal-3D-balls.png deleted file mode 100644 index 511db1ea16f2..000000000000 Binary files a/common/static/images/capa/vsepr/Pentagonal-pyramidal-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Pyramidal-3D-balls.png b/common/static/images/capa/vsepr/Pyramidal-3D-balls.png deleted file mode 100644 index 0383528d3d59..000000000000 Binary files a/common/static/images/capa/vsepr/Pyramidal-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Seesaw-3D-balls.png b/common/static/images/capa/vsepr/Seesaw-3D-balls.png deleted file mode 100644 index b7665da3b5ef..000000000000 Binary files a/common/static/images/capa/vsepr/Seesaw-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Square-antiprismatic-3D-balls.png b/common/static/images/capa/vsepr/Square-antiprismatic-3D-balls.png deleted file mode 100644 index 675ba88c5c24..000000000000 Binary files a/common/static/images/capa/vsepr/Square-antiprismatic-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Square-planar-3D-balls.png b/common/static/images/capa/vsepr/Square-planar-3D-balls.png deleted file mode 100644 index 6a90a0c361d6..000000000000 Binary files a/common/static/images/capa/vsepr/Square-planar-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/T-shaped-3D-balls.png b/common/static/images/capa/vsepr/T-shaped-3D-balls.png deleted file mode 100644 index b3eaa47f8acc..000000000000 Binary files a/common/static/images/capa/vsepr/T-shaped-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Tetrahedral-3D-balls.png b/common/static/images/capa/vsepr/Tetrahedral-3D-balls.png deleted file mode 100644 index 9ff8731ac0ea..000000000000 Binary files a/common/static/images/capa/vsepr/Tetrahedral-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Tetrahedral-stick.png b/common/static/images/capa/vsepr/Tetrahedral-stick.png deleted file mode 100644 index 09a41164b65d..000000000000 Binary files a/common/static/images/capa/vsepr/Tetrahedral-stick.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Trigonal-3D-balls.png b/common/static/images/capa/vsepr/Trigonal-3D-balls.png deleted file mode 100644 index 20e7c957d879..000000000000 Binary files a/common/static/images/capa/vsepr/Trigonal-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Trigonal-bipyramidal-3D-balls.png b/common/static/images/capa/vsepr/Trigonal-bipyramidal-3D-balls.png deleted file mode 100644 index ab5f0133965e..000000000000 Binary files a/common/static/images/capa/vsepr/Trigonal-bipyramidal-3D-balls.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Trigonal-bipyramidal-stick.png b/common/static/images/capa/vsepr/Trigonal-bipyramidal-stick.png deleted file mode 100644 index 3b36dcd5c66b..000000000000 Binary files a/common/static/images/capa/vsepr/Trigonal-bipyramidal-stick.png and /dev/null differ diff --git a/common/static/images/capa/vsepr/Trigonal-planar-stick.png b/common/static/images/capa/vsepr/Trigonal-planar-stick.png deleted file mode 100644 index f2fd25c56f80..000000000000 Binary files a/common/static/images/capa/vsepr/Trigonal-planar-stick.png and /dev/null differ diff --git a/common/static/js/capa/README b/common/static/js/capa/README deleted file mode 100644 index ca845717fe53..000000000000 --- a/common/static/js/capa/README +++ /dev/null @@ -1 +0,0 @@ -These files really should be in the capa block, but we don't have a way to load js from there at the moment. (TODO) diff --git a/common/static/js/capa/annotationinput.js b/common/static/js/capa/annotationinput.js deleted file mode 100644 index 09adde930c83..000000000000 --- a/common/static/js/capa/annotationinput.js +++ /dev/null @@ -1,98 +0,0 @@ -(function() { - var debug = false; - - var module = { - debug: debug, - inputSelector: '.annotation-input', - tagSelector: '.tag', - tagsSelector: '.tags', - commentSelector: 'textarea.comment', - valueSelector: 'input.value', // stash tag selections and comment here as a JSON string... - - singleSelect: true, - - init: function() { - var that = this; - - if (this.debug) { console.log('annotation input loaded: '); } - - $(this.inputSelector).each(function(index, el) { - if (!$(el).data('listening')) { - $(el).delegate(that.tagSelector, 'click', $.proxy(that.onClickTag, that)); - $(el).delegate(that.commentSelector, 'change', $.proxy(that.onChangeComment, that)); - $(el).data('listening', 'yes'); - } - }); - }, - onChangeComment: function(e) { - var value_el = this.findValueEl(e.target); - var current_value = this.loadValue(value_el); - var target_value = $(e.target).val(); - - current_value.comment = target_value; - this.storeValue(value_el, current_value); - }, - onClickTag: function(e) { - var target_el = e.target, - target_value, target_index; - var value_el, current_value; - - value_el = this.findValueEl(e.target); - current_value = this.loadValue(value_el); - target_value = $(e.target).data('id'); - - if (!$(target_el).hasClass('selected')) { - if (this.singleSelect) { - current_value.options = [target_value]; - } else { - current_value.options.push(target_value); - } - } else { - if (this.singleSelect) { - current_value.options = []; - } else { - target_index = current_value.options.indexOf(target_value); - if (target_index !== -1) { - current_value.options.splice(target_index, 1); - } - } - } - - this.storeValue(value_el, current_value); - - if (this.singleSelect) { - $(target_el).closest(this.tagsSelector) - .find(this.tagSelector) - .not(target_el) - .removeClass('selected'); - } - $(target_el).toggleClass('selected'); - }, - findValueEl: function(target_el) { - var input_el = $(target_el).closest(this.inputSelector); - return $(this.valueSelector, input_el); - }, - loadValue: function(value_el) { - var json = $(value_el).val(); - - var result = JSON.parse(json); - if (result === null) { - result = {}; - } - if (!result.hasOwnProperty('options')) { - result.options = []; - } - if (!result.hasOwnProperty('comment')) { - result.comment = ''; - } - - return result; - }, - storeValue: function(value_el, new_value) { - var json = JSON.stringify(new_value); - $(value_el).val(json); - } - }; - - module.init(); -}).call(this); diff --git a/common/static/js/capa/chemical_equation_preview.js b/common/static/js/capa/chemical_equation_preview.js deleted file mode 100644 index d23d8e51d3f6..000000000000 --- a/common/static/js/capa/chemical_equation_preview.js +++ /dev/null @@ -1,36 +0,0 @@ -(function() { - update = function() { - function create_handler(saved_div) { - return (function(response) { - if (response.error) { - edx.HtmlUtils.setHtml( - saved_div, - edx.HtmlUtils.joinHtml( - edx.HtmlUtils.HTML(""), - response.error, - edx.HtmlUtils.HTML('') - ) - ); - } else { - saved_div.html(edx.HtmlUtils.HTML(response.preview).toString()); - } - }); - } - - prev_id = '#' + this.id + '_preview'; - preview_div = $(prev_id); - - // find the closest parent problems-wrapper and use that url - url = $(this).closest('.problems-wrapper').data('url'); - // grab the input id from the input - input_id = $(this).data('input-id'); - - Problem.inputAjax(url, input_id, 'preview_chemcalc', {formula: this.value}, create_handler(preview_div)); - }; - - inputs = $('.chemicalequationinput input'); - // update on load - inputs.each(update); - // and on every change - inputs.bind('input', update); -}).call(this); diff --git a/common/static/js/capa/choicetextinput.js b/common/static/js/capa/choicetextinput.js deleted file mode 100644 index 3d08c94ba7f2..000000000000 --- a/common/static/js/capa/choicetextinput.js +++ /dev/null @@ -1,73 +0,0 @@ -(function() { - var update = function() { - // Whenever a value changes create a new serialized version of this - // problem's inputs and set the hidden input field's value to equal it. - var parent = $(this).closest('section.choicetextinput'); - // find the closest parent problems-wrapper and use that as the problem - // grab the input id from the input - // real_input is the hidden input field - var $real_input = $('input.choicetextvalue', parent); - var $all_inputs = $('input.ctinput', parent); - var user_inputs = {}; - $($all_inputs).each(function(index, elt) { - var $node = $(elt); - var name = $node.attr('id'); - var val = $node.val(); - var radio_value = $node.attr('value'); - var type = $node.attr('type'); - var is_checked = $node.attr('checked'); - if (type === 'radio' || type === 'checkbox') { - if (is_checked === 'checked' || is_checked === 'true') { - user_inputs[name] = radio_value; - } - } else { - user_inputs[name] = val; - } - }); - var val_string = JSON.stringify(user_inputs); - // this is what gets submitted as the answer, we deserialize it later - $real_input.val(val_string); - }; - - var check_parent = function(event) { - // This looks for the containing choice of a textinput - // and sets it to be checked. - var $elt = $(event.target); - var parent_container = $elt.closest('section[id^="forinput"]'); - var choice = parent_container.find("input[type='checkbox'], input[type='radio']"); - choice.attr('checked', 'checked'); - choice.change(); - // need to check it then trigger the change event - }; - - var imitate_label = function(event) { - // This causes a section to check and uncheck - // a radiobutton/checkbox whenever a user clicks on it - // If the button/checkbox is disabled, nothing happens - var $elt = $(event.target); - var parent_container = $elt.closest('section[id^="forinput"]'); - var choice = parent_container.find("input[type='checkbox'], input[type='radio']"); - if (choice.attr('type') === 'radio') { - choice.attr('checked', 'checked'); - } else { - if (choice.attr('checked')) { - choice.prop('checked', false); - } else { - choice.prop('checked', true); - } - } - choice.change(); - update(); - }; - var $choices = $('.mock_label'); - var $inputs = $('.choicetextinput .ctinput'); - var $text_inputs = $('.choicetextinput .ctinput[type="text"]'); - // update on load - $inputs.each(update); - // and on every change - // This allows text inside of choices to behave as if they were part of - // a label for the choice's button/checkbox - $choices.click(imitate_label); - $inputs.bind('change', update); - $text_inputs.click(check_parent); -}).call(this); diff --git a/common/static/js/capa/design-protein-2d.js b/common/static/js/capa/design-protein-2d.js deleted file mode 100644 index 84a372156e00..000000000000 --- a/common/static/js/capa/design-protein-2d.js +++ /dev/null @@ -1,85 +0,0 @@ -(function() { - var timeout = 1000; - - waitForProtex(); - - function waitForProtex() { - if (typeof protex !== 'undefined' && protex) { - protex.onInjectionDone('protex'); - // eslint-disable-next-line brace-style - } - /* if (typeof(protex) !== "undefined") { - //initializeProtex(); - } */ - else { - setTimeout(function() { waitForProtex(); }, timeout); - } - } - - // NOTE: - // Protex uses three global functions: - // protexSetTargetShape (exported from GWT) - // exported protexCheckAnswer (exported from GWT) - // It calls protexIsReady with a deferred command when it has finished - // initialization and has drawn itself - - function updateProtexField() { - var problem = $('#protex_container').parents('.problem'); - var input_field = problem.find('input[type=hidden]'); - var protex_answer = protexCheckAnswer(); - var value = {protex_answer: protex_answer}; - // console.log(JSON.stringify(value)); - input_field.val(JSON.stringify(value)); - } - - protexIsReady = function() { - // Load target shape - var target_shape = $('#target_shape').val(); - protexSetTargetShape(target_shape); - - // Get answer from protex and store it into the hidden input field - // when Check button is clicked - var $fold_button = $('#fold-button'); - $fold_button.on('click', function() { - var problem = $('#protex_container').parents('.problem'); - var input_field = problem.find('input[type=hidden]'); - var protex_answer = protexCheckAnswer(); - var value = {protex_answer: protex_answer}; - // console.log(JSON.stringify(value)); - input_field.val(JSON.stringify(value)); - }); - updateProtexField(); - }; - - /* function initializeProtex() { - //Check to see if the two exported GWT functions protexSetTargetShape - // and protexCheckAnswer have been appended to global scope -- this - //happens at the end of onModuleLoad() in GWT - if (typeof(protexSetTargetShape) === "function" && - typeof(protexCheckAnswer) === "function") { - - //Load target shape - var target_shape = $('#target_shape').val(); - //protexSetTargetShape(target_shape); - - //Get answer from protex and store it into the hidden input field - //when Check button is clicked - var problem = $('#protex_container').parents('.problem'); - var check_button = problem.find('input.check'); - var input_field = problem.find('input[type=hidden]'); - check_button.on('click', function() { - var protex_answer = protexCheckAnswer(); - var value = {protex_answer: protex_answer}; - input_field.val(JSON.stringify(value)); - }); - - //TO DO: Fix this, it works but is utterly ugly and unreliable - setTimeout(function() { - protexSetTargetShape(target_shape);}, 2000); - - } - else { - setTimeout(function() {initializeProtex(); }, timeout); - } - } */ -}).call(this); diff --git a/common/static/js/capa/drag_and_drop.js b/common/static/js/capa/drag_and_drop.js deleted file mode 100644 index aedf86612f11..000000000000 --- a/common/static/js/capa/drag_and_drop.js +++ /dev/null @@ -1,25 +0,0 @@ -// Wrapper for RequireJS. It will make the standard requirejs(), require(), and -// define() functions from Require JS available inside the anonymous function. -// -// See https://openedx.atlassian.net/wiki/display/PLAT/Integration+of+Require+JS+into+the+system -(function(requirejs, require, define) { -// HACK: this should be removed when it is safe to do so - if (window.baseUrl) { - requirejs.config({baseUrl: baseUrl}); - } - - // The current JS file will be loaded and run each time. It will require a - // single dependency which will be loaded and stored by RequireJS. On - // subsequent runs, RequireJS will return the dependency from memory, rather - // than loading it again from the server. For that reason, it is a good idea to - // keep the current JS file as small as possible, and move everything else into - // RequireJS module dependencies. - require(['js/capa/drag_and_drop/main'], function(Main) { - Main(); - }); - -// 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/base_image.js b/common/static/js/capa/drag_and_drop/base_image.js deleted file mode 100644 index 736d8d343812..000000000000 --- a/common/static/js/capa/drag_and_drop/base_image.js +++ /dev/null @@ -1,45 +0,0 @@ -(function(requirejs, require, define) { - define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { - return BaseImage; - - function BaseImage(state) { - var $baseImageElContainer; - - $baseImageElContainer = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
') - ).toString()); - - state.baseImageEl = $('', { - alt: gettext('Drop target image') - }); - - state.baseImageEl.attr('src', state.config.baseImage); - state.baseImageEl.load(function() { - $baseImageElContainer.css({ - width: this.width, - height: this.height - }); - - state.baseImageEl.appendTo($baseImageElContainer); - $baseImageElContainer.appendTo(state.containerEl); - - state.baseImageEl.mousedown(function(event) { - event.preventDefault(); - }); - - state.baseImageLoaded = true; - }); - state.baseImageEl.error(function() { - var errorMsg = HtmlUtils.joinHtml( - HtmlUtils.HTML(''), - HtmlUtils.HTML('ERROR: Image "'), state.config.baseImage, HtmlUtils.HTML('" was not found!'), - HtmlUtils.HTML('') - ); - console.log('ERROR: Image "' + state.config.baseImage + '" was not found!'); - HtmlUtils.setHtml($baseImageElContainer, errorMsg); - $baseImageElContainer.appendTo(state.containerEl); - }); - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/config_parser.js b/common/static/js/capa/drag_and_drop/config_parser.js deleted file mode 100644 index bbd574b0d33a..000000000000 --- a/common/static/js/capa/drag_and_drop/config_parser.js +++ /dev/null @@ -1,271 +0,0 @@ -(function(requirejs, require, define) { - define([], function() { - return configParser; - - function configParser(state, config) { - state.config = { - draggables: [], - baseImage: '', - targets: [], - onePerTarget: null, // Specified by user. No default. - targetOutline: true, - labelBgColor: '#d6d6d6', - individualTargets: null, // Depends on 'targets'. - foundErrors: false // Whether or not we find errors while processing the config. - }; - - getDraggables(state, config); - getBaseImage(state, config); - getTargets(state, config); - getOnePerTarget(state, config); - getTargetOutline(state, config); - getLabelBgColor(state, config); - - setIndividualTargets(state); - - if (state.config.foundErrors !== false) { - return false; - } - - return true; - } - - function getDraggables(state, config) { - if (config.hasOwnProperty('draggables') === false) { - console.log('ERROR: "config" does not have a property "draggables".'); - state.config.foundErrors = true; - } else if ($.isArray(config.draggables) === true) { - config.draggables.every(function(draggable) { - if (processDraggable(state, draggable) !== true) { - state.config.foundErrors = true; - - // Exit immediately from .every() call. - return false; - } - - // Continue to next .every() call. - return true; - }); - } else { - console.log('ERROR: The type of config.draggables is no supported.'); - state.config.foundErrors = true; - } - } - - function getBaseImage(state, config) { - if (config.hasOwnProperty('base_image') === false) { - console.log('ERROR: "config" does not have a property "base_image".'); - state.config.foundErrors = true; - } else if (typeof config.base_image === 'string') { - state.config.baseImage = config.base_image; - } else { - console.log('ERROR: Property config.base_image is not of type "string".'); - state.config.foundErrors = true; - } - } - - function getTargets(state, config) { - if (config.hasOwnProperty('targets') === false) { - // It is possible that no "targets" were specified. This is not an error. - // In this case the default value of "[]" (empty array) will be used. - // Draggables can be positioned anywhere on the image, and the server will - // get an answer in the form of (x, y) coordinates for each draggable. - } else if ($.isArray(config.targets) === true) { - config.targets.every(function(target) { - if (processTarget(state, target) !== true) { - state.config.foundErrors = true; - - // Exit immediately from .every() call. - return false; - } - - // Continue to next .every() call. - return true; - }); - } else { - console.log('ERROR: Property config.targets is not of a supported type.'); - state.config.foundErrors = true; - } - } - - function getOnePerTarget(state, config) { - if (config.hasOwnProperty('one_per_target') === false) { - console.log('ERROR: "config" does not have a property "one_per_target".'); - state.config.foundErrors = true; - } else if (typeof config.one_per_target === 'string') { - if (config.one_per_target.toLowerCase() === 'true') { - state.config.onePerTarget = true; - } else if (config.one_per_target.toLowerCase() === 'false') { - state.config.onePerTarget = false; - } else { - console.log('ERROR: Property config.one_per_target can either be "true", or "false".'); - state.config.foundErrors = true; - } - } else { - console.log('ERROR: Property config.one_per_target is not of a supported type.'); - state.config.foundErrors = true; - } - } - - function getTargetOutline(state, config) { - // It is possible that no "target_outline" was specified. This is not an error. - // In this case the default value of 'true' (boolean) will be used. - - if (config.hasOwnProperty('target_outline') === true) { - if (typeof config.target_outline === 'string') { - if (config.target_outline.toLowerCase() === 'true') { - state.config.targetOutline = true; - } else if (config.target_outline.toLowerCase() === 'false') { - state.config.targetOutline = false; - } else { - console.log('ERROR: Property config.target_outline can either be "true", or "false".'); - state.config.foundErrors = true; - } - } else { - console.log('ERROR: Property config.target_outline is not of a supported type.'); - state.config.foundErrors = true; - } - } - } - - function getLabelBgColor(state, config) { - // It is possible that no "label_bg_color" was specified. This is not an error. - // In this case the default value of '#d6d6d6' (string) will be used. - - if (config.hasOwnProperty('label_bg_color') === true) { - if (typeof config.label_bg_color === 'string') { - state.config.labelBgColor = config.label_bg_color; - } else { - console.log('ERROR: Property config.label_bg_color is not of a supported type.'); - } - } - } - - function setIndividualTargets(state) { - if (state.config.targets.length === 0) { - state.config.individualTargets = false; - } else { - state.config.individualTargets = true; - } - } - - function processDraggable(state, obj) { - if ( - (attrIsString(obj, 'id') === false) - || (attrIsString(obj, 'icon') === false) - || (attrIsString(obj, 'label') === false) - - || (attrIsBoolean(obj, 'can_reuse', false) === false) - - || (obj.hasOwnProperty('target_fields') === false) - ) { - return false; - } - - // Check that all targets in the 'target_fields' property are proper target objects. - // We will be testing the return value from .every() call (it can be 'true' or 'false'). - if (obj.target_fields.every( - function(targetObj) { - return processTarget(state, targetObj, false); - } - ) === false) { - return false; - } - - state.config.draggables.push(obj); - - return true; - } - - // We need 'pushToState' parameter in order to simply test an object for the fact that it is a - // proper target (without pushing it to the 'state' object). When - // - // pushToState === false - // - // the object being tested is not going to be pushed to 'state'. The function will onyl return - // 'true' or 'false. - function processTarget(state, obj, pushToState) { - if ( - (attrIsString(obj, 'id') === false) - - || (attrIsInteger(obj, 'w') === false) - || (attrIsInteger(obj, 'h') === false) - - || (attrIsInteger(obj, 'x') === false) - || (attrIsInteger(obj, 'y') === false) - ) { - return false; - } - - if (pushToState !== false) { - state.config.targets.push(obj); - } - - return true; - } - - function attrIsString(obj, attr) { - if (obj.hasOwnProperty(attr) === false) { - console.log('ERROR: Attribute "obj.' + attr + '" is not present.'); - - return false; - } else if (typeof obj[attr] !== 'string') { - console.log('ERROR: Attribute "obj.' + attr + '" is not a string.'); - - return false; - } - - return true; - } - - function attrIsInteger(obj, attr) { - var tempInt; - - if (obj.hasOwnProperty(attr) === false) { - console.log('ERROR: Attribute "obj.' + attr + '" is not present.'); - - return false; - } - - tempInt = parseInt(obj[attr], 10); - - if (isFinite(tempInt) === false) { - console.log('ERROR: Attribute "obj.' + attr + '" is not an integer.'); - - return false; - } - - obj[attr] = tempInt; - - return true; - } - - function attrIsBoolean(obj, attr, defaultVal) { - if (obj.hasOwnProperty(attr) === false) { - if (defaultVal === undefined) { - console.log('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 { - console.log('ERROR: Attribute "obj.' + attr + '" is not a boolean.'); - - return false; - } - - return true; - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/container.js b/common/static/js/capa/drag_and_drop/container.js deleted file mode 100644 index 35107a8b0df4..000000000000 --- a/common/static/js/capa/drag_and_drop/container.js +++ /dev/null @@ -1,13 +0,0 @@ -(function(requirejs, require, define) { - define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { - return Container; - - function Container(state) { - state.containerEl = $( - '
' - ); - - $('#inputtype_' + state.problemId).before(HtmlUtils.HTML(state.containerEl).toString()); - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/draggable_events.js b/common/static/js/capa/drag_and_drop/draggable_events.js deleted file mode 100644 index 667cd54fe3ae..000000000000 --- a/common/static/js/capa/drag_and_drop/draggable_events.js +++ /dev/null @@ -1,143 +0,0 @@ -(function(requirejs, require, define) { - define([], function() { - return { - attachMouseEventsTo: function(element) { - var self; - - self = this; - - this[element].mousedown(function(event) { - self.mouseDown(event); - }); - this[element].mouseup(function(event) { - self.mouseUp(event); - }); - this[element].mousemove(function(event) { - self.mouseMove(event); - }); - }, - - mouseDown: function(event) { - if (this.mousePressed === false) { - // So that the browser does not perform a default drag. - // If we don't do this, each drag operation will - // potentially cause the highlghting of the dragged element. - event.preventDefault(); - event.stopPropagation(); - - if (this.numDraggablesOnMe > 0) { - return; - } - - // If this draggable is just being dragged out of the - // container, we must perform some additional tasks. - if (this.inContainer === true) { - if ((this.isReusable === true) && (this.isOriginal === true)) { - this.makeDraggableCopy(function(draggableCopy) { - draggableCopy.mouseDown(event); - }); - - return; - } - - if (this.isOriginal === true) { - this.containerEl.hide(); - this.iconEl.detach(); - } - - if (this.iconImgEl !== null) { - this.iconImgEl.css({ - width: this.iconWidth, - height: this.iconHeight - }); - } - this.iconEl.css({ - 'background-color': this.iconElBGColor, - 'padding-left': this.iconElPadding, - 'padding-right': this.iconElPadding, - border: this.iconElBorder, - width: this.iconWidth, - height: this.iconHeight, - left: event.pageX - this.state.baseImageEl.offset().left - this.iconWidth * 0.5 - this.iconElLeftOffset, - top: event.pageY - this.state.baseImageEl.offset().top - this.iconHeight * 0.5 - }); - this.iconEl.appendTo(this.state.baseImageEl.parent()); - - if (this.labelEl !== null) { - if (this.isOriginal === true) { - this.labelEl.detach(); - } - this.labelEl.css({ - 'background-color': this.state.config.labelBgColor, - 'padding-left': 8, - 'padding-right': 8, - border: '1px solid black', - left: event.pageX - this.state.baseImageEl.offset().left - this.labelWidth * 0.5 - 9, // Account for padding, border. - top: event.pageY - this.state.baseImageEl.offset().top + this.iconHeight * 0.5 + 5 - }); - this.labelEl.appendTo(this.state.baseImageEl.parent()); - } - - this.inContainer = false; - if (this.isOriginal === true) { - this.state.numDraggablesInSlider -= 1; - } - // SR: global "screen reader" object in accessibility_tools.js - window.SR.readText(gettext('dragging out of slider')); - } else { - window.SR.readText(gettext('dragging')); - } - - this.zIndex = 1000; - this.iconEl.css('z-index', '1000'); - if (this.labelEl !== null) { - this.labelEl.css('z-index', '1000'); - } - this.iconEl.attr('aria-grabbed', 'true').focus(); - this.toggleTargets(true); - this.mousePressed = true; - this.state.currentMovingDraggable = this; - } - }, - - mouseUp: function() { - if (this.mousePressed === true) { - this.state.currentMovingDraggable = null; - this.iconEl.attr('aria-grabbed', 'false'); - - this.checkLandingElement(); - if (this.inContainer === true) { - window.SR.readText(gettext('dropped in slider')); - } else { - window.SR.readText(gettext('dropped on target')); - } - this.toggleTargets(false); - } - }, - - mouseMove: function(event) { - if (this.mousePressed === true) { - // Because we have also attached a 'mousemove' event to the - // 'document' (that will do the same thing), let's tell the - // browser not to bubble up this event. The attached event - // on the 'document' will only be triggered when the mouse - // pointer leaves the draggable while it is in the middle - // of a drag operation (user moves the mouse very quickly). - event.stopPropagation(); - - this.iconEl.css({ - left: event.pageX - this.state.baseImageEl.offset().left - this.iconWidth * 0.5 - this.iconElLeftOffset, - top: event.pageY - this.state.baseImageEl.offset().top - this.iconHeight * 0.5 - }); - - if (this.labelEl !== null) { - this.labelEl.css({ - left: event.pageX - this.state.baseImageEl.offset().left - this.labelWidth * 0.5 - 9, // Acoount for padding, border. - top: event.pageY - this.state.baseImageEl.offset().top + this.iconHeight * 0.5 + 5 - }); - } - } - } - }; // End-of: return { - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/draggable_logic.js b/common/static/js/capa/drag_and_drop/draggable_logic.js deleted file mode 100644 index 5de987fd128c..000000000000 --- a/common/static/js/capa/drag_and_drop/draggable_logic.js +++ /dev/null @@ -1,400 +0,0 @@ -(function(requirejs, require, define) { - define(['js/capa/drag_and_drop/update_input', 'js/capa/drag_and_drop/targets'], function(updateInput, Targets) { - return { - moveDraggableTo: function(moveType, target, funcCallback) { - var self, offset; - - if (this.hasLoaded === false) { - self = this; - - setTimeout(function() { - self.moveDraggableTo(moveType, target, funcCallback); - }, 50); - - return; - } - - if ((this.isReusable === true) && (this.isOriginal === true)) { - this.makeDraggableCopy(function(draggableCopy) { - draggableCopy.moveDraggableTo(moveType, target, funcCallback); - }); - - return; - } - - offset = 0; - if (this.state.config.targetOutline === true) { - offset = 1; - } - - this.inContainer = false; - - if (this.isOriginal === true) { - this.containerEl.hide(); - this.iconEl.detach(); - } - - if (this.iconImgEl !== null) { - this.iconImgEl.css({ - width: this.iconWidth, - height: this.iconHeight - }); - } - - this.iconEl.css({ - 'background-color': this.iconElBGColor, - 'padding-left': this.iconElPadding, - 'padding-right': this.iconElPadding, - border: this.iconElBorder, - width: this.iconWidth, - height: this.iconHeight - }); - if (moveType === 'target') { - this.iconEl.css({ - left: target.offset.left + 0.5 * target.w - this.iconWidth * 0.5 + offset - this.iconElLeftOffset, - top: target.offset.top + 0.5 * target.h - this.iconHeight * 0.5 + offset - }); - } else { - this.iconEl.css({ - left: target.x - this.iconWidth * 0.5 + offset - this.iconElLeftOffset, - top: target.y - this.iconHeight * 0.5 + offset - }); - } - this.iconEl.appendTo(this.state.baseImageEl.parent()); - - if (this.labelEl !== null) { - if (this.isOriginal === true) { - this.labelEl.detach(); - } - this.labelEl.css({ - 'background-color': this.state.config.labelBgColor, - 'padding-left': 8, - 'padding-right': 8, - border: '1px solid black' - }); - if (moveType === 'target') { - this.labelEl.css({ - left: target.offset.left + 0.5 * target.w - this.labelWidth * 0.5 + offset - 9, // Account for padding, border. - top: target.offset.top + 0.5 * target.h + this.iconHeight * 0.5 + 5 + offset - }); - } else { - this.labelEl.css({ - left: target.x - this.labelWidth * 0.5 + offset - 9, // Account for padding, border. - top: target.y - this.iconHeight * 0.5 + this.iconHeight + 5 + offset - }); - } - this.labelEl.appendTo(this.state.baseImageEl.parent()); - } - - if (moveType === 'target') { - target.addDraggable(this); - } else { - this.x = target.x; - this.y = target.y; - } - - this.zIndex = 1000; - this.correctZIndexes(); - - Targets.initializeTargetField(this); - - if (this.isOriginal === true) { - this.state.numDraggablesInSlider -= 1; - this.state.updateArrowOpacity(); - } - - if ($.isFunction(funcCallback) === true) { - funcCallback(); - } - }, - - // At this point the mouse was realeased, and we need to check - // where the draggable eneded up. Based on several things, we - // will either move the draggable back to the slider, or update - // the input with the user's answer (X-Y position of the draggable, - // or the ID of the target where it landed. - checkLandingElement: function() { - var positionIE; - - this.mousePressed = false; - positionIE = this.iconEl.position(); - - if (this.state.config.individualTargets === true) { - if (this.checkIfOnTarget(positionIE) === true) { - this.correctZIndexes(); - - Targets.initializeTargetField(this); - } else { - if (this.onTarget !== null) { - this.onTarget.removeDraggable(this); - } - - this.moveBackToSlider(); - - if (this.isOriginal === true) { - this.state.numDraggablesInSlider += 1; - } - } - } else { - if ( - (positionIE.left < 0) - || (positionIE.left + this.iconWidth > this.state.baseImageEl.width()) - || (positionIE.top < 0) - || (positionIE.top + this.iconHeight > this.state.baseImageEl.height()) - ) { - this.moveBackToSlider(); - - this.x = -1; - this.y = -1; - - if (this.isOriginal === true) { - this.state.numDraggablesInSlider += 1; - } - } else { - this.correctZIndexes(); - - this.x = positionIE.left + this.iconWidth * 0.5; - this.y = positionIE.top + this.iconHeight * 0.5; - - Targets.initializeTargetField(this); - } - } - - if (this.isOriginal === true) { - this.state.updateArrowOpacity(); - } - updateInput.update(this.state); - }, - - // Determine if a draggable, after it was relased, ends up on a - // target. We do this by iterating over all of the targets, and - // for each one we check whether the draggable's center is - // within the target's dimensions. - // - // positionIE is the object as returned by - // - // this.iconEl.position() - checkIfOnTarget: function(positionIE) { - var c1, target; - - for (c1 = 0; c1 < this.state.targets.length; c1 += 1) { - target = this.state.targets[c1]; - - // If only one draggable per target is allowed, and - // the current target already has a draggable on it - // (with an ID different from the one we are checking - // against), then go to next target. - if ( - (this.state.config.onePerTarget === true) - && (target.draggableList.length === 1) - && (target.draggableList[0].uniqueId !== this.uniqueId) - ) { - // eslint-disable-next-line no-continue - continue; - } - - // If the target is on a draggable (from target field), we must make sure that - // this draggable is not the same as "this" one. - if ((target.type === 'on_drag') && (target.draggableObj.uniqueId === this.uniqueId)) { - // eslint-disable-next-line no-continue - continue; - } - - // Check if the draggable's center coordinate is within - // the target's dimensions. If not, go to next target. - if ( - (positionIE.top + this.iconHeight * 0.5 < target.offset.top) - || (positionIE.top + this.iconHeight * 0.5 > target.offset.top + target.h) - || (positionIE.left + this.iconWidth * 0.5 < target.offset.left) - || (positionIE.left + this.iconWidth * 0.5 > target.offset.left + target.w) - ) { - // eslint-disable-next-line no-continue - continue; - } - - // If the draggable was moved from one target to - // another, then we need to remove it from the - // previous target's draggables list, and add it to the - // new target's draggables list. - if ((this.onTarget !== null) && (this.onTarget.uniqueId !== target.uniqueId)) { - this.onTarget.removeDraggable(this); - target.addDraggable(this); - // eslint-disable-next-line brace-style - } - // If the draggable was moved from the slider to a - // target, remember the target, and add ID to the - // target's draggables list. - else if (this.onTarget === null) { - target.addDraggable(this); - } - - // Reposition the draggable so that it's center - // coincides with the center of the target. - this.snapToTarget(target); - - // Target was found. - return true; - } - - // Target was not found. - return false; - }, - - toggleTargets: function(isEnabled) { - var effect = isEnabled ? 'move' : null; - - this.state.baseImageEl.attr('aria-dropeffect', effect); - $.each(this.state.targets, function(index, target) { - target.targetEl.attr('aria-dropeffect', effect); - }); - }, - - snapToTarget: function(target) { - var offset; - - offset = 0; - if (this.state.config.targetOutline === true) { - offset = 1; - } - - this.iconEl.css({ - left: target.offset.left + 0.5 * target.w - this.iconWidth * 0.5 + offset - this.iconElLeftOffset, - top: target.offset.top + 0.5 * target.h - this.iconHeight * 0.5 + offset - }); - - if (this.labelEl !== null) { - this.labelEl.css({ - left: target.offset.left + 0.5 * target.w - this.labelWidth * 0.5 + offset - 9, // Acoount for padding, border. - top: target.offset.top + 0.5 * target.h + this.iconHeight * 0.5 + 5 + offset - }); - } - }, - - // Go through all of the draggables subtract 1 from the z-index - // of all whose z-index is higher than the old z-index of the - // current element. After, set the z-index of the current - // element to 1 + N (where N is the number of draggables - i.e. - // the highest z-index possible). - // - // This will make sure that after releasing a draggable, it - // will be on top of all of the other draggables. Also, the - // ordering of the visibility (z-index) of the other draggables - // will not change. - correctZIndexes: function() { - var c1, highestZIndex; - - highestZIndex = -10000; - - if (this.state.config.individualTargets === true) { - if (this.onTarget.draggableList.length > 0) { - for (c1 = 0; c1 < this.onTarget.draggableList.length; c1 += 1) { - if ( - (this.onTarget.draggableList[c1].zIndex > highestZIndex) - && (this.onTarget.draggableList[c1].zIndex !== 1000) - ) { - highestZIndex = this.onTarget.draggableList[c1].zIndex; - } - } - } else { - highestZIndex = 0; - } - } else { - for (c1 = 0; c1 < this.state.draggables.length; c1++) { - if (this.inContainer === false) { - if ( - (this.state.draggables[c1].zIndex > highestZIndex) - && (this.state.draggables[c1].zIndex !== 1000) - ) { - highestZIndex = this.state.draggables[c1].zIndex; - } - } - } - } - - if (highestZIndex === -10000) { - highestZIndex = 0; - } - - this.zIndex = highestZIndex + 1; - - this.iconEl.css('z-index', this.zIndex); - if (this.labelEl !== null) { - this.labelEl.css('z-index', this.zIndex); - } - }, - - // If a draggable was released in a wrong positione, we will - // move it back to the slider, placing it in the same position - // that it was dragged out of. - moveBackToSlider: function() { - var c1; - - Targets.destroyTargetField(this); - - if (this.isOriginal === false) { - this.iconEl.remove(); - if (this.labelEl !== null) { - this.labelEl.remove(); - } - - this.state.draggables.splice(this.stateDraggablesIndex, 1); - - for (c1 = 0; c1 < this.state.draggables.length; c1 += 1) { - if (this.state.draggables[c1].stateDraggablesIndex > this.stateDraggablesIndex) { - this.state.draggables[c1].stateDraggablesIndex -= 1; - } - } - - return; - } - - this.containerEl.show(); - this.zIndex = 1; - - this.iconEl.detach(); - if (this.iconImgEl !== null) { - this.iconImgEl.css({ - width: this.iconWidthSmall, - height: this.iconHeightSmall - }); - } - this.iconEl.css({ - border: 'none', - 'background-color': 'transparent', - 'padding-left': 0, - 'padding-right': 0, - 'z-index': this.zIndex, - width: this.iconWidthSmall, - height: this.iconHeightSmall, - left: 50 - this.iconWidthSmall * 0.5, - - // Before: - // 'top': ((this.labelEl !== null) ? (100 - this.iconHeightSmall - 25) * 0.5 : 50 - this.iconHeightSmall * 0.5) - // After: - top: ((this.labelEl !== null) ? 37.5 : 50.0) - 0.5 * this.iconHeightSmall - }); - this.iconEl.appendTo(this.containerEl); - - if (this.labelEl !== null) { - this.labelEl.detach(); - this.labelEl.css({ - border: 'none', - 'background-color': 'transparent', - 'padding-left': 0, - 'padding-right': 0, - 'z-index': this.zIndex, - left: 50 - this.labelWidth * 0.5, - - // Before: - // 'top': (100 - this.iconHeightSmall - 25) * 0.5 + this.iconHeightSmall + 5 - // After: - top: 42.5 + 0.5 * this.iconHeightSmall - }); - this.labelEl.appendTo(this.containerEl); - } - - this.inContainer = true; - } - }; // End-of: return { - }); // End-of: define(['update_input', 'targets'], function (updateInput, Targets) { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/draggables.js b/common/static/js/capa/drag_and_drop/draggables.js deleted file mode 100644 index 13e26c28de49..000000000000 --- a/common/static/js/capa/drag_and_drop/draggables.js +++ /dev/null @@ -1,281 +0,0 @@ -(function(requirejs, require, define) { - define(['js/capa/drag_and_drop/draggable_events', 'js/capa/drag_and_drop/draggable_logic', - 'edx-ui-toolkit/js/utils/html-utils'], - function(draggableEvents, draggableLogic, HtmlUtils) { - return { - init: init - }; - - function init(state) { - state.config.draggables.every(function(draggable) { - processDraggable(state, draggable); - - return true; - }); - } - - function makeDraggableCopy(callbackFunc) { - var draggableObj, property; - - // Make a full proper copy of the draggable object, with some modifications. - draggableObj = {}; - for (property in this) { - if (this.hasOwnProperty(property) === true) { - draggableObj[property] = this[property]; - } - } - // The modifications to the draggable copy. - draggableObj.isOriginal = false; // This new draggable is a copy. - draggableObj.uniqueId = draggableObj.state.getUniqueId(); // Is newly set. - draggableObj.stateDraggablesIndex = null; // Will be set. - draggableObj.containerEl = null; // Not needed, since a copy will never return to a container element. - draggableObj.iconEl = null; // Will be created. - draggableObj.iconImgEl = null; // Will be created. - draggableObj.labelEl = null; // Will be created. - draggableObj.targetField = []; // Will be populated. - - // Create DOM elements and attach events. - if (draggableObj.originalConfigObj.icon.length > 0) { - draggableObj.iconEl = $('
'); - draggableObj.iconImgEl = $(''); - draggableObj.iconImgEl.attr('src', draggableObj.originalConfigObj.icon); - draggableObj.iconImgEl.load(function() { - draggableObj.iconEl.css({ - position: 'absolute', - width: draggableObj.iconWidthSmall, - height: draggableObj.iconHeightSmall, - left: 50 - draggableObj.iconWidthSmall * 0.5, - top: ((draggableObj.originalConfigObj.label.length > 0) ? 5 : 50 - draggableObj.iconHeightSmall * 0.5) - }); - draggableObj.iconImgEl.css({ - position: 'absolute', - width: draggableObj.iconWidthSmall, - height: draggableObj.iconHeightSmall, - left: 0, - top: 0 - }); - draggableObj.iconImgEl.appendTo(draggableObj.iconEl); - - if (draggableObj.originalConfigObj.label.length > 0) { - draggableObj.labelEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML( - '
' - ), - draggableObj.originalConfigObj.label, - HtmlUtils.HTML('
') - ).toString()); - draggableObj.labelEl.css({ - left: 50 - draggableObj.labelWidth * 0.5, - top: 5 + draggableObj.iconHeightSmall + 5 - }); - - draggableObj.attachMouseEventsTo('labelEl'); - } - - draggableObj.attachMouseEventsTo('iconEl'); - - draggableObj.stateDraggablesIndex = draggableObj.state.draggables.push(draggableObj) - 1; - - setTimeout(function() { - callbackFunc(draggableObj); - }, 0); - }); - } else { - if (draggableObj.originalConfigObj.label.length > 0) { - draggableObj.iconEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
'), - draggableObj.originalConfigObj.label, - HtmlUtils.HTML('
') - ).toString()); - draggableObj.iconEl.css({ - left: 50 - draggableObj.iconWidthSmall * 0.5, - top: 50 - draggableObj.iconHeightSmall * 0.5 - }); - - draggableObj.attachMouseEventsTo('iconEl'); - - draggableObj.stateDraggablesIndex = draggableObj.state.draggables.push(draggableObj) - 1; - - setTimeout(function() { - callbackFunc(draggableObj); - }, 0); - } - } - } - - function processDraggable(state, obj) { - var draggableObj; - - draggableObj = { - uniqueId: state.getUniqueId(), - originalConfigObj: obj, - stateDraggablesIndex: null, - id: obj.id, - isReusable: obj.can_reuse, - isOriginal: true, - x: -1, - y: -1, - zIndex: 1, - containerEl: null, - iconEl: null, - iconImgEl: null, - iconElBGColor: null, - iconElPadding: null, - iconElBorder: null, - iconElLeftOffset: null, - iconWidth: null, - iconHeight: null, - iconWidthSmall: null, - iconHeightSmall: null, - labelEl: null, - labelWidth: null, - hasLoaded: false, - inContainer: true, - mousePressed: false, - onTarget: null, - onTargetIndex: null, - state: state, - - mouseDown: draggableEvents.mouseDown, - mouseUp: draggableEvents.mouseUp, - mouseMove: draggableEvents.mouseMove, - - checkLandingElement: draggableLogic.checkLandingElement, - checkIfOnTarget: draggableLogic.checkIfOnTarget, - snapToTarget: draggableLogic.snapToTarget, - correctZIndexes: draggableLogic.correctZIndexes, - moveBackToSlider: draggableLogic.moveBackToSlider, - moveDraggableTo: draggableLogic.moveDraggableTo, - toggleTargets: draggableLogic.toggleTargets, - - makeDraggableCopy: makeDraggableCopy, - - attachMouseEventsTo: draggableEvents.attachMouseEventsTo, - - targetField: [], - numDraggablesOnMe: 0 - }; - - draggableObj.containerEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
') - ).toString()); - - draggableObj.containerEl.appendTo(state.sliderEl); - - if (obj.icon.length > 0) { - draggableObj.iconElBGColor = 'transparent'; - draggableObj.iconElPadding = 0; - draggableObj.iconElBorder = 'none'; - draggableObj.iconElLeftOffset = 0; - - draggableObj.iconEl = $('
'); - - draggableObj.iconImgEl = $(''); - draggableObj.iconImgEl.attr('src', obj.icon); - draggableObj.iconImgEl.load(function() { - draggableObj.iconWidth = this.width; - draggableObj.iconHeight = this.height; - - if (draggableObj.iconWidth >= draggableObj.iconHeight) { - draggableObj.iconWidthSmall = 60; - draggableObj.iconHeightSmall = draggableObj.iconWidthSmall * (draggableObj.iconHeight / draggableObj.iconWidth); - } else { - draggableObj.iconHeightSmall = 60; - draggableObj.iconWidthSmall = draggableObj.iconHeightSmall * (draggableObj.iconWidth / draggableObj.iconHeight); - } - - draggableObj.iconEl.css({ - position: 'absolute', - width: draggableObj.iconWidthSmall, - height: draggableObj.iconHeightSmall, - left: 50 - draggableObj.iconWidthSmall * 0.5, - - // Before: - // 'top': ((obj.label.length > 0) ? (100 - draggableObj.iconHeightSmall - 25) * 0.5 : 50 - draggableObj.iconHeightSmall * 0.5) - // After: - top: ((obj.label.length > 0) ? 37.5 : 50.0) - 0.5 * draggableObj.iconHeightSmall - }); - draggableObj.iconImgEl.css({ - position: 'absolute', - width: draggableObj.iconWidthSmall, - height: draggableObj.iconHeightSmall, - left: 0, - top: 0 - }); - draggableObj.iconImgEl.appendTo(draggableObj.iconEl); - draggableObj.iconEl.appendTo(draggableObj.containerEl); - - if (obj.label.length > 0) { - draggableObj.labelEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML( - '
' - ), - obj.label, - HtmlUtils.HTML('
') - ).toString()); - - draggableObj.labelEl.appendTo(draggableObj.containerEl); - draggableObj.labelWidth = draggableObj.labelEl.width(); - draggableObj.labelEl.css({ - left: 50 - draggableObj.labelWidth * 0.5, - - // Before: - // 'top': (100 - this.iconHeightSmall - 25) * 0.5 + this.iconHeightSmall + 5 - // After: - top: 42.5 + 0.5 * draggableObj.iconHeightSmall - }); - - draggableObj.attachMouseEventsTo('labelEl'); - } - - draggableObj.hasLoaded = true; - }); - } else { - // To make life easier, if there is no icon, but there is a - // label, we will create a label and store it as if it was an - // icon. All the existing code will work, and the user will - // see a label instead of an icon. - if (obj.label.length > 0) { - draggableObj.iconElBGColor = state.config.labelBgColor; - draggableObj.iconElPadding = 8; - draggableObj.iconElBorder = '1px solid black'; - draggableObj.iconElLeftOffset = 9; - - draggableObj.iconEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML( - '
'), - obj.label, - HtmlUtils.HTML('
') - ).toString()); - - draggableObj.iconEl.appendTo(draggableObj.containerEl); - - draggableObj.iconWidth = draggableObj.iconEl.width() + 1; - draggableObj.iconHeight = draggableObj.iconEl.height(); - draggableObj.iconWidthSmall = draggableObj.iconWidth; - draggableObj.iconHeightSmall = draggableObj.iconHeight; - - draggableObj.iconEl.css({ - left: 50 - draggableObj.iconWidthSmall * 0.5, - top: 50 - draggableObj.iconHeightSmall * 0.5 - }); - - draggableObj.hasLoaded = true; - } else { - // If no icon and no label, don't create a draggable. - return; - } - } - - draggableObj.attachMouseEventsTo('iconEl'); - draggableObj.attachMouseEventsTo('containerEl'); - - state.numDraggablesInSlider += 1; - draggableObj.stateDraggablesIndex = state.draggables.push(draggableObj) - 1; - } - }); // End-of: define(['draggable_events', 'draggable_logic'], function (draggableEvents, draggableLogic) { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/main.js b/common/static/js/capa/drag_and_drop/main.js deleted file mode 100644 index 3cd15971bfd6..000000000000 --- a/common/static/js/capa/drag_and_drop/main.js +++ /dev/null @@ -1,107 +0,0 @@ -(function(requirejs, require, define) { - define( - ['js/capa/drag_and_drop/state', - 'js/capa/drag_and_drop/config_parser', 'js/capa/drag_and_drop/container', - 'js/capa/drag_and_drop/base_image', 'js/capa/drag_and_drop/scroller', - 'js/capa/drag_and_drop/draggables', 'js/capa/drag_and_drop/targets', - 'js/capa/drag_and_drop/update_input'], - function(State, configParser, Container, BaseImage, Scroller, Draggables, Targets, updateInput) { - return Main; - - function Main() { - // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every - // - // Array.prototype.every is a recent addition to the ECMA-262 standard; as such it may not be present in - // other implementations of the standard. - if (!Array.prototype.every) { - // eslint-disable-next-line no-extend-native - Array.prototype.every = function(fun /* , thisp */) { - var thisp, t, len, i; - - if (this == null) { - throw new TypeError(); - } - - t = Object(this); - // eslint-disable-next-line no-bitwise - len = t.length >>> 0; - if (typeof fun !== 'function') { - throw new TypeError(); - } - - thisp = arguments[1]; - - for (i = 0; i < len; i++) { - if (i in t && !fun.call(thisp, t[i], i, t)) { - return false; - } - } - - return true; - }; - } - - $('.drag_and_drop_problem_div').each(processProblem); - } - - // $(value) - get the element of the entire problem - function processProblem(index, value) { - var problemId, 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') { - console.log('ERROR: Could not find the ID of the problem DOM element.'); - - return; - } - - try { - config = JSON.parse($('#drag_and_drop_json_' + problemId).html()); - } catch (err) { - console.log('ERROR: Could not parse the JSON configuration options.'); - console.log('Error message: "' + err.message + '".'); - - return; - } - - state = State(problemId); - - if (configParser(state, config) !== true) { - console.log('ERROR: Could not make sense of the JSON configuration options.'); - - return; - } - - Container(state); - BaseImage(state); - - (function addContent() { - if (state.baseImageLoaded !== true) { - setTimeout(addContent, 50); - - return; - } - - Targets.initializeBaseTargets(state); - Scroller(state); - Draggables.init(state); - - state.updateArrowOpacity(); - - // Update the input element, checking first that it is not filled with - // an answer from the server. - if (updateInput.check(state) === false) { - updateInput.update(state); - } - }()); - } - }); // End-of: define( -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/scroller.js b/common/static/js/capa/drag_and_drop/scroller.js deleted file mode 100644 index eb6646141d3d..000000000000 --- a/common/static/js/capa/drag_and_drop/scroller.js +++ /dev/null @@ -1,162 +0,0 @@ -(function(requirejs, require, define) { - define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { - return Scroller; - - function Scroller(state) { - var $parentEl, $moveLeftEl, $showEl, $moveRightEl, showElLeftMargin; - - $parentEl = $(HtmlUtils.HTML( - '
' - ).toString()); - - $moveLeftEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
') - ).toString()); - $moveLeftEl.appendTo($parentEl); - - // The below is necessary to prevent the browser thinking that we want - // to perform a drag operation, or a highlight operation. If we don't - // do this, the browser will then highlight with a gray shade the - // element. - $moveLeftEl.mousemove(function(event) { event.preventDefault(); }); - $moveLeftEl.mousedown(function(event) { event.preventDefault(); }); - - // This event will be responsible for moving the scroller left. - // Hidden draggables will be shown. - $moveLeftEl.mouseup(function(event) { - event.preventDefault(); - - // When there are no more hidden draggables, prevent from - // scrolling infinitely. - if (showElLeftMargin > -102) { - return; - } - - showElLeftMargin += 102; - - // We scroll by changing the 'margin-left' CSS property smoothly. - state.sliderEl.animate({ - 'margin-left': showElLeftMargin + 'px' - }, 100, function() { - updateArrowOpacity(); - }); - }); - - $showEl = $(HtmlUtils.HTML( - '
' - ).toString()); - $showEl.appendTo($parentEl); - - showElLeftMargin = 0; - - // Element where the draggables will be contained. It is very long - // so that any SANE number of draggables will fit in a single row. It - // will be contained in a parent element whose 'overflow' CSS value - // will be hidden, preventing the long row from fully being visible. - // eslint-disable-next-line no-param-reassign - state.sliderEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
') - ).toString()); - state.sliderEl.appendTo($showEl); - - state.sliderEl.mousedown(function(event) { - event.preventDefault(); - }); - - $moveRightEl = $(HtmlUtils.joinHtml( - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
'), - HtmlUtils.HTML('
') - ).toString()); - $moveRightEl.appendTo($parentEl); - - // The below is necessary to prevent the browser thinking that we want - // to perform a drag operation, or a highlight operation. If we don't - // do this, the browser will then highlight with a gray shade the - // element. - $moveRightEl.mousemove(function(event) { event.preventDefault(); }); - $moveRightEl.mousedown(function(event) { event.preventDefault(); }); - - // This event will be responsible for moving the scroller right. - // Hidden draggables will be shown. - $moveRightEl.mouseup(function(event) { - event.preventDefault(); - - // When there are no more hidden draggables, prevent from - // scrolling infinitely. - if (showElLeftMargin < -102 * (state.numDraggablesInSlider - 6)) { - return; - } - - showElLeftMargin -= 102; - - // We scroll by changing the 'margin-left' CSS property smoothly. - state.sliderEl.animate({ - 'margin-left': showElLeftMargin + 'px' - }, 100, function() { - updateArrowOpacity(); - }); - }); - - $parentEl.appendTo(state.containerEl); - - // Make the function available throughout the application. We need to - // call it in several places: - // - // 1.) When initially reading answer from server, if draggables will be - // positioned on the base image, the scroller's right and left arrows - // opacity must be updated. - // - // 2.) When creating draggable elements, the scroller's right and left - // arrows opacity must be updated according to the number of - // draggables. - state.updateArrowOpacity = updateArrowOpacity; - - // eslint-disable-next-line no-useless-return - return; - - function updateArrowOpacity() { - $moveLeftEl.children('div').css('opacity', '1'); - $moveRightEl.children('div').css('opacity', '1'); - - if (showElLeftMargin < -102 * (state.numDraggablesInSlider - 6)) { - $moveRightEl.children('div').css('opacity', '.4'); - } - if (showElLeftMargin > -102) { - $moveLeftEl.children('div').css('opacity', '.4'); - } - } - } // End-of: function Scroller(state) - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/state.js b/common/static/js/capa/drag_and_drop/state.js deleted file mode 100644 index 6ea9d5b62374..000000000000 --- a/common/static/js/capa/drag_and_drop/state.js +++ /dev/null @@ -1,95 +0,0 @@ -(function(requirejs, require, define) { - define([], function() { - return State; - - function State(problemId) { - var state; - - state = { - config: null, - - baseImageEl: null, - baseImageLoaded: false, - - containerEl: null, - - sliderEl: null, - - problemId: problemId, - - draggables: [], - numDraggablesInSlider: 0, - currentMovingDraggable: null, - - targets: [], - - updateArrowOpacity: null, - - uniqueId: 0, - salt: makeSalt(), - - getUniqueId: getUniqueId - }; - - $(document).mousemove(function(event) { - documentMouseMove(state, event); - }); - - return state; - } - - 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; - } - - function documentMouseMove(state, event) { - if (state.currentMovingDraggable !== null) { - state.currentMovingDraggable.iconEl.css( - 'left', - event.pageX - - state.baseImageEl.offset().left - - state.currentMovingDraggable.iconWidth * 0.5 - - state.currentMovingDraggable.iconElLeftOffset - ); - state.currentMovingDraggable.iconEl.css( - 'top', - event.pageY - - state.baseImageEl.offset().top - - state.currentMovingDraggable.iconHeight * 0.5 - ); - - if (state.currentMovingDraggable.labelEl !== null) { - state.currentMovingDraggable.labelEl.css( - 'left', - event.pageX - - state.baseImageEl.offset().left - - state.currentMovingDraggable.labelWidth * 0.5 - - 9 // Account for padding, border. - ); - state.currentMovingDraggable.labelEl.css( - 'top', - event.pageY - - state.baseImageEl.offset().top - + state.currentMovingDraggable.iconHeight * 0.5 - + 5 - ); - } - } - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/targets.js b/common/static/js/capa/drag_and_drop/targets.js deleted file mode 100644 index 553053fbc063..000000000000 --- a/common/static/js/capa/drag_and_drop/targets.js +++ /dev/null @@ -1,266 +0,0 @@ -(function(requirejs, require, define) { - define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { - return { - initializeBaseTargets: initializeBaseTargets, - initializeTargetField: initializeTargetField, - destroyTargetField: destroyTargetField - }; - - function initializeBaseTargets(state) { - (function(c1) { - while (c1 < state.config.targets.length) { - processTarget(state, state.config.targets[c1]); - - c1 += 1; - } - }(0)); - } - - function initializeTargetField(draggableObj) { - var iconElOffset; - - if (draggableObj.targetField.length === 0) { - draggableObj.originalConfigObj.target_fields.every(function(targetObj) { - processTarget(draggableObj.state, targetObj, true, draggableObj); - - return true; - }); - } else { - iconElOffset = draggableObj.iconEl.position(); - - draggableObj.targetField.every(function(targetObj) { - targetObj.offset.top = iconElOffset.top + targetObj.y; - targetObj.offset.left = iconElOffset.left + targetObj.x; - - return true; - }); - } - } - - function destroyTargetField(draggableObj) { - var indexOffset, lowestRemovedIndex; - - indexOffset = 0; - lowestRemovedIndex = draggableObj.state.targets.length + 1; - - draggableObj.targetField.every(function(target) { - target.el.remove(); - - if (lowestRemovedIndex > target.indexInStateArray) { - lowestRemovedIndex = target.indexInStateArray; - } - - draggableObj.state.targets.splice(target.indexInStateArray - indexOffset, 1); - indexOffset += 1; - - return true; - }); - - draggableObj.state.targets.every(function(target) { - if (target.indexInStateArray > lowestRemovedIndex) { - target.indexInStateArray -= indexOffset; - } - - return true; - }); - - draggableObj.targetField = []; - } - - function processTarget(state, obj, fromTargetField, draggableObj) { - var $targetEl, borderCss, $numTextEl, targetObj; - - borderCss = ''; - if (state.config.targetOutline === true) { - borderCss = 'border: 1px dashed gray; '; - } - - $targetEl = $( - HtmlUtils.joinHtml( - HtmlUtils.HTML('
') - ).toString() - ); - if (fromTargetField === true) { - $targetEl.appendTo(draggableObj.iconEl); - } else { - $targetEl.appendTo(state.baseImageEl.parent()); - } - - $targetEl.mousedown(function(event) { - event.preventDefault(); - }); - - if (state.config.onePerTarget === false) { - $numTextEl = $( - HtmlUtils.joinHtml( - HtmlUtils.HTML('
0
') - ).toString() - ); - } else { - $numTextEl = null; - } - - targetObj = { - uniqueId: state.getUniqueId(), - - id: obj.id, - - x: obj.x, - y: obj.y, - - w: obj.w, - h: obj.h, - - el: $targetEl, - offset: $targetEl.position(), - - draggableList: [], - - state: state, - - targetEl: $targetEl, - - numTextEl: $numTextEl, - updateNumTextEl: updateNumTextEl, - - removeDraggable: removeDraggable, - addDraggable: addDraggable, - - type: 'base', - draggableObj: null - }; - - if (fromTargetField === true) { - targetObj.offset = draggableObj.iconEl.position(); - targetObj.offset.top += obj.y; - targetObj.offset.left += obj.x; - - targetObj.type = 'on_drag'; - targetObj.draggableObj = draggableObj; - } - - if (state.config.onePerTarget === false) { - $numTextEl.appendTo(state.baseImageEl.parent()); - $numTextEl.mousedown(function(event) { - event.preventDefault(); - }); - $numTextEl.mouseup(function() { - cycleDraggableOrder.call(targetObj); - }); - } - - targetObj.indexInStateArray = state.targets.push(targetObj) - 1; - - if (fromTargetField === true) { - draggableObj.targetField.push(targetObj); - } - } - - function removeDraggable(draggable) { - var c1; - - this.draggableList.splice(draggable.onTargetIndex, 1); - - // An item from the array was removed. We need to updated all indexes accordingly. - // Shift all indexes down by one if they are higher than the index of the removed item. - c1 = 0; - while (c1 < this.draggableList.length) { - if (this.draggableList[c1].onTargetIndex > draggable.onTargetIndex) { - this.draggableList[c1].onTargetIndex -= 1; - } - - c1 += 1; - } - - draggable.onTarget = null; - draggable.onTargetIndex = null; - - if (this.type === 'on_drag') { - this.draggableObj.numDraggablesOnMe -= 1; - } - - this.updateNumTextEl(); - } - - function addDraggable(draggable) { - draggable.onTarget = this; - draggable.onTargetIndex = this.draggableList.push(draggable) - 1; - - if (this.type === 'on_drag') { - this.draggableObj.numDraggablesOnMe += 1; - } - - this.updateNumTextEl(); - } - - /* - * function cycleDraggableOrder - * - * Parameters: - * none - This function does not expect any parameters. - * - * Returns: - * undefined - The return value of this function is not used. - * - * Description: - * Go through all draggables that are on the current target, and decrease their - * z-index by 1, making sure that the bottom-most draggable ends up on the top. - */ - function cycleDraggableOrder() { - var c1, lowestZIndex, highestZIndex; - - if (this.draggableList.length < 2) { - return; - } - - highestZIndex = -10000; - lowestZIndex = 10000; - - for (c1 = 0; c1 < this.draggableList.length; c1 += 1) { - if (this.draggableList[c1].zIndex < lowestZIndex) { - lowestZIndex = this.draggableList[c1].zIndex; - } - - if (this.draggableList[c1].zIndex > highestZIndex) { - highestZIndex = this.draggableList[c1].zIndex; - } - } - - for (c1 = 0; c1 < this.draggableList.length; c1 += 1) { - if (this.draggableList[c1].zIndex === lowestZIndex) { - this.draggableList[c1].zIndex = highestZIndex; - } else { - this.draggableList[c1].zIndex -= 1; - } - - this.draggableList[c1].iconEl.css('z-index', this.draggableList[c1].zIndex); - if (this.draggableList[c1].labelEl !== null) { - this.draggableList[c1].labelEl.css('z-index', this.draggableList[c1].zIndex); - } - } - } - - function updateNumTextEl() { - if (this.numTextEl !== null) { - this.numTextEl.text(this.draggableList.length); - } - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/drag_and_drop/update_input.js b/common/static/js/capa/drag_and_drop/update_input.js deleted file mode 100644 index c7769c4891ec..000000000000 --- a/common/static/js/capa/drag_and_drop/update_input.js +++ /dev/null @@ -1,373 +0,0 @@ -(function(requirejs, require, define) { - define([], function() { - return { - check: check, - update: update - }; - - function update(state) { - var draggables, tempObj; - - draggables = []; - - if (state.config.individualTargets === false) { - (function(c1) { - while (c1 < state.draggables.length) { - if (state.draggables[c1].x !== -1) { - tempObj = {}; - tempObj[state.draggables[c1].id] = [ - state.draggables[c1].x, - state.draggables[c1].y - ]; - draggables.push(tempObj); - tempObj = null; - } - - c1 += 1; - } - }(0)); - } else { - (function(c1) { - while (c1 < state.targets.length) { - // eslint-disable-next-line no-loop-func - (function(c2) { - while (c2 < state.targets[c1].draggableList.length) { - tempObj = {}; - - if (state.targets[c1].type === 'base') { - tempObj[state.targets[c1].draggableList[c2].id] = state.targets[c1].id; - } else { - addTargetRecursively(tempObj, state.targets[c1].draggableList[c2], state.targets[c1]); - } - draggables.push(tempObj); - tempObj = null; - - c2 += 1; - } - }(0)); - - c1 += 1; - } - }(0)); - } - - $('#input_' + state.problemId).val(JSON.stringify(draggables)); - } - - function addTargetRecursively(tempObj, draggable, target) { - if (target.type === 'base') { - tempObj[draggable.id] = target.id; - } else { - tempObj[draggable.id] = {}; - tempObj[draggable.id][target.id] = {}; - - addTargetRecursively(tempObj[draggable.id][target.id], target.draggableObj, target.draggableObj.onTarget); - } - } - - // Check if input has an answer from server. If yes, then position - // all draggables according to answer. - function check(state) { - var inputElVal; - - inputElVal = $('#input_' + state.problemId).val(); - - if (inputElVal.length === 0) { - return false; - } - - repositionDraggables(state, JSON.parse(inputElVal)); - - return true; - } - - function processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i) { - var baseDraggableId, baseDraggable, baseTargetId, baseTarget, - layeredDraggableId, layeredDraggable, layeredTargetId, layeredTarget, - chain; - - if (depth === 0) { - // We are at the lowest depth? The end. - - return; - } - - if (answerSortedByDepth.hasOwnProperty(depth) === false) { - // We have a depth that ts not valid, we decrease the depth by one. - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth - 1, 0); - - return; - } - - if (answerSortedByDepth[depth].length <= i) { - // We ran out of answers at this depth, go to the next depth down. - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth - 1, 0); - - return; - } - - chain = answerSortedByDepth[depth][i]; - - baseDraggableId = Object.keys(chain)[0]; - - // This is a hack. For now we will work with depths 1 and 3. - if (depth === 1) { - baseTargetId = chain[baseDraggableId]; - - layeredTargetId = null; - layeredDraggableId = null; - - // createBaseDraggableOnTarget(state, baseDraggableId, baseTargetId); - } else if (depth === 3) { - layeredDraggableId = baseDraggableId; - - layeredTargetId = Object.keys(chain[layeredDraggableId])[0]; - - baseDraggableId = Object.keys(chain[layeredDraggableId][layeredTargetId])[0]; - - baseTargetId = chain[layeredDraggableId][layeredTargetId][baseDraggableId]; - } - - checkBaseDraggable(); - - // eslint-disable-next-line no-useless-return - return; - - function checkBaseDraggable() { - // eslint-disable-next-line no-cond-assign - if ((baseDraggable = getById(state, 'draggables', baseDraggableId, null, false, baseTargetId)) === null) { - createBaseDraggableOnTarget(state, baseDraggableId, baseTargetId, true, function() { - // eslint-disable-next-line no-cond-assign - if ((baseDraggable = getById(state, 'draggables', baseDraggableId, null, false, baseTargetId)) === null) { - console.log('ERROR: Could not successfully create a base draggable on a base target.'); - } else { - baseTarget = baseDraggable.onTarget; - - if ((layeredTargetId === null) || (layeredDraggableId === null)) { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i + 1); - } else { - checklayeredDraggable(); - } - } - }); - } else { - baseTarget = baseDraggable.onTarget; - - if ((layeredTargetId === null) || (layeredDraggableId === null)) { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i + 1); - } else { - checklayeredDraggable(); - } - } - } - - function checklayeredDraggable() { - // eslint-disable-next-line no-cond-assign - if ((layeredDraggable = getById(state, 'draggables', layeredDraggableId, null, false, layeredTargetId, baseDraggableId, baseTargetId)) === null) { - layeredDraggable = getById(state, 'draggables', layeredDraggableId); - layeredTarget = null; - baseDraggable.targetField.every(function(target) { - if (target.id === layeredTargetId) { - layeredTarget = target; - } - - return true; - }); - - if ((layeredDraggable !== null) && (layeredTarget !== null)) { - layeredDraggable.moveDraggableTo('target', layeredTarget, function() { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i + 1); - }); - } else { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i + 1); - } - } else { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, depth, i + 1); - } - } - } - - function createBaseDraggableOnTarget(state, draggableId, targetId, reportError, funcCallback) { - var draggable, target; - - // eslint-disable-next-line no-cond-assign - if ((draggable = getById(state, 'draggables', draggableId)) === null) { - if (reportError !== false) { - console.log( - 'ERROR: In answer there exists a ' - + 'draggable ID "' + draggableId + '". No ' - + 'draggable with this ID could be found.' - ); - } - - return false; - } - - // eslint-disable-next-line no-cond-assign - if ((target = getById(state, 'targets', targetId)) === null) { - if (reportError !== false) { - console.log( - 'ERROR: In answer there exists a target ' - + 'ID "' + targetId + '". No target with this ' - + 'ID could be found.' - ); - } - - return false; - } - - draggable.moveDraggableTo('target', target, funcCallback); - - return true; - } - - function processAnswerPositions(state, answer) { - var draggableId, draggable; - - (function(c1) { - while (c1 < answer.length) { - for (draggableId in answer[c1]) { - if (answer[c1].hasOwnProperty(draggableId) === false) { - // eslint-disable-next-line no-continue - continue; - } - - // eslint-disable-next-line no-cond-assign - if ((draggable = getById(state, 'draggables', draggableId)) === null) { - console.log( - 'ERROR: In answer there exists a ' - + 'draggable ID "' + draggableId + '". No ' - + 'draggable with this ID could be found.' - ); - - // eslint-disable-next-line no-continue - continue; - } - - draggable.moveDraggableTo('XY', { - x: answer[c1][draggableId][0], - y: answer[c1][draggableId][1] - }); - } - - c1 += 1; - } - }(0)); - } - - function repositionDraggables(state, answer) { - var answerSortedByDepth, minDepth, maxDepth; - - answerSortedByDepth = {}; - minDepth = 1000; - maxDepth = 0; - - answer.every(function(chain) { - var depth; - - depth = findDepth(chain, 0); - - if (depth < minDepth) { - minDepth = depth; - } - if (depth > maxDepth) { - maxDepth = depth; - } - - if (answerSortedByDepth.hasOwnProperty(depth) === false) { - answerSortedByDepth[depth] = []; - } - - answerSortedByDepth[depth].push(chain); - - return true; - }); - - if (answer.length === 0) { - return; - } - - // For now we support only one case. - if ((minDepth < 1) || (maxDepth > 3)) { - return; - } - - if (state.config.individualTargets === true) { - processAnswerTargets(state, answerSortedByDepth, minDepth, maxDepth, maxDepth, 0); - } else if (state.config.individualTargets === false) { - processAnswerPositions(state, answer); - } - } - - function findDepth(tempObj, depth) { - var i; - - if ($.isPlainObject(tempObj) === false) { - return depth; - } - - depth += 1; - - for (i in tempObj) { - if (tempObj.hasOwnProperty(i) === true) { - depth = findDepth(tempObj[i], depth); - } - } - - return depth; - } - - function getById(state, type, id, fromTargetField, inContainer, targetId, baseDraggableId, baseTargetId) { - return (function(c1) { - while (c1 < state[type].length) { - if (type === 'draggables') { - if ((targetId !== undefined) && (inContainer === false) && (baseDraggableId !== undefined) && (baseTargetId !== undefined)) { - if ( - (state[type][c1].id === id) - && (state[type][c1].inContainer === false) - && (state[type][c1].onTarget.id === targetId) - && (state[type][c1].onTarget.type === 'on_drag') - && (state[type][c1].onTarget.draggableObj.id === baseDraggableId) - && (state[type][c1].onTarget.draggableObj.onTarget.id === baseTargetId) - ) { - return state[type][c1]; - } - } else if ((targetId !== undefined) && (inContainer === false)) { - if ( - (state[type][c1].id === id) - && (state[type][c1].inContainer === false) - && (state[type][c1].onTarget.id === targetId) - ) { - return state[type][c1]; - } - } else { - if (inContainer === false) { - if ((state[type][c1].id === id) && (state[type][c1].inContainer === false)) { - return state[type][c1]; - } - } else { - if ((state[type][c1].id === id) && (state[type][c1].inContainer === true)) { - return state[type][c1]; - } - } - } - } else { // 'targets' - if (fromTargetField === true) { - if ((state[type][c1].id === id) && (state[type][c1].type === 'on_drag')) { - return state[type][c1]; - } - } else { - if ((state[type][c1].id === id) && (state[type][c1].type === 'base')) { - return state[type][c1]; - } - } - } - - c1 += 1; - } - - return null; - }(0)); - } - }); // End-of: define([], function () { -}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define) { diff --git a/common/static/js/capa/edit-a-gene.js b/common/static/js/capa/edit-a-gene.js deleted file mode 100644 index 0ef55a06fb12..000000000000 --- a/common/static/js/capa/edit-a-gene.js +++ /dev/null @@ -1,71 +0,0 @@ -(function() { - var timeout = 1000; - - waitForGenex(); - - function waitForGenex() { - if (typeof genex !== 'undefined' && genex) { - genex.onInjectionDone('genex'); - } else { - setTimeout(function() { waitForGenex(); }, timeout); - } - } - - // NOTE: - // Genex uses 8 global functions, all prefixed with genex: - // 6 are exported from GWT: - // genexSetDefaultDNASequence - // genexSetDNASequence - // genexGetDNASequence - // genexSetClickEvent - // genexSetKeyEvent - // genexSetProblemNumber - // - // It calls genexIsReady with a deferred command when it has finished - // initialization and has drawn itself - // genexStoreAnswer(answer) is called each time the DNA sequence changes - // through user interaction - - // Genex does not call the following function - genexGetInputField = function() { - var problem = $('#genex_container').parents('.problem'); - return problem.find('input[type="hidden"][name!="genex_dna_sequence"][name!="genex_problem_number"]'); - }; - - genexIsReady = function() { - var input_field = genexGetInputField(); - var genex_saved_state = input_field.val(); - var genex_default_dna_sequence; - var genex_dna_sequence; - - // Get the DNA sequence from xml file - genex_default_dna_sequence = $('#genex_dna_sequence').val(); - // Set the default DNA - genexSetDefaultDNASequence(genex_default_dna_sequence); - - // Now load problem - var genex_problem_number = $('#genex_problem_number').val(); - genexSetProblemNumber(genex_problem_number); - - // Set the DNA sequence that is displayed - if (genex_saved_state === '') { - // Load DNA sequence from xml file - genex_dna_sequence = genex_default_dna_sequence; - } else { - // Load DNA sequence from saved value - genex_saved_state = JSON.parse(genex_saved_state); - genex_dna_sequence = genex_saved_state.genex_dna_sequence; - } - genexSetDNASequence(genex_dna_sequence); - - // Now load mouse and keyboard handlers - genexSetClickEvent(); - genexSetKeyEvent(); - }; - - genexStoreAnswer = function(answer) { - var input_field = genexGetInputField(); - var value = {genex_dna_sequence: genexGetDNASequence(), genex_answer: answer}; - input_field.val(JSON.stringify(value)); - }; -}).call(this); diff --git a/common/static/js/capa/fixtures/jsinput.html b/common/static/js/capa/fixtures/jsinput.html deleted file mode 100644 index 039fe3d8d1df..000000000000 --- a/common/static/js/capa/fixtures/jsinput.html +++ /dev/null @@ -1,53 +0,0 @@ -
-
- -
- - -
-
-
- -
- - -
-
-
diff --git a/common/static/js/capa/genex/21B31BA00E7CE7B6BD63DD13A8586A45.cache.html b/common/static/js/capa/genex/21B31BA00E7CE7B6BD63DD13A8586A45.cache.html deleted file mode 100644 index ec8170eb4793..000000000000 --- a/common/static/js/capa/genex/21B31BA00E7CE7B6BD63DD13A8586A45.cache.html +++ /dev/null @@ -1,652 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/63308EE54E8033A708B414CAC05B0C32.cache.html b/common/static/js/capa/genex/63308EE54E8033A708B414CAC05B0C32.cache.html deleted file mode 100644 index 952e3b5f37dc..000000000000 --- a/common/static/js/capa/genex/63308EE54E8033A708B414CAC05B0C32.cache.html +++ /dev/null @@ -1,642 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/7AC57DC6EC8C1D8672DDF6E6D4EF57CC.cache.html b/common/static/js/capa/genex/7AC57DC6EC8C1D8672DDF6E6D4EF57CC.cache.html deleted file mode 100644 index 95cb962805c7..000000000000 --- a/common/static/js/capa/genex/7AC57DC6EC8C1D8672DDF6E6D4EF57CC.cache.html +++ /dev/null @@ -1,628 +0,0 @@ - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/9B4F4D4EFA24CDE2E4287CC07897F249.cache.html b/common/static/js/capa/genex/9B4F4D4EFA24CDE2E4287CC07897F249.cache.html deleted file mode 100644 index 5c828c120943..000000000000 --- a/common/static/js/capa/genex/9B4F4D4EFA24CDE2E4287CC07897F249.cache.html +++ /dev/null @@ -1,654 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/A069AC107D79C29D6237614AC340F0C0.cache.html b/common/static/js/capa/genex/A069AC107D79C29D6237614AC340F0C0.cache.html deleted file mode 100644 index bcf15330d988..000000000000 --- a/common/static/js/capa/genex/A069AC107D79C29D6237614AC340F0C0.cache.html +++ /dev/null @@ -1,652 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/C6220FCC8B9234FEAD8D826A73C6D2A4.cache.html b/common/static/js/capa/genex/C6220FCC8B9234FEAD8D826A73C6D2A4.cache.html deleted file mode 100644 index 5ab12af71887..000000000000 --- a/common/static/js/capa/genex/C6220FCC8B9234FEAD8D826A73C6D2A4.cache.html +++ /dev/null @@ -1,642 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/genex/clear.cache.gif b/common/static/js/capa/genex/clear.cache.gif deleted file mode 100644 index e565824aafaf..000000000000 Binary files a/common/static/js/capa/genex/clear.cache.gif and /dev/null differ diff --git a/common/static/js/capa/genex/genex.css b/common/static/js/capa/genex/genex.css deleted file mode 100644 index 459c854f92e4..000000000000 --- a/common/static/js/capa/genex/genex.css +++ /dev/null @@ -1,122 +0,0 @@ -.genex-button { - margin-right: -8px; - height: 40px !important; -} - -.genex-label { - /*font: normal normal normal 10pt/normal 'Open Sans', Verdana, Geneva, sans-serif !important;*/ - /*padding: 4px 0px 0px 10px !important;*/ - font-family: sans-serif !important; - font-size: 13px !important; - font-style: normal !important; - font-variant: normal !important; - font-weight: bold !important; - padding-top: 6px !important; - margin-left: 18px; -} - -.gwt-HTML { - cursor: default; - overflow-x: auto !important; - overflow-y: auto !important; - background-color: rgb(248, 248, 248) !important; -} - -.genex-scrollpanel { - word-wrap: normal !important; - white-space: pre !important; -} - -pre, #dna-strand { - font-family: 'courier new', courier !important; - font-size: 13px !important; - font-style: normal !important; - font-variant: normal !important; - font-weight: normal !important; - border-style: none !important; - background-color: rgb(248, 248, 248) !important; - word-wrap: normal !important; - white-space: pre !important; - overflow-x: visible !important; - overflow-y: visible !important; -} - -.gwt-DialogBox .Caption { - background: #F1F1F1; - padding: 4px 8px 4px 4px; - cursor: default; - font-family: Arial Unicode MS, Arial, sans-serif; - font-weight: bold; - border-bottom: 1px solid #bbbbbb; - border-top: 1px solid #D2D2D2; -} -.gwt-DialogBox .dialogContent { -} -.gwt-DialogBox .dialogMiddleCenter { - padding: 3px; - background: white; -} -.gwt-DialogBox .dialogBottomCenter { - background: url(images/hborder.png) repeat-x 0px -2945px; - -background: url(images/hborder_ie6.png) repeat-x 0px -2144px; -} -.gwt-DialogBox .dialogMiddleLeft { - background: url(images/vborder.png) repeat-y -31px 0px; -} -.gwt-DialogBox .dialogMiddleRight { - background: url(images/vborder.png) repeat-y -32px 0px; - -background: url(images/vborder_ie6.png) repeat-y -32px 0px; -} -.gwt-DialogBox .dialogTopLeftInner { - width: 10px; - height: 8px; - zoom: 1; -} -.gwt-DialogBox .dialogTopRightInner { - width: 12px; - zoom: 1; -} -.gwt-DialogBox .dialogBottomLeftInner { - width: 10px; - height: 12px; - zoom: 1; -} -.gwt-DialogBox .dialogBottomRightInner { - width: 12px; - height: 12px; - zoom: 1; -} -.gwt-DialogBox .dialogTopLeft { - background: url(images/circles.png) no-repeat -20px 0px; - -background: url(images/circles_ie6.png) no-repeat -20px 0px; -} -.gwt-DialogBox .dialogTopRight { - background: url(images/circles.png) no-repeat -28px 0px; - -background: url(images/circles_ie6.png) no-repeat -28px 0px; -} -.gwt-DialogBox .dialogBottomLeft { - background: url(images/circles.png) no-repeat 0px -36px; - -background: url(images/circles_ie6.png) no-repeat 0px -36px; -} -.gwt-DialogBox .dialogBottomRight { - background: url(images/circles.png) no-repeat -8px -36px; - -background: url(images/circles_ie6.png) no-repeat -8px -36px; -} -* html .gwt-DialogBox .dialogTopLeftInner { - width: 10px; - overflow: hidden; -} -* html .gwt-DialogBox .dialogTopRightInner { - width: 12px; - overflow: hidden; -} -* html .gwt-DialogBox .dialogBottomLeftInner { - width: 10px; - height: 12px; - overflow: hidden; -} -* html .gwt-DialogBox .dialogBottomRightInner { - width: 12px; - height: 12px; - overflow: hidden; -} \ No newline at end of file diff --git a/common/static/js/capa/genex/genex.nocache.js b/common/static/js/capa/genex/genex.nocache.js deleted file mode 100644 index 11f9714afbe1..000000000000 --- a/common/static/js/capa/genex/genex.nocache.js +++ /dev/null @@ -1,18 +0,0 @@ -function genex(){var P='',xb='" for "gwt:onLoadErrorFn"',vb='" for "gwt:onPropertyErrorFn"',ib='"><\/script>',Z='#',Xb='.cache.html',_='/',lb='//',Qb='21B31BA00E7CE7B6BD63DD13A8586A45',Rb='63308EE54E8033A708B414CAC05B0C32',Sb='7AC57DC6EC8C1D8672DDF6E6D4EF57CC',Tb='9B4F4D4EFA24CDE2E4287CC07897F249',Wb=':',pb='::',dc=' - -This html file is for Development Mode support. - diff --git a/common/static/js/capa/genex/images/circles.png b/common/static/js/capa/genex/images/circles.png deleted file mode 100644 index ba580a3acf7f..000000000000 Binary files a/common/static/js/capa/genex/images/circles.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/circles_ie6.png b/common/static/js/capa/genex/images/circles_ie6.png deleted file mode 100644 index 466f11923f25..000000000000 Binary files a/common/static/js/capa/genex/images/circles_ie6.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/corner.png b/common/static/js/capa/genex/images/corner.png deleted file mode 100644 index d0b8aad882a9..000000000000 Binary files a/common/static/js/capa/genex/images/corner.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/corner_ie6.png b/common/static/js/capa/genex/images/corner_ie6.png deleted file mode 100644 index 853d5b038d3b..000000000000 Binary files a/common/static/js/capa/genex/images/corner_ie6.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/hborder.png b/common/static/js/capa/genex/images/hborder.png deleted file mode 100644 index bbc37366ff86..000000000000 Binary files a/common/static/js/capa/genex/images/hborder.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/hborder_ie6.png b/common/static/js/capa/genex/images/hborder_ie6.png deleted file mode 100644 index 2add622a5881..000000000000 Binary files a/common/static/js/capa/genex/images/hborder_ie6.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/thumb_horz.png b/common/static/js/capa/genex/images/thumb_horz.png deleted file mode 100644 index 6c9baa03c7bf..000000000000 Binary files a/common/static/js/capa/genex/images/thumb_horz.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/thumb_vertical.png b/common/static/js/capa/genex/images/thumb_vertical.png deleted file mode 100644 index 5ea57dbd77a9..000000000000 Binary files a/common/static/js/capa/genex/images/thumb_vertical.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/vborder.png b/common/static/js/capa/genex/images/vborder.png deleted file mode 100644 index 070d25184ff6..000000000000 Binary files a/common/static/js/capa/genex/images/vborder.png and /dev/null differ diff --git a/common/static/js/capa/genex/images/vborder_ie6.png b/common/static/js/capa/genex/images/vborder_ie6.png deleted file mode 100644 index 061736f01d66..000000000000 Binary files a/common/static/js/capa/genex/images/vborder_ie6.png and /dev/null differ diff --git a/common/static/js/capa/jsinput/jsinput_example.css b/common/static/js/capa/jsinput/jsinput_example.css deleted file mode 100644 index 8f1144ac40aa..000000000000 --- a/common/static/js/capa/jsinput/jsinput_example.css +++ /dev/null @@ -1,9 +0,0 @@ -.directions { - font-size: large -} - -.feedback { - font-size: medium; - border: 2px solid cornflowerblue; - padding: 5px; -} diff --git a/common/static/js/capa/jsinput/jsinput_example.html b/common/static/js/capa/jsinput/jsinput_example.html deleted file mode 100644 index caa034fff95d..000000000000 --- a/common/static/js/capa/jsinput/jsinput_example.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Dropdown with Dynamic Text - - - - - - -

- - diff --git a/common/static/js/capa/jsinput/jsinput_example.js b/common/static/js/capa/jsinput/jsinput_example.js deleted file mode 100644 index f3ee144a2ca1..000000000000 --- a/common/static/js/capa/jsinput/jsinput_example.js +++ /dev/null @@ -1,86 +0,0 @@ -/* globals Channel */ - -(function() { - 'use strict'; - - // state will be populated via initial_state via the `setState` method. Defining dummy values here - // to make the expected structure clear. - var state = { - availableChoices: [], - selectedChoice: '' - }, - channel, - select = document.getElementsByClassName('choices')[0], - feedback = document.getElementsByClassName('feedback')[0]; - - function populateSelect() { - // Populate the select from `state.availableChoices`. - var i, option; - - // Clear out any pre-existing options. - while (select.firstChild) { - select.removeChild(select.firstChild); - } - - // Populate the select with the available choices. - for (i = 0; i < state.availableChoices.length; i++) { - option = document.createElement('option'); - option.value = i; - option.innerHTML = state.availableChoices[i]; - if (state.availableChoices[i] === state.selectedChoice) { - option.selected = true; - } - select.appendChild(option); - } - feedback.innerText = "The currently selected answer is '" + state.selectedChoice + "'."; - } - - function getGrade() { - // The following return value may or may not be used to grade server-side. - // If getState and setState are used, then the Python grader also gets access - // to the return value of getState and can choose it instead to grade. - return JSON.stringify(state.selectedChoice); - } - - function getState() { - // Returns the current state (which can be used for grading). - return JSON.stringify(state); - } - - // This function will be called with 1 argument when JSChannel is not used, - // 2 otherwise. In the latter case, the first argument is a transaction - // object that will not be used here - // (see http://mozilla.github.io/jschannel/docs/) - function setState() { - var stateString = arguments.length === 1 ? arguments[0] : arguments[1]; - state = JSON.parse(stateString); - populateSelect(); - } - - // Establish a channel only if this application is embedded in an iframe. - // This will let the parent window communicate with this application using - // RPC and bypass SOP restrictions. - if (window.parent !== window) { - channel = Channel.build({ - window: window.parent, - origin: '*', - scope: 'JSInput' - }); - - channel.bind('getGrade', getGrade); - channel.bind('getState', getState); - channel.bind('setState', setState); - } - - select.addEventListener('change', function() { - state.selectedChoice = select.options[select.selectedIndex].text; - feedback.innerText = "You have selected '" + state.selectedChoice - + "'. Click Submit to grade your answer."; - }); - - return { - getState: getState, - setState: setState, - getGrade: getGrade - }; -}()); diff --git a/common/static/js/capa/protex/39CC89519B0E1FCB47B935AC9FE13D7B.cache.html b/common/static/js/capa/protex/39CC89519B0E1FCB47B935AC9FE13D7B.cache.html deleted file mode 100644 index e5db692aaca7..000000000000 --- a/common/static/js/capa/protex/39CC89519B0E1FCB47B935AC9FE13D7B.cache.html +++ /dev/null @@ -1,743 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/6E05B1CD5BFCAF7D53C7C64D84318178.cache.html b/common/static/js/capa/protex/6E05B1CD5BFCAF7D53C7C64D84318178.cache.html deleted file mode 100644 index ce6b444862d6..000000000000 --- a/common/static/js/capa/protex/6E05B1CD5BFCAF7D53C7C64D84318178.cache.html +++ /dev/null @@ -1,750 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/C824A958AB642DC2213DFFDAC640BEAA.cache.html b/common/static/js/capa/protex/C824A958AB642DC2213DFFDAC640BEAA.cache.html deleted file mode 100644 index f84a8b982238..000000000000 --- a/common/static/js/capa/protex/C824A958AB642DC2213DFFDAC640BEAA.cache.html +++ /dev/null @@ -1,760 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/D9267DE8FB02F8B995B4A58C66C76E29.cache.html b/common/static/js/capa/protex/D9267DE8FB02F8B995B4A58C66C76E29.cache.html deleted file mode 100644 index b6fc4f6a081a..000000000000 --- a/common/static/js/capa/protex/D9267DE8FB02F8B995B4A58C66C76E29.cache.html +++ /dev/null @@ -1,758 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/F275492F7098103BCB05F4F86ABF6218.cache.html b/common/static/js/capa/protex/F275492F7098103BCB05F4F86ABF6218.cache.html deleted file mode 100644 index 311c82b3a0f0..000000000000 --- a/common/static/js/capa/protex/F275492F7098103BCB05F4F86ABF6218.cache.html +++ /dev/null @@ -1,750 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/F3301B0E65F38C7FCF2EF3764B3BB0B6.cache.html b/common/static/js/capa/protex/F3301B0E65F38C7FCF2EF3764B3BB0B6.cache.html deleted file mode 100644 index f39f0d68d26b..000000000000 --- a/common/static/js/capa/protex/F3301B0E65F38C7FCF2EF3764B3BB0B6.cache.html +++ /dev/null @@ -1,754 +0,0 @@ - - - - \ No newline at end of file diff --git a/common/static/js/capa/protex/clear.cache.gif b/common/static/js/capa/protex/clear.cache.gif deleted file mode 100644 index e565824aafaf..000000000000 Binary files a/common/static/js/capa/protex/clear.cache.gif and /dev/null differ diff --git a/common/static/js/capa/protex/hosted.html b/common/static/js/capa/protex/hosted.html deleted file mode 100644 index 48b87f39b57a..000000000000 --- a/common/static/js/capa/protex/hosted.html +++ /dev/null @@ -1,365 +0,0 @@ - - - -This html file is for Development Mode support. - diff --git a/common/static/js/capa/protex/protex.css b/common/static/js/capa/protex/protex.css deleted file mode 100644 index b0300c33ea83..000000000000 --- a/common/static/js/capa/protex/protex.css +++ /dev/null @@ -1,57 +0,0 @@ -.protex-absolute-panel { - background-color: #BBBBBB; -} - -.protex-canvas { - outline: none; -} - -.protex-caption-panel { - padding: 10px 10px 10px 10px; - margin: 0px 0px 0px 0px; - border:2px solid #4E4E4E; - font: normal normal normal 14pt/normal 'Open Sans', sans-serif; - background-color: #B2B2FF; -} - -.protex-textbox { - font: normal normal normal 12pt/normal 'Open Sans', sans-serif !important; - padding: 2px 2px 2px 2px !important; -} - -.protex-caption-panel-ss-bonds-on { - padding: 10px 10px 10px 10px; - margin: 0px 0px 0px 0px; - border:2px solid #4E4E4E; - font: normal normal normal 14pt/normal 'Open Sans', sans-serif; - background-color: #B2FFFF; -} - -.protex-button { - margin-right: 15px; -} - -.protex-listbox { -} - -.gwt-ProgressBar-shell { - border: 2px solid #faf9f7; - border-right: 2px solid #848280; - border-bottom: 2px solid #848280; - background-color: #AAAAAA; - height: 14pt; - width: 50%; - margin-left: 15px; -} -.gwt-ProgressBar-shell .gwt-ProgressBar-bar { - background-color: #67A7E3; -} -.gwt-ProgressBar-shell .gwt-ProgressBar-text { - padding: 0px; - margin: 0px; - color: white; -} - -div#protex-panel[style] { - overflow: scroll !important; -} diff --git a/common/static/js/capa/protex/protex.nocache.js b/common/static/js/capa/protex/protex.nocache.js deleted file mode 100644 index 77f770bf9c9a..000000000000 --- a/common/static/js/capa/protex/protex.nocache.js +++ /dev/null @@ -1,18 +0,0 @@ -function protex(){var P='',xb='" for "gwt:onLoadErrorFn"',vb='" for "gwt:onPropertyErrorFn"',ib='"><\/script>',Z='#',Xb='.cache.html',_='/',lb='//',Qb='39CC89519B0E1FCB47B935AC9FE13D7B',Rb='6E05B1CD5BFCAF7D53C7C64D84318178',Wb=':',pb='::',dc=' from the problem.xml file, and exec it in the - context of this problem. Provides ability to randomize problems, and also set - variables for problem answer checking. - - Problem XML goes to Python execution context. Runs everything in script tags. - """ - context = {} - context["seed"] = self.seed - context["anonymous_student_id"] = self.capa_system.anonymous_student_id - all_code = "" - - python_path = [] - - for script in tree.findall(".//script"): - - stype = script.get("type") - if stype: - if "javascript" in stype: - continue # skip javascript - if "perl" in stype: - continue # skip perl - # TODO: evaluate only python - - for d in self._extract_system_path(script): - if d not in python_path and os.path.exists(d): - python_path.append(d) - - xmlesc = {"'": "'", """: '"'} - code = unescape(script.text, xmlesc) - all_code += code - - extra_files = [] - if all_code: - # An asset named python_lib.zip can be imported by Python code. - zip_lib = self.capa_system.get_python_lib_zip() - if zip_lib is not None: - extra_files.append(("python_lib.zip", zip_lib)) - python_path.append("python_lib.zip") - - try: - safe_exec( - all_code, - context, - random_seed=self.seed, - python_path=python_path, - extra_files=extra_files, - cache=self.capa_system.cache, - limit_overrides_context=get_course_id_from_capa_block(self.capa_block), - slug=self.problem_id, - unsafely=self.capa_system.can_execute_unsafe_code(), - ) - except Exception as err: - log.exception("Error while execing script code: %s", all_code) - msg = Text(f"Error while executing script code: {err}") - raise responsetypes.LoncapaProblemError(msg) - - # Store code source in context, along with the Python path needed to run it correctly. - context["script_code"] = all_code - context["python_path"] = python_path - context["extra_files"] = extra_files or None - return context - - def _extract_html( # private - self, problemtree - ): # pylint: disable=too-many-statements,too-many-locals,too-many-branches,too-many-return-statements - """ - Main (private) function which converts Problem XML tree to HTML. - Calls itself recursively. - - Returns Element tree of XHTML representation of problemtree. - Calls render_html of Response instances to render responses into XHTML. - - Used by get_html. - """ - if not isinstance(problemtree.tag, str): - # Comment and ProcessingInstruction nodes are not Elements, - # and we're ok leaving those behind. - # BTW: etree gives us no good way to distinguish these things - # other than to examine .tag to see if it's a string. :( - return None - - if problemtree.tag == "script" and problemtree.get("type") and "javascript" in problemtree.get("type"): - # leave javascript intact. - return deepcopy(problemtree) - - if problemtree.tag in html_problem_semantics: - return None - - problemid = problemtree.get("id") # my ID - - if problemtree.tag in inputtypes.registry.registered_tags(): - # If this is an inputtype subtree, let it render itself. - response_data = self.problem_data[problemid] - - status = "unsubmitted" - msg = "" - hint = "" - hintmode = None - input_id = problemtree.get("id") - answervariable = None - if problemid in self.correct_map: - pid = input_id - - # If we're withholding correctness, don't show adaptive hints either. - # Note that regular, "demand" hints will be shown, if the course author has added them to the problem. - if not self.capa_block.correctness_available(): - status = "submitted" - else: - # If the the problem has not been saved since the last submit set the status to the - # current correctness value and set the message as expected. Otherwise we do not want to - # display correctness because the answer may have changed since the problem was graded. - if not self.has_saved_answers: - status = self.correct_map.get_correctness(pid) - msg = self.correct_map.get_msg(pid) - - hint = self.correct_map.get_hint(pid) - hintmode = self.correct_map.get_hintmode(pid) - answervariable = self.correct_map.get_property(pid, "answervariable") - - value = "" - if self.student_answers and problemid in self.student_answers: - value = self.student_answers[problemid] - - if input_id not in self.input_state: - self.input_state[input_id] = {} - - # do the rendering - state = { - "value": value, - "status": status, - "id": input_id, - "input_state": self.input_state[input_id], - "answervariable": answervariable, - "response_data": response_data, - "has_saved_answers": self.has_saved_answers, - "feedback": { - "message": msg, - "hint": hint, - "hintmode": hintmode, - }, - } - - input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag) - # save the input type so that we can make ajax calls on it if we need to - self.inputs[input_id] = input_type_cls(self.capa_system, problemtree, state) - return self.inputs[input_id].get_html() - - # let each Response render itself - if problemtree in self.responders: - overall_msg = self.correct_map.get_overall_message() - return self.responders[problemtree].render_html(self._extract_html, response_msg=overall_msg) - - # let each custom renderer render itself: - if problemtree.tag in customrender.registry.registered_tags(): - renderer_class = customrender.registry.get_class_for_tag(problemtree.tag) - renderer = renderer_class(self.capa_system, problemtree) - return renderer.get_html() - - # otherwise, render children recursively, and copy over attributes - tree = etree.Element(problemtree.tag) - for item in problemtree: - item_xhtml = self._extract_html(item) - if item_xhtml is not None: - tree.append(item_xhtml) - - if tree.tag in html_transforms: - tree.tag = html_transforms[problemtree.tag]["tag"] - else: - # copy attributes over if not innocufying - for key, value in problemtree.items(): - tree.set(key, value) - - tree.text = problemtree.text - tree.tail = problemtree.tail - - return tree - - def _preprocess_problem(self, tree, minimal_init): # private - """ - Assign IDs to all the responses - Assign sub-IDs to all entries (textline, schematic, etc.) - Annoted correctness and value - In-place transformation - - Also create capa Response instances for each responsetype and save as self.responders - - Obtain all responder answers and save as self.responder_answers dict (key = response) - """ - response_id = 1 - problem_data = {} - self.responders = {} - for response in tree.xpath("//" + "|//".join(responsetypes.registry.registered_tags())): - responsetype_id = self.problem_id + "_" + str(response_id) - # create and save ID for this response - response.set("id", responsetype_id) - response_id += 1 - - answer_id = 1 - input_tags = inputtypes.registry.registered_tags() - inputfields = tree.xpath( - "|".join(["//" + response.tag + "[@id=$id]//" + x for x in input_tags]), id=responsetype_id - ) - - # assign one answer_id for each input type - for entry in inputfields: - entry.attrib["response_id"] = str(response_id) - entry.attrib["answer_id"] = str(answer_id) - entry.attrib["id"] = f"{self.problem_id}_{response_id}_{answer_id}" - answer_id = answer_id + 1 - - self.response_a11y_data(response, inputfields, responsetype_id, problem_data) - - # instantiate capa Response - responsetype_cls = responsetypes.registry.get_class_for_tag(response.tag) - responder = responsetype_cls( - response, inputfields, self.context, self.capa_system, self.capa_block, minimal_init - ) - # save in list in self - self.responders[response] = responder - - if not minimal_init: - # get responder answers (do this only once, since there may be a performance cost, - # eg with externalresponse) - self.responder_answers = {} - for response, responder in self.responders.items(): - try: - self.responder_answers[response] = responder.get_answers() - except Exception: - log.debug("responder %s failed to properly return get_answers()", responder) # FIXME - raise - - # ... may not be associated with any specific response; give - # IDs for those separately - # TODO: We should make the namespaces consistent and unique (e.g. %s_problem_%i). - solution_id = 1 - for solution in tree.findall(".//solution"): - solution.attrib["id"] = f"{self.problem_id}_solution_{solution_id}" - solution_id += 1 - - return problem_data - - def response_a11y_data( # pylint: disable=too-many-locals,too-many-branches - self, response, inputfields, responsetype_id, problem_data - ): - """ - Construct data to be used for a11y. - - Arguments: - response (object): xml response object - inputfields (list): list of inputfields in a responsetype - responsetype_id (str): responsetype id - problem_data (dict): dict to be filled with response data - """ - # if there are no inputtypes then don't do anything - if not inputfields: - return - - element_to_be_deleted = None - label = "" - - if len(inputfields) > 1: - response.set("multiple_inputtypes", "true") - group_label_tag = response.find("label") - group_description_tags = response.findall("description") - group_label_tag_id = f"multiinput-group-label-{responsetype_id}" - group_label_tag_text = "" - if group_label_tag is not None: - group_label_tag.tag = "p" - group_label_tag.set("id", group_label_tag_id) - group_label_tag.set("class", "multi-inputs-group-label") - group_label_tag_text = stringify_children(group_label_tag) - response.set("multiinput-group-label-id", group_label_tag_id) - - group_description_ids = [] - for index, group_description_tag in enumerate(group_description_tags): - group_description_tag_id = f"multiinput-group-description-{responsetype_id}-{index}" - group_description_tag.tag = "p" - group_description_tag.set("id", group_description_tag_id) - group_description_tag.set("class", "multi-inputs-group-description question-description") - group_description_ids.append(group_description_tag_id) - - if group_description_ids: - response.set("multiinput-group_description_ids", " ".join(group_description_ids)) - - for inputfield in inputfields: - problem_data[inputfield.get("id")] = { - "group_label": group_label_tag_text, - "label": HTML(inputfield.attrib.get("label", "")), - "descriptions": {}, - } - else: - # Extract label value from