You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/02/18 21:55:30 UTC

[myfaces-tobago] branch master updated: update/fix TinyMCE example

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new 461c526  update/fix TinyMCE example
461c526 is described below

commit 461c526c402e1b1a19d22ac97a9127ad22b5339b
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Feb 18 22:43:53 2021 +0100

    update/fix TinyMCE example
---
 .../src/main/webapp/WEB-INF/tobago-config.xml      |  9 +++-
 .../110-wysiwyg/00-tinymce/TinyMCE.xhtml           | 33 ++++++------
 .../20-component/110-wysiwyg/00-tinymce/tinymce.js | 61 ++--------------------
 3 files changed, 28 insertions(+), 75 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
index 67391c0..a5c43e4 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
@@ -50,13 +50,20 @@
   <content-security-policy mode="on">
     <!-- script-src: 'unsafe-inline' is required for WebSockets -->
 <!--    <directive name="script-src">'unsafe-inline'</directive>-->
-    <!-- needed for <tc:object>  -->
+
+    <!-- needed for <tc:object> demo -->
     <directive name="child-src">https://www.openstreetmap.org</directive>
     <directive name="child-src">https://*.apache.org</directive>
+
     <!-- needed for the test suite -->
     <directive name="child-src">'self'</directive>
+
     <!-- needed for the test suite -->
     <directive name="frame-ancestors">'self'</directive>
+
+    <!-- needed for the tinymce editor demo -->
+    <directive name="script-src">https://cdn.tiny.cloud/</directive>
+    <directive name="style-src">https://cdn.tiny.cloud/</directive>
   </content-security-policy>
 
   <!-- "disable" is the default -->
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/TinyMCE.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/TinyMCE.xhtml
index 217face..0d0a096 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/TinyMCE.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/TinyMCE.xhtml
@@ -23,24 +23,27 @@
                 xmlns:tc="http://myfaces.apache.org/tobago/component"
                 xmlns:ui="http://java.sun.com/jsf/facelets">
 
-  <tc:script
-          file="#{request.contextPath}/content/20-component/110-wysiwyg/00-tinymce/tinymce/js/tinymce/tinymce.min.js"/>
+  <tc:script file="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"/>
   <tc:script file="#{request.contextPath}/content/20-component/110-wysiwyg/00-tinymce/tinymce.js"/>
 
-<!--  todo-->
-  <tc:badge value="Todo: This page needs to be refactored, still using jQuery..." markup="warning"/>
+  <tc:section label="Setup">
+    <p>
+      This demo uses the CDN of TinyMCE.
+      For more information to setup see <tc:link image="fa-edit" link="https://www.tiny.cloud/" label="TinyMCE"/>.
+    </p>
 
-  <tc:section label="Installation">
-    <p>Download <tc:link link="http://www.tinymce.com/" target="_blank" label="TinyMCE"/>
-      and unpack the ZIP file directly beside this XHTML-file.</p>
-  </tc:section>
+    <p>
+      The setup needs an entry in <code>tobago-config.xml</code>, because of CSP.
+    </p>
 
-  <tc:section label="Editor">
-    <p>This facelet contains two <code class="language-markup">&lt;tc:script/></code> tags,
+    <p>
+      This page contains two <code class="language-markup">&lt;tc:script/></code> tags,
       one for the TinyMCE and the other for the integration in this application.
       The <code class="language-markup">&lt;tc:textarea/></code> contain
-      <code class="language-markup">&lt;tc:dataAttribute name="html-editor" value=""/></code>,
-      to mark this textarea to be used as rich text editor. The rest does the script: tinymce.js</p>
+      <code class="language-markup">&lt;tc:dataAttribute name="html-editor" value="tinymce"/></code>,
+      to mark this textarea to be used as rich text editor. The initialization is initialted by the
+      <code>tinymce.js</code> script.
+    </p>
 
     <tc:box id="sourceCodeBox" label="tinymce.js" collapsed="true" collapsedMode="hidden">
       <f:facet name="bar">
@@ -56,12 +59,8 @@
       <demo-highlight language="javascript"><tc:out value="#{tinyMceController.source}"/></demo-highlight>
     </tc:box>
 
-    <tc:out markup="strong" rendered="#{not tinyMceController.editorAvailable}"
-            value="The TinyMCE is not installed! Using the fallback textarea."/>
-
     <tc:textarea value="#{tinyMceController.text}">
-      <tc:style width="400px" height="300px"/>
-      <tc:dataAttribute name="html-editor" value=""/>
+      <tc:dataAttribute name="html-editor" value="tinymce"/>
     </tc:textarea>
     <tc:button label="Submit"/>
   </tc:section>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/tinymce.js b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/tinymce.js
index 4262f9d..711e212 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/tinymce.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/110-wysiwyg/00-tinymce/tinymce.js
@@ -15,61 +15,8 @@
  * limitations under the License.
  */
 
-(function ($) {
-
-  $.widget("demo.htmlEditor", {
-
-    _create: function () {
-
-      if (typeof tinymce == "undefined") {
-        console.error("No TinyMCE installation found!");
-        return;
-      }
-      tinymce.init({
-        selector: "#" + this.element.id.replace(/([:.])/g, "\\$1"),
-        init_instance_callback: function (editor) {
-          var textarea = document.getElementById(editor.id); // fixme: works not in Shadow DOM
-          var editorContainer = jQuery(editor.editorContainer);
-
-          editorContainer.css("height", textarea.css("height"));
-          editorContainer.css("width", textarea.css("width"));
-          editorContainer.css("left", textarea.css("left"));
-          editorContainer.css("top", textarea.css("top"));
-          editorContainer.css("position", textarea.css("position"));
-
-          var text = jQuery(editor.contentAreaContainer);
-
-          // set estimated height
-          text.outerHeight(text.outerHeight - 107);
-
-          // compute the real height a bit later, (didn't found an event to listen, so using setTimeout)
-          setTimeout(function () {
-            var heightDelta = 2; // extra pixel...
-            editorContainer.find(".mce-toolbar, .mce-statusbar").each(function () {
-              heightDelta += jQuery(this).outerHeight();
-            });
-            text.outerHeight(text.outerHeight() - heightDelta);
-          }, 50);
-        },
-        setup: function(ed) {
-          ed.on('init', function(args) {
-            // TinyMCE v4
-            if (jQuery("#" + args.target.id.replace(/:/g, "\\:")).attr('readonly') == "readonly") {
-              tinymce.get(args.target.id).setMode('readonly');
-            }
-          });
-        }
-      });
-    },
-
-    _destroy: function () {
-      // tbd: instance.destroy()
-    }
-
+document.addEventListener("DOMContentLoaded", (event) => {
+  tinymce.init({
+    selector: "textarea[data-html-editor=tinymce]"
   });
-
-}(jQuery));
-
-Listener.register(function () {
-  jQuery("[data-html-editor]").htmlEditor();
-}, Phase.DOCUMENT_READY);
+});