From e13e33356949af248b29fad121fa37642398be0a Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 4 Dec 2012 23:07:41 +0000 Subject: [PATCH] When inserting an image From URL, show the fields only if it looks like we have a valid image. Props koopersmith fixes #22740 git-svn-id: https://develop.svn.wordpress.org/trunk@23048 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/media-views.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index fe98ab00ce..399b6dfd8e 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -761,6 +761,7 @@ url = this.props.get('url'), image = new Image(); + // Try to load the image and find its width/height. image.onload = function() { if ( state !== frame.state() || url !== state.props.get('url') ) return; @@ -773,6 +774,11 @@ }; image.src = url; + + // Check if the URL looks like an image; skew toward success. + url = url.replace( /([?|#].*)$/, '' ); + if ( /\.(png|jpe?g|gif)$/i.test( url ) ) + attributes.type = 'image'; }, refresh: function() {