Make WordPress Core

Ticket #41052: 41052.3.diff

File 41052.3.diff, 2.9 KB (added by westonruter, 7 years ago)
  • src/wp-admin/js/widgets/media-widgets.js

    diff --git src/wp-admin/js/widgets/media-widgets.js src/wp-admin/js/widgets/media-widgets.js
    index ad21e37a7e..a76ad1bdce 100644
    wp.mediaWidgets = ( function( $ ) { 
    8484         */
    8585        component.MediaEmbedView = wp.media.view.Embed.extend({
    8686
     87                /**
     88                 * Initialize.
     89                 *
     90                 * @param {object} options - Options.
     91                 * @returns {void}
     92                 */
     93                initialize: function( options ) {
     94                        var embedController;
     95                        wp.media.view.Embed.prototype.initialize.call( this, options );
     96                        if ( 'image' !== this.controller.options.mimeType ) {
     97                                embedController = this.controller.states.get( 'embed' );
     98                                embedController.off( 'scan', embedController.scanImage, embedController );
     99                        }
     100                },
     101
    87102                /**
    88103                 * Refresh embed view.
    89104                 *
    wp.mediaWidgets = ( function( $ ) { 
    139154                                                }
    140155                                        },
    141156
     157                                        /**
     158                                         * Update oEmbed.
     159                                         *
     160                                         * @returns {void}
     161                                         */
     162                                        updateoEmbed: function() {
     163                                                var embedLinkView = this, url; // eslint-disable-line consistent-this
     164                                                wp.media.view.EmbedLink.prototype.updateoEmbed.call( embedLinkView );
     165
     166                                                url = embedLinkView.model.get( 'url' );
     167
     168                                                if ( url && ! embedLinkView.isValidUrl( url ) ) {
     169                                                        $( '#embed-url-field' ).addClass( 'invalid' );
     170                                                        embedLinkView.setAddToWidgetButtonDisabled( true );
     171                                                }
     172                                        },
     173
     174                                        /**
     175                                         * Determine if embed URL has more than 11 characters (e.g. http://a.io) and looks like a URL.
     176                                         *
     177                                         * @param {string} url - URL.
     178                                         * @returns {boolean} Is valid URL.
     179                                         */
     180                                        isValidUrl: function( url ) {
     181                                                return url.match( /^(http|https):\/\/.+\// );
     182                                        },
     183
    142184                                        /**
    143185                                         * Fetch media.
    144186                                         *
    wp.mediaWidgets = ( function( $ ) { 
    146188                                         */
    147189                                        fetch: function() {
    148190                                                var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url, re, youTubeEmbedMatch; // eslint-disable-line consistent-this
     191                                                url = embedLinkView.model.get( 'url' );
    149192
    150193                                                if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) {
    151194                                                        embedLinkView.dfd.abort();
    152195                                                }
    153196
    154197                                                // Abort if the URL field was emptied out.
    155                                                 if ( ! embedLinkView.model.get( 'url' ) ) {
     198                                                if ( ! url ) {
    156199                                                        embedLinkView.setErrorNotice( '' );
    157200                                                        return;
    158201                                                }
    wp.mediaWidgets = ( function( $ ) { 
    170213                                                };
    171214
    172215                                                urlParser = document.createElement( 'a' );
    173                                                 urlParser.href = embedLinkView.model.get( 'url' );
     216                                                urlParser.href = url;
    174217                                                matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ );
    175218                                                if ( matches ) {
    176219                                                        fileExt = matches[1];
    wp.mediaWidgets = ( function( $ ) { 
    185228                                                }
    186229
    187230                                                // Support YouTube embed links.
    188                                                 url = embedLinkView.model.get( 'url' );
    189231                                                re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
    190232                                                youTubeEmbedMatch = re.exec( url );
    191233                                                if ( youTubeEmbedMatch ) {