Make WordPress Core

Changeset 41179


Ignore:
Timestamp:
07/28/2017 02:35:56 AM (9 years ago)
Author:
westonruter
Message:

Media: Improve acceptance of YouTube /embed/ URLs when inserting in media modal.

Props timmydcrawford.
Fixes #41201.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/widgets/media-widgets.js

    r40941 r41179  
    146146                                         */
    147147                                        fetch: function() {
    148                                                 var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser; // eslint-disable-line consistent-this
     148                                                var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url, re, youTubeEmbedMatch; // eslint-disable-line consistent-this
    149149
    150150                                                if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) {
    … …  
    191191                                                }
    192192
     193                                                // Support YouTube embed links.
     194                                                url = embedLinkView.model.get( 'url' );
     195                                                re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
     196                                                youTubeEmbedMatch = re.exec( url );
     197                                                if ( youTubeEmbedMatch ) {
     198                                                        url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
     199                                                        // silently change url to proper oembed-able version.
     200                                                        embedLinkView.model.attributes.url = url;
     201                                                }
     202
    193203                                                embedLinkView.dfd = $.ajax({
    194204                                                        url: wp.media.view.settings.oEmbedProxyUrl,
    195205                                                        data: {
    196                                                                 url: embedLinkView.model.get( 'url' ),
     206                                                                url: url,
    197207                                                                maxwidth: embedLinkView.model.get( 'width' ),
    198208                                                                maxheight: embedLinkView.model.get( 'height' ),
  • trunk/src/wp-includes/js/media-views.js

    r41009 r41179  
    46254625
    46264626        fetch: function() {
     4627                var url = this.model.get( 'url' ), re, youTubeEmbedMatch;
    46274628
    46284629                // check if they haven't typed in 500 ms
    4629                 if ( $('#embed-url-field').val() !== this.model.get('url') ) {
     4630                if ( $('#embed-url-field').val() !== url ) {
    46304631                        return;
    46314632                }
    … …  
    46334634                if ( this.dfd && 'pending' === this.dfd.state() ) {
    46344635                        this.dfd.abort();
     4636                }
     4637
     4638                // Support YouTube embed urls, since they work once in the editor.
     4639                re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
     4640                youTubeEmbedMatch = re.exec( url );
     4641                if ( youTubeEmbedMatch ) {
     4642                        url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
    46354643                }
    46364644
    … …  
    46384646                        url: wp.media.view.settings.oEmbedProxyUrl,
    46394647                        data: {
    4640                                 url: this.model.get( 'url' ),
     4648                                url: url,
    46414649                                maxwidth: this.model.get( 'width' ),
    46424650                                maxheight: this.model.get( 'height' ),
  • trunk/src/wp-includes/js/media/views/embed/link.js

    r40628 r41179  
    3636
    3737        fetch: function() {
     38                var url = this.model.get( 'url' ), re, youTubeEmbedMatch;
    3839
    3940                // check if they haven't typed in 500 ms
    40                 if ( $('#embed-url-field').val() !== this.model.get('url') ) {
     41                if ( $('#embed-url-field').val() !== url ) {
    4142                        return;
    4243                }
    … …  
    4647                }
    4748
     49                // Support YouTube embed urls, since they work once in the editor.
     50                re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/;
     51                youTubeEmbedMatch = re.exec( url );
     52                if ( youTubeEmbedMatch ) {
     53                        url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
     54                }
     55
    4856                this.dfd = $.ajax({
    4957                        url: wp.media.view.settings.oEmbedProxyUrl,
    5058                        data: {
    51                                 url: this.model.get( 'url' ),
     59                                url: url,
    5260                                maxwidth: this.model.get( 'width' ),
    5361                                maxheight: this.model.get( 'height' ),
Note: See TracChangeset for help on using the changeset viewer.