When fetching in media/views/embed/link.js, call abort() on any existing XHRs.

Use `$.ajax` instead of `wp.ajax.send()` to allow this.
Pass `this` as `context` to the options to remove the need to bind callbacks.

Fixes #32035.


git-svn-id: https://develop.svn.wordpress.org/trunk@32460 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-05-08 19:15:34 +00:00
parent c6592462ef
commit c8ca3c2304
2 changed files with 36 additions and 14 deletions

View File

@@ -4561,28 +4561,39 @@ EmbedLink = wp.media.view.Settings.extend({
return;
}
if ( this.dfd && 'pending' === this.dfd.state() ) {
this.dfd.abort();
}
embed = new wp.shortcode({
tag: 'embed',
attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
content: this.model.get('url')
});
wp.ajax.send( 'parse-embed', {
data : {
this.dfd = $.ajax({
type: 'POST',
url: wp.ajax.settings.url,
context: this,
data: {
action: 'parse-embed',
post_ID: wp.media.view.settings.post.id,
shortcode: embed.string()
}
} )
.done( _.bind( this.renderoEmbed, this ) )
.fail( _.bind( this.renderFail, this ) );
})
.done( this.renderoEmbed )
.fail( this.renderFail );
},
renderFail: function () {
renderFail: function ( response, status ) {
if ( 'abort' === status ) {
return;
}
this.$( '.link-text' ).show();
},
renderoEmbed: function( response ) {
var html = ( response && response.body ) || '';
var html = ( response && response.data && response.data.body ) || '';
if ( html ) {
this.$('.embed-container').show().find('.embed-preview').html( html );

View File

@@ -45,28 +45,39 @@ EmbedLink = wp.media.view.Settings.extend({
return;
}
if ( this.dfd && 'pending' === this.dfd.state() ) {
this.dfd.abort();
}
embed = new wp.shortcode({
tag: 'embed',
attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
content: this.model.get('url')
});
wp.ajax.send( 'parse-embed', {
data : {
this.dfd = $.ajax({
type: 'POST',
url: wp.ajax.settings.url,
context: this,
data: {
action: 'parse-embed',
post_ID: wp.media.view.settings.post.id,
shortcode: embed.string()
}
} )
.done( _.bind( this.renderoEmbed, this ) )
.fail( _.bind( this.renderFail, this ) );
})
.done( this.renderoEmbed )
.fail( this.renderFail );
},
renderFail: function () {
renderFail: function ( response, status ) {
if ( 'abort' === status ) {
return;
}
this.$( '.link-text' ).show();
},
renderoEmbed: function( response ) {
var html = ( response && response.body ) || '';
var html = ( response && response.data && response.data.body ) || '';
if ( html ) {
this.$('.embed-container').show().find('.embed-preview').html( html );