Skip to content

Commit

Permalink
Merge pull request #251 from projectblacklight/extract-blacklight
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo committed Feb 2, 2024
2 parents 3de6a19 + 9d750f7 commit 65d2b14
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/blacklight_range_limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@
//= require 'blacklight_range_limit/range_limit_plotting'
//= require 'blacklight_range_limit/range_limit_slider'
//= require 'blacklight_range_limit/range_limit_distro_facets'

Blacklight.onLoad(function() {
// Support for Blacklight 7 and 8:
modalSelector = Blacklight.modal?.modalSelector || Blacklight.Modal.modalSelector
BlacklightRangeLimit.initializeDistroFacets(modalSelector)
BlacklightRangeLimit.initializeSlider(modalSelector)
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// for Blacklight.onLoad:

/**
* Closure functions in this file are mainly concerned with initializing, resizing, and updating
* range limit functionality based off of page load, facet opening, page resizing, and otherwise
* events.
*/

Blacklight.onLoad(function() {

BlacklightRangeLimit.initializeDistroFacets = function(modalSelector) {
// Facets already on the page? Turn em into a chart.
$(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
Expand All @@ -32,7 +29,7 @@ Blacklight.onLoad(function() {
});

// For Blacklight version < 8, when loaded in a modal
$(BlacklightRangeLimit.modalSelector).on('shown.bs.modal', function() {
$(modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
});
Expand All @@ -42,7 +39,7 @@ Blacklight.onLoad(function() {
});

// Use a mutation observer to detect when the HTML dialog is open
BlacklightRangeLimit.initPlotModalObserver();
BlacklightRangeLimit.initPlotModalObserver(modalSelector);

$("body").on("shown.bs.collapse", function(event) {
var container = $(event.target).filter(".facet-content").find(".chart_js");
Expand Down Expand Up @@ -74,4 +71,4 @@ Blacklight.onLoad(function() {
BlacklightRangeLimit.redrawPlot($(container));
});
}, 350));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,32 @@ BlacklightRangeLimit.domDependenciesMet = function domDependenciesMet() {
return typeof $.plot != "undefined"
}

// Support for Blacklight 7 and 8:
BlacklightRangeLimit.modalSelector = Blacklight.modal?.modalSelector || Blacklight.Modal.modalSelector

BlacklightRangeLimit.modalObserverConfig = {
attributes: true,
}

BlacklightRangeLimit.initSliderModalObserver = function() {
BlacklightRangeLimit.initSliderModalObserver = function(modalSelector) {
// Use a mutation observer to detect when the modal dialog is open
const modalObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName !== 'open') {return;}
if (mutation.target.hasAttribute('open')) {
$(BlacklightRangeLimit.modalSelector).find(".range_limit .profile .range.slider_js").each(function() {
$(modalSelector).find(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});
}
});
});
modalObserver.observe($(BlacklightRangeLimit.modalSelector)[0], BlacklightRangeLimit.modalObserverConfig);
modalObserver.observe(document.querySelector(modalSelector), BlacklightRangeLimit.modalObserverConfig);
}

BlacklightRangeLimit.initPlotModalObserver = function() {
BlacklightRangeLimit.initPlotModalObserver = function(modalSelector) {
// Use a mutation observer to detect when the modal dialog is open
const modalObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName !== 'open') {return;}
if (mutation.target.hasAttribute('open')) {
$(BlacklightRangeLimit.modalSelector).find(".range_limit .profile .distribution.chart_js ul").each(function() {
$(modalSelector).find(".range_limit .profile .distribution.chart_js ul").each(function() {
BlacklightRangeLimit.turnIntoPlot($(this).parent());
});

Expand All @@ -109,5 +106,5 @@ BlacklightRangeLimit.initPlotModalObserver = function() {
}
});
});
modalObserver.observe($(BlacklightRangeLimit.modalSelector)[0], BlacklightRangeLimit.modalObserverConfig);
modalObserver.observe(document.querySelector(modalSelector), BlacklightRangeLimit.modalObserverConfig);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// for Blacklight.onLoad:

Blacklight.onLoad(function() {
BlacklightRangeLimit.initializeSlider = function(modalSelector) {

$(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});

// For Blacklight < 8, when loaded in a modal
$(BlacklightRangeLimit.modalSelector).on('shown.bs.modal', function() {
$(modalSelector).on('shown.bs.modal', function() {
$(this).find(".range_limit .profile .range.slider_js").each(function() {
BlacklightRangeLimit.buildSlider(this);
});
});

// For Blacklight 8, use a mutation observer to detect when the HTML dialog is open
BlacklightRangeLimit.initSliderModalObserver();
BlacklightRangeLimit.initSliderModalObserver(modalSelector);

// catch event for redrawing chart, to redraw slider to match width
$("body").on("plotDrawn.blacklight.rangeLimit", function(event) {
Expand All @@ -27,7 +27,7 @@ Blacklight.onLoad(function() {
slider_el.css("display", "block")
}
});
});
}

// returns two element array min/max as numbers. If there is a limit applied,
// it's boundaries are are limits. Otherwise, min/max in current result
Expand Down

0 comments on commit 65d2b14

Please sign in to comment.