Skip to content
Snippets Groups Projects
Commit a41e783f authored by Tobias Baden's avatar Tobias Baden
Browse files

Fixed the scroll-by-items functionality - ListSearch

- Updated Version Number
parent 1af80472
Branches
No related tags found
No related merge requests found
/*! hshcourselist 2018-08-31 */ /*! hshcourselist 2018-09-12 */
define(["jquery"],function(a){function b(b,c){var d=c+"/course/view.php?id="+b.val();a("#hshcourseform").attr("action",d)}function c(a){a.removeClass("active"),a.removeClass("activeCourseSearch")}function d(a){a.addClass("active"),a.addClass("activeCourseSearch")}function e(a){var b=window.innerHeight,c=a.getBoundingClientRect(),d=c.bottom,e=c.top;d>b&&a.scrollIntoView({block:"end",behavior:"smooth"}),e<0&&a.scrollIntoView({block:"start",behavior:"smooth"})}return{init:function(f){a("input").keydown(function(g){var h,i=a(".hshcoursesearchlistitem"),j=g.keyCode,k=i.filter(".activeCourseSearch");40!==j&&38!==j&&13!==j||(c(i),38===j?(h=!k.length||k.is(":first-child")?i.last():k.prev(),b(h,f)):40===j?(h=!k.length||k.is(":last-child")?i.eq(0):k.next(),b(h,f)):13===j&&(h=k,isNaN(h.val())&&(h=i.eq(0)),b(h,f)),d(h),e(h.eq(0)))})}}}); define(["jquery"],function(a){function b(b,c){var d=c+"/course/view.php?id="+b.val();a("#hshcourseform").attr("action",d)}function c(a){a.removeClass("active"),a.removeClass("activeCourseSearch")}function d(a){a.addClass("active"),a.addClass("activeCourseSearch")}function e(a){var b=window.innerHeight,c=a.getBoundingClientRect(),d=c.bottom,e=c.top;d>b&&a.scrollIntoView({block:"end",behavior:"smooth"}),e<0&&a.scrollIntoView({block:"start",behavior:"smooth"})}return{init:function(f){a("input").keydown(function(g){var h,i=a(".hshcoursesearchlistitem"),j=i.filter(".activeCourseSearch"),k=g.keyCode;if(40===k||38===k||13===k){c(i),38===k?(h=!j.length||j.is(":first-child")?i.last():j.prev(),b(h,f)):40===k?(h=!j.length||j.is(":last-child")?i.eq(0):j.next(),b(h,f)):13===k&&(h=j,isNaN(h.val())&&(h=i.eq(0)),b(h,f)),d(h);e(document.getElementsByClassName("activeCourseSearch")[0])}})}}});
\ No newline at end of file \ No newline at end of file
define(['jquery'], function ($) { define(["jquery"], function($) {
function changeActionString(current, wwwroot) { function changeActionString(current, wwwroot) {
var actionString = wwwroot + '/course/view.php?id=' + current.val(); var actionString = wwwroot + "/course/view.php?id=" + current.val();
$('#hshcourseform').attr('action', actionString); $("#hshcourseform").attr("action", actionString);
} }
function setInactive(target) { function setInactive(target) {
target.removeClass('active'); target.removeClass("active");
target.removeClass('activeCourseSearch'); target.removeClass("activeCourseSearch");
} }
function setActive(target) { function setActive(target) {
target.addClass('active'); target.addClass("active");
target.addClass('activeCourseSearch'); target.addClass("activeCourseSearch");
} }
function scrollIntoViewIfNeeded(element) { function scrollIntoViewIfNeeded(element) {
...@@ -32,9 +32,9 @@ define(['jquery'], function ($) { ...@@ -32,9 +32,9 @@ define(['jquery'], function ($) {
return { return {
init: function(wwwroot) { init: function(wwwroot) {
$('input').keydown(function (e) { $("input").keydown(function(e) {
var listItems = $('.hshcoursesearchlistitem'); var listItems = $(".hshcoursesearchlistitem");
var selected = listItems.filter('.activeCourseSearch'); var selected = listItems.filter(".activeCourseSearch");
var current; var current;
var key = e.keyCode; var key = e.keyCode;
...@@ -44,21 +44,24 @@ define(['jquery'], function ($) { ...@@ -44,21 +44,24 @@ define(['jquery'], function ($) {
setInactive(listItems); setInactive(listItems);
if (key === 38) { // KEY UP if (key === 38) {
if (!selected.length || selected.is(':first-child')) { // KEY UP
if (!selected.length || selected.is(":first-child")) {
current = listItems.last(); current = listItems.last();
} else { } else {
current = selected.prev(); current = selected.prev();
} }
changeActionString(current, wwwroot); changeActionString(current, wwwroot);
} else if (key === 40) { // KEY DOWN } else if (key === 40) {
if (!selected.length || selected.is(':last-child')) { // KEY DOWN
if (!selected.length || selected.is(":last-child")) {
current = listItems.eq(0); current = listItems.eq(0);
} else { } else {
current = selected.next(); current = selected.next();
} }
changeActionString(current, wwwroot); changeActionString(current, wwwroot);
} else if (key === 13) { // KEY ENTER } else if (key === 13) {
// KEY ENTER
current = selected; current = selected;
if (isNaN(current.val())) { if (isNaN(current.val())) {
current = listItems.eq(0); current = listItems.eq(0);
...@@ -67,8 +70,11 @@ define(['jquery'], function ($) { ...@@ -67,8 +70,11 @@ define(['jquery'], function ($) {
} }
setActive(current); setActive(current);
scrollIntoViewIfNeeded(current.eq(0)); var scrollToElement = document.getElementsByClassName(
"activeCourseSearch"
)[0];
scrollIntoViewIfNeeded(scrollToElement);
}); });
},
} }
};
}); });
<?php <?php
$plugin->component = 'block_hshcourselist'; $plugin->component = 'block_hshcourselist';
$plugin->version = 2018083100; // YYYYMMDDHH $plugin->version = 2018091200; // YYYYMMDDHH
$plugin->requires = 2016112900; // YYYYMMDDHH $plugin->requires = 2016112900; // YYYYMMDDHH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment