oembed.js (845B)
1 ( function ( $, _, rwmb ) { 2 'use strict'; 3 4 /** 5 * Show preview of oembeded media. 6 */ 7 function showPreview( e ) { 8 e.preventDefault(); 9 10 var $this = $( this ), 11 $spinner = $this.siblings( '.spinner' ), 12 data = { 13 action: 'rwmb_get_embed', 14 url: this.value, 15 not_available: $this.data( 'not-available' ), 16 }; 17 18 $spinner.css( 'visibility', 'visible' ); 19 $.post( ajaxurl, data, function ( response ) { 20 $spinner.css( 'visibility', 'hidden' ); 21 $this.siblings( '.rwmb-embed-media' ).html( response.data ); 22 }, 'json' ); 23 } 24 25 /** 26 * Remove oembed preview when cloning. 27 */ 28 function removePreview() { 29 $( this ).siblings( '.rwmb-embed-media' ).html( '' ); 30 } 31 32 rwmb.$document 33 .on( 'change', '.rwmb-oembed', _.debounce( showPreview, 250 ) ) 34 .on( 'clone', '.rwmb-oembed', removePreview ); 35 } )( jQuery, _, rwmb );