blacklight_range_limit 8.5.0 → 9.0.0.beta2

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +117 -26
  3. data/.gitignore +2 -1
  4. data/.solr_wrapper.yml +8 -0
  5. data/Gemfile +7 -1
  6. data/README.md +84 -87
  7. data/Rakefile +69 -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 +27 -9
  12. data/app/components/blacklight_range_limit/range_form_component.html.erb +23 -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 +15 -11
  16. data/app/presenters/blacklight_range_limit/filter_field.rb +9 -3
  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/doc/example-screenshot.png +0 -0
  25. data/lib/blacklight_range_limit/controller_override.rb +8 -35
  26. data/lib/blacklight_range_limit/engine.rb +48 -0
  27. data/lib/blacklight_range_limit/range_limit_builder.rb +61 -3
  28. data/lib/blacklight_range_limit.rb +10 -30
  29. data/lib/generators/blacklight_range_limit/assets_generator.rb +82 -18
  30. data/lib/generators/blacklight_range_limit/install_generator.rb +5 -2
  31. data/lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb +98 -0
  32. data/package-lock.json +8 -7
  33. data/package.json +10 -14
  34. data/spec/components/range_facet_component_spec.rb +101 -32
  35. data/spec/components/range_form_component_spec.rb +2 -2
  36. data/spec/components/range_segments_component_spec.rb +64 -0
  37. data/spec/features/blacklight_range_limit_spec.rb +21 -13
  38. data/spec/features/run_through_spec.rb +210 -0
  39. data/spec/presenters/facet_field_presenter_spec.rb +72 -0
  40. data/spec/presenters/filter_field_spec.rb +36 -1
  41. data/spec/requests/bad_param_requests_spec.rb +61 -0
  42. data/spec/spec_helper.rb +10 -0
  43. data/spec/test_app_templates/Gemfile.extra +11 -1
  44. data/spec/test_app_templates/lib/generators/test_app_generator.rb +37 -6
  45. metadata +27 -51
  46. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.esm.js +0 -534
  47. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.esm.js.map +0 -1
  48. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.umd.js +0 -542
  49. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.umd.js.map +0 -1
  50. data/app/assets/javascripts/blacklight_range_limit.js +0 -27
  51. data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +0 -60
  52. data/app/assets/stylesheets/blacklight_range_limit.css +0 -7
  53. data/app/helpers/range_limit_helper.rb +0 -130
  54. data/app/javascript/blacklight_range_limit/index.js +0 -11
  55. data/app/javascript/blacklight_range_limit/range_limit_distro_facets.js +0 -76
  56. data/app/javascript/blacklight_range_limit/range_limit_plotting.js +0 -186
  57. data/app/javascript/blacklight_range_limit/range_limit_shared.js +0 -112
  58. data/app/javascript/blacklight_range_limit/range_limit_slider.js +0 -163
  59. data/app/javascripts/blacklight_range_limit/index.js +0 -13
  60. data/app/views/blacklight_range_limit/_range_segments.html.erb +0 -8
  61. data/app/views/blacklight_range_limit/range_segments.html.erb +0 -1
  62. data/app/views/catalog/range_limit_panel.html.erb +0 -1
  63. data/rollup.config.js +0 -37
  64. data/spec/features/a_javascript_spec.rb +0 -70
  65. data/spec/helpers/blacklight_range_limit_helper_spec.rb +0 -37
  66. data/vendor/assets/javascripts/bootstrap-slider.js +0 -388
  67. data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +0 -549
  68. data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +0 -199
  69. data/vendor/assets/javascripts/flot/jquery.event.drag.js +0 -145
  70. data/vendor/assets/javascripts/flot/jquery.flot.browser.js +0 -98
  71. data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +0 -662
  72. data/vendor/assets/javascripts/flot/jquery.flot.hover.js +0 -359
  73. data/vendor/assets/javascripts/flot/jquery.flot.js +0 -2818
  74. data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +0 -43
  75. data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -527
  76. data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +0 -10
  77. data/vendor/assets/stylesheets/slider.css +0 -138
@@ -1,60 +0,0 @@
1
- form.range_limit {
2
- /* leave room for buttons not to collide on line wrap */
3
- line-height: 3;
4
- }
5
-
6
- .range_limit .range-limit-input-group {
7
- max-width: 350px;
8
- width: 100% !important;
9
- }
10
-
11
- .range_limit input.range_begin, .range_limit input.range_end {
12
- display: inline-block;
13
- width: 4.5em;
14
- }
15
-
16
- .limit_content .subsection {
17
- margin-top: 0.5em;
18
- }
19
-
20
- .hover_legend {
21
- padding: 0.25em;
22
- }
23
-
24
- .slider_js .slider-selection {
25
- /* color from flot selection */
26
- background: #e8cfac;
27
- }
28
-
29
- .slider_js .slider-horizontal {
30
- margin-left: 5px;
31
- margin-right: 5px;
32
- }
33
-
34
- .chart_js .flot-x-axis {
35
- font-size: 14px;
36
- }
37
-
38
- .modal-body .view_larger {
39
- display: none;
40
- }
41
-
42
- /* Prevent an unstyled flash of content for values we'll replace with a chart */
43
- .js .distribution .facet-values {
44
- display: none;
45
- }
46
-
47
- .modal-body .range_limit {
48
- justify-content: center;
49
- }
50
-
51
- .view_larger {
52
- display: block;
53
- text-align: center;
54
- }
55
-
56
- .range_limit .chart_js {
57
- min-height: 80px;
58
- margin-left: -12px;
59
- margin-right: -14px;
60
- }
@@ -1,7 +0,0 @@
1
- /* Master manifest file for engine, so local app can require
2
- * this one file, but get all our files -- and local app
3
- * require does not need to change if we change file list.
4
- *
5
- *= require 'slider'
6
- *= require_tree './blacklight_range_limit'
7
- */
@@ -1,130 +0,0 @@
1
- module RangeLimitHelper
2
- extend Deprecation
3
-
4
- def range_limit_url(options = {})
5
- main_app.url_for(search_state.to_h.merge(action: 'range_limit').merge(options))
6
- end
7
- deprecation_deprecate :range_limit_url
8
-
9
- def range_limit_panel_url(options = {})
10
- search_facet_path(id: options[:id])
11
- end
12
- deprecation_deprecate :range_limit_panel_url
13
-
14
- # type is 'begin' or 'end'
15
- def render_range_input(solr_field, type, input_label = nil, maxlength=4)
16
- range_form_component(solr_field).render_range_input(type, input_label, maxlength)
17
- end
18
- deprecation_deprecate :render_range_input
19
-
20
- # type is 'min' or 'max'
21
- # Returns smallest and largest value in current result set, if available
22
- # from stats component response.
23
- def range_results_endpoint(solr_field, type)
24
- presenter = range_facet_field_presenter(solr_field)
25
-
26
- case type.to_s
27
- when 'min'
28
- presenter.min
29
- when 'max'
30
- presenter.max
31
- end
32
- end
33
- deprecation_deprecate :range_results_endpoint
34
-
35
- def range_display(solr_field, my_params = params)
36
- facet_config = blacklight_config.facet_fields[solr_field]
37
- presenter = range_facet_field_presenter(solr_field)
38
- return unless presenter.selected_range
39
-
40
- facet_item = Blacklight::Solr::Response::Facets::FacetItem.new(value: presenter.selected_range, hits: presenter.response.total)
41
-
42
- facet_config.item_presenter.new(facet_item, facet_config, self, solr_field).label
43
- end
44
- deprecation_deprecate :range_display
45
-
46
- ##
47
- # A method that is meant to be overridden downstream to format how a range
48
- # label might be displayed to a user. By default it just returns the value
49
- # as rendered by the presenter
50
- def format_range_display_value(value, solr_field)
51
- Deprecation.warn(RangeLimitHelper, 'Helper #format_range_display_value is deprecated without replacement')
52
- facet_item_presenter(facet_configuration_for_field(solr_field), value, solr_field).label
53
- end
54
-
55
- # Show the limit area if:
56
- # 1) we have a limit already set
57
- # OR
58
- # 2) stats show max > min, OR
59
- # 3) count > 0 if no stats available.
60
- def should_show_limit(solr_field)
61
- presenter = range_facet_field_presenter(solr_field)
62
-
63
- presenter.selected_range ||
64
- (presenter.max && presenter.min && presenter.max > presenter.min) ||
65
- @response.total.positive?
66
- end
67
-
68
- def stats_for_field(solr_field)
69
- range_facet_field_presenter(solr_field).send(:stats_for_field)
70
- end
71
- deprecation_deprecate :stats_for_field
72
-
73
- def stats_for_field?(solr_field)
74
- stats_for_field(solr_field).present?
75
- end
76
- deprecation_deprecate :stats_for_field?
77
-
78
- def add_range_missing(solr_field, my_params = params)
79
- Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).add(Blacklight::SearchState::FilterField::MISSING)
80
- end
81
- deprecation_deprecate :add_range_missing
82
-
83
- def add_range(solr_field, from, to, my_params = params)
84
- Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).add(from..to)
85
- end
86
- deprecation_deprecate :add_range
87
-
88
- def has_selected_range_limit?(solr_field)
89
- range_facet_field_presenter(solr_field).selected_range.present?
90
- end
91
- deprecation_deprecate :has_selected_range_limit?
92
-
93
- def selected_missing_for_range_limit?(solr_field)
94
- search_state.filter(solr_field).values.first == Blacklight::SearchState::FilterField::MISSING
95
- end
96
- deprecation_deprecate :selected_missing_for_range_limit?
97
-
98
- def remove_range_param(solr_field, my_params = params)
99
- Blacklight::SearchState.new(my_params.except(:page), blacklight_config).filter(solr_field).remove(0..0)
100
- end
101
-
102
- # Looks in the solr @response for ["facet_counts"]["facet_queries"][solr_field], for elements
103
- # expressed as "solr_field:[X to Y]", turns them into
104
- # a list of hashes with [:from, :to, :count], sorted by
105
- # :from. Assumes integers for sorting purposes.
106
- def solr_range_queries_to_a(solr_field)
107
- range_facet_field_presenter(solr_field).range_queries.map do |item|
108
- { from: item.value.first, to: item.value.last, count: item.hits }
109
- end
110
- end
111
- deprecation_deprecate :solr_range_queries_to_a
112
-
113
- def range_config(solr_field)
114
- BlacklightRangeLimit.range_config(blacklight_config, solr_field)
115
- end
116
- deprecation_deprecate :range_config
117
-
118
- private
119
-
120
- def range_facet_field_presenter(key)
121
- facet_config = blacklight_config.facet_fields[key] || Blacklight::Configuration::FacetField.new(key: key, **BlacklightRangeLimit.default_range_config)
122
- facet_field_presenter(facet_config, Blacklight::Solr::Response::Facets::FacetField.new(key, [], response: @response))
123
- end
124
-
125
- def range_form_component(key)
126
- presenter = range_facet_field_presenter(key)
127
-
128
- BlacklightRangeLimit::RangeFormComponent.new(facet_field: presenter)
129
- end
130
- end
@@ -1,11 +0,0 @@
1
- import BlacklightRangeLimit from 'range_limit_shared'
2
- import 'range_limit_plotting'
3
- import 'range_limit_distro_facets'
4
- import 'range_limit_slider'
5
-
6
- BlacklightRangeLimit.initialize = function(modalSelector) {
7
- BlacklightRangeLimit.initializeDistroFacets(modalSelector)
8
- BlacklightRangeLimit.initializeSlider(modalSelector)
9
- }
10
-
11
- export default BlacklightRangeLimit
@@ -1,76 +0,0 @@
1
- /**
2
- * Closure functions in this file are mainly concerned with initializing, resizing, and updating
3
- * range limit functionality based off of page load, facet opening, page resizing, and otherwise
4
- * events.
5
- */
6
-
7
- import BlacklightRangeLimit from 'range_limit_shared'
8
-
9
- BlacklightRangeLimit.initializeDistroFacets = function(modalSelector) {
10
- // Facets already on the page? Turn em into a chart.
11
- $(".range_limit .profile .distribution.chart_js ul").each(function() {
12
- BlacklightRangeLimit.turnIntoPlot($(this).parent());
13
- });
14
-
15
- BlacklightRangeLimit.checkForNeededFacetsToFetch();
16
-
17
- // Listen for twitter bootstrap collapsible open events, to render flot
18
- // in previously hidden divs on open, if needed.
19
- $("body").on("show.bs.collapse", function(event) {
20
- // Was the target a .facet-content including a .chart-js?
21
- var container = $(event.target).filter(".facet-content").find(".chart_js");
22
-
23
- // only if it doesn't already have a canvas, it isn't already drawn
24
- if (container && container.find("canvas").length == 0) {
25
- // be willing to wait up to 1100ms for container to
26
- // have width -- right away on show.bs is too soon, but
27
- // shown.bs is later than we want, we want to start rendering
28
- // while animation is still in progress.
29
- BlacklightRangeLimit.turnIntoPlot(container, 1100);
30
- }
31
- });
32
-
33
- // For Blacklight version < 8, when loaded in a modal
34
- $(modalSelector).on('shown.bs.modal', function() {
35
- $(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
36
- BlacklightRangeLimit.turnIntoPlot($(this).parent());
37
- });
38
-
39
- // Case when there is no currently selected range
40
- BlacklightRangeLimit.checkForNeededFacetsToFetch();
41
- });
42
-
43
- // Use a mutation observer to detect when the HTML dialog is open
44
- BlacklightRangeLimit.initPlotModalObserver(modalSelector);
45
-
46
- $("body").on("shown.bs.collapse", function(event) {
47
- var container = $(event.target).filter(".facet-content").find(".chart_js");
48
- BlacklightRangeLimit.redrawPlot(container);
49
- });
50
-
51
- // debouce borrowed from underscore
52
- // Returns a function, that, as long as it continues to be invoked, will not
53
- // be triggered. The function will be called after it stops being called for
54
- // N milliseconds. If `immediate` is passed, trigger the function on the
55
- // leading edge, instead of the trailing.
56
- const debounce = function(func, wait, immediate) {
57
- var timeout;
58
- return function() {
59
- var context = this, args = arguments;
60
- var later = function() {
61
- timeout = null;
62
- if (!immediate) func.apply(context, args);
63
- };
64
- var callNow = immediate && !timeout;
65
- clearTimeout(timeout);
66
- timeout = setTimeout(later, wait);
67
- if (callNow) func.apply(context, args);
68
- };
69
- };
70
-
71
- $(window).on("resize", debounce(function() {
72
- $(".chart_js").each(function(i, container) {
73
- BlacklightRangeLimit.redrawPlot($(container));
74
- });
75
- }, 350));
76
- }
@@ -1,186 +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
- import BlacklightRangeLimit from 'range_limit_shared'
10
-
11
- BlacklightRangeLimit.turnIntoPlot = function turnIntoPlot(container, wait_for_visible) {
12
- // flot can only render in a a div with a defined width.
13
- // for instance, a hidden div can't generally be rendered in (although if you set
14
- // an explicit width on it, it might work)
15
- //
16
- // We'll count on later code that catch bootstrap collapse open to render
17
- // on show, for currently hidden divs.
18
-
19
- // for some reason width sometimes return negative, not sure
20
- // why but it's some kind of hidden.
21
- if (container.width() > 0) {
22
- var height = container.width() * BlacklightRangeLimit.display_ratio;
23
-
24
- // Need an explicit height to make flot happy.
25
- container.height( height )
26
-
27
- BlacklightRangeLimit.areaChart($(container));
28
-
29
- $(container).trigger(BlacklightRangeLimit.redrawnEvent);
30
- }
31
- else if (wait_for_visible > 0) {
32
- setTimeout(function() {
33
- BlacklightRangeLimit.turnIntoPlot(container, wait_for_visible - 50);
34
- }, 50);
35
- }
36
- }
37
-
38
- BlacklightRangeLimit.parseSegment = function parseSegment(el) {
39
- if ($(el).find("span.single").first().data('blrlSingle')) {
40
- var val = BlacklightRangeLimit.parseNum($(el).find("span.single").first().data('blrlSingle'));
41
-
42
- return [val, val];
43
- } else {
44
- var from = BlacklightRangeLimit.parseNum($(el).find("span.from").first().data('blrlBegin'));
45
- var to = BlacklightRangeLimit.parseNum($(el).find("span.to").first().data('blrlEnd'));
46
-
47
- return [from, to];
48
- }
49
- }
50
-
51
- // Takes a div holding a ul of distribution segments produced by
52
- // blacklight_range_limit/_range_facets and makes it into
53
- // a flot area chart.
54
- BlacklightRangeLimit.areaChart = function areaChart(container) {
55
- //flot loaded? And canvas element supported.
56
- if ( BlacklightRangeLimit.domDependenciesMet() ) {
57
-
58
- // Grab the data from the ul div
59
- var series_data = new Array();
60
- var pointer_lookup = new Array();
61
- var x_ticks = new Array();
62
- var min = BlacklightRangeLimit.parseSegment($(container).find("ul li:first-child").first())[0];
63
- var max = BlacklightRangeLimit.parseSegment($(container).find("ul li:last-child").first())[1];
64
-
65
- $(container).find("ul li").each(function() {
66
- var segment = BlacklightRangeLimit.parseSegment(this);
67
- var from = segment[0];
68
- var to = segment[1];
69
-
70
- var count = BlacklightRangeLimit.parseNum($(this).find("span.facet-count,span.count").text());
71
- var avg = (count / (to - from + 1));
72
-
73
- //We use the avg as the y-coord, to make the area of each
74
- //segment proportional to how many documents it holds.
75
- series_data.push( [from, avg ] );
76
- series_data.push( [to+1, avg] );
77
-
78
- x_ticks.push(from);
79
-
80
- pointer_lookup.push({'from': from, 'to': to, 'count': count, 'label': $(this).find(".facet-select,.facet_select").html() });
81
- });
82
-
83
- x_ticks.push( max + 1 );
84
-
85
- var plot;
86
- var config = $(container).closest('.blrl-plot-config').data('plot-config') || $(container).closest('.facet-limit').data('plot-config') || {};
87
-
88
- try {
89
- plot = $.plot($(container), [series_data],
90
- $.extend(true, config, {
91
- yaxis: { ticks: [], min: 0, autoscaleMargin: 0.1},
92
- //xaxis: { ticks: x_ticks },
93
- xaxis: { tickDecimals: 0 }, // force integer ticks
94
- series: { lines: { fill: true, steps: true }},
95
- grid: {clickable: true, hoverable: true, autoHighlight: false, margin: { left: 0, right: 0 }},
96
- selection: {mode: "x"}
97
- }));
98
- }
99
- catch(err) {
100
- alert(err);
101
- }
102
-
103
- var find_segment_for = BlacklightRangeLimit.function_for_find_segment(pointer_lookup);
104
- var last_segment = null;
105
- $(container).tooltip({'html': true, 'placement': 'bottom', 'trigger': 'manual', 'delay': { show: 0, hide: 100}});
106
-
107
- $(container).bind("plothover", function (event, pos, item) {
108
- var segment = find_segment_for(pos.x);
109
-
110
- if(segment != last_segment) {
111
- var title = find_segment_for(pos.x).label + ' (' + BlacklightRangeLimit.parseNum(segment.count) + ')';
112
- $(container).attr("title", title).tooltip("_fixTitle").tooltip("show");
113
-
114
- last_segment = segment;
115
- }
116
- });
117
-
118
- $(container).bind("mouseout", function() {
119
- last_segment = null;
120
- $(container).tooltip('hide');
121
- });
122
- $(container).bind("plotclick", function (event, pos, item) {
123
- if ( plot.getSelection() == null) {
124
- segment = find_segment_for(pos.x);
125
- plot.setSelection(BlacklightRangeLimit.normalized_selection(segment.from, segment.to));
126
- }
127
- });
128
- $(container).bind("plotselected plotselecting", function(event, ranges) {
129
- if (ranges != null ) {
130
- var from = Math.floor(ranges.xaxis.from);
131
- var to = Math.floor(ranges.xaxis.to);
132
-
133
- var form = $(container).closest(".limit_content").find("form.range_limit");
134
- form.find("input.range_begin").val(from);
135
- form.find("input.range_end").val(to);
136
-
137
- var slider_placeholder = $(container).closest(".limit_content").find("[data-slider-placeholder]");
138
- if (slider_placeholder) {
139
- slider_placeholder.slider("setValue", [from, to]);
140
- }
141
- }
142
- });
143
-
144
- var form = $(container).closest(".limit_content").find("form.range_limit");
145
- form.find("input.range_begin, input.range_end").on('input', function () {
146
- plot.setSelection( BlacklightRangeLimit.form_selection(form, min, max), true );
147
- });
148
- $(container).closest(".limit_content").find(".profile .range").on("slide", function(event, ui) {
149
- var values = $(event.target).data("slider").getValue();
150
- form.find("input.range_begin").val(values[0]);
151
- form.find("input.range_end").val(values[1]);
152
- plot.setSelection(BlacklightRangeLimit.normalized_selection(values[0], Math.max(values[0], values[1])), true);
153
- });
154
-
155
- // initially entirely selected, to match slider
156
- plot.setSelection(BlacklightRangeLimit.normalized_selection(min, max));
157
- }
158
- }
159
-
160
- // after a collapsible facet contents is fully shown,
161
- // resize the flot chart to current conditions. This way, if you change
162
- // browser window size, you can get chart resized to fit by closing and opening
163
- // again, if needed.
164
- BlacklightRangeLimit.redrawPlot = function redrawPlot(container) {
165
- if (container && container.width() > 0) {
166
- // resize the container's height, since width may have changed.
167
- container.height( container.width() * BlacklightRangeLimit.display_ratio );
168
-
169
- // redraw the chart.
170
- var plot = container.data("plot");
171
- if (plot) {
172
- // how to redraw after possible resize?
173
- // Cribbed from https://github.com/flot/flot/blob/master/jquery.flot.resize.js
174
- plot.resize();
175
- plot.setupGrid();
176
- plot.draw();
177
- // plus trigger redraw of the selection, which otherwise ain't always right
178
- // we'll trigger a fake event on one of the boxes
179
- var form = $(container).closest(".limit_content").find("form.range_limit");
180
- form.find("input.range_begin").trigger("change");
181
-
182
- // send our custom event to trigger redraw of slider
183
- $(container).trigger(BlacklightRangeLimit.redrawnEvent);
184
- }
185
- }
186
- }
@@ -1,112 +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
- }
74
-
75
- BlacklightRangeLimit.modalObserverConfig = {
76
- attributes: true,
77
- }
78
-
79
- BlacklightRangeLimit.initSliderModalObserver = function(modalSelector) {
80
- // Use a mutation observer to detect when the modal dialog is open
81
- const modalObserver = new MutationObserver(function(mutations) {
82
- mutations.forEach(function(mutation) {
83
- if (mutation.attributeName !== 'open') {return;}
84
- if (mutation.target.hasAttribute('open')) {
85
- $(modalSelector).find(".range_limit .profile .range.slider_js").each(function() {
86
- BlacklightRangeLimit.buildSlider(this);
87
- });
88
- }
89
- });
90
- });
91
- modalObserver.observe(document.querySelector(modalSelector), BlacklightRangeLimit.modalObserverConfig);
92
- }
93
-
94
- BlacklightRangeLimit.initPlotModalObserver = function(modalSelector) {
95
- // Use a mutation observer to detect when the modal dialog is open
96
- const modalObserver = new MutationObserver(function(mutations) {
97
- mutations.forEach(function(mutation) {
98
- if (mutation.attributeName !== 'open') {return;}
99
- if (mutation.target.hasAttribute('open')) {
100
- $(modalSelector).find(".range_limit .profile .distribution.chart_js ul").each(function() {
101
- BlacklightRangeLimit.turnIntoPlot($(this).parent());
102
- });
103
-
104
- // Case when there is no currently selected range
105
- BlacklightRangeLimit.checkForNeededFacetsToFetch();
106
- }
107
- });
108
- });
109
- modalObserver.observe(document.querySelector(modalSelector), BlacklightRangeLimit.modalObserverConfig);
110
- }
111
-
112
- export default BlacklightRangeLimit