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( $ ) { |
| 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 | 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 | |
| 142 | 184 | /** |
| 143 | 185 | * Fetch media. |
| 144 | 186 | * |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 146 | 188 | */ |
| 147 | 189 | fetch: function() { |
| 148 | 190 | var embedLinkView = this, fetchSuccess, matches, fileExt, urlParser, url, re, youTubeEmbedMatch; // eslint-disable-line consistent-this |
| | 191 | url = embedLinkView.model.get( 'url' ); |
| 149 | 192 | |
| 150 | 193 | if ( embedLinkView.dfd && 'pending' === embedLinkView.dfd.state() ) { |
| 151 | 194 | embedLinkView.dfd.abort(); |
| 152 | 195 | } |
| 153 | 196 | |
| 154 | 197 | // Abort if the URL field was emptied out. |
| 155 | | if ( ! embedLinkView.model.get( 'url' ) ) { |
| | 198 | if ( ! url ) { |
| 156 | 199 | embedLinkView.setErrorNotice( '' ); |
| 157 | 200 | return; |
| 158 | 201 | } |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 170 | 213 | }; |
| 171 | 214 | |
| 172 | 215 | urlParser = document.createElement( 'a' ); |
| 173 | | urlParser.href = embedLinkView.model.get( 'url' ); |
| | 216 | urlParser.href = url; |
| 174 | 217 | matches = urlParser.pathname.toLowerCase().match( /\.(\w+)$/ ); |
| 175 | 218 | if ( matches ) { |
| 176 | 219 | fileExt = matches[1]; |
| … |
… |
wp.mediaWidgets = ( function( $ ) { |
| 185 | 228 | } |
| 186 | 229 | |
| 187 | 230 | // Support YouTube embed links. |
| 188 | | url = embedLinkView.model.get( 'url' ); |
| 189 | 231 | re = /https?:\/\/www\.youtube\.com\/embed\/([^/]+)/; |
| 190 | 232 | youTubeEmbedMatch = re.exec( url ); |
| 191 | 233 | if ( youTubeEmbedMatch ) { |