File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
app/assets/javascripts/blacklight_oembed
lib/generators/blacklight_oembed/templates Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
- //= require 'blacklight_oembed/jquery. oembed.js '
1
+ import oembed from 'blacklight_oembed/oembed'
2
2
3
3
Blacklight . onLoad ( function ( ) {
4
- $ ( '[data-embed-url]' ) . oEmbed ( ) ;
5
- } ) ;
4
+ oembed ( document . querySelectorAll ( '[data-embed-url]' ) ) ;
5
+ } ) ;
You can’t perform that action at this time.
0 commit comments