blacklight_range_limit 8.4.0 → 9.0.0.beta1

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +117 -23
  3. data/.gitignore +2 -0
  4. data/.solr_wrapper.yml +8 -0
  5. data/Gemfile +7 -1
  6. data/README.md +77 -86
  7. data/Rakefile +31 -0
  8. data/VERSION +1 -1
  9. data/app/assets/javascripts/blacklight-range-limit/index.js +345 -0
  10. data/app/components/blacklight_range_limit/range_facet_component.html.erb +29 -27
  11. data/app/components/blacklight_range_limit/range_facet_component.rb +15 -9
  12. data/app/components/blacklight_range_limit/range_form_component.html.erb +13 -5
  13. data/app/components/blacklight_range_limit/range_form_component.rb +8 -20
  14. data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +13 -2
  15. data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +6 -11
  16. data/app/presenters/blacklight_range_limit/filter_field.rb +2 -2
  17. data/blacklight_range_limit.gemspec +1 -1
  18. data/config/importmap.rb +9 -0
  19. data/config/locales/blacklight_range_limit.ar.yml +13 -8
  20. data/config/locales/blacklight_range_limit.de.yml +13 -8
  21. data/config/locales/blacklight_range_limit.en.yml +5 -1
  22. data/config/locales/blacklight_range_limit.es.yml +18 -0
  23. data/config/locales/blacklight_range_limit.it.yml +13 -8
  24. data/lib/blacklight_range_limit/controller_override.rb +1 -25
  25. data/lib/blacklight_range_limit/engine.rb +48 -0
  26. data/lib/blacklight_range_limit/range_limit_builder.rb +40 -3
  27. data/lib/blacklight_range_limit.rb +8 -31
  28. data/lib/generators/blacklight_range_limit/assets_generator.rb +82 -18
  29. data/lib/generators/blacklight_range_limit/install_generator.rb +1 -1
  30. data/lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb +98 -0
  31. data/package-lock.json +51 -0
  32. data/package.json +10 -11
  33. data/spec/components/range_facet_component_spec.rb +41 -32
  34. data/spec/components/range_form_component_spec.rb +2 -2
  35. data/spec/components/range_segments_component_spec.rb +64 -0
  36. data/spec/features/blacklight_range_limit_spec.rb +21 -13
  37. data/spec/features/run_through_spec.rb +157 -0
  38. data/spec/presenters/facet_field_presenter_spec.rb +72 -0
  39. data/spec/presenters/filter_field_spec.rb +36 -1
  40. data/spec/spec_helper.rb +10 -0
  41. data/spec/test_app_templates/Gemfile.extra +11 -1
  42. data/spec/test_app_templates/lib/generators/test_app_generator.rb +37 -6
  43. metadata +26 -44
  44. data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +0 -77
  45. data/app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js +0 -185
  46. data/app/assets/javascripts/blacklight_range_limit/range_limit_shared.js +0 -73
  47. data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +0 -161
  48. data/app/assets/javascripts/blacklight_range_limit.js +0 -25
  49. data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +0 -60
  50. data/app/assets/stylesheets/blacklight_range_limit.css +0 -7
  51. data/app/helpers/range_limit_helper.rb +0 -130
  52. data/app/views/blacklight_range_limit/_range_segments.html.erb +0 -8
  53. data/app/views/blacklight_range_limit/range_segments.html.erb +0 -1
  54. data/app/views/catalog/range_limit_panel.html.erb +0 -1
  55. data/spec/features/a_javascript_spec.rb +0 -70
  56. data/spec/helpers/blacklight_range_limit_helper_spec.rb +0 -37
  57. data/vendor/assets/javascripts/bootstrap-slider.js +0 -388
  58. data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +0 -549
  59. data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +0 -199
  60. data/vendor/assets/javascripts/flot/jquery.event.drag.js +0 -145
  61. data/vendor/assets/javascripts/flot/jquery.flot.browser.js +0 -98
  62. data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +0 -662
  63. data/vendor/assets/javascripts/flot/jquery.flot.hover.js +0 -359
  64. data/vendor/assets/javascripts/flot/jquery.flot.js +0 -2818
  65. data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +0 -43
  66. data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -527
  67. data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +0 -10
  68. data/vendor/assets/stylesheets/slider.css +0 -138
@@ -3,19 +3,50 @@ require 'rails/generators'
3
3
  class TestAppGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path("../../../../spec/test_app_templates", __FILE__)
5
5
 
6
- # This is only necessary for Rails 3
7
- def remove_index
8
- remove_file "public/index.html"
6
+ # While blacklight works with jsbundling-rails (and vite-ruby with layout modification),
7
+ # it's generators can't set it up at present, we hackily do so.
8
+ def run_bl7_jsbundling_fixup
9
+ if File.exist?("package.json") && Blacklight::VERSION.split(".").first == "7"
10
+ say_status("warning", "BlacklightRangeLimit: Blacklight 7.x package.json-based Test App fixup", {color: :yellow})
11
+ generate "blacklight_range_limit:jsbundling_bl7_fixup"
12
+ end
13
+ end
14
+
15
+ def run_bl8_jsbundling_fixup
16
+ # while it's named confusingly, the BL8 assets:propshaft generator has what we need
17
+ # for jsbundling, I think.
18
+ if File.exist?("package.json") && Blacklight::VERSION.split(".").first == "8"
19
+ generate "blacklight:assets:propshaft"
20
+ end
9
21
  end
10
22
 
11
23
  def run_blacklight_generator
12
- say_status("warning", "GENERATING BL", :yellow)
24
+ say_status("warning", "GENERATING Blacklight", :yellow)
13
25
 
14
26
  generate 'blacklight:install', '--devise'
15
27
  end
16
28
 
29
+ def run_bl8_importmaps_fixup
30
+ # In BL8, if we have CSS-bundling rails but ALSO are using importmaps for JS, the BL8 installer
31
+ # gets us a LOT of the way there, but doesn't actually set up importmap pins for JS and needs
32
+ # some fixup. Maybe fixed in BL9? We fix up here if we are in that situation.
33
+ if Pathname(destination_root).join("config/importmap.rb").exist? && Blacklight::VERSION.split(".").first == "8"
34
+ # BL's importmap setup annoyingly uses a different name for the BL package than their package.json setup
35
+ gsub_file("app/javascript/application.js", 'import Blacklight from "blacklight-frontend";', 'import Blacklight from "blacklight";')
36
+
37
+ # these pins copied from BL8 ImportMapsGenerator
38
+ append_to_file 'config/importmap.rb' do
39
+ <<~CONTENT
40
+ pin "@github/auto-complete-element", to: "https://cdn.skypack.dev/@github/auto-complete-element"
41
+ pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.6/dist/umd/popper.min.js"
42
+ pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.3.2'}/dist/js/bootstrap.js"
43
+ CONTENT
44
+ end
45
+ end
46
+ end
47
+
17
48
  def run_blacklight_range_limit_generator
18
- say_status("warning", "GENERATING BL", :yellow)
49
+ say_status("warning", "GENERATING BlacklightRangeLimit", :yellow)
19
50
 
20
51
  generate 'blacklight_range_limit:install'
21
52
  end
@@ -27,7 +58,7 @@ class TestAppGenerator < Rails::Generators::Base
27
58
 
28
59
  def inject_into_catalog_controller
29
60
  inject_into_file 'app/controllers/catalog_controller.rb', after: /config.add_facet_field 'format'.*$/ do
30
- "\n config.add_facet_field 'pub_date_si', label: 'Publication Date Sort', **default_range_config"
61
+ "\n config.add_facet_field 'pub_date_si', label: 'Publication Date Sort', range: true"
31
62
  end
32
63
  end
33
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_range_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.4.0
4
+ version: 9.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-11-02 00:00:00.000000000 Z
12
+ date: 2024-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -51,20 +51,6 @@ dependencies:
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '4'
54
- - !ruby/object:Gem::Dependency
55
- name: deprecation
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- type: :runtime
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
54
  - !ruby/object:Gem::Dependency
69
55
  name: rspec
70
56
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +93,20 @@ dependencies:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
95
  version: '3'
96
+ - !ruby/object:Gem::Dependency
97
+ name: capybara-screenshot
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: sqlite3
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -193,31 +193,23 @@ files:
193
193
  - README.md
194
194
  - Rakefile
195
195
  - VERSION
196
- - app/assets/javascripts/blacklight_range_limit.js
197
- - app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js
198
- - app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js
199
- - app/assets/javascripts/blacklight_range_limit/range_limit_shared.js
200
- - app/assets/javascripts/blacklight_range_limit/range_limit_slider.js
201
- - app/assets/stylesheets/blacklight_range_limit.css
202
- - app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css
196
+ - app/assets/javascripts/blacklight-range-limit/index.js
203
197
  - app/components/blacklight_range_limit/range_facet_component.html.erb
204
198
  - app/components/blacklight_range_limit/range_facet_component.rb
205
199
  - app/components/blacklight_range_limit/range_form_component.html.erb
206
200
  - app/components/blacklight_range_limit/range_form_component.rb
207
201
  - app/components/blacklight_range_limit/range_segments_component.html.erb
208
202
  - app/components/blacklight_range_limit/range_segments_component.rb
209
- - app/helpers/range_limit_helper.rb
210
203
  - app/presenters/blacklight_range_limit/facet_field_presenter.rb
211
204
  - app/presenters/blacklight_range_limit/facet_item_presenter.rb
212
205
  - app/presenters/blacklight_range_limit/filter_field.rb
213
- - app/views/blacklight_range_limit/_range_segments.html.erb
214
- - app/views/blacklight_range_limit/range_segments.html.erb
215
- - app/views/catalog/range_limit_panel.html.erb
216
206
  - blacklight_range_limit.gemspec
207
+ - config/importmap.rb
217
208
  - config/jetty.yml
218
209
  - config/locales/blacklight_range_limit.ar.yml
219
210
  - config/locales/blacklight_range_limit.de.yml
220
211
  - config/locales/blacklight_range_limit.en.yml
212
+ - config/locales/blacklight_range_limit.es.yml
221
213
  - config/locales/blacklight_range_limit.it.yml
222
214
  - config/routes.rb
223
215
  - config/solr.yml
@@ -234,7 +226,9 @@ files:
234
226
  - lib/blacklight_range_limit/version.rb
235
227
  - lib/generators/blacklight_range_limit/assets_generator.rb
236
228
  - lib/generators/blacklight_range_limit/install_generator.rb
229
+ - lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb
237
230
  - lib/tasks/blacklight_range_limit.rake
231
+ - package-lock.json
238
232
  - package.json
239
233
  - solr/conf/_rest_managed.json
240
234
  - solr/conf/admin-extra.html
@@ -255,11 +249,11 @@ files:
255
249
  - solr/sample_solr_documents.yml
256
250
  - spec/components/range_facet_component_spec.rb
257
251
  - spec/components/range_form_component_spec.rb
258
- - spec/features/a_javascript_spec.rb
252
+ - spec/components/range_segments_component_spec.rb
259
253
  - spec/features/blacklight_range_limit_spec.rb
254
+ - spec/features/run_through_spec.rb
260
255
  - spec/fixtures/solr_documents/unknown_year.yml
261
256
  - spec/fixtures/solr_documents/zero_year.yml
262
- - spec/helpers/blacklight_range_limit_helper_spec.rb
263
257
  - spec/lib/blacklight_range_limit/segment_calculation_spec.rb
264
258
  - spec/presenters/facet_field_presenter_spec.rb
265
259
  - spec/presenters/facet_item_presenter_spec.rb
@@ -268,18 +262,6 @@ files:
268
262
  - spec/support/presenter_test_helpers.rb
269
263
  - spec/test_app_templates/Gemfile.extra
270
264
  - spec/test_app_templates/lib/generators/test_app_generator.rb
271
- - vendor/assets/javascripts/bootstrap-slider.js
272
- - vendor/assets/javascripts/flot/jquery.canvaswrapper.js
273
- - vendor/assets/javascripts/flot/jquery.colorhelpers.js
274
- - vendor/assets/javascripts/flot/jquery.event.drag.js
275
- - vendor/assets/javascripts/flot/jquery.flot.browser.js
276
- - vendor/assets/javascripts/flot/jquery.flot.drawSeries.js
277
- - vendor/assets/javascripts/flot/jquery.flot.hover.js
278
- - vendor/assets/javascripts/flot/jquery.flot.js
279
- - vendor/assets/javascripts/flot/jquery.flot.saturated.js
280
- - vendor/assets/javascripts/flot/jquery.flot.selection.js
281
- - vendor/assets/javascripts/flot/jquery.flot.uiConstants.js
282
- - vendor/assets/stylesheets/slider.css
283
265
  homepage: https://github.com/projectblacklight/blacklight_range_limit
284
266
  licenses:
285
267
  - Apache 2.0
@@ -299,18 +281,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
281
  - !ruby/object:Gem::Version
300
282
  version: '0'
301
283
  requirements: []
302
- rubygems_version: 3.4.21
284
+ rubygems_version: 3.5.9
303
285
  signing_key:
304
286
  specification_version: 4
305
287
  summary: Blacklight Range Limit plugin
306
288
  test_files:
307
289
  - spec/components/range_facet_component_spec.rb
308
290
  - spec/components/range_form_component_spec.rb
309
- - spec/features/a_javascript_spec.rb
291
+ - spec/components/range_segments_component_spec.rb
310
292
  - spec/features/blacklight_range_limit_spec.rb
293
+ - spec/features/run_through_spec.rb
311
294
  - spec/fixtures/solr_documents/unknown_year.yml
312
295
  - spec/fixtures/solr_documents/zero_year.yml
313
- - spec/helpers/blacklight_range_limit_helper_spec.rb
314
296
  - spec/lib/blacklight_range_limit/segment_calculation_spec.rb
315
297
  - spec/presenters/facet_field_presenter_spec.rb
316
298
  - spec/presenters/facet_item_presenter_spec.rb
@@ -1,77 +0,0 @@
1
- // for Blacklight.onLoad:
2
-
3
- /**
4
- * Closure functions in this file are mainly concerned with initializing, resizing, and updating
5
- * range limit functionality based off of page load, facet opening, page resizing, and otherwise
6
- * events.
7
- */
8
-
9
- Blacklight.onLoad(function() {
10
-
11
- // Facets already on the page? Turn em into a chart.
12
- $(".range_limit .profile .distribution.chart_js ul").each(function() {
13
- BlacklightRangeLimit.turnIntoPlot($(this).parent());
14
- });
15
-
16
- BlacklightRangeLimit.checkForNeededFacetsToFetch();
17
-
18
- // Listen for twitter bootstrap collapsible open events, to render flot
19
- // in previously hidden divs on open, if needed.
20
- $("body").on("show.bs.collapse", function(event) {
21
- // Was the target a .facet-content including a .chart-js?
22
- var container = $(event.target).filter(".facet-content").find(".chart_js");
23
-
24
- // only if it doesn't already have a canvas, it isn't already drawn
25
- if (container && container.find("canvas").length == 0) {
26
- // be willing to wait up to 1100ms for container to
27
- // have width -- right away on show.bs is too soon, but
28
- // shown.bs is later than we want, we want to start rendering
29
- // while animation is still in progress.
30
- BlacklightRangeLimit.turnIntoPlot(container, 1100);
31
- }
32
- });
33
-
34
- // Support for Blacklight 7 and 8:
35
- const modalSelector = Blacklight.modal?.modalSelector || Blacklight.Modal.modalSelector
36
-
37
- // When loaded in a modal
38
- $(modalSelector).on('shown.bs.modal', function() {
39
- $(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
40
- BlacklightRangeLimit.turnIntoPlot($(this).parent());
41
- });
42
-
43
- // Case when there is no currently selected range
44
- BlacklightRangeLimit.checkForNeededFacetsToFetch();
45
- });
46
-
47
- $("body").on("shown.bs.collapse", function(event) {
48
- var container = $(event.target).filter(".facet-content").find(".chart_js");
49
- BlacklightRangeLimit.redrawPlot(container);
50
- });
51
-
52
- // debouce borrowed from underscore
53
- // Returns a function, that, as long as it continues to be invoked, will not
54
- // be triggered. The function will be called after it stops being called for
55
- // N milliseconds. If `immediate` is passed, trigger the function on the
56
- // leading edge, instead of the trailing.
57
- const debounce = function(func, wait, immediate) {
58
- var timeout;
59
- return function() {
60
- var context = this, args = arguments;
61
- var later = function() {
62
- timeout = null;
63
- if (!immediate) func.apply(context, args);
64
- };
65
- var callNow = immediate && !timeout;
66
- clearTimeout(timeout);
67
- timeout = setTimeout(later, wait);
68
- if (callNow) func.apply(context, args);
69
- };
70
- };
71
-
72
- $(window).on("resize", debounce(function() {
73
- $(".chart_js").each(function(i, container) {
74
- BlacklightRangeLimit.redrawPlot($(container));
75
- });
76
- }, 350));
77
- });
@@ -1,185 +0,0 @@
1
- // second arg, if provided, is a number of ms we're willing to
2
- // wait for the container to have width before giving up -- we'll
3
- // set 50ms timers to check back until timeout is expired or the
4
- // container is finally visible. The timeout is used when we catch
5
- // bootstrap show event, but the animation hasn't barely begun yet -- but
6
- // we don't want to wait until it's finished, we want to start rendering
7
- // as soon as we can.
8
- //
9
- // We also will
10
- BlacklightRangeLimit.turnIntoPlot = function turnIntoPlot(container, wait_for_visible) {
11
- // flot can only render in a a div with a defined width.
12
- // for instance, a hidden div can't generally be rendered in (although if you set
13
- // an explicit width on it, it might work)
14
- //
15
- // We'll count on later code that catch bootstrap collapse open to render
16
- // on show, for currently hidden divs.
17
-
18
- // for some reason width sometimes return negative, not sure
19
- // why but it's some kind of hidden.
20
- if (container.width() > 0) {
21
- var height = container.width() * BlacklightRangeLimit.display_ratio;
22
-
23
- // Need an explicit height to make flot happy.
24
- container.height( height )
25
-
26
- BlacklightRangeLimit.areaChart($(container));
27
-
28
- $(container).trigger(BlacklightRangeLimit.redrawnEvent);
29
- }
30
- else if (wait_for_visible > 0) {
31
- setTimeout(function() {
32
- BlacklightRangeLimit.turnIntoPlot(container, wait_for_visible - 50);
33
- }, 50);
34
- }
35
- }
36
-
37
- BlacklightRangeLimit.parseSegment = function parseSegment(el) {
38
- if ($(el).find("span.single").first().data('blrlSingle')) {
39
- var val = BlacklightRangeLimit.parseNum($(el).find("span.single").first().data('blrlSingle'));
40
-
41
- return [val, val];
42
- } else {
43
- var from = BlacklightRangeLimit.parseNum($(el).find("span.from").first().data('blrlBegin'));
44
- var to = BlacklightRangeLimit.parseNum($(el).find("span.to").first().data('blrlEnd'));
45
-
46
- return [from, to];
47
- }
48
- }
49
-
50
- // Takes a div holding a ul of distribution segments produced by
51
- // blacklight_range_limit/_range_facets and makes it into
52
- // a flot area chart.
53
- BlacklightRangeLimit.areaChart = function areaChart(container) {
54
- //flot loaded? And canvas element supported.
55
- if ( BlacklightRangeLimit.domDependenciesMet() ) {
56
-
57
- // Grab the data from the ul div
58
- var series_data = new Array();
59
- var pointer_lookup = new Array();
60
- var x_ticks = new Array();
61
- var min = BlacklightRangeLimit.parseSegment($(container).find("ul li:first-child").first())[0];
62
- var max = BlacklightRangeLimit.parseSegment($(container).find("ul li:last-child").first())[1];
63
-
64
- $(container).find("ul li").each(function() {
65
- var segment = BlacklightRangeLimit.parseSegment(this);
66
- var from = segment[0];
67
- var to = segment[1];
68
-
69
- var count = BlacklightRangeLimit.parseNum($(this).find("span.facet-count,span.count").text());
70
- var avg = (count / (to - from + 1));
71
-
72
- //We use the avg as the y-coord, to make the area of each
73
- //segment proportional to how many documents it holds.
74
- series_data.push( [from, avg ] );
75
- series_data.push( [to+1, avg] );
76
-
77
- x_ticks.push(from);
78
-
79
- pointer_lookup.push({'from': from, 'to': to, 'count': count, 'label': $(this).find(".facet-select,.facet_select").html() });
80
- });
81
-
82
- x_ticks.push( max + 1 );
83
-
84
- var plot;
85
- var config = $(container).closest('.blrl-plot-config').data('plot-config') || $(container).closest('.facet-limit').data('plot-config') || {};
86
-
87
- try {
88
- plot = $.plot($(container), [series_data],
89
- $.extend(true, config, {
90
- yaxis: { ticks: [], min: 0, autoscaleMargin: 0.1},
91
- //xaxis: { ticks: x_ticks },
92
- xaxis: { tickDecimals: 0 }, // force integer ticks
93
- series: { lines: { fill: true, steps: true }},
94
- grid: {clickable: true, hoverable: true, autoHighlight: false, margin: { left: 0, right: 0 }},
95
- selection: {mode: "x"}
96
- }));
97
- }
98
- catch(err) {
99
- alert(err);
100
- }
101
-
102
- var find_segment_for = BlacklightRangeLimit.function_for_find_segment(pointer_lookup);
103
- var last_segment = null;
104
- $(container).tooltip({'html': true, 'placement': 'bottom', 'trigger': 'manual', 'delay': { show: 0, hide: 100}});
105
-
106
- $(container).bind("plothover", function (event, pos, item) {
107
- var segment = find_segment_for(pos.x);
108
-
109
- if(segment != last_segment) {
110
- var title = find_segment_for(pos.x).label + ' (' + BlacklightRangeLimit.parseNum(segment.count) + ')';
111
- $(container).attr("title", title).tooltip("_fixTitle").tooltip("show");
112
-
113
- last_segment = segment;
114
- }
115
- });
116
-
117
- $(container).bind("mouseout", function() {
118
- last_segment = null;
119
- $(container).tooltip('hide');
120
- });
121
- $(container).bind("plotclick", function (event, pos, item) {
122
- if ( plot.getSelection() == null) {
123
- segment = find_segment_for(pos.x);
124
- plot.setSelection(BlacklightRangeLimit.normalized_selection(segment.from, segment.to));
125
- }
126
- });
127
- $(container).bind("plotselected plotselecting", function(event, ranges) {
128
- if (ranges != null ) {
129
- var from = Math.floor(ranges.xaxis.from);
130
- var to = Math.floor(ranges.xaxis.to);
131
-
132
- var form = $(container).closest(".limit_content").find("form.range_limit");
133
- form.find("input.range_begin").val(from);
134
- form.find("input.range_end").val(to);
135
-
136
- var slider_placeholder = $(container).closest(".limit_content").find("[data-slider-placeholder]");
137
- if (slider_placeholder) {
138
- slider_placeholder.slider("setValue", [from, to]);
139
- }
140
- }
141
- });
142
-
143
- var form = $(container).closest(".limit_content").find("form.range_limit");
144
- form.find("input.range_begin, input.range_end").on('input', function () {
145
- plot.setSelection( BlacklightRangeLimit.form_selection(form, min, max), true );
146
- });
147
- $(container).closest(".limit_content").find(".profile .range").on("slide", function(event, ui) {
148
- var values = $(event.target).data("slider").getValue();
149
- form.find("input.range_begin").val(values[0]);
150
- form.find("input.range_end").val(values[1]);
151
- plot.setSelection(BlacklightRangeLimit.normalized_selection(values[0], Math.max(values[0], values[1])), true);
152
- });
153
-
154
- // initially entirely selected, to match slider
155
- plot.setSelection(BlacklightRangeLimit.normalized_selection(min, max));
156
- }
157
- }
158
-
159
- // after a collapsible facet contents is fully shown,
160
- // resize the flot chart to current conditions. This way, if you change
161
- // browser window size, you can get chart resized to fit by closing and opening
162
- // again, if needed.
163
- BlacklightRangeLimit.redrawPlot = function redrawPlot(container) {
164
- if (container && container.width() > 0) {
165
- // resize the container's height, since width may have changed.
166
- container.height( container.width() * BlacklightRangeLimit.display_ratio );
167
-
168
- // redraw the chart.
169
- var plot = container.data("plot");
170
- if (plot) {
171
- // how to redraw after possible resize?
172
- // Cribbed from https://github.com/flot/flot/blob/master/jquery.flot.resize.js
173
- plot.resize();
174
- plot.setupGrid();
175
- plot.draw();
176
- // plus trigger redraw of the selection, which otherwise ain't always right
177
- // we'll trigger a fake event on one of the boxes
178
- var form = $(container).closest(".limit_content").find("form.range_limit");
179
- form.find("input.range_begin").trigger("change");
180
-
181
- // send our custom event to trigger redraw of slider
182
- $(container).trigger(BlacklightRangeLimit.redrawnEvent);
183
- }
184
- }
185
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * BlacklightRangeLimit module setup.
3
- */
4
- 'use strict';
5
-
6
- const BlacklightRangeLimit = function (options) {
7
- this.options = options || {};
8
- }
9
-
10
- BlacklightRangeLimit.display_ratio = 1/(1.618 * 2); // half a golden rectangle, why not
11
- /* A custom event "plotDrawn.blacklight.rangeLimit" will be sent when flot plot
12
- is (re-)drawn on screen possibly with a new size. target of event will be the DOM element
13
- containing the plot. Used to resize slider to match. */
14
- BlacklightRangeLimit.redrawnEvent = "plotDrawn.blacklight.rangeLimit";
15
-
16
- // takes a string and parses into an integer, but throws away commas first, to avoid truncation when there is a comma
17
- // use in place of javascript's native parseInt
18
- BlacklightRangeLimit.parseNum = function parseNum(str) {
19
- str = String(str).replace(/[^0-9-]/g, '');
20
- return parseInt(str, 10);
21
- };
22
-
23
- BlacklightRangeLimit.form_selection = function form_selection(form, min, max) {
24
- var begin_val = BlacklightRangeLimit.parseNum($(form).find("input.range_begin").val());
25
- if (isNaN(begin_val) || begin_val < min) {
26
- begin_val = min;
27
- }
28
- var end_val = BlacklightRangeLimit.parseNum($(form).find("input.range_end").val());
29
- if (isNaN(end_val) || end_val > max) {
30
- end_val = max;
31
- }
32
-
33
- return BlacklightRangeLimit.normalized_selection(begin_val, end_val);
34
- }
35
-
36
- // Add AJAX fetched range facets if needed, and add a chart to em
37
- BlacklightRangeLimit.checkForNeededFacetsToFetch = function checkForNeededFacetsToFetch() {
38
- $(".range_limit .profile .distribution a.load_distribution").each(function() {
39
- var container = $(this).parent('div.distribution');
40
-
41
- $(container).load($(this).attr('href'), function(response, status) {
42
- if ($(container).hasClass("chart_js") && status == "success" ) {
43
- BlacklightRangeLimit.turnIntoPlot(container);
44
- }
45
- });
46
- });
47
- }
48
-
49
- BlacklightRangeLimit.function_for_find_segment = function function_for_find_segment(pointer_lookup_arr) {
50
- return function(x_coord) {
51
- for (var i = pointer_lookup_arr.length-1 ; i >= 0 ; i--) {
52
- var hash = pointer_lookup_arr[i];
53
- if (x_coord >= hash.from)
54
- return hash;
55
- }
56
- return pointer_lookup_arr[0];
57
- };
58
- }
59
-
60
- // Send endpoint to endpoint+0.99999 to have display
61
- // more closely approximate limiting behavior esp
62
- // at small resolutions. (Since we search on whole numbers,
63
- // inclusive, but flot chart is decimal.)
64
- BlacklightRangeLimit.normalized_selection = function normalized_selection(min, max) {
65
- max += 0.99999;
66
-
67
- return {xaxis: { 'from':min, 'to':max}}
68
- }
69
-
70
- // Check if Flot is loaded
71
- BlacklightRangeLimit.domDependenciesMet = function domDependenciesMet() {
72
- return typeof $.plot != "undefined"
73
- }