Bug 20931: JS error "ReferenceError: $ is not defined" when CircSidebar is turned on
authorOwen Leonard <oleonard@myacpl.org>
Wed, 20 Jun 2018 17:16:16 +0000 (17:16 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 2 Jul 2018 11:10:00 +0000 (11:10 +0000)
This patch reorganizes the way sidebar menus get highlighted based on
the current page. A global function is added to handle most cases.
Individual menu-handling scripts have been modified to handle only the
edge cases which aren't covered by the global one.

A new class is added to the global CSS file so that highlighted menu
links can be custom-styled.

To test, apply the patch and clear your cache if necessary.

View various pages to confirm that current-page-highlighting in the
sidebar menu is working correctly and that there are no JS errors in the
browser console. For example:

 - Administration -> Currencies and exchange rates.
 - Acquisitions -> Invoices
 - Tools -> Patron lists
 - Tools -> Export

And with CircSidebar turned on test various circulation pages, e.g.

 - Circulation -> Set library

Signed-off-by: Charles Farmer <charles.farmer@inLibro.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/css/staff-global.css
koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc
koha-tmpl/intranet-tmpl/prog/js/acq.js
koha-tmpl/intranet-tmpl/prog/js/acquisitions-menu.js
koha-tmpl/intranet-tmpl/prog/js/admin-menu.js
koha-tmpl/intranet-tmpl/prog/js/staff-global.js
koha-tmpl/intranet-tmpl/prog/js/tools-menu.js

index 57d3622..2f01f7a 100644 (file)
@@ -163,7 +163,11 @@ label input[type="radio"],
 }
 
 #navmenulist li a {
-       text-decoration : none;
+    text-decoration : none;
+}
+
+#navmenulist li a.current {
+    font-weight: bold;
 }
 
 #doc, #doc1, #doc2, #doc3 {
index 844926c..b6dc7fb 100644 (file)
@@ -1,17 +1,4 @@
 [% USE Branches %]
-<script type="text/javascript">//<![CDATA[
-    $(document).ready(function() {
-        var path = location.pathname.substring(1);
-        var url = window.location.toString();
-        var params = '';
-        if ( url.match(/\?(.+)$/) ) {
-            params = "?" + RegExp.$1;
-        }
-        $('#navmenulist a[href$="/' + path + params + '"]').css('font-weight','bold');
-    });
-//]]>
-</script>
-
 <div id="navmenu">
     <div id="navmenulist">
 
index 63575b3..9d3983c 100644 (file)
@@ -374,8 +374,3 @@ function hideAllColumns(){
     $("#plan td:nth-child(2),#plan th:nth-child(2)").nextUntil("th:nth-child("+(allCols-1)+"),td:nth-child("+(allCols-1)+")").hide(); // hide all but the last two columns
     $("#hideall").prop("checked", true).parent().addClass("selected");
 }
-
-$(document).ready(function() {
-    var path = location.pathname.substring(1);
-    $('#navmenulist a[href$="/' + path + '"]').css('font-weight','bold');
-});
index 08bcc85..30c0567 100644 (file)
@@ -1,8 +1,6 @@
 $(document).ready(function() {
     var path = location.pathname.substring(1);
     if (path.indexOf("invoice") >= 0) {
-        $('#navmenulist a[href$="/cgi-bin/koha/acqui/invoices.pl"]').css('font-weight','bold');
-    } else {
-        $('#navmenulist a[href$="/' + path + '"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/acqui/invoices.pl"]').addClass("current");
     }
 });
index d0557fe..f7b69c7 100644 (file)
@@ -1,16 +1,14 @@
 $(document).ready(function() {
     var path = location.pathname.substring(1);
     if (path == "cgi-bin/koha/admin/marctagstructure.pl" || path == "cgi-bin/koha/admin/marc_subfields_structure.pl") {
-        $('#navmenulist a[href$="/cgi-bin/koha/admin/biblio_framework.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/admin/biblio_framework.pl"]').addClass("current");
     } else if (path == "cgi-bin/koha/admin/auth_tag_structure.pl" || path == "cgi-bin/koha/admin/auth_subfields_structure.pl") {
-        $('#navmenulist a[href$="/cgi-bin/koha/admin/authtypes.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/admin/authtypes.pl"]').addClass("current");
     } else if (path == "cgi-bin/koha/admin/oai_set_mappings.pl") {
-        $('#navmenulist a[href$="/cgi-bin/koha/admin/oai_sets.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/admin/oai_sets.pl"]').addClass("current");
     } else if (path == "cgi-bin/koha/admin/items_search_field.pl") {
-        $('#navmenulist a[href$="/cgi-bin/koha/admin/items_search_fields.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/admin/items_search_fields.pl"]').addClass("current");
     } else if (path == "cgi-bin/koha/admin/clone-rules.pl") {
-        $('#navmenulist a[href$="/cgi-bin/koha/admin/smart-rules.pl"]').css('font-weight','bold');
-    } else {
-        $('#navmenulist a[href$="/' + path + '"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/admin/smart-rules.pl"]').addClass("current");
     }
 });
index cd586da..db5539a 100644 (file)
@@ -62,6 +62,18 @@ $.fn.selectTabByID = function (tabID) {
         e.preventDefault();
         $( $(this).data("element") ).toggle();
     });
+
+    var navmenulist = $("#navmenulist");
+    if( navmenulist.length > 0 ){
+        var path = location.pathname.substring(1);
+        var url = window.location.toString();
+        var params = '';
+        if ( url.match(/\?(.+)$/) ) {
+            params = "?" + RegExp.$1;
+        }
+        $("a[href$=\"/" + path + params + "\"]", navmenulist).addClass("current");
+    }
+
 });
 
 // http://jennifermadden.com/javascript/stringEnterKeyDetector.html
index 9751f76..4b6e4a0 100644 (file)
@@ -1,22 +1,20 @@
   $(document).ready(function() {
       var path = location.pathname.substring(1);
       if (path.indexOf("labels") >= 0 && path.indexOf("spine") < 0 ) {
-        $('#navmenulist a[href$="/cgi-bin/koha/labels/label-home.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/labels/label-home.pl"]').addClass("current");
       } else if (path.indexOf("patroncards") >= 0 ) {
-        $('#navmenulist a[href$="/cgi-bin/koha/patroncards/home.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/patroncards/home.pl"]').addClass("current");
       } else if (path.indexOf("clubs") >= 0 ) {
-          $('#navmenulist a[href$="/cgi-bin/koha/clubs/clubs.pl"]').css('font-weight','bold');
+          $('#navmenulist a[href$="/cgi-bin/koha/clubs/clubs.pl"]').addClass("current");
       } else if (path.indexOf("patron_lists") >= 0 ) {
-        $('#navmenulist a[href$="/cgi-bin/koha/patron_lists/lists.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/patron_lists/lists.pl"]').addClass("current");
       } else if (path.indexOf("rotating_collections") >= 0 ){
-        $('#navmenulist a[href$="/cgi-bin/koha/rotating_collections/rotatingCollections.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/rotating_collections/rotatingCollections.pl"]').addClass("current");
       } else if ((path+location.search).indexOf("batchMod.pl?del=1") >= 0 ) {
-        $('#navmenulist a[href$="/cgi-bin/koha/tools/batchMod.pl?del=1"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/tools/batchMod.pl?del=1"]').addClass("current");
       } else if (path.indexOf("quotes-upload.pl") >= 0 ){
-        $('#navmenulist a[href$="/cgi-bin/koha/tools/quotes.pl"]').css('font-weight','bold');
+        $('#navmenulist a[href$="/cgi-bin/koha/tools/quotes.pl"]').addClass("current");
       } else if (path.indexOf("plugins") >= 0 ) {
-          $('#navmenulist a[href$="/cgi-bin/koha/plugins/plugins-home.pl?method=tool"]').css('font-weight','bold');
-      } else {
-        $('#navmenulist a[href$="/' + path + '"]').css('font-weight','bold');
+          $('#navmenulist a[href$="/cgi-bin/koha/plugins/plugins-home.pl?method=tool"]').addClass("current");
       }
   });