Skip to content

Commit

Permalink
FEATURE: Load jQuery if not present
Browse files Browse the repository at this point in the history
Dynamically loads jQuery if it is not already present when the script
loads. This makes using the plugin easier on pages that do not already
load jQuery in their head.
  • Loading branch information
Johannes Hertenstein committed Mar 11, 2020
1 parent e41c20d commit 4c844fb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Resources/Public/js/cachevisualisation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$(document).ready(function () {

function initialize() {
$('div[data-vivomedia-cache-visualisation]').hover(
function() {
var container = $( this );
Expand Down Expand Up @@ -33,4 +32,15 @@ $(document).ready(function () {
}
});
});
})
}

if (window.$) {
$(document).ready(initialize);
} else {
var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
script.setAttribute('integrity', 'sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=');
script.setAttribute('crossorigin', 'anonymous');
script.addEventListener('load', initialize);
document.head.appendChild(script);
}

0 comments on commit 4c844fb

Please sign in to comment.