Advertisement
jensens

Untitled

Apr 19th, 2021
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require(["tinymce"], function (tinymce) {
  2.   console.log("create and add collectivebbcodesnippets")
  3.  
  4.   tinymce.create("tinymce.plugins.CollectiveBBCodeSnippetsPlugin", {
  5.     init: function (editor) {
  6.       editor.on("init", function () {
  7.         console.log("editor on init!")
  8.       })
  9.       editor.addMenuItem("example", {
  10.         text: "Example plugin",
  11.         context: "tools",
  12.         onclick: function () {
  13.           // Open window with a specific url
  14.           editor.windowManager.open({
  15.             title: "TinyMCE site",
  16.             url: "https://www.tinymce.com",
  17.             width: 800,
  18.             height: 600,
  19.             buttons: [
  20.               {
  21.                 text: "Close",
  22.                 onclick: "close",
  23.               },
  24.             ],
  25.           })
  26.         },
  27.       })
  28.       // Adds a menu item to the tools menu
  29.       const portalUrl = document.body.dataset["portalUrl"]
  30.       const bbcodesnippet_enabled_url = portalUrl + "/@bbcodesnippets_enabled"
  31.       fetch(
  32.         bbcodesnippet_enabled_url,
  33.         {
  34.           headers: {'Accept': 'application/json'}
  35.         }
  36.       )
  37.       .then(response => response.json())
  38.       .then(data => {
  39.         console.log(data)
  40.         data.forEach( (entry, index) => {
  41.           const identifier = 'bbcs' + entry.name
  42.           console.log(index + " " + identifier)
  43.           editor.addMenuItem(identifier, {
  44.             text: entry.name + " (" + entry.snippet + ")",
  45.             context: "tools",
  46.             onAction: () => {
  47.               alert(entry.template)
  48.             }
  49.           })
  50.         })
  51.       })
  52.       .catch( (err) => {
  53.         console.log(err)
  54.       })
  55.     },
  56.   })
  57.   tinymce.PluginManager.add(
  58.     "collectivebbcodesnippets",
  59.     tinymce.plugins.CollectiveBBCodeSnippetsPlugin
  60.   )
  61. })()
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement