https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43762

--- Comment #1 from Christopher Brannon <[email protected]> ---
This is what I currently use instead of FilterSearchResultsByLoggedInBranch:

  // Enhance item locations in search results (10/8/26)
  if ($('#catalog_results').length) {
    $('.availability').each(function () {
      let $availability = $(this);
      let $allItems = $availability.find('li');
      let $localItems = $allItems.filter('.' + currentLibrary.code);
      let $otherItems = $allItems.not('.' + currentLibrary.code);
      // Highlight local copies
      $localItems.css({
        'color': '#78A42F',
        'font-weight': 'bold',
        'background-color': '#f5fbe9',
        'border-left': '4px solid #78A42F',
        'padding-left': '6px'
      });
      // CASE 1: Local copies exist AND other libraries have copies
      if ($localItems.length && $otherItems.length) {
        $otherItems.hide();
        $('<div class="location-toggle">' +
          '<a href="#" class="btn btn-outline-secondary btn-sm
toggle-locations" style="margin-top:8px; display:inline-block;">' +
          'Show ' + $otherItems.length +
          ' copies at other libraries</a>' +
          '</div>')
          .insertAfter($availability)
          .on('click', 'a', function (e) {
          e.preventDefault();
          $otherItems.toggle();
          $(this).text(
            $otherItems.first().is(':visible')
            ? 'Hide other libraries'
            : 'Show ' + $otherItems.length + ' copies at other libraries'
          );
        });
      }
      // CASE 1A: Only local copies exist
      else if ($localItems.length) {
        // Nothing to hide and no toggle needed
      }
      // CASE 2: No local copies exist
      else {
        $allItems.hide();
        $('<div class="location-toggle no-local">' +
          '<strong>No copies at ' + currentLibrary.name + '</strong><br>' +
          '<a href="#" class="btn btn-outline-secondary btn-sm
toggle-locations" style="margin-top:8px; display:inline-block;">' +
          'Show ' + $allItems.length +
          ' copies at other libraries</a>' +
          '</div>')
          .insertAfter($availability)
          .on('click', 'a', function (e) {
          e.preventDefault();
          $allItems.toggle();
          $(this).text(
            $allItems.first().is(':visible')
            ? 'Hide other libraries'
            : 'Show ' + $allItems.length + ' copies at other libraries'
          );
        });
      }
    });
    // Add global button only if at least one toggle exists
    if ($('.toggle-locations').length) {
      $('<span id="toggle-all-locations-container" ' +
        'style="float:right; margin-left:1em; margin-top:-35px;
position:relative; z-index:1;">' +
        '<a href="#" id="toggle-all-locations" class="btn btn-primary btn-sm">'
+
        'Show all locations' +
        '</a>' +
        '</span>')
        .appendTo('#searchresults nav:first');
      let allExpanded = false;
      $(document).on('click', '#toggle-all-locations', function (e) {
        e.preventDefault();
        if (!allExpanded) {
          $('.toggle-locations').each(function () {
            if ($(this).text().startsWith('Show')) {
              $(this).trigger('click');
            }
          });
          $(this).text('Hide other locations');
          allExpanded = true;
        } else {
          $('.toggle-locations').each(function () {
            if ($(this).text().startsWith('Hide')) {
              $(this).trigger('click');
            }
          });
          $(this).text('Show all locations');
          allExpanded = false;
        }
      });
    }
  }
  // END Enhance item locations in search results

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to