I created a file manager to upload images to tinyMCE and get the form upload and list of images from another file ( attachment_path). At first I managed to get the URL of the image and put on field_namewhen I select the image. But now I want the Insert disable button to be false when you select an image and put the image URL in the button (use a custom attribute).
script on index_path:
file_browser_callback: function(field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
title: 'My File Manager',
file: "<%= attachments_path %>",
width: 450,
height: 305,
resizable : "no",
inline : "yes",
close_previous : "no",
buttons: [{
text: 'Insert',
classes: 'widget btn primary first abs-layout-item',
disabled: true,
onclick: 'close',
id: 'insertButton'
}, {
text: 'Close',
onclick: 'close',
window : win,
input : field_name
}]
}, {
oninsert: function(url) {
win.document.getElementById(field_name).value = url;
},
onselect: function() {
}
});
return false;
}
Here's the script when selecting the image (on attachment_path):
$('a[data-rel="colorbox"]').on('click', function(e){
e.preventDefault();
var url = $(this).find('img:first').attr('src');
top.tinymce.activeEditor.windowManager.getParams().onselect();
});
I managed to find http://www.tinymce.com/wiki.php/api4:class.tinymce.WindowManager , but I can not find to configure the buttons.
Workflow Image

disabled: true:
<div id="insertButton" class="mce-disabled mce-widget mce-btn mce-primary mce-first mce-abs-layout-item" tabindex="-1" aria-labelledby="insertButton" role="button" aria-disabled="true" style="left: 319px; top: 10px; width: 56px; height: 28px;">
<button role="presentation" type="button" tabindex="-1" style="height: 100%; width: 100%;">Insert</button>
</div>
disabled: false:
<div id="insertButton" class="mce-widget mce-btn mce-primary mce-first mce-abs-layout-item" tabindex="-1" aria-labelledby="insertButton" role="button" aria-disabled="false" style="left: 319px; top: 10px; width: 56px; height: 28px;">
<button role="presentation" type="button" tabindex="-1" style="height: 100%; width: 100%;">Insert</button>
</div>
, onselect, , , .
onselect: function() {
var adiv = $('#insertButton').closest('div');
adiv.removeClass('mce-disabled');
adiv.attr('aria-disabled', 'false');
}