Commit 97f82f48 by Chris Rodriguez

Keyboard functionality success

parent 0b7ec75a
......@@ -66,10 +66,54 @@
//jQuery loupeAndLightbox Plugin
.zooming-image-place {
.larger {
left: 0 !important;
bottom: 100% !important;
}
.indicator {
display: none;
position: absolute;
left: 46%;
top: 45%;
width: 50px;
height: 50px;
background: $gray-d4;
color: $white;
font-size: 32px;
text-align: center;
line-height: 50px;
}
a:focus {
.indicator {
display: block;
}
}
a:hover,
a:active {
.indicator {
display: none;
}
}
.larger {
display: none;
position: absolute;
height: 350px;
width: 350px;
top: 10% !important;
right: -350px !important;
border-radius: 50%;
border: 2px solid $gray-d4;
background: $white;
box-shadow: 0 0 3px $gray-d4;
overflow: hidden;
cursor: none;
.is-visible {
display: block;
}
}
}
// ====================
......
......@@ -5,21 +5,21 @@ data: |
<h3 class="hd hd-2">Zooming Image Tool</h3>
<p>Use the Zooming Image Tool to enable learners to see details of large, complex images.</p>
<p>With the Zooming Image Tool, the learner can move the mouse pointer over a part of the image to enlarge it and see more detail.</p>
<p>To use the Zooming Image Tool, you must first add the <a href="http://files.edx.org/jquery.loupeAndLightbox.js" target="_blank">jquery.loupeAndLightbox.js JavaScript file</a> to your course.</p>
<p>To use the Zooming Image Tool, you must first add the <a href="http://files.edx.org/image-zoom-tool.js" target="_blank">image-zoom-tool.js JavaScript file</a> to your course.</p>
<p>You must also add both the regular and magnified image files to your course.</p>
<p>The following HTML code shows the format required to use the Zooming Image tool. For the example in this template, you must replace the values in <i>italics</i>.</p>
<pre>
&lt;div class="zooming-image-place" style="position: relative;"&gt;
&lt;a class="loupe" href="<i>path to the magnified version of the image</i>"&gt;
&lt;a class="edx-zoom" href="<i>path to the magnified version of the image</i>"&gt;
&lt;img alt="<i>Text for screen readers</i>"
src="<i>path to the image you want to display in the unit</i>" /&gt;
&lt;/a>
&lt;div class="script_placeholder"
data-src="<i>path to the jquery.loupeAndLightbox.js JavaScript file in your course</i>"/&gt;
data-src="<i>path to the image-zoom-tool.js JavaScript file in your course</i>"/&gt;
&lt;/div&gt;
&lt;script type="text/javascript"&gt;// &gt;![CDATA[
JavascriptLoader.executeModuleScripts($('.zooming-image-place').eq(0), function() {
$('.loupe').loupeAndLightbox({
$('.loupe').edxImageZoomTool({
width: 350,
height: 350,
lightbox: false
......@@ -40,14 +40,14 @@ data: |
<p>You can view the chemical structures of the molecules by clicking on them. The magnified view also lists the enzymes involved in each step.</p>
<p class="sr">Press spacebar to open the magnifier.</p>
<div class="zooming-image-place" style="position: relative;">
<a class="loupe" href="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_detail_01.png">
<a class="edx-zoom" href="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_detail_01.png">
<img alt="magnify" src="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_overview_01.png" />
</a>
<div class="script_placeholder" data-src="https://studio.edx.org/c4x/edX/DemoX/asset/jquery.loupeAndLightbox.js" />
<div class="script_placeholder" data-src="https://studio.edx.org/c4x/edX/DemoX/asset/image-zoom-tool.js" />
</div>
<script type="text/javascript">// <![CDATA[
JavascriptLoader.executeModuleScripts($('.zooming-image-place').eq(0), function() {
$('.loupe').loupeAndLightbox({
$('.edx-zoom').edxImageZoomTool({
width: 350,
height: 350,
lightbox: false
......
......@@ -2,20 +2,20 @@
metadata:
display_name: Zooming Image
data: |
<h2>ZOOMING DIAGRAMS</h2>
<h3 class="hd hd-2">Zooming Image Tool</h3>
<p>Some edX classes use extremely large, extremely detailed graphics. To make it easier to understand we can offer two versions of those graphics, with the zoomed section showing when you click on the main view.</p>
<p>The example below is from <a href="https://www.edx.org/course/mit/7-00x/introduction-biology-secret-life/1014" target="_blank">7.00x: Introduction to Biology</a> and shows a subset of the biochemical reactions that cells carry out. </p>
<p>You can view the chemical structures of the molecules by clicking on them. The magnified view also lists the enzymes involved in each step.</p>
<p class="sr">Press spacebar to open the magifier.</p>
<div class="zooming-image-place" style="position: relative;">
<a class="loupe" href="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_detail_01.png">
<img alt="magnify" src="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_overview_01.png" />
<a class="edx-zoom" href="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_detail_01.png">
<img alt="Enable image zoom" src="https://studio.edx.org/c4x/edX/DemoX/asset/pathways_overview_01.png" />
<span class="indicator icon fa fa-search-plus" aria-hidden="true"></span>
</a>
<div class="script_placeholder" data-src="https://studio.edx.org/c4x/edX/DemoX/asset/jquery.loupeAndLightbox.js" />
<div class="script_placeholder" data-src="https://studio.edx.org/c4x/edX/DemoX/asset/image-zoom-tool.js" />
</div>
<script type="text/javascript">// <![CDATA[
JavascriptLoader.executeModuleScripts($('.zooming-image-place').eq(0), function() {
$('.loupe').loupeAndLightbox({
$('.edx-zoom').edxImageZoomTool({
width: 350,
height: 350,
lightbox: false
......
/*
* edX Image Zoom Tool
* v0.0.1
*
* This script was modified from our jquery.loupeAndLightbox.js script, but
* goes further and adds keyboard accessibility to the zooming controls.
*/
(function($){
$.fn.edxImageZoomTool = function(options) {
var settings = $.extend({}, $.fn.edxImageZoomTool.defaults, options),
keys = {
up: 38,
down: 40,
left: 37,
right: 39,
space: 32,
enter: 13,
esc: 27,
tab: 9
};
return this.each(function() {
var $this = $(this),
$targetImage = $this.find('> img'),
$magnifiedImage = $('<img />'),
$zoomed = $('<div class="larger" style="overflow: hidden;" tabindex="-1">'),
$lightbox = $('<div class="edx_imagezoom_lightbox">'),
$errorMessage = $('<div class="edx_imagezoom_errorMessage">'),
$loader = $('<div class="edx_imagezoom_loader">Loading...</div>'),
$imageArea = $('.zooming-image-place a'),
$indicator = $('.zooming-image-place .indicator');
$this.css({
cursor: 'default'
});
$targetImage.css({
cursor: 'pointer'
});
$magnifiedImage.css({
position: 'absolute',
maxWidth: 'none'
});
$lightbox.css({
position: 'absolute',
left: 0,
top: 0,
zIndex: settings.zIndex-1,
opacity: 0.75,
filter: 'alpha(opacity=75)',
background: '#000'
});
$errorMessage
.text(settings.errorMessage)
.css({
height: settings.height,
width: settings.width
});
$loader.css({
height: settings.height,
width: settings.width
});
$this.on('click keydown', function(event) {
event.preventDefault();
});
$targetImage.on('click', function(event) {
if (!$zoomed.hasClass('is-visible')) {
var left = event.pageX,
top = event.pageY;
if (!$magnifiedImage.hasClass('is-appended')) {
getMagnifiedImage();
}
setTimeout(function() {
appendZoomed();
magnifyWithMouse(left, top);
if (settings.lightbox == true) {
appendLightbox();
}
}, 100);
}
}).mousemove(function(event) {
var left = event.pageX,
top = event.pageY,
offsetTop = $targetImage.offset().top - ($zoomed.width() / 2),
offsetLeft = $targetImage.offset().left - ($zoomed.height() / 2),
offsetBottom = $targetImage.offset().top + $targetImage.height() + ($zoomed.height() / 2),
offsetRight = $targetImage.offset().left + $targetImage.width() + ($zoomed.width() / 2);
if (left < offsetLeft || left > offsetRight || top < offsetTop || top > offsetBottom) {
$targetImage.css({ cursor: 'default' });
} else {
$targetImage.css({ cursor: 'crosshair' });
magnifyWithMouse(left, top);
}
}).click(function() {
detachZoomed();
if (settings.lightbox == true) {
detachLightbox();
}
}).mouseleave(function() {
pulseZoomed();
});
$imageArea.on('keydown', function(event) {
var left = event.pageX,
top = event.pageY;
switch (event.which) {
case keys.tab:
return true;
break;
case keys.enter:
case keys.space:
if (!$zoomed.hasClass('is-visible')) {
var left = event.pageX,
top = event.pageY;
if (!$magnifiedImage.hasClass('is-appended')) {
getMagnifiedImage();
}
setTimeout(function() {
appendZoomed(true);
magnifyWithMouse(left, top, true);
if (settings.lightbox == true) {
appendLightbox();
}
}, 100);
}
break;
default:
return true;
}
});
$zoomed.on('keydown', function(event) {
event.preventDefault();
var left,
top,
$zoomedImage = $zoomed.find('img'),
offsetTop = $targetImage.offset().top - ($zoomed.width() / 2),
offsetLeft = $targetImage.offset().left - ($zoomed.height() / 2),
offsetBottom = $targetImage.offset().top + $targetImage.height() + ($zoomed.height() / 2),
offsetRight = $targetImage.offset().left + $targetImage.width() + ($zoomed.width() / 2);
switch (event.which) {
case keys.esc:
case keys.tab:
if ($zoomed.hasClass('is-visible')) {
detachZoomed();
if (settings.lightbox == true) {
detachLightbox();
}
$imageArea.focus();
}
break;
case keys.up:
magnifyWithKeyboard(0, -1);
break;
case keys.down:
magnifyWithKeyboard(0, 1);
break;
case keys.left:
magnifyWithKeyboard(-1, 0);
break;
case keys.right:
magnifyWithKeyboard(1, 0);
break;
default:
return true;
}
});
$(document).click(function(event) {
if ($zoomed.hasClass('is-visible')) {
detachZoomed();
if (settings.lightbox == true) {
detachLightbox();
}
}
});
$(window).resize(function() {
if ($zoomed.is(':visible')) {
// $zoomed.css({
// left: $targetImage.offset().left + ($targetImage.width() / 2) - ($zoomed.width() / 2),
// top: $targetImage.offset().top + ($targetImage.height() / 2) - ($zoomed.height() / 2)
// });
$magnifiedImage.css({
left: -($magnifiedImage.width() / 2) + ($zoomed.width() / 2),
top: -($magnifiedImage.height() / 2) + ($zoomed.height() / 2)
});
$lightbox.css({
height: $(document).height(),
width: $(document).width()
});
}
});
function magnifyWithMouse(left, top, centered) {
var heightDiff = $magnifiedImage.height() / $targetImage.height(),
widthDiff = $magnifiedImage.width() / $targetImage.width(),
magnifierTop,
magnifierLeft;
if (centered) {
magnifierTop = -$magnifiedImage.height() / 2;
magnifierLeft = -$magnifiedImage.width() / 2;
} else {
magnifierTop = (-(top - $targetImage.offset().top) * heightDiff) + (settings.height / 2);
magnifierLeft = (-(left - $targetImage.offset().left) * widthDiff) + (settings.width / 2);
}
$magnifiedImage.css({
top: magnifierTop,
left: magnifierLeft
});
};
function magnifyWithKeyboard(left, top) {
var newLeft,
newTop;
newLeft = $magnifiedImage.css('left');
newLeft = newLeft.replace('px', '');
newLeft = parseInt(newLeft) + left;
newTop = $magnifiedImage.css('top');
newTop = newTop.replace('px', '');
newTop = parseInt(newTop) + top;
$magnifiedImage.css({
top: newTop + 'px',
left: newLeft + 'px'
});
};
function appendZoomed(focus) {
$zoomed.appendTo($('.zooming-image-place'))
.append($magnifiedImage)
.fadeIn(settings.fadeSpeed, function() {
$(this).addClass('is-visible');
});
if (focus) {
$zoomed.focus();
}
};
function getMagnifiedImage() {
var src = $this.attr('href');
$loader.appendTo($zoomed);
$magnifiedImage.load(function() {
$(this).addClass('is-appended');
$loader.detach();
})
.error(function () {
$(this).hide();
$zoomed.append($errorMessage)
.addClass('edx_imagezoom_loadError');
$loader.detach();
})
.attr('src', src);
};
function detachZoomed() {
$zoomed.fadeOut(settings.fadeSpeed, function() {
$(this).removeClass('is-visible')
.detach();
});
};
function appendLightbox() {
$lightbox.appendTo('body')
.css({
height: $(document).height(),
width: $(document).width()
})
.fadeIn(settings.fadeSpeed);
};
function detachLightbox() {
$lightbox.fadeOut(settings.fadeSpeed, function() {
$(this).detach();
});
};
function pulseZoomed() {
$zoomed.fadeTo(150, 0.25, function() {
$(this).fadeTo(150, 1.0);
});
};
});
};
$.fn.edxImageZoomTool.defaults = {
zIndex: 1000,
// width: 150,
// height: 150,
// border: '2px solid #191919',
fadeSpeed: 250,
lightbox: true,
errorMessage: 'Image load error'
};
})(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