-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from projectblacklight/without-jquery
Remove jquery dependency
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default function oEmbed(elements) { | ||
if (!elements) return; | ||
|
||
// Ensure elements is an array-like collection | ||
elements = elements instanceof NodeList ? Array.from(elements) : [elements]; | ||
|
||
elements.forEach(function(embedViewer) { | ||
const embedURL = embedViewer.dataset.embedUrl; // Get the embed URL from the data attribute | ||
|
||
if (!embedURL) return; | ||
|
||
// Fetch JSON data from the embed URL | ||
fetch(embedURL) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
if (data === null) { | ||
return; | ||
} | ||
// Set the inner HTML of the element | ||
embedViewer.innerHTML = data.html; | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching embed data:', error); | ||
}); | ||
}); | ||
} |
6 changes: 3 additions & 3 deletions
6
lib/generators/blacklight_oembed/templates/blacklight_oembed.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//= require 'blacklight_oembed/jquery.oembed.js' | ||
import oembed from 'blacklight_oembed/oembed' | ||
|
||
Blacklight.onLoad(function() { | ||
$('[data-embed-url]').oEmbed(); | ||
}); | ||
oembed(document.querySelectorAll('[data-embed-url]')); | ||
}); |