imageinsert.min.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Redactor.add("plugin", "imageinsert", {
  2. init: function (app) {
  3. this.app = app;
  4. this.toolbar = app.toolbar;
  5. this.inputImageValue = "null";
  6. },
  7. start: function () {
  8. var buttonData = {
  9. title: "Image",
  10. icon: "image",
  11. api: "plugin.imageinsert.loadQorMedia",
  12. };
  13. this.hiddenContainer = this.app.container
  14. .getElement()
  15. .nextElement()
  16. .find(".go-plaid-portal")
  17. .first();
  18. if (this.hiddenContainer.length == 0) {
  19. return;
  20. }
  21. this.toolbar.addButton("image", buttonData);
  22. var that = this;
  23. // checking dom change and update input data
  24. var observe = new MutationObserver(function (mutations, observer) {
  25. that.selectImageInput = that.hiddenContainer.find("input[type=hidden]");
  26. that.inputImageValue =
  27. that.selectImageInput.length != 0
  28. ? that.selectImageInput.val()
  29. : "null";
  30. if (that.inputImageValue && that.inputImageValue != "null") {
  31. that.insertQorImage();
  32. }
  33. });
  34. observe.observe(this.hiddenContainer.get(), {
  35. childList: true,
  36. attributes: true,
  37. });
  38. },
  39. loadQorMedia: function () {
  40. this.app.selection.save();
  41. this.hiddenContainer.find("button").trigger("click");
  42. },
  43. insertQorImage: function () {
  44. this.app.selection.restore();
  45. var inputImageJSON = JSON.parse(this.inputImageValue);
  46. this.app.insertion.insertHtml(`
  47. <figure><img src="${inputImageJSON.Url}" data-image="${inputImageJSON.ID}" alt="${inputImageJSON.Description}"></figure>
  48. `);
  49. },
  50. });