Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(["tinymce"], function (tinymce) {
- console.log("create and add collectivebbcodesnippets")
- tinymce.create("tinymce.plugins.CollectiveBBCodeSnippetsPlugin", {
- init: function (editor) {
- editor.on("init", function () {
- console.log("editor on init!")
- })
- editor.addMenuItem("example", {
- text: "Example plugin",
- context: "tools",
- onclick: function () {
- // Open window with a specific url
- editor.windowManager.open({
- title: "TinyMCE site",
- url: "https://www.tinymce.com",
- width: 800,
- height: 600,
- buttons: [
- {
- text: "Close",
- onclick: "close",
- },
- ],
- })
- },
- })
- // Adds a menu item to the tools menu
- const portalUrl = document.body.dataset["portalUrl"]
- const bbcodesnippet_enabled_url = portalUrl + "/@bbcodesnippets_enabled"
- fetch(
- bbcodesnippet_enabled_url,
- {
- headers: {'Accept': 'application/json'}
- }
- )
- .then(response => response.json())
- .then(data => {
- console.log(data)
- data.forEach( (entry, index) => {
- const identifier = 'bbcs' + entry.name
- console.log(index + " " + identifier)
- editor.addMenuItem(identifier, {
- text: entry.name + " (" + entry.snippet + ")",
- context: "tools",
- onAction: () => {
- alert(entry.template)
- }
- })
- })
- })
- .catch( (err) => {
- console.log(err)
- })
- },
- })
- tinymce.PluginManager.add(
- "collectivebbcodesnippets",
- tinymce.plugins.CollectiveBBCodeSnippetsPlugin
- )
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement