Commit 7ebeccd4 by Valera Rozuvan

Updating ImageInput JS code base.

parent a78400a8
<span> <span>
<input type="hidden" class="imageinput" src="${src}" name="input_${id}" id="input_${id}" value="${value}" /> <input
<div id="imageinput_${id}" onclick="image_input_click('${id}',event);" style = "background-image:url('${src}');width:${width}px;height:${height}px;position: relative; left: 0; top: 0;"> type="hidden"
<img src="${STATIC_URL}green-pointer.png" id="cross_${id}" style="position: absolute;top: ${gy}px;left: ${gx}px;" /> class="imageinput"
src="${src}"
name="input_${id}"
id="input_${id}"
value="${value}"
/>
<div
id="imageinput_${id}"
style="background-image: url('${src}'); width: ${width}px; height: ${height}px; position: relative; left: 0; top: 0;"
>
<img
src="${STATIC_URL}green-pointer.png"
id="cross_${id}"
style="position: absolute; top: ${gy}px; left: ${gx}px;"
/>
</div> </div>
<script type="text/javascript" charset="utf-8">
(new ImageInput('${id}'));
</script>
% if status == 'unsubmitted': % if status == 'unsubmitted':
<span class="unanswered" style="display:inline-block;" id="status_${id}" aria-describedby="input_${id}"> <span
class="unanswered"
style="display: inline-block;"
id="status_${id}"
aria-describedby="input_${id}"
>
<span class="sr">Status: unanswered</span> <span class="sr">Status: unanswered</span>
</span> </span>
% elif status == 'correct': % elif status == 'correct':
<span class="correct" id="status_${id}" aria-describedby="input_${id}"> <span
class="correct"
id="status_${id}"
aria-describedby="input_${id}"
>
<span class="sr">Status: correct</span> <span class="sr">Status: correct</span>
</span> </span>
% elif status == 'incorrect': % elif status == 'incorrect':
<span class="incorrect" id="status_${id}" aria-describedby="input_${id}"> <span
class="incorrect"
id="status_${id}"
aria-describedby="input_${id}"
>
<span class="sr">Status: incorrect</span> <span class="sr">Status: incorrect</span>
</span> </span>
% elif status == 'incomplete': % elif status == 'incomplete':
<span class="incorrect" id="status_${id}" aria-describedby="input_${id}"> <span
class="incorrect"
id="status_${id}"
aria-describedby="input_${id}"
>
<span class="sr">Status: incorrect</span> <span class="sr">Status: incorrect</span>
</span> </span>
% endif % endif
......
...@@ -13,24 +13,50 @@ ...@@ -13,24 +13,50 @@
* ~ Chinese Proverb * ~ Chinese Proverb
*/ */
window.image_input_click = function (id, event) { window.ImageInput = (function ($, undefined) {
var iiDiv = document.getElementById('imageinput_' + id), var ImageInput = ImageInputConstructor;
posX = event.offsetX ? event.offsetX : event.pageX - iiDiv.offsetLeft, ImageInput.prototype = {
posY = event.offsetY ? event.offsetY : event.pageY - iiDiv.offsetTop, constructor: ImageInputConstructor,
clickHandler: clickHandler
};
cross = document.getElementById('cross_' + id), return ImageInput;
// To reduce differences between values returned by different kinds of function ImageInputConstructor(elementId) {
// browsers, we round `posX` and `posY`. var _this = this;
this.elementId = elementId;
this.el = $('#imageinput_' + elementId);
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. // IE10: `posX` and `posY` - float.
// Chrome, FF: `posX` and `posY` - integers. // Chrome, FF: `posX` and `posY` - integers.
result = '[' + Math.round(posX) + ',' + Math.round(posY) + ']'; result = '[' + Math.round(posX) + ',' + Math.round(posY) + ']';
console.log('[image_input_click]: event = ', event);
cross.style.left = (posX - 15) + 'px'; cross.style.left = (posX - 15) + 'px';
cross.style.top = (posY - 15) + 'px'; cross.style.top = (posY - 15) + 'px';
cross.style.visibility = 'visible'; cross.style.visibility = 'visible';
document.getElementById('input_' + id).value = result; document.getElementById('input_' + this.elementId).value = result;
}; }
}).call(this, window.jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment