From a41e783fb75ee6ddfe000b62fa548ca36ea86a5c Mon Sep 17 00:00:00 2001
From: Tobias Baden <tobias.baden@stud.hs-hannover.de>
Date: Wed, 12 Sep 2018 17:00:37 +0200
Subject: [PATCH] Fixed the scroll-by-items functionality - ListSearch -
 Updated Version Number

---
 amd/build/listselect.min.js |  4 ++--
 amd/src/listselect.js       | 44 +++++++++++++++++++++----------------
 version.php                 |  2 +-
 3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/amd/build/listselect.min.js b/amd/build/listselect.min.js
index 86c50b6..2655698 100644
--- a/amd/build/listselect.min.js
+++ b/amd/build/listselect.min.js
@@ -1,2 +1,2 @@
-/*! hshcourselist 2018-08-31 */
-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)))})}}});
\ No newline at end of file
+/*! 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=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
diff --git a/amd/src/listselect.js b/amd/src/listselect.js
index 8b87822..2d9c2d1 100644
--- a/amd/src/listselect.js
+++ b/amd/src/listselect.js
@@ -1,17 +1,17 @@
-define(['jquery'], function ($) {
+define(["jquery"], function($) {
     function changeActionString(current, wwwroot) {
-        var actionString = wwwroot + '/course/view.php?id=' + current.val();
-        $('#hshcourseform').attr('action', actionString);
+        var actionString = wwwroot + "/course/view.php?id=" + current.val();
+        $("#hshcourseform").attr("action", actionString);
     }
 
     function setInactive(target) {
-        target.removeClass('active');
-        target.removeClass('activeCourseSearch');
+        target.removeClass("active");
+        target.removeClass("activeCourseSearch");
     }
 
     function setActive(target) {
-        target.addClass('active');
-        target.addClass('activeCourseSearch');
+        target.addClass("active");
+        target.addClass("activeCourseSearch");
     }
 
     function scrollIntoViewIfNeeded(element) {
@@ -31,10 +31,10 @@ define(['jquery'], function ($) {
     }
 
     return {
-        init: function (wwwroot) {
-            $('input').keydown(function (e) {
-                var listItems = $('.hshcoursesearchlistitem');
-                var selected = listItems.filter('.activeCourseSearch');
+        init: function(wwwroot) {
+            $("input").keydown(function(e) {
+                var listItems = $(".hshcoursesearchlistitem");
+                var selected = listItems.filter(".activeCourseSearch");
                 var current;
                 var key = e.keyCode;
 
@@ -44,21 +44,24 @@ define(['jquery'], function ($) {
 
                 setInactive(listItems);
 
-                if (key === 38) { // KEY UP
-                    if (!selected.length || selected.is(':first-child')) {
+                if (key === 38) {
+                    // KEY UP
+                    if (!selected.length || selected.is(":first-child")) {
                         current = listItems.last();
                     } else {
                         current = selected.prev();
                     }
                     changeActionString(current, wwwroot);
-                } else if (key === 40) { // KEY DOWN
-                    if (!selected.length || selected.is(':last-child')) {
+                } else if (key === 40) {
+                    // KEY DOWN
+                    if (!selected.length || selected.is(":last-child")) {
                         current = listItems.eq(0);
                     } else {
                         current = selected.next();
                     }
                     changeActionString(current, wwwroot);
-                } else if (key === 13) { // KEY ENTER
+                } else if (key === 13) {
+                    // KEY ENTER
                     current = selected;
                     if (isNaN(current.val())) {
                         current = listItems.eq(0);
@@ -67,8 +70,11 @@ define(['jquery'], function ($) {
                 }
 
                 setActive(current);
-                scrollIntoViewIfNeeded(current.eq(0));
+                var scrollToElement = document.getElementsByClassName(
+                    "activeCourseSearch"
+                )[0];
+                scrollIntoViewIfNeeded(scrollToElement);
             });
-        },
-    }
+        }
+    };
 });
diff --git a/version.php b/version.php
index 2d31840..92cb4aa 100644
--- a/version.php
+++ b/version.php
@@ -1,4 +1,4 @@
 <?php
 $plugin->component = 'block_hshcourselist';
-$plugin->version = 2018083100;  // YYYYMMDDHH
+$plugin->version = 2018091200;  // YYYYMMDDHH
 $plugin->requires = 2016112900; // YYYYMMDDHH
-- 
GitLab