File Frame captura correctamente el fichero del modal y borra en caso de eliminarlo

This commit is contained in:
lrullo 2018-11-12 17:54:57 +01:00
parent a1c75ce154
commit 41a98ca2f6

View File

@ -52,6 +52,16 @@
this.marker.addEventListener('dragend', this.markerDrag, this); this.marker.addEventListener('dragend', this.markerDrag, this);
} }
//_.bindAll(this); //_.bindAll(this);
//init elements
this.file_frame = wp.media({
multiple: false,
library: {
type: 'audio'
}
});
console.log(this.file_frame)
console.log('iniciando file_frame')
this.initEvents(); this.initEvents();
; ;
@ -60,7 +70,7 @@
initEvents: function(){ initEvents: function(){
$('#add_files').bind('click', this.openMediaManager); $('#add_files').bind('click', this.openMediaManager);
this.file_frame.on('select',this.mediaSelected, this); wp.media.frames.file_frame.on('select',this.mediaSelected, this);
$('.delete-att-item').live('click', this.removeMedia); $('.delete-att-item').live('click', this.removeMedia);
}, },
@ -68,13 +78,15 @@
$(event.currentTarget).parents('.soundmap-attach-item').remove(); $(event.currentTarget).parents('.soundmap-attach-item').remove();
}, },
openMediaManager: function(event){ openMediaManager: function(event){
this.file_frame = wp.media.frames.file_frame
event.preventDefault(); event.preventDefault();
if ( this.file_frame ){ if ( this.file_frame ){
this.file_frame.open(); this.file_frame.open();
return; return;
}; }
}, },
mediaSelected: function(event){ mediaSelected: function(event){
this.file_frame = wp.media.frames.file_frame
var attachment = this.file_frame.state().get('selection').first().toJSON(); var attachment = this.file_frame.state().get('selection').first().toJSON();
var _cT = _.template(this.attachTemplate); var _cT = _.template(this.attachTemplate);
var _o = _cT({ var _o = _cT({