Browse Source

added tinyMCE script in index.html

AlexiCauvin 6 years ago
parent
commit
e54a35dd78
1 changed files with 100 additions and 0 deletions
  1. 100 0
      dist/index.html

+ 100 - 0
dist/index.html View File

@@ -54,5 +54,105 @@
54 54
   <script type='text/javascript'>
55 55
     // appPageHtml.renderApp('content')
56 56
   </script>
57
+
58
+  <script type="text/javascript" src="/asset/tinymce/jquery.tinymce.min.js"></script>
59
+  <script type="text/javascript" src="/asset/tinymce/tinymce.min.js"></script>
60
+
61
+  <script type='text/javascript'>
62
+      if (window.matchMedia("(min-width:1200px)").matches) {
63
+
64
+        var jsScript = document.createElement("script");
65
+        jsScript.type = "text/javascript";
66
+        jsScript.src = "https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=dfdhxdokxj2wagzkbxfgysgh86d6rr9m3dln0172vo3shipc";
67
+
68
+        jsScript.onload = function() {
69
+          function base64EncodeAndTinyMceInsert (files) {
70
+            for (var i = 0; i < files.length; i++) {
71
+              if (files[i].size > 1000000)
72
+                files[i].allowed = confirm(files[i].name + " fait plus de 1mo et peut prendre du temps à insérer, voulez-vous continuer ?")
73
+            }
74
+
75
+            for (var i = 0; i < files.length; i++) {
76
+              if (files[i].allowed !== false && files[i].type.match('image.*')) {
77
+                var img = document.createElement('img')
78
+
79
+                var fr = new FileReader()
80
+
81
+                fr.readAsDataURL(files[i])
82
+
83
+                fr.onloadend = function (e) {
84
+                  img.src = e.target.result
85
+                  tinymce.activeEditor.execCommand('mceInsertContent', false, img.outerHTML)
86
+                }
87
+              }
88
+            }
89
+          }
90
+
91
+          // HACK: The tiny mce source code modal contain a textarea, but we
92
+          // can't edit it (like it's readonly). The following solution
93
+          // solve the bug: https://stackoverflow.com/questions/36952148/tinymce-code-editor-is-readonly-in-jtable-grid
94
+          $(document).on('focusin', function(e) {
95
+            if ($(e.target).closest(".mce-window").length) {
96
+              e.stopImmediatePropagation();
97
+            }
98
+          });
99
+
100
+          tinymce.init({
101
+            selector: 'textarea',
102
+            height: 130,
103
+            // width: 530,
104
+            menubar: false,
105
+            resize: false,
106
+            plugins: [
107
+              'advlist autolink lists link image charmap print preview anchor textcolor',
108
+              'searchreplace visualblocks code fullscreen',
109
+              'insertdatetime media table contextmenu paste code help'
110
+            ],
111
+            toolbar: 'insert | formatselect | bold italic underline strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | table | code ',
112
+            content_css: [
113
+              '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
114
+              '//www.tinymce.com/css/codepen.min.css'
115
+            ],
116
+            setup: function ($editor) {
117
+              //////////////////////////////////////////////
118
+              // add custom btn to handle image by selecting them with system explorer
119
+              $editor.addButton('customInsertImage', {
120
+                icon: 'mce-ico mce-i-image',
121
+                title: 'Image',
122
+                onclick: function () {
123
+                  var hiddenTinyMceInput = $('#hidden_tinymce_fileinput')
124
+
125
+                  if (hiddenTinyMceInput.length > 0) hiddenTinyMceInput.remove()
126
+
127
+                  fileTag = document.createElement('input')
128
+                  fileTag.id = 'hidden_tinymce_fileinput'
129
+                  fileTag.type = 'file'
130
+                  $('body').append(fileTag)
131
+
132
+                  hiddenTinyMceInput.on('change', function () {
133
+                    base64EncodeAndTinyMceInsert($(this)[0].files)
134
+                  })
135
+
136
+                  hiddenTinyMceInput.click()
137
+                }
138
+              })
139
+
140
+              //////////////////////////////////////////////
141
+              // Handle drag & drop image into TinyMce by encoding them in base64 (to avoid uploading them somewhere and keep saving comment in string format)
142
+              $editor
143
+                .on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
144
+                  e.preventDefault()
145
+                  e.stopPropagation()
146
+                })
147
+                .on('drop', function(e) {
148
+                  base64EncodeAndTinyMceInsert(e.dataTransfer.files)
149
+                })
150
+            }
151
+          });
152
+        }
153
+        document.getElementsByTagName("body")[0].appendChild(jsScript);
154
+      }
155
+    </script>
156
+
57 157
 </body>
58 158
 </html>