有人能帮我吗,我想销毁我以前的媒体上传器框架,并删除他们创建的所有元素以更改媒体文件类型,但我做不到,在最后一次搜索中,我在media editor的评论中找到了。js和媒体视图。来自wordpress文件夹的js,他们用dispose 函数,但在我复制并遵循它之后,dispose什么也不做。我想,如果满足某些条件,dispose可以运行,但我不知道是什么,有人能帮我吗?非常感谢。
这是我制作媒体上传器框架的代码
var $j = jQuery.noConflict();
function call_media_library() {
var media_uploader;
$j(document).on(\'click\', \'.video_media_btn\', function(e){
e.preventDefault();
var btn_uploader = $j(this);
//change media type
var med_type;
if(btn_uploader.hasClass(\'mp4-media-btn\')){
media_type=\'video/mp4\';
}else if(btn_uploader.hasClass(\'webm-media-btn\')){
media_type=\'video/webm\';
}else if(btn_uploader.hasClass(\'ogg-media-btn\')){
media_type=\'video/ogv\';
}else{
media_type=\'video\';
}
//after I have call media uploader in twice the previous media_uploader cant destroy
if (media_uploader) {
//this is not working
media_uploader.dispose();
}
media_uploader = wp.media({
title: \'Upload media\',
library : { type : media_type},
multiple: false
}).on(\'select\', function(e){
// This will return the selected media from the Media Uploader, the result is an object
var uploaded_media = media.state().get(\'selection\').first();
// Convert uploaded_media to a JSON object to make accessing it easier
var media_url = uploaded_media.toJSON().url;
// Assign the url value to the input field
if(btn_uploader.hasClass(\'mp4-media-btn\')){
btn_uploader.parent().closest(\'.input-group.input-group-xs\').siblings( \'.input-media-display\' ).find(\'.mp4-media-src\').attr("src", media_url);
}else if(btn_uploader.hasClass(\'webm-media-btn\')){
btn_uploader.parent().closest(\'.input-group.input-group-xs\').siblings( \'.input-media-display\' ).find(\'.webm-media-src\').attr("src", media_url);
}else if(btn_uploader.hasClass(\'ogg-media-btn\')){
btn_uploader.parent().closest(\'.input-group.input-group-xs\').siblings( \'.input-media-display\' ).find(\'.ogg-media-src\').attr("src", media_url);
}
btn_uploader.parent().closest(\'.input-group.input-group-xs\').siblings( \'.input-media-display\' ).find(\'video\')[0].load();
}).open();
});
}
这是我的wp排队功能。php
add_action( \'wp_enqueue_scripts\', \'insert_script_to_my_plugin\' );
function insert_script_to_my_plugin(){
wp_enqueue_media();
}
这是来自wp-includes/js/media-editor的代码。js公司
// Destroy the previous gallery frame.
if ( this.frame ) {
this.frame.dispose();
}
// Store the current frame.
this.frame = wp.media({
frame: \'post\',
state: state,
title: this.editTitle,
editing: true,
multiple: true,
selection: selection
}).open();