From d31268e790401f4447da48f12d013a23ee390195 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Wed, 11 Dec 2013 16:56:44 +0200 Subject: [PATCH] Minor changes by Valera. --- .../xmodule/xmodule/js/src/capa/imageinput.js | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/imageinput.js b/common/lib/xmodule/xmodule/js/src/capa/imageinput.js index 47b3b06c22..518cd91bba 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/imageinput.js +++ b/common/lib/xmodule/xmodule/js/src/capa/imageinput.js @@ -1,27 +1,36 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Simple image input -// -//////////////////////////////////////////////////////////////////////////////// +/** + * Simple image input + * + * + * Click on image. Update the coordinates of a dot on the image. + * The new coordinates are the location of the click. + */ -// click on image, update coordinates -// put a dot at location of click, on image +/** + * 'The wise adapt themselves to circumstances, as water molds itself to the + * pitcher.' + * + * ~ Chinese Proverb + */ window.image_input_click = function (id, event) { - var iidiv = document.getElementById("imageinput_" + id), - pos_x = event.offsetX ? (event.offsetX) : event.pageX - iidiv.offsetLeft, - pos_y = event.offsetY ? (event.offsetY) : event.pageY - iidiv.offsetTop, - // To reduce differences between values returned by different kinds of - // browsers, we round `pos_x` and `pos_y`. - // IE10: `pos_x` and `pos_y` - float. - // Chrome, FF: `pos_x` and `pos_y` - integers. - result = "[" + Math.round(pos_x) + "," + Math.round(pos_y) + "]", - cx = (pos_x - 15) + "px", - cy = (pos_y - 15) + "px", - cross = document.getElementById("cross_" + id); + var iiDiv = document.getElementById('imageinput_' + id), - cross.style.left = cx; - cross.style.top = cy; - cross.style.visibility = "visible" ; - document.getElementById("input_" + id).value = result; + posX = event.offsetX ? event.offsetX : event.pageX - iiDiv.offsetLeft, + posY = event.offsetY ? event.offsetY : event.pageY - iiDiv.offsetTop, + + cross = document.getElementById('cross_' + id), + + // 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) + ']'; + + cross.style.left = (posX - 15) + 'px'; + cross.style.top = (posY - 15) + 'px'; + cross.style.visibility = 'visible'; + + document.getElementById('input_' + id).value = result; };