blacklight-hierarchy 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 697c2ee0eb4208a5849d3d4ac87a06649926581ff2bceebf4286251a6502cb31
4
- data.tar.gz: 243b6ae6bcb6a0f9f25335e251fee8d45b2ee0020337f4187728c0a20b2fd643
3
+ metadata.gz: '05896464df5a8c0e3b6d878771afb366c74eb679a9acbb3cc91b48fc1ec21a67'
4
+ data.tar.gz: f6544b27132185268d971b49e634b6f83a4ad8986e78014f65cc121d233a7fb1
5
5
  SHA512:
6
- metadata.gz: 575224c30019574f9cd0396676e1dc402a3c5d4743538bcb04cd0eeefbb97106102f35deb02f342063d6d8c51da5f719a86d5bcb290998124ea0e0d81423599b
7
- data.tar.gz: 1ca5e9d6fe3a6aae330a2bb4d6815e40b8923df00e9559a7dcb6ac3145837f02df1d844bd0bed964d7c245a78bf33c3e0dee4cc3ee905ec9f313b7e35a8e86b0
6
+ metadata.gz: e239a2df4fac7caf7a0cce0917fd361c04c1a29ba904246275a592769ede706425cf8a4573c2734829f402f43555c76d3b8b393b6a645350644e4aabe60d5659
7
+ data.tar.gz: c727ad909a5820f59e4484ef3cf517ade8e48ec61646b943d79f1a52991e2eff290a73bc2033f00bfe62d418ddedc1ebb138fa9f246fc8713857cca1aff34028
@@ -18,7 +18,7 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby: [2.6, 2.7]
21
+ ruby: [2.7, 3.0]
22
22
  steps:
23
23
  - uses: actions/checkout@v2
24
24
  - name: Set up Ruby
@@ -35,7 +35,7 @@ jobs:
35
35
  runs-on: ubuntu-latest
36
36
  strategy:
37
37
  matrix:
38
- ruby: [2.5, 2.6]
38
+ ruby: [2.7, 2.6]
39
39
  steps:
40
40
  - uses: actions/checkout@v2
41
41
  - name: Set up Ruby
@@ -0,0 +1,12 @@
1
+ import { Controller } from 'stimulus'
2
+
3
+ export default class extends Controller {
4
+ static targets = [ "list" ]
5
+ connect() {
6
+ this.element.classList.add("twiddle")
7
+ }
8
+
9
+ toggle() {
10
+ this.element.classList.toggle("twiddle-open")
11
+ }
12
+ }
@@ -8,27 +8,23 @@ Blacklight.onLoad(function(){
8
8
  Blacklight.hierarchical_facet_expand_contract
9
9
  );
10
10
  }
11
- Blacklight.do_hierarchical_facet_expand_contract_behavior.selector = 'li.h-node';
11
+ Blacklight.do_hierarchical_facet_expand_contract_behavior.selector = '[data-controller="b-h-collapsible"]';
12
+ Blacklight.do_hierarchical_facet_expand_contract_behavior.handle = '[data-action="click->b-h-collapsible#toggle"]';
13
+ Blacklight.do_hierarchical_facet_expand_contract_behavior.list = '[data-b-h-collapsible-target="list"]';
12
14
 
13
15
  Blacklight.hierarchical_facet_expand_contract = function() {
14
16
  var li = $(this);
17
+ li.addClass('twiddle');
15
18
 
16
- $('ul', this).each(function() {
17
- li.addClass('twiddle');
18
- if($('span.selected', this).length == 0){
19
- $(this).hide();
20
- } else {
19
+ $(Blacklight.do_hierarchical_facet_expand_contract_behavior.list, this).each(function() {
20
+ if($('span.selected', this).length != 0){
21
21
  li.addClass('twiddle-open');
22
- li.children('.toggle-handle').attr('aria-expanded', 'true');
23
22
  }
24
23
  });
25
24
 
26
25
  // attach the toggle behavior to the li tag
27
- li.children('.toggle-handle').click(function(e){
28
- // toggle the content
29
- $(this).attr('aria-expanded', $(this).attr('aria-expanded') === 'true' ? 'false' : 'true');
30
- $(this).parent('li').toggleClass('twiddle-open');
31
- $(this).parent('li').children('ul').slideToggle();
26
+ li.children(Blacklight.do_hierarchical_facet_expand_contract_behavior.handle).click(function(e){
27
+ li.toggleClass('twiddle-open');
32
28
  });
33
29
  };
34
30
  })(jQuery);
@@ -1,5 +1,6 @@
1
- <li class="<%= li_class %>" role="treeitem">
2
- <%= helpers.facet_toggle_button(field_name, id) if subset.any? %>
1
+ <li class="<%= li_class %>" data-controller="<%= controller_name %>" role="treeitem">
2
+ <% ul_id = "b-h-#{SecureRandom.alphanumeric(10)}" %>
3
+ <%= helpers.facet_toggle_button(field_name, id, ul_id) if subset.any? %>
3
4
  <% if item.nil? %>
4
5
  <%= key %>
5
6
  <% elsif qfacet_selected? %>
@@ -9,7 +10,7 @@
9
10
  <% end %>
10
11
 
11
12
  <% unless subset.empty? %>
12
- <ul role=\"group\">
13
+ <ul id="<%= ul_id %>" class="collapse" data-b-h-collapsible-target="list" role=\"group\">
13
14
  <% subset.keys.sort.each do |subkey| %>
14
15
  <%= render self.class.new(field_name: field_name, tree: subset[subkey], key: subkey) %>
15
16
  <% end %>
@@ -20,6 +20,11 @@ module Blacklight
20
20
  subset.empty? ? 'h-leaf' : 'h-node'
21
21
  end
22
22
 
23
+ def controller_name
24
+ subset.empty? ? '' : 'b-h-collapsible'
25
+ end
26
+
27
+
23
28
  def item
24
29
  tree[:_]
25
30
  end
@@ -1,4 +1,5 @@
1
1
  <span class="selected"><%= render Blacklight::Hierarchy::QfacetValueComponent.new(field_name: field_name, item: item, suppress_link: true) %></span>
2
- <%= link_to remove_href, class: 'remove' do %>
3
- <span class="glyphicon glyphicon-remove"></span><span class="sr-only">[remove]</span>
2
+ <%= link_to(remove_href, class: 'remove') do %>
3
+ <span class="remove-icon" aria-hidden="true">✖</span>
4
+ <span class="sr-only"><%= t('blacklight.search.facets.selected.remove') %></span>
4
5
  <% end %>
@@ -1,17 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Blacklight::HierarchyHelper
4
- def facet_toggle_button(field_name, described_by)
4
+ def facet_toggle_button(field_name, described_by, controls)
5
5
  aria_label = I18n.t(
6
6
  "blacklight.hierarchy.#{field_name}_toggle_aria_label",
7
7
  default: :'blacklight.hierarchy.toggle_aria_label'
8
8
  )
9
9
 
10
10
  # For Rails 5.2 support all options must be symbols. See https://github.com/rails/rails/issues/39813
11
- tag.button(:'aria-expanded' => 'false',
12
- :'aria-label' => aria_label,
13
- :'aria-describedby' => described_by,
14
- class: 'toggle-handle') do
11
+ tag.button(aria: {
12
+ expanded: 'false',
13
+ label: aria_label,
14
+ describedby: described_by,
15
+ controls: controls
16
+ },
17
+ data: {
18
+ action: 'click->b-h-collapsible#toggle',
19
+ toggle: 'collapse',
20
+ target: "##{controls}"
21
+ },
22
+ class: 'toggle-handle') do
15
23
  tag.span(Blacklight::Hierarchy::Engine.config.closed_icon, :'aria-hidden' => 'true', class: 'closed') +
16
24
  tag.span(Blacklight::Hierarchy::Engine.config.opened_icon, :'aria-hidden' => 'true', class: 'opened')
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Hierarchy
3
- VERSION = '5.0.0'.freeze
3
+ VERSION = '5.1.0'.freeze
4
4
  end
5
5
  end
@@ -1 +1,9 @@
1
- //= require blacklight/hierarchy/hierarchy
1
+ //= require blacklight/hierarchy/hierarchy
2
+
3
+ // If you use Stimulus in your application you can remove the line above and require
4
+ // blacklight_hierarchy_controller instead:
5
+ //
6
+ // import BlacklightHierarchyController from 'blacklight-hierarchy/app/assets/javascripts/blacklight/hierarchy/blacklight_hierarchy_controller'
7
+ // import { Application } from 'stimulus'
8
+ // const application = Application.start()
9
+ // application.register("b-h-collapsible", BlacklightHierarchyController)
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blacklight-hierarchy",
3
- "version": "4.1.0",
3
+ "version": "5.1.0",
4
4
  "description": "[![Build Status](https://github.com/sul-dlss/blacklight-hierarchy/workflows/CI/badge.svg)](https://github.com/sul-dlss/blacklight-hierarchy/actions?query=branch%3Amain)",
5
5
  "main": "app/assets/javascripts/blacklight/hierarchy/hierarchy.js",
6
6
  "files": [
@@ -31,8 +31,8 @@ shared_examples 'catalog' do
31
31
 
32
32
  it 'should display the hierarchy' do
33
33
  visit '/'
34
- expect(page).to have_selector('li.h-node', text: 'a')
35
- expect(page).to have_selector('li.h-node > ul > li.h-node', text: 'b')
34
+ expect(page).to have_selector('li.h-node[data-controller="b-h-collapsible"]', text: 'a')
35
+ expect(page).to have_selector('li.h-node > ul > li.h-node[data-controller="b-h-collapsible"]', text: 'b')
36
36
  expect(page).to have_selector('li.h-node li.h-leaf', text: 'c 30')
37
37
  expect(page).to have_selector('li.h-node li.h-leaf', text: 'd 25')
38
38
  expect(page).to have_selector('li.h-node > ul > li.h-node', text: 'c')
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Blacklight::HierarchyHelper do
4
4
  describe '#facet_toggle_button' do
5
- subject { helper.facet_toggle_button(field_name, described_by) }
5
+ subject { helper.facet_toggle_button(field_name, described_by, 'randomtext123') }
6
6
  let(:field_name) { 'exploded_tag_ssim' }
7
7
  let(:described_by) { 'unique-string' }
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-hierarchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael B. Klein
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blacklight
@@ -159,6 +159,7 @@ files:
159
159
  - LICENSE
160
160
  - README.md
161
161
  - Rakefile
162
+ - app/assets/javascripts/blacklight/hierarchy/blacklight_hierarchy_controller.js
162
163
  - app/assets/javascripts/blacklight/hierarchy/hierarchy.js
163
164
  - app/assets/stylesheets/blacklight/hierarchy/hierarchy.scss
164
165
  - app/components/blacklight/hierarchy/facet_field_component.html.erb