WordPress.org

Make WordPress Core

Changeset 22558


Ignore:
Timestamp:
11/13/12 03:33:41 (2 years ago)
Author:
koopersmith
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r22552 r22558  
    543543        }, 
    544544 
    545         initialize: function() { 
    546             this.on( 'change:url', this.scan, this ); 
     545        // The amount of time used when debouncing the scan. 
     546        sensitivity: 200, 
     547 
     548        initialize: function() { 
     549            this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity ); 
     550            this.on( 'change:url', this.debouncedScan, this ); 
     551            this.on( 'scan', this.scanImage, this ); 
    547552            media.controller.State.prototype.initialize.apply( this, arguments ); 
    548553        }, 
     
    551556            var attributes = { type: 'link' }; 
    552557 
    553             if ( /(?:jpe?g|png|gif)$/i.test( this.get('url') ) ) 
    554                 attributes.type = 'image'; 
    555  
    556558            this.trigger( 'scan', attributes ); 
    557559            this.set( attributes ); 
     560        }, 
     561 
     562        scanImage: function( attributes ) { 
     563            var frame = this.frame, 
     564                state = this, 
     565                url = this.get('url'), 
     566                image = new Image(); 
     567 
     568            image.onload = function() { 
     569                if ( state === frame.state() && url === state.get('url') ) 
     570                    state.set( 'type', 'image' ); 
     571            }; 
     572 
     573            image.src = url; 
    558574        }, 
    559575 
Note: See TracChangeset for help on using the changeset viewer.