I am using my own custom file picker with TinyMCE 4's new file_picker_callback function. The documentation on this isn't great, so credit goes to Fred for getting me this far - https://stackoverflow.com/a/24571800/2460995
The custom file picker is working and when you click on an image it fills in the "Source" and also the "Dimensions". I'm just wondering if there is any way to automatically fill in the "Image description" field as well.
The information for the images is generated from a database table, so I already have a description and it would be nice to automatically fill it in for the user. After trying various ways of passing the data back I'm struggling to understand how it can be done.
Code for TinyMCE:
tinymce.init({
...
file_picker_callback: function(callback, value, meta) {
myImagePicker(callback, value, meta);
}
});
function myImagePicker(callback, value, meta) {
tinymce.activeEditor.windowManager.open({
title: 'Image Browser',
url: '/media/browser/1?type=' + meta.filetype,
width: 800,
height: 550,
}, {
oninsert: function (url) {
callback(url);
}
});
};
Code for the Custom File Picker:
$(function(){
$('.img').on('click', function(event){
mySubmit('/upload/' + $(this).data('filename'));
});
});
function mySubmit(url) {
top.tinymce.activeEditor.windowManager.getParams().oninsert(url);
top.tinymce.activeEditor.windowManager.close();
}
My javascript knowledge isn't the greatest yet as I'm quite new to it, so if you could please illustrate any answers with examples and/or clear logic that would be very useful and much appreciated.