Skip to content

Commit

Permalink
Validate URLs on load
Browse files Browse the repository at this point in the history
  • Loading branch information
dlh01 committed Nov 27, 2024
1 parent dc1da65 commit 0a5da8b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions assets/js/cover-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,27 @@

// Set up URL validation for video URLs.
(function () {
var $videoInputs = $( '[name="apple_news_cover_video_url"], [name="apple_news_cover_embedwebvideo_url"]' );

$videoInputs.on( 'input', function () {
var input = $( this ),
$container = input.closest( '.apple-news-cover-media-provider-container' ),
$notice = $container.find( '.notice' ),
options;

options = {
path: '/apple-news/v1/is-valid-cover-media',
data: {
url: input.val(),
type: $container.data( 'provider' ),
},
var $videoInputs = $( '[name="apple_news_cover_video_url"], [name="apple_news_cover_embedwebvideo_url"]' ),
validateVideoUrl = function () {
var input = $(this),
$container = input.closest('.apple-news-cover-media-provider-container'),
$notice = $container.find('.notice'),
options;

options = {
path: '/apple-news/v1/is-valid-cover-media',
data: {
url: input.val(),
type: $container.data('provider'),
},
};

wp.apiRequest(options).done(function (response) {
$notice.toggle(!response.isValidCoverMedia);
});
};

wp.apiRequest(options).done( function( response ) {
$notice.toggle( ! response.isValidCoverMedia );
} );

} );
$videoInputs.each( validateVideoUrl );
$videoInputs.on( 'input', validateVideoUrl );
})();
})( jQuery, window );

0 comments on commit 0a5da8b

Please sign in to comment.