diff --git src/wp-admin/js/widgets/media-widgets.js src/wp-admin/js/widgets/media-widgets.js
index ad21e37a7e..efcbc2a26c 100644
|
|
|
wp.mediaWidgets = ( function( $ ) { |
| 84 | 84 | */ |
| 85 | 85 | component.MediaEmbedView = wp.media.view.Embed.extend({ |
| 86 | 86 | |
| | 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 | |
| 87 | 102 | /** |
| 88 | 103 | * Refresh embed view. |
| 89 | 104 | * |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 139 | 154 | } |
| 140 | 155 | }, |
| 141 | 156 | |
| | 157 | /** |
| | 158 | * Update oEmbed. |
| | 159 | * |
| | 160 | * @returns {void} |
| | 161 | */ |
| | 162 | updateoEmbed: function() { |
| | 163 | var embedLinkView = this, url; // eslint-disable-line consistent-this |
| | 164 | |
| | 165 | url = embedLinkView.model.get( 'url' ); |
| | 166 | |
| | 167 | // Abort if the URL field was emptied out. |
| | 168 | if ( ! url ) { |
| | 169 | embedLinkView.setErrorNotice( '' ); |
| | 170 | embedLinkView.setAddToWidgetButtonDisabled( true ); |
| | 171 | return; |
| | 172 | } |
| | 173 | |
| | 174 | if ( ! url.match( /^(http|https):\/\/.+\// ) ) { |
| | 175 | $( '#embed-url-field' ).addClass( 'invalid' ); |
| | 176 | embedLinkView.setAddToWidgetButtonDisabled( true ); |
| | 177 | } |
| | 178 | |
| | 179 | wp.media.view.EmbedLink.prototype.updateoEmbed.call( embedLinkView ); |
| | 180 | }, |
| | 181 | |
| 142 | 182 | /** |
| 143 | 183 | * Fetch media. |
| 144 | 184 | * |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 146 | 186 | */ |
| 147 | 187 | fetch: function() { |
| 148 | 188 | var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url, re, youTubeEmbedMatch; // eslint-disable-line consistent-this |
| | 189 | url = embedLinkView.model.get( 'url' ); |
| 149 | 190 | |
| 150 | 191 | if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) { |
| 151 | 192 | embedLinkView.dfd.abort(); |
| 152 | 193 | } |
| 153 | 194 | |
| 154 | | // Abort if the URL field was emptied out. |
| 155 | | if ( ! embedLinkView.model.get( 'url' ) ) { |
| 156 | | embedLinkView.setErrorNotice( '' ); |
| 157 | | return; |
| 158 | | } |
| 159 | | |
| 160 | 195 | fetchSuccess = function( response ) { |
| 161 | 196 | embedLinkView.renderoEmbed({ |
| 162 | 197 | data: { |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 170 | 205 | }; |
| 171 | 206 | |
| 172 | 207 | urlParser = document.createElement( 'a' ); |
| 173 | | urlParser.href = embedLinkView.model.get( 'url' ); |
| | 208 | urlParser.href = url; |
| 174 | 209 | matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); |
| 175 | 210 | if ( matches ) { |
| 176 | 211 | fileExt = matches[1]; |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 185 | 220 | } |
| 186 | 221 | |
| 187 | 222 | // Support YouTube embed links. |
| 188 | | url = embedLinkView.model.get( 'url' ); |
| 189 | 223 | re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/; |
| 190 | 224 | youTubeEmbedMatch = re.exec( url ); |
| 191 | 225 | if ( youTubeEmbedMatch ) { |