WordPress/wp-includes/js/media/views/embed/link.js
Scott Taylor b191013198 Media JS files:
* In media manifests, ditch IIFEs and global injection, these get dynamically scoped via Browserify
* Remove the `debug` option from `browserify:media`
* Add `jshint:media` to `jshint:corejs`
* Add a trailing newline to all new module files

Props iseulde.
See #28510.

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


git-svn-id: http://core.svn.wordpress.org/trunk@31366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-09 16:01:29 +00:00

66 lines
1.5 KiB
JavaScript

/**
* 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;