TinyMCE wpView: fix showing errors for non-embeddable URLs, no-ssl or no items. Props avryl, fixes #29114, see #29268.

Built from https://develop.svn.wordpress.org/trunk@29577


git-svn-id: http://core.svn.wordpress.org/trunk@29351 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-08-22 18:55:15 +00:00
parent f2c881cf3b
commit 42258a6d89
3 changed files with 34 additions and 18 deletions

View File

@ -2723,7 +2723,10 @@ function wp_ajax_parse_media_shortcode() {
$shortcode = do_shortcode( wp_unslash( $_REQUEST['shortcode'] ) );
if ( empty( $shortcode ) ) {
wp_send_json_error( array( 'statusText' => __( 'No items found.' ) ) );
wp_send_json_error( array(
'type' => 'no-items',
'message' => __( 'No items found.' ),
) );
}
ob_start();

View File

@ -561,8 +561,8 @@ window.wp = window.wp || {};
setNodes: function () {
if ( this.parsed ) {
this.setIframes( this.parsed );
} else if ( this.parsed === false ) {
this.setContent( '<p>' + this.original + '</p>', 'replace' );
} else {
this.fail();
}
},
@ -576,30 +576,43 @@ window.wp = window.wp || {};
shortcode: this.shortcode.string()
}
} )
.always( function() {
self.parsed = false;
} )
.done( function( response ) {
if ( response ) {
self.parsed = response;
self.setIframes( response );
} else {
self.fail( true );
}
} )
.fail( function( response ) {
if ( response && response.message ) {
if ( ( response.type === 'not-embeddable' && self.type === 'embed' ) ||
response.type === 'not-ssl' ) {
self.setError( response.message, 'admin-media' );
} else {
self.setContent( '<p>' + self.original + '</p>', 'replace' );
}
} else if ( response && response.statusText ) {
self.setError( response.statusText, 'admin-media' );
}
self.fail( response || true );
} );
},
fail: function( error ) {
if ( ! this.error ) {
if ( error ) {
this.error = error
} else {
return;
}
}
if ( this.error.message ) {
if ( ( this.error.type === 'not-embeddable' && this.type === 'embed' ) || this.error.type === 'not-ssl' ||
this.error.type === 'no-items' ) {
this.setError( this.error.message, 'admin-media' );
} else {
this.setContent( '<p>' + this.original + '</p>', 'replace' );
}
} else if ( this.error.statusText ) {
this.setError( this.error.statusText, 'admin-media' );
} else if ( this.original ) {
this.setContent( '<p>' + this.original + '</p>', 'replace' );
}
},
stopPlayers: function( remove ) {
var rem = remove === 'remove';

File diff suppressed because one or more lines are too long