|
15 | 15 | <meta charset="utf-8"> |
16 | 16 | <title>Conditional blocks</title> |
17 | 17 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
18 | | - <script src="https://cdn.tiny.cloud/1/qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc/tinymce/5-dev/tinymce.min.js" referrerpolicy="origin"></script> |
| 18 | + <script src="https://cdn.tiny.cloud/1/qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc/tinymce/8/tinymce.min.js" referrerpolicy="origin"></script> |
19 | 19 |
|
20 | 20 | <script> |
21 | 21 | tinymce.init({ |
22 | 22 | selector: '#editor', |
23 | 23 |
|
24 | 24 | // Tip! To make TinyMCE leaner, only include the plugins you actually need. |
25 | | - plugins: 'autoresize advcode link lists noneditable', |
| 25 | + plugins: 'autoresize advcode link lists mergetags', |
26 | 26 |
|
27 | | - // We have put our custom insert conditional block button last. |
28 | | - toolbar: 'bold italic strikethrough backcolor | bullist numlist link | conditionalblock | code', |
| 27 | + // We have put our custom insert conditional block button second to last. |
| 28 | + toolbar: 'bold italic strikethrough backcolor | bullist numlist link mergetags | conditionalblock | code', |
29 | 29 |
|
30 | 30 | // "Thin" is a premium icon pack you get wth the cloud essential plan. |
31 | 31 | // See https://www.tiny.cloud for more details and purchasing options |
32 | 32 | // You can also create your own icon packs for TinyMCE |
33 | | - // https://www.tiny.cloud/docs/advanced/creating-an-icon-pack/ |
| 33 | + // https://www.tiny.cloud/docs/tinymce/latest/enhanced-skins-and-icon-packs/ |
| 34 | + // https://www.tiny.cloud/docs/tinymce/latest/creating-an-icon-pack/ |
34 | 35 | icons: 'thin', |
35 | 36 |
|
36 | | - // "Naked" is a premium icon pack you get wth the cloud essential plan |
| 37 | + // "Naked" is a premium icon pack you get with the cloud essential plan |
37 | 38 | // See https://www.tiny.cloud for more details and purchasing options |
38 | 39 | // You can also create your own skins for TinyMCE |
39 | | - // https://www.tiny.cloud/docs/advanced/creating-a-skin/ |
| 40 | + // https://www.tiny.cloud/docs/tinymce/latest/creating-a-skin/ |
40 | 41 | skin: 'naked', |
41 | 42 |
|
42 | 43 | // If we don't need the menubar we can hide it |
43 | | - // https://www.tiny.cloud/docs/configure/editor-appearance/#menubar |
| 44 | + // https://www.tiny.cloud/docs/tinymce/latest/menus-configuration-options/#menubar |
44 | 45 | menubar: false, |
45 | 46 |
|
| 47 | + // Easily configure replacement values using merge tags plugin |
| 48 | + // https://www.tiny.cloud/docs/tinymce/latest/mergetags/ |
| 49 | + mergetags_list: [ |
| 50 | + { title: "first_name", value: "first_name" }, |
| 51 | + { title: "number_of_people", value: "number_of_people" }, |
| 52 | + { title: "agent_first_name", value: "agent_first_name" }, |
| 53 | + ], |
| 54 | + |
46 | 55 | // Tell TinyMCE that conditional-block is a valid element. |
47 | | - // https://www.tiny.cloud/docs/configure/content-filtering/#custom_elements |
| 56 | + // https://www.tiny.cloud/docs/tinymce/latest/content-filtering/#custom_elements |
48 | 57 | custom_elements: 'conditional-block', |
49 | 58 |
|
50 | 59 | setup: (editor) => { |
51 | 60 | // Instead of defining a custom icon pack, we can register individual |
52 | 61 | // icons using the API. |
53 | | - // https://www.tiny.cloud/docs/api/tinymce.editor.ui/tinymce.editor.ui.registry/#addicon |
| 62 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.editor.ui.registry/#addicon |
54 | 63 | editor.ui.registry.addIcon('conditional-block', '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M19 4a2 2 0 1 1-1.854 2.751L15 6.75c-1.239 0-1.85.61-2.586 2.31l-.3.724c-.42 1.014-.795 1.738-1.246 2.217.406.43.751 1.06 1.12 1.92l.426 1.018c.704 1.626 1.294 2.256 2.428 2.307l.158.004h2.145a2 2 0 1 1 0 1.501L15 18.75l-.219-.004c-1.863-.072-2.821-1.086-3.742-3.208l-.49-1.17c-.513-1.163-.87-1.57-1.44-1.614L9 12.75l-2.146.001a2 2 0 1 1 0-1.501H9c.636 0 1.004-.383 1.548-1.619l.385-.92c.955-2.291 1.913-3.382 3.848-3.457L15 5.25h2.145A2 2 0 0 1 19 4z" fill-rule="evenodd"/></svg>'); |
55 | 64 |
|
56 | 65 | // The preinit event is fired after the editor is loaded but before |
57 | 66 | // the content is loaded |
58 | | - // https://www.tiny.cloud/docs/advanced/events/#editorcoreevents |
| 67 | + // https://www.tiny.cloud/docs/tinymce/latest/events/ |
59 | 68 | editor.on('PreInit', () => { |
60 | 69 | // Get the iframe window object and the iframes document object |
61 | 70 | // and call our setup function that creates the web component |
62 | | - // https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getwin |
63 | | - // https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#getdoc |
| 71 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.editor/#getWin |
| 72 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.editor/#getDoc |
64 | 73 | const win = editor.getWin(); |
65 | 74 | const doc = editor.getDoc(); |
66 | 75 | setupWebComponent(win, doc, editor); |
|
69 | 78 | // on the web component to make it behave like a noneditable but selectable |
70 | 79 | // element inside TinyMCE. But we don't want the contenteditable attribute |
71 | 80 | // to be saved with the content. We therefore need to filter out the attribute |
72 | | - // upon serlialization (which happens on "save", view sourcecode and preview |
| 81 | + // upon serialization (which happens on "save", view source code and preview |
73 | 82 | // among others). |
74 | | - // https://www.tiny.cloud/docs/api/tinymce.dom/tinymce.dom.serializer/#addnodefilter |
| 83 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.serializer/#addNodeFilter |
75 | 84 | editor.serializer.addNodeFilter('conditional-block', (nodes) => { |
76 | 85 | // Iterate through all filtered nodes and remove the contenteditable attribute |
77 | 86 | // as well as the wrapper <div> we add when creating the custom element |
|
81 | 90 | node.attr('contenteditable', null); |
82 | 91 | // Traverse into the first child which would be the <div contenteditable="true"> |
83 | 92 | // and use unwrap to remove the <div> but keep the children. |
84 | | - // https://www.tiny.cloud/docs/api/tinymce.html/tinymce.html.node/#unwrap |
| 93 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.html.node/#unwrap |
85 | 94 | node.firstChild.unwrap(); |
86 | 95 | } |
87 | 96 | }); |
88 | 97 | }); |
89 | 98 | }); |
90 | 99 |
|
91 | 100 | // Register a custom toolbar menu button to insert the conditional block |
92 | | - // https://www.tiny.cloud/docs/ui-components/typesoftoolbarbuttons/#menubutton |
| 101 | + // https://www.tiny.cloud/docs/tinymce/latest/custom-menu-toolbar-button/ |
93 | 102 | editor.ui.registry.addButton('conditionalblock', { |
94 | 103 | icon: 'conditional-block', |
95 | 104 | tooltip: 'Insert conditional block', |
|
104 | 113 | // In a real world scenario, with much more custom styles for headings |
105 | 114 | // links, tables, images etc, it's recommended to use the content_css |
106 | 115 | // option to load a separate CSS file. Makes editing easier too. |
107 | | - // https://www.tiny.cloud/docs/configure/content-appearance/#content_style |
108 | | - // https://www.tiny.cloud/docs/configure/content-appearance/#content_css |
| 116 | + // https://www.tiny.cloud/docs/tinymce/latest/add-css-options/#content_style |
| 117 | + // https://www.tiny.cloud/docs/tinymce/latest/add-css-options/#content_css |
109 | 118 | content_style: ` |
110 | 119 | /* We remove the default selected outline because it doesn't follow the |
111 | 120 | * border radius and reintroduce it as a box-shadow. |
|
307 | 316 | const dialogManager = (conditionalBlock, editor) => { |
308 | 317 | // Open a TinyMCE modal where the user can set the badge's |
309 | 318 | // background and text color. |
310 | | - // https://www.tiny.cloud/docs/ui-components/dialog/ |
311 | | - // https://www.tiny.cloud/docs/ui-components/dialogcomponents/ |
| 319 | + // https://www.tiny.cloud/docs/tinymce/latest/dialog/ |
312 | 320 | editor.windowManager.open({ |
313 | 321 | title: 'Insert/edit Conditional block', |
314 | 322 | body: { |
|
368 | 376 | // Check if a block is edited or a new block is to be inserted |
369 | 377 | if (!conditionalBlock) { |
370 | 378 | // Insert content at the location of the cursor. |
371 | | - // https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#insertcontent |
| 379 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.editor/#insertContent |
372 | 380 | editor.insertContent(`<conditional-block data-property="${data.property}" data-operator="${data.operator}" data-value="${data.value}"><p>Write conditional text here</p></conditional-block>`); |
373 | 381 | } |
374 | 382 | else { |
375 | 383 | // Working directly with the DOM often requires manually adding |
376 | 384 | // the actions to the undo stack. |
377 | | - // https://www.tiny.cloud/docs/api/tinymce/tinymce.undomanager/ |
| 385 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.undomanager/ |
378 | 386 | editor.undoManager.transact(() => { |
379 | 387 | // Update the data-attributes on the conditional-block element |
380 | 388 | conditionalBlock.dataset.property = data.property; |
|
383 | 391 | }); |
384 | 392 |
|
385 | 393 | // Tell TinyMCE that the ui has been updated. |
386 | | - // https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#nodechanged |
| 394 | + // https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.editor/#nodeChanged |
387 | 395 | editor.nodeChanged(); |
388 | 396 | } |
389 | 397 |
|
|
0 commit comments