更改windowManager TinyMCE上按钮的配置

itx*_*itx 6 javascript jquery file-manager tinymce-4

我已经制作了一个文件管理器,用于在tinyMCE上上传图像,并从另一个文件(attachment_path)获取表单上传和图像列表。首先,我成功获取了图像网址,并field_name在选择图像时将其放置在该位置。但是现在我想在选择图像时将禁用按钮(Insert)更改为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;
    }
Run Code Online (Sandbox Code Playgroud)

选择图像(在上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();
});
Run Code Online (Sandbox Code Playgroud)

我可以找到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>
Run Code Online (Sandbox Code Playgroud)

当按钮设置为时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>
Run Code Online (Sandbox Code Playgroud)

因此,我尝试删除类并更改onselect函数的属性,并且可以单击插入按钮,但是单击该按钮时,模态不会关闭。

onselect: function() {
  var adiv = $('#insertButton').closest('div');
  adiv.removeClass('mce-disabled');
  adiv.attr('aria-disabled', 'false');
}
Run Code Online (Sandbox Code Playgroud)

Ars*_*mad 6

为按钮提供某种唯一标识符,例如Id,然后从回调中启用按钮。例如,您可以执行以下操作:

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',
          id: 'uniqueid',
          disabled: true,
          onclick: 'close'
      }, {
          text: 'Close',
          onclick: 'close',
          window : win,
          input : field_name
      }]
    }, {
        oninsert: function(url) {
            win.document.getElementById(field_name).value = url; 
        },
        onselect: function() {
            // 
        }
    });

    return false;
}
Run Code Online (Sandbox Code Playgroud)

然后在回调中执行以下操作:

$('a[data-rel="colorbox"]').on('click', function(e){
     e.preventDefault();
     $('#uniqueid').removeAttr('disabled');
     var url = $(this).find('img:first').attr('src');
     // top.tinymce.activeEditor.windowManager.getParams().oninsert(url);
     top.tinymce.activeEditor.windowManager.getParams().onselect();
});
Run Code Online (Sandbox Code Playgroud)