【发布时间】:2014-12-21 07:17:06
【问题描述】:
我已经为 tinyMCE 上的图像上传创建了一个文件管理器,并从另一个文件 (attachment_path) 获取表单上传和图像列表。首先,当我选择图像时,我已成功获取图像 url 并放入field_name。但是现在我想在选择图像时将禁用按钮(插入)更改为 false,并将图像的 url 放入按钮(使用自定义属性)。
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;
}
这是选择图像时的脚本(在 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().oninsert(url);
top.tinymce.activeEditor.windowManager.getParams().onselect();
});
我能找到http://www.tinymce.com/wiki.php/api4:class.tinymce.WindowManager,但我找不到按钮的设置配置。
工作流程图片
当按钮设置为 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');
}
【问题讨论】:
标签: javascript jquery tinymce-4 file-manager