Media: Better image detection in the embed from URL tab. see #21390.

git-svn-id: https://develop.svn.wordpress.org/trunk@22558 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2012-11-13 03:33:41 +00:00
parent 9fb6e29102
commit b7395456eb
1 changed files with 20 additions and 4 deletions

View File

@ -542,21 +542,37 @@
type: 'link'
},
// The amount of time used when debouncing the scan.
sensitivity: 200,
initialize: function() {
this.on( 'change:url', this.scan, this );
this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
this.on( 'change:url', this.debouncedScan, this );
this.on( 'scan', this.scanImage, this );
media.controller.State.prototype.initialize.apply( this, arguments );
},
scan: function() {
var attributes = { type: 'link' };
if ( /(?:jpe?g|png|gif)$/i.test( this.get('url') ) )
attributes.type = 'image';
this.trigger( 'scan', attributes );
this.set( attributes );
},
scanImage: function( attributes ) {
var frame = this.frame,
state = this,
url = this.get('url'),
image = new Image();
image.onload = function() {
if ( state === frame.state() && url === state.get('url') )
state.set( 'type', 'image' );
};
image.src = url;
},
reset: function() {
_.each( _.difference( _.keys( this.attributes ), _.keys( this.defaults ) ), function( key ) {
this.unset( key );