Explorar el Código

added tinymce lib to index.html

Skylsmoi hace 6 años
padre
commit
a9c99cd11a
Se han modificado 1 ficheros con 95 adiciones y 0 borrados
  1. 95 0
      dist/index.html

+ 95 - 0
dist/index.html Ver fichero

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