diff --git a/common/lib/capa/capa/templates/imageinput.html b/common/lib/capa/capa/templates/imageinput.html index 394f180d3e..77977a8d12 100644 --- a/common/lib/capa/capa/templates/imageinput.html +++ b/common/lib/capa/capa/templates/imageinput.html @@ -1,24 +1,60 @@ - -
- -
+ - % if status == 'unsubmitted': - - Status: unanswered - - % elif status == 'correct': - - Status: correct - - % elif status == 'incorrect': - - Status: incorrect - - % elif status == 'incomplete': - - Status: incorrect - - % endif +
+ +
+ + + + % if status == 'unsubmitted': + + Status: unanswered + + % elif status == 'correct': + + Status: correct + + % elif status == 'incorrect': + + Status: incorrect + + % elif status == 'incomplete': + + Status: incorrect + + % endif
diff --git a/common/lib/xmodule/xmodule/js/src/capa/imageinput.js b/common/lib/xmodule/xmodule/js/src/capa/imageinput.js index 518cd91bba..059ff65dd3 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/imageinput.js +++ b/common/lib/xmodule/xmodule/js/src/capa/imageinput.js @@ -13,24 +13,50 @@ * ~ Chinese Proverb */ -window.image_input_click = function (id, event) { - var iiDiv = document.getElementById('imageinput_' + id), +window.ImageInput = (function ($, undefined) { + var ImageInput = ImageInputConstructor; - posX = event.offsetX ? event.offsetX : event.pageX - iiDiv.offsetLeft, - posY = event.offsetY ? event.offsetY : event.pageY - iiDiv.offsetTop, + ImageInput.prototype = { + constructor: ImageInputConstructor, + clickHandler: clickHandler + }; - cross = document.getElementById('cross_' + id), + return ImageInput; - // To reduce differences between values returned by different kinds of - // browsers, we round `posX` and `posY`. - // - // IE10: `posX` and `posY` - float. - // Chrome, FF: `posX` and `posY` - integers. - result = '[' + Math.round(posX) + ',' + Math.round(posY) + ']'; + function ImageInputConstructor(elementId) { + var _this = this; - cross.style.left = (posX - 15) + 'px'; - cross.style.top = (posY - 15) + 'px'; - cross.style.visibility = 'visible'; + this.elementId = elementId; + this.el = $('#imageinput_' + elementId); - document.getElementById('input_' + id).value = result; -}; + this.el.on('click', function (event) { + _this.clickHandler(event); + }); + } + + function clickHandler(event) { + var iiDiv = document.getElementById('imageinput_' + this.elementId), + + posX = event.offsetX ? + event.offsetX : event.pageX - iiDiv.offsetLeft, + posY = event.offsetY ? + event.offsetY : event.pageY - iiDiv.offsetTop, + + cross = document.getElementById('cross_' + this.elementId), + + // To reduce differences between values returned by different kinds + // of browsers, we round `posX` and `posY`. + // + // IE10: `posX` and `posY` - float. + // Chrome, FF: `posX` and `posY` - integers. + result = '[' + Math.round(posX) + ',' + Math.round(posY) + ']'; + + console.log('[image_input_click]: event = ', event); + + cross.style.left = (posX - 15) + 'px'; + cross.style.top = (posY - 15) + 'px'; + cross.style.visibility = 'visible'; + + document.getElementById('input_' + this.elementId).value = result; + } +}).call(this, window.jQuery);