- md5
- 8ebccc678d5ab096ed97a2f048c07893
- sha1
- 785f3c0c54b9e8ff48d0dfd84c895d90d2945ab9
- sha256
- 0e94c369f5140386750c6c6df97769d15a899ae9a96678a5dee266c2e3888f65
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
/*globals _ */
/**
* wp.media.view.AttachmentCompat
*
* A view to display fields added via the `attachment_fields_to_edit` filter.
*
* @class
* @augments wp.media.View
* @augments wp.Backbone.View
* @augments Backbone.View
*/
var View = wp.media.View,
AttachmentCompat;
AttachmentCompat = View.extend({
tagName: 'form',
className: 'compat-item',
events: {
'submit': 'preventDefault',
'change input': 'save',
'change select': 'save',
'change textarea': 'save'
},
initialize: function() {
this.listenTo( this.model, 'change:compat', this.render );
},
/**
* @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
*/
dispose: function() {
if ( this.$(':focus').length ) {
this.save();
}
/**
* call 'dispose' directly on the parent class
*/
return View.prototype.dispose.apply( this, arguments );
},
/**
* @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining
*/
render: function() {
var compat = this.model.get('compat');
if ( ! compat || ! compat.item ) {
return;
}
this.views.detach();
this.$el.html( compat.item );
this.views.render();
return this;
},
/**
* @param {Object} event
*/
preventDefault: function( event ) {
event.preventDefault();
},
/**
* @param {Object} event
*/
save: function( event ) {
var data = {};
if ( event ) {
event.preventDefault();
}
_.each( this.$el.serializeArray(), function( pair ) {
data[ pair.name ] = pair.value;
});
this.controller.trigger( 'attachment:compat:waiting', ['waiting'] );
this.model.saveCompat( data ).always( _.bind( this.postSave, this ) );
},
postSave: function() {
this.controller.trigger( 'attachment:compat:ready', ['ready'] );
}
});
module.exports = AttachmentCompat;
No other release has this exact content. See every version of this file.