plugin.min.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. tinymce.PluginManager.add('gallery', function (editor, url) {
  2. // 注册一个工具栏按钮名称
  3. editor.ui.registry.addButton('gallery', {
  4. text: '素材库',
  5. onAction: function (e) {
  6. $Gallery.GalleryDialogOpen({
  7. max: 10,
  8. size: 100,
  9. is_new: 1,
  10. suffix: 'bmp,gif,jpg,jpeg,png',
  11. type: '1',
  12. tabs: true,
  13. multiple: true,
  14. callback: function (res) {
  15. $.each(res, function (key, val) {
  16. if (parseInt(val.type) === 1) {
  17. var html = '<p><img src="' + val.url + '" alt="' + val.original + '" width="" height="" /></p>';
  18. editor.insertContent(html);
  19. } else {
  20. // editor.insertContent(`<video src=` + val.url + ` width="100%" controls="controls"></video>`);
  21. var html = `<p><span class="mce-preview-object mce-object-video" contenteditable="false" data-mce-object="video" data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="no" data-mce-p-scrolling="no" data-mce-p-src=${val.url} data-mce-html="%20"><video src=${val.url} width="100%" controls="controls"></video></span></p>`;
  22. editor.insertContent(html);
  23. }
  24. })
  25. }
  26. });
  27. }
  28. });
  29. return {
  30. getMetadata: function () {
  31. return {
  32. //插件名和链接会显示在“帮助”→“插件”→“已安装的插件”中
  33. name: "gallery",//插件名称
  34. url: "http://exampleplugindocsurl.com", //作者网址
  35. };
  36. }
  37. };
  38. });