Skip to content

Commit 69f7a25

Browse files
authored
Merge pull request #19 from projectblacklight/without-jquery
Remove jquery dependency
2 parents aa25888 + 4584c94 commit 69f7a25

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default function oEmbed(elements) {
2+
if (!elements) return;
3+
4+
// Ensure elements is an array-like collection
5+
elements = elements instanceof NodeList ? Array.from(elements) : [elements];
6+
7+
elements.forEach(function(embedViewer) {
8+
const embedURL = embedViewer.dataset.embedUrl; // Get the embed URL from the data attribute
9+
10+
if (!embedURL) return;
11+
12+
// Fetch JSON data from the embed URL
13+
fetch(embedURL)
14+
.then(response => {
15+
if (!response.ok) {
16+
throw new Error('Network response was not ok');
17+
}
18+
return response.json();
19+
})
20+
.then(data => {
21+
if (data === null) {
22+
return;
23+
}
24+
// Set the inner HTML of the element
25+
embedViewer.innerHTML = data.html;
26+
})
27+
.catch(error => {
28+
console.error('Error fetching embed data:', error);
29+
});
30+
});
31+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//= require 'blacklight_oembed/jquery.oembed.js'
1+
import oembed from 'blacklight_oembed/oembed'
22

33
Blacklight.onLoad(function() {
4-
$('[data-embed-url]').oEmbed();
5-
});
4+
oembed(document.querySelectorAll('[data-embed-url]'));
5+
});

0 commit comments

Comments
 (0)