index.html 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <meta name="viewport" content="width=device-width, user-scalable=no" />
  6. <title>Html-documents App Tracim</title>
  7. <link rel='shortcut icon' href='favicon.ico'>
  8. <link rel="stylesheet" type="text/css" href="./font/font-awesome-4.7.0/css/font-awesome.css">
  9. <link href="https://fonts.googleapis.com/css?family=Quicksand:300,400,500,700" rel="stylesheet">
  10. <link rel="stylesheet" type="text/css" href="./dev/bootstrap-4.0.0-beta.css">
  11. </head>
  12. <body>
  13. <script src="./dev/jquery-3.2.1.js"></script>
  14. <script src="./dev/popper-1.12.3.js"></script>
  15. <script src="./dev/bootstrap-4.0.0-beta.2.js"></script>
  16. <script type="text/javascript" src="/asset/tinymce/jquery.tinymce.min.js"></script>
  17. <script type="text/javascript" src="/asset/tinymce/tinymce.min.js"></script>
  18. <div id='content'></div>
  19. <script type='text/javascript'>
  20. (function () {
  21. wysiwyg = function (selector, handleOnChange) {
  22. function base64EncodeAndTinyMceInsert (files) {
  23. for (var i = 0; i < files.length; i++) {
  24. if (files[i].size > 1000000)
  25. files[i].allowed = confirm(files[i].name + " fait plus de 1mo et peut prendre du temps à insérer, voulez-vous continuer ?")
  26. }
  27. for (var i = 0; i < files.length; i++) {
  28. if (files[i].allowed !== false && files[i].type.match('image.*')) {
  29. var img = document.createElement('img')
  30. var fr = new FileReader()
  31. fr.readAsDataURL(files[i])
  32. fr.onloadend = function (e) {
  33. img.src = e.target.result
  34. tinymce.activeEditor.execCommand('mceInsertContent', false, img.outerHTML)
  35. }
  36. }
  37. }
  38. }
  39. // HACK: The tiny mce source code modal contain a textarea, but we
  40. // can't edit it (like it's readonly). The following solution
  41. // solve the bug: https://stackoverflow.com/questions/36952148/tinymce-code-editor-is-readonly-in-jtable-grid
  42. $(document).on('focusin', function(e) {
  43. if ($(e.target).closest(".mce-window").length) {
  44. e.stopImmediatePropagation();
  45. }
  46. });
  47. tinymce.init({
  48. selector: selector,
  49. // height: 130,
  50. // width: 530,
  51. menubar: false,
  52. resize: false,
  53. plugins: [
  54. 'advlist autolink lists link image charmap print preview anchor textcolor',
  55. 'searchreplace visualblocks code fullscreen',
  56. 'insertdatetime media table contextmenu paste code help'
  57. ],
  58. toolbar: 'insert | formatselect | bold italic underline strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | table | code ',
  59. content_css: [
  60. '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
  61. '//www.tinymce.com/css/codepen.min.css'
  62. ],
  63. setup: function ($editor) {
  64. $editor.on('change', function(e) {
  65. handleOnChange({target: {value: $editor.getContent()}}) // target.value to emulate a js event so the react handler can expect one
  66. })
  67. //////////////////////////////////////////////
  68. // add custom btn to handle image by selecting them with system explorer
  69. $editor.addButton('customInsertImage', {
  70. icon: 'mce-ico mce-i-image',
  71. title: 'Image',
  72. onclick: function () {
  73. if ($('#hidden_tinymce_fileinput').length > 0) $('#hidden_tinymce_fileinput').remove()
  74. fileTag = document.createElement('input')
  75. fileTag.id = 'hidden_tinymce_fileinput'
  76. fileTag.type = 'file'
  77. $('body').append(fileTag)
  78. $('#hidden_tinymce_fileinput').on('change', function () {
  79. base64EncodeAndTinyMceInsert($(this)[0].files)
  80. })
  81. $('#hidden_tinymce_fileinput').click()
  82. }
  83. })
  84. //////////////////////////////////////////////
  85. // Handle drag & drop image into TinyMce by encoding them in base64 (to avoid uploading them somewhere and keep saving comment in string format)
  86. $editor
  87. .on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
  88. e.preventDefault()
  89. e.stopPropagation()
  90. })
  91. .on('drop', function(e) {
  92. base64EncodeAndTinyMceInsert(e.dataTransfer.files)
  93. })
  94. }
  95. })
  96. }
  97. })()
  98. </script>
  99. <script src='./html-documents.app.dev.js'></script>
  100. </body>
  101. </html>