Media: Better image detection in the embed from URL tab. see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22558 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0188fc3e52
commit
8e775dff4b
|
@ -542,21 +542,37 @@
|
||||||
type: 'link'
|
type: 'link'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The amount of time used when debouncing the scan.
|
||||||
|
sensitivity: 200,
|
||||||
|
|
||||||
initialize: function() {
|
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 );
|
media.controller.State.prototype.initialize.apply( this, arguments );
|
||||||
},
|
},
|
||||||
|
|
||||||
scan: function() {
|
scan: function() {
|
||||||
var attributes = { type: 'link' };
|
var attributes = { type: 'link' };
|
||||||
|
|
||||||
if ( /(?:jpe?g|png|gif)$/i.test( this.get('url') ) )
|
|
||||||
attributes.type = 'image';
|
|
||||||
|
|
||||||
this.trigger( 'scan', attributes );
|
this.trigger( 'scan', attributes );
|
||||||
this.set( 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() {
|
reset: function() {
|
||||||
_.each( _.difference( _.keys( this.attributes ), _.keys( this.defaults ) ), function( key ) {
|
_.each( _.difference( _.keys( this.attributes ), _.keys( this.defaults ) ), function( key ) {
|
||||||
this.unset( key );
|
this.unset( key );
|
||||||
|
|
Loading…
Reference in New Issue