Change button configuration on windowManager TinyMCE

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().oninsert(url);
     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

enter image description here

​​ 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');
}
+4
3

- , 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;
}

:

$('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();
});
+4

, : () TinyMCE, " " attachment_path js , url .

:

  • , prop URL-
  • , data-url field_name windowManager

:

<button class="btn btn-sm btn-primary no-radius" type="button" id="iButton" data-rel="tooltip" placeholder="You need to select an image" title="" data-placement="bottom" data-url="" disabled>
        <i class="ace-icon fa fa-plus-square-o"></i>
        Insert
</button>

javascript:

$('#iButton').on('click', function(){
    if (($('#list-all-image li').hasClass('active')) && ($(this).attr('data-url') != "")){
        var url = $(this).attr('data-url');
        top.tinymce.activeEditor.windowManager.getParams().oninsert(url);
        top.tinymce.activeEditor.windowManager.close();
    } else {
        alert('Please select an image first!');
    }
});
0

win.statusbar. items(), tinymce.ui.Collection.

( "" ),

// Enable the button
win.statusbar.items().eq(0).disabled(false);
// Disable the button
win.statusbar.items().eq(0).disabled(true);

0 1 ..

, , . , , .

0

Source: https://habr.com/ru/post/1568504/


All Articles