Skip to content

Commit

Permalink
🐛 Fix JavaScript issues caused by double jquery
Browse files Browse the repository at this point in the history
This commit will copy over the exact implementation of the range limit
js files and move it to the bottom of the page.  We are doing this
because in v7.0.1 (which is the highest version we can upgrade to) there
is a require of jquery in their manifest.  This is causing a double
loading of jquery which then causes issues.
  • Loading branch information
kirkkwang committed Feb 28, 2024
1 parent 0fe9a3a commit aa6cb1e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
14 changes: 10 additions & 4 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
//= require jquery3
//= require jquery_ujs
//= require jquery.fontselect
//= require flot/jquery.flot.js
//= require flot/jquery.flot.selection.js
//= require bootstrap-slider
//= require bootstrap/tooltip
//= require_tree ./blacklight_range_limit
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require stat_slider
Expand Down Expand Up @@ -55,3 +51,13 @@
//= require statistics_tab_manager
//= require blacklight_gallery/default
//= require allinson_flex/application

// This is required for the Blacklight Range Limit gem v7.0.1
//
// We copied all the js over in the ./blacklight_range_limit because
// In the gem, there is a `//= require 'jquery'` in the `blacklight_range_limit.js`
// that double loads jquery which causes issues beacuse we are using jquery3 in this project.
//= require flot/jquery.flot.js
//= require flot/jquery.flot.selection.js
//= require bootstrap-slider
//= require_tree ./blacklight_range_limit
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// for Blacklight.onLoad:

/* A custom event "plotDrawn.blacklight.rangeLimit" will be sent when flot plot
is (re-)drawn on screen possibly with a new size. target of event will be the DOM element
containing the plot. Used to resize slider to match. */

$(document).on('turbolinks:load', function() {
// ratio of width to height for desired display, multiply width by this ratio
// to get height. hard-coded in for now.
var display_ratio = 1/(1.618 * 2); // half a golden rectangle, why not
var redrawnEvent = "plotDrawn.blacklight.rangeLimit";
Blacklight.onLoad(function() {
// ratio of width to height for desired display, multiply width by this ratio
// to get height. hard-coded in for now.
var display_ratio = 1/(1.618 * 2); // half a golden rectangle, why not
var redrawnEvent = "plotDrawn.blacklight.rangeLimit";



Expand Down Expand Up @@ -294,4 +296,4 @@ $(document).on('turbolinks:load', function() {

return (flotLoaded && canvasAvailable);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
this.options = options || {};
}

BlacklightRangeLimit.noConflict = function noConflict() {
global.BlacklightRangeLimit = previousBlacklightRangeLimit;
return BlacklightRangeLimit;
};

BlacklightRangeLimit.parseNum = function parseNum(str) {
str = String(str).replace(/[^0-9]/g, '');
return parseInt(str, 10);
};

BlacklightRangeLimit.noConflict = function noConflict() {
global.BlacklightRangeLimit = previousBlacklightRangeLimit;
return BlacklightRangeLimit;
};

global.BlacklightRangeLimit = BlacklightRangeLimit;
}(this);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// for Blacklight.onLoad:

$(document).on('turbolinks:load', function() {
Blacklight.onLoad(function() {

$(".range_limit .profile .range.slider_js").each(function() {
var range_element = $(this);

Expand Down

0 comments on commit aa6cb1e

Please sign in to comment.