mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-10 18:37:58 +01:00
d9a2e85bfe
* specify globals in more files * add missing `wp.media.*` namespace docs * add doc blocks to files that had none See #28510. Built from https://develop.svn.wordpress.org/trunk@31492 git-svn-id: http://core.svn.wordpress.org/trunk@31473 1a063a9b-81f0-0310-95a4-ce76da25c4cd
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
/*globals wp, _, jQuery */
|
|
|
|
/**
|
|
* wp.media.view.EmbedLink
|
|
*
|
|
* @class
|
|
* @augments wp.media.view.Settings
|
|
* @augments wp.media.View
|
|
* @augments wp.Backbone.View
|
|
* @augments Backbone.View
|
|
*/
|
|
var Settings = require( '../settings.js' ),
|
|
$ = jQuery,
|
|
EmbedLink;
|
|
|
|
EmbedLink = Settings.extend({
|
|
className: 'embed-link-settings',
|
|
template: wp.template('embed-link-settings'),
|
|
|
|
initialize: function() {
|
|
this.spinner = $('<span class="spinner" />');
|
|
this.$el.append( this.spinner[0] );
|
|
this.listenTo( this.model, 'change:url', this.updateoEmbed );
|
|
},
|
|
|
|
updateoEmbed: function() {
|
|
var url = this.model.get( 'url' );
|
|
|
|
this.$('.setting.title').show();
|
|
// clear out previous results
|
|
this.$('.embed-container').hide().find('.embed-preview').html('');
|
|
|
|
// only proceed with embed if the field contains more than 6 characters
|
|
if ( url && url.length < 6 ) {
|
|
return;
|
|
}
|
|
|
|
this.spinner.show();
|
|
|
|
setTimeout( _.bind( this.fetch, this ), 500 );
|
|
},
|
|
|
|
fetch: function() {
|
|
// check if they haven't typed in 500 ms
|
|
if ( $('#embed-url-field').val() !== this.model.get('url') ) {
|
|
return;
|
|
}
|
|
|
|
wp.ajax.send( 'parse-embed', {
|
|
data : {
|
|
post_ID: wp.media.view.settings.post.id,
|
|
shortcode: '[embed]' + this.model.get('url') + '[/embed]'
|
|
}
|
|
} ).done( _.bind( this.renderoEmbed, this ) );
|
|
},
|
|
|
|
renderoEmbed: function( response ) {
|
|
var html = ( response && response.body ) || '';
|
|
|
|
this.spinner.hide();
|
|
|
|
this.$('.setting.title').hide();
|
|
this.$('.embed-container').show().find('.embed-preview').html( html );
|
|
}
|
|
});
|
|
|
|
module.exports = EmbedLink;
|