我正在运行一个问题我使用js代码和“wp.media”api进行自定义媒体上传但问题是它没有显示侧边栏('从图库插入','设置精选图像')菜单正在显示当我们添加任何图像以从后备
发布时这是我打开媒体上传弹出窗口的代码忽略'insertAtCaret'功能
$(document).ready(function () {
var file_frame;
jQuery('#uploadmedia').live('click', function (event) {
event.preventDefault();
// If the media frame already exists, reopen it.
if (file_frame) {
file_frame.open();
return;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: jQuery(this).data('uploader_title'),
button: {
text: jQuery(this).data('uploader_button_text'),
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on('select', function () {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
});
// Finally, open the modal
file_frame.open();
file_frame.on('select', function () {
var selection = file_frame.state().get('selection');
selection.map(function (attachment) {
attachment = attachment.toJSON();
console.log(attachment.url);
// Do something with attachment.id and/or attachment.url here
// $('#mycustomeditor').insertAtCaret('<img src="'+attachment.url+'" alt="" />');
});
});
});
$.fn.insertAtCaret = function (text) {
return this.each(function () {
if (document.selection && this.tagName == 'TEXTAREA') {
//IE textarea support
this.focus();
sel = document.selection.createRange();
sel.text = text;
this.focus();
} else if (this.selectionStart || this.selectionStart == '0') {
//MOZILLA/NETSCAPE support
startPos = this.selectionStart;
endPos = this.selectionEnd;
scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos) + text + this.value.substring(endPos, this.value.length);
this.focus();
this.selectionStart = startPos + text.length;
this.selectionEnd = startPos + text.length;
this.scrollTop = scrollTop;
} else {
// IE input[type=text] and other browsers
this.value += text;
this.focus();
this.value = this.value; // forces cursor to end
}
});
};
});
这是我从上面的代码
得到的但我想显示下面的内容
感谢您的回复