blacklight-hierarchy 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 301106611145298332bcd99baa46b594bb6e81cfbb91c67c144ad67ea82ffd4e
4
- data.tar.gz: 3de7c9ffe277ba90bc6e3cfd1518f0dd1b91234399c5de0bfa37ed821da23cf3
3
+ metadata.gz: 7f9ee155eb2b3ed03902a2de1322be9adcd84c8f976476c1531e10a2113ebe71
4
+ data.tar.gz: d43f7f0f8f2bd2180adfb39f98499c5ccb464c356b210c1083aea7d13fccb0fa
5
5
  SHA512:
6
- metadata.gz: 49ed3184d67352e89bcf78badd554617c9a8618f2bf0ddb4260ec68d43e003604b05b5874a19d2bf5d2d5ac59f0c555f302a6630dd4ca9258ca81269936095ac
7
- data.tar.gz: 33cff3c6d664380a251c8956f1de68be41c297067385babbd628b55e61a3e046adf8239a6b5ac04a6d33e861512a122c6601e8ffc9389e5b5e01b54b73e684de
6
+ metadata.gz: 924135616707307f18fd9411bf2ba6aee1c5a14eff9f5c79cacb86f5bdb4d04db81ed38357aa7cae95a2f855cb9ac3f0e67adf270e2df85d34e61de13cb471b4
7
+ data.tar.gz: 35415e9645e01d973adb5a9a7b65a50c276bb520d2d2c2f4efd913697ddc611b50576ded53a05ba8d1f7374f7fcf075fd393fc213bb4f604404e13be35e522b3
data/Gemfile CHANGED
@@ -31,6 +31,11 @@ else
31
31
  gem 'rails', ENV['RAILS_VERSION']
32
32
  end
33
33
  end
34
+
35
+ case ENV['RAILS_VERSION']
36
+ when /^5.[12]/, /^6.0/
37
+ gem 'sass-rails', '~> 5.0'
38
+ end
34
39
  end
35
40
  # END ENGINE_CART BLOCK
36
41
  eval_gemfile File.expand_path("spec/test_app_templates/Gemfile.extra", File.dirname(__FILE__))
data/README.md CHANGED
@@ -83,6 +83,29 @@ Facet fields should be added for each permutation of hierarchy key and term valu
83
83
  config.facet_display[:hierarchy].each{ |k,v| puts "#{k}_#{v}" }
84
84
  ```
85
85
 
86
+ ### Overriding the icon
87
+ The icon is available in an engine configuration. You can change them in an initializer in your app.
88
+
89
+ ```ruby
90
+ Blacklight::Hierarchy::Engine.config.closed_icon = '➕'
91
+ Blacklight::Hierarchy::Engine.config.opened_icon = '➖'
92
+
93
+ ```
94
+
95
+ ### Aria Labels
96
+ For screen reader purposes we have used "Toggle subgroup" as the aria-label attribute of the button. This is internationalized using rails' i18n feature.
97
+
98
+ The field name is used in the key to allow for facet specific aria labels or defaults back to the generic key/"Toggle subgroup" text.
99
+
100
+ ```yml
101
+ # config/locales/en.yml
102
+ en:
103
+ blacklight:
104
+ hierarchy:
105
+ format_ssim_toggle_aria_label: Toggle format section
106
+ toggle_aria_label: Toggle call number section
107
+ ```
108
+
86
109
  ## Caveats
87
110
 
88
111
  This code was ripped out of another project, and is still quite immature as a standalone project. Every effort has been made to make it as plug-and-play as possible, but it may stomp on Blacklight in unintended ways (e.g., ways that made sense in context of its former host app, but which aren't compatible with generic Blacklight). Proceed with caution, and report issues.
@@ -12,23 +12,23 @@ Blacklight.onLoad(function(){
12
12
 
13
13
  Blacklight.hierarchical_facet_expand_contract = function() {
14
14
  var li = $(this);
15
-
15
+
16
16
  $('ul', this).each(function() {
17
17
  li.addClass('twiddle');
18
18
  if($('span.selected', this).length == 0){
19
19
  $(this).hide();
20
20
  } else {
21
21
  li.addClass('twiddle-open');
22
+ li.children('.toggle-handle').attr('aria-expanded', 'true');
22
23
  }
23
24
  });
24
25
 
25
26
  // attach the toggle behavior to the li tag
26
- li.click(function(e){
27
- if (e.target == this) {
28
- // toggle the content
29
- $(this).toggleClass('twiddle-open');
30
- $(this).children('ul').slideToggle();
31
- }
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();
32
32
  });
33
33
  };
34
34
  })(jQuery);
@@ -1,23 +1,63 @@
1
- $text-muted: #777777 !default;
1
+ $text-muted: #777 !default;
2
2
 
3
3
  .facet-hierarchy {
4
- margin-left: -28px;
4
+ list-style-type: none;
5
+ padding-left: 0;
5
6
 
6
7
  ul {
7
- margin-left: 0;
8
- border-bottom: none;
8
+ border-bottom: 0;
9
+ list-style-type: none;
9
10
  padding-bottom: 0;
10
- li {
11
- margin-left: 8px;
11
+ padding-left: 1.3em;
12
+ }
13
+
14
+ .facet_select {
15
+ display: inline-block;
16
+ margin-bottom: 6px;
17
+ max-width: calc(100% - 5em);
18
+ }
19
+
20
+ .facet-count {
21
+ float: right;
22
+ }
23
+
24
+ .toggle-handle {
25
+ border: 0;
26
+ margin: 0;
27
+ min-width: 1em;
28
+ padding: 0;
29
+ vertical-align: top;
30
+
31
+ .closed,
32
+ .opened {
33
+ display: none;
12
34
  }
13
35
  }
36
+
37
+ .twiddle>.toggle-handle .closed {
38
+ display: inline;
39
+ }
40
+
41
+ .twiddle>.toggle-handle .opened {
42
+ display: none;
43
+ }
44
+
45
+ .twiddle-open>.toggle-handle .closed {
46
+ display: none;
47
+ }
48
+
49
+ .twiddle-open>.toggle-handle .opened {
50
+ display: inline;
51
+ }
52
+
53
+ .h-leaf {
54
+ padding-left: 1.3em;
55
+ }
56
+
14
57
  .h-node {
15
58
  cursor: pointer;
16
- list-style-image: asset_data_url("collapsed.png")
17
- }
18
- .h-node.twiddle-open {
19
- list-style-image: asset_data_url("expanded.png");
20
59
  }
60
+
21
61
  .remove {
22
62
  color: $text-muted;
23
63
  }
@@ -7,23 +7,26 @@ module Blacklight::HierarchyHelper
7
7
  subset = data.reject { |k, _v| !k.is_a?(String) }
8
8
 
9
9
  li_class = subset.empty? ? 'h-leaf' : 'h-node'
10
+ id = SecureRandom.uuid
10
11
  ul = ''
11
- li = if item.nil?
12
- key
13
- elsif facet_in_params?(field_name, item.qvalue)
14
- render_selected_qfacet_value(field_name, item)
15
- else
16
- render_qfacet_value(field_name, item)
17
- end
12
+ li = ''
13
+ li << facet_toggle_button(field_name, id) if subset.any?
14
+ li << if item.nil?
15
+ key
16
+ elsif facet_in_params?(field_name, item.qvalue)
17
+ render_selected_qfacet_value(field_name, item)
18
+ else
19
+ render_qfacet_value(field_name, item, id: id)
20
+ end
18
21
 
19
22
  unless subset.empty?
20
23
  subul = subset.keys.sort.collect do |subkey|
21
24
  render_facet_hierarchy_item(field_name, subset[subkey], subkey)
22
25
  end.join('')
23
- ul = "<ul>#{subul}</ul>".html_safe
26
+ ul = "<ul role=\"group\">#{subul}</ul>".html_safe
24
27
  end
25
28
 
26
- %(<li class="#{li_class}">#{li.html_safe}#{ul.html_safe}</li>).html_safe
29
+ %(<li class="#{li_class}" role="treeitem">#{li.html_safe}#{ul.html_safe}</li>).html_safe
27
30
  end
28
31
 
29
32
  # @param [Blacklight::Configuration::FacetField] as defined in controller with config.add_facet_field (and with :partial => 'blacklight/hierarchy/facet_hierarchy')
@@ -41,7 +44,8 @@ module Blacklight::HierarchyHelper
41
44
  end
42
45
 
43
46
  def render_qfacet_value(facet_solr_field, item, options = {})
44
- (link_to_unless(options[:suppress_link], item.value, path_for_facet(facet_solr_field, item.qvalue), class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe
47
+ id = options.delete(:id)
48
+ (link_to_unless(options[:suppress_link], item.value, path_for_facet(facet_solr_field, item.qvalue), id: id, class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe
45
49
  end
46
50
 
47
51
  # Standard display of a SELECTED facet value, no link, special span with class, and 'remove' button.
@@ -100,6 +104,24 @@ module Blacklight::HierarchyHelper
100
104
  @facet_tree[hkey]
101
105
  end
102
106
 
107
+ def facet_toggle_button(field_name, described_by)
108
+ aria_label = I18n.t(
109
+ "blacklight.hierarchy.#{field_name}_toggle_aria_label",
110
+ default: :'blacklight.hierarchy.toggle_aria_label'
111
+ )
112
+ <<-HTML
113
+ <button
114
+ aria-expanded="false"
115
+ aria-label="#{aria_label}"
116
+ aria-describedby="#{described_by}"
117
+ class="toggle-handle"
118
+ >
119
+ <span aria-hidden="true" class="closed">#{Blacklight::Hierarchy::Engine.config.closed_icon}</span>
120
+ <span aria-hidden="true" class="opened">#{Blacklight::Hierarchy::Engine.config.opened_icon}</span>
121
+ </button>
122
+ HTML
123
+ end
124
+
103
125
  # --------------------------------------------------------------------------------------------------------------------------------
104
126
  # below are methods pertaining to the "rotate" notion where you may want to look at the same tree data organized another way
105
127
  # --------------------------------------------------------------------------------------------------------------------------------
@@ -1,3 +1,3 @@
1
- <ul class="facet-hierarchy">
1
+ <ul class="facet-hierarchy" role="tree">
2
2
  <%= render_hierarchy(facet_field) %>
3
3
  </ul>
@@ -18,9 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_dependency 'rails', '>= 4.1', '< 6'
21
+ # Most likely available for even earlier versions of Blacklight, but this is what I validated
22
+ s.add_dependency 'blacklight', '> 6.20', '< 8.0'
23
+ s.add_dependency 'rails', '>= 5.1', '< 7'
22
24
  s.add_dependency 'jquery-rails'
23
- s.add_dependency 'blacklight', '~> 7.0'
24
25
 
25
26
  s.add_development_dependency 'rsolr'
26
27
  s.add_development_dependency 'rspec-rails'
@@ -0,0 +1,4 @@
1
+ en:
2
+ blacklight:
3
+ hierarchy:
4
+ toggle_aria_label: Toggle subgroup
@@ -4,6 +4,8 @@ require 'rails'
4
4
  module Blacklight
5
5
  module Hierarchy
6
6
  class Engine < Rails::Engine
7
+ config.closed_icon = '⊞'
8
+ config.opened_icon = '⊟'
7
9
  end
8
10
  end
9
11
  end
@@ -1,5 +1,5 @@
1
1
  module Blacklight
2
2
  module Hierarchy
3
- VERSION = '3.0.0'.freeze
3
+ VERSION = '4.0.0'.freeze
4
4
  end
5
5
  end
@@ -17,4 +17,12 @@ class TestAppGenerator < Rails::Generators::Base
17
17
  def run_hierarchy_install
18
18
  generate 'blacklight_hierarchy:install'
19
19
  end
20
+
21
+ def create_images_directory
22
+ run 'mkdir app/assets/images'
23
+ end
24
+
25
+ def add_js_reference
26
+ inject_into_file 'app/assets/config/manifest.js', "\n//= link application.js", after: '//= link_directory ../stylesheets .css'
27
+ end
20
28
  end
metadata CHANGED
@@ -1,63 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-hierarchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.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: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: blacklight
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '6.20'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6'
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
27
+ - - ">"
28
28
  - !ruby/object:Gem::Version
29
- version: '4.1'
29
+ version: '6.20'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6'
32
+ version: '8.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: jquery-rails
34
+ name: rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '5.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '7'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
47
  - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: '0'
49
+ version: '5.1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7'
47
53
  - !ruby/object:Gem::Dependency
48
- name: blacklight
54
+ name: jquery-rails
49
55
  requirement: !ruby/object:Gem::Requirement
50
56
  requirements:
51
- - - "~>"
57
+ - - ">="
52
58
  - !ruby/object:Gem::Version
53
- version: '7.0'
59
+ version: '0'
54
60
  type: :runtime
55
61
  prerelease: false
56
62
  version_requirements: !ruby/object:Gem::Requirement
57
63
  requirements:
58
- - - "~>"
64
+ - - ">="
59
65
  - !ruby/object:Gem::Version
60
- version: '7.0'
66
+ version: '0'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: rsolr
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -159,14 +165,12 @@ files:
159
165
  - LICENSE
160
166
  - README.md
161
167
  - Rakefile
162
- - app/assets/images/collapsed.png
163
- - app/assets/images/expanded.png
164
168
  - app/assets/javascripts/blacklight/hierarchy/hierarchy.js
165
169
  - app/assets/stylesheets/blacklight/hierarchy/hierarchy.scss
166
170
  - app/helpers/blacklight/hierarchy_helper.rb
167
171
  - app/views/blacklight/hierarchy/_facet_hierarchy.html.erb
168
- - app/views/blacklight/hierarchy/_facet_hierarchy_item.html.erb
169
172
  - blacklight-hierarchy.gemspec
173
+ - config/locales/blacklight-hierarchy.en.yml
170
174
  - lib/blacklight-hierarchy.rb
171
175
  - lib/blacklight/hierarchy.rb
172
176
  - lib/blacklight/hierarchy/engine.rb
@@ -1,25 +0,0 @@
1
- <%
2
- item = data[:_]
3
- subset = data.reject { |k,v| ! k.is_a?(String) }
4
- %>
5
-
6
- <li class="<%= subset.empty? ? 'h-leaf' : 'h-node' %>">
7
- <% if item.nil? %>
8
- <%= key %>
9
- <% else %>
10
- <% if facet_in_params?(field_name, item.qvalue) %>
11
- <%= render_selected_qfacet_value( field_name, item )%>
12
- <% else %>
13
- <%= render_qfacet_value(field_name, item) %>
14
- <% end %>
15
- <% end %>
16
- <% unless subset.empty? %>
17
- <ul>
18
- <%=
19
- raw(subset.keys.sort.collect { |subkey|
20
- render :partial => 'facet_hierarchy_item', :locals => { :field_name => field_name, :data => subset[subkey], :key => subkey }
21
- })
22
- %>
23
- </ul>
24
- <% end %>
25
- </li>