|  | @@ -30,6 +30,28 @@
 | 
	
		
			
			| 30 | 30 |  
 | 
	
		
			
			| 31 | 31 |  <%def name="TINYMCE_INIT_SCRIPT(selector)">
 | 
	
		
			
			| 32 | 32 |      <script>
 | 
	
		
			
			|  | 33 | +        function base64EncodeAndTinyMceInsert (files) {
 | 
	
		
			
			|  | 34 | +          for (var i = 0; i < files.length; i++) {
 | 
	
		
			
			|  | 35 | +            if (files[i].size > 1000000)
 | 
	
		
			
			|  | 36 | +              files[i].allowed = confirm(files[i].name + " fait plus de 1mo et peut prendre du temps à insérer, voulez-vous continuer ?")
 | 
	
		
			
			|  | 37 | +          }
 | 
	
		
			
			|  | 38 | +
 | 
	
		
			
			|  | 39 | +          for (var i = 0; i < files.length; i++) {
 | 
	
		
			
			|  | 40 | +            if (files[i].allowed !== false && files[i].type.match('image.*')) {
 | 
	
		
			
			|  | 41 | +              var img = document.createElement('img')
 | 
	
		
			
			|  | 42 | +
 | 
	
		
			
			|  | 43 | +              var fr = new FileReader()
 | 
	
		
			
			|  | 44 | +
 | 
	
		
			
			|  | 45 | +              fr.readAsDataURL(files[i])
 | 
	
		
			
			|  | 46 | +
 | 
	
		
			
			|  | 47 | +              fr.onloadend = function (e) {
 | 
	
		
			
			|  | 48 | +                img.src = e.target.result
 | 
	
		
			
			|  | 49 | +                tinymce.activeEditor.execCommand('mceInsertContent', false, img.outerHTML)
 | 
	
		
			
			|  | 50 | +              }
 | 
	
		
			
			|  | 51 | +            }
 | 
	
		
			
			|  | 52 | +          }
 | 
	
		
			
			|  | 53 | +        }
 | 
	
		
			
			|  | 54 | +
 | 
	
		
			
			| 33 | 55 |          tinymce.init({
 | 
	
		
			
			| 34 | 56 |              menubar:false,
 | 
	
		
			
			| 35 | 57 |              statusbar:true,
 | 
	
	
		
			
			|  | @@ -38,7 +60,7 @@
 | 
	
		
			
			| 38 | 60 |              skin : 'tracim',
 | 
	
		
			
			| 39 | 61 |              selector:'${selector}',
 | 
	
		
			
			| 40 | 62 |              toolbar: [
 | 
	
		
			
			| 41 |  | -              "undo redo | bold italic underline strikethrough | bullist numlist outdent indent | table | charmap | styleselect | alignleft aligncenter alignright | fullscreen",
 | 
	
		
			
			|  | 63 | +              "undo redo | bold italic underline strikethrough | bullist numlist outdent indent | table | charmap | styleselect | alignleft aligncenter alignright | fullscreen | customInsertImage",
 | 
	
		
			
			| 42 | 64 |              ],
 | 
	
		
			
			| 43 | 65 |              paste_data_images: true,
 | 
	
		
			
			| 44 | 66 |              table_default_attributes: {
 | 
	
	
		
			
			|  | @@ -54,8 +76,40 @@
 | 
	
		
			
			| 54 | 76 |                  {title: 'Normal', value: 'user_content'},
 | 
	
		
			
			| 55 | 77 |                  {title: 'First row is header', value: 'user_content first_row_headers'},
 | 
	
		
			
			| 56 | 78 |                  {title: 'First column is header', value: 'user_content first_column_headers'}
 | 
	
		
			
			| 57 |  | -            ]
 | 
	
		
			
			|  | 79 | +            ],
 | 
	
		
			
			|  | 80 | +            setup: function ($editor) {
 | 
	
		
			
			|  | 81 | +              //////////////////////////////////////////////
 | 
	
		
			
			|  | 82 | +              // add custom btn to handle image by selecting them with system explorer
 | 
	
		
			
			|  | 83 | +              $editor.addButton('customInsertImage', {
 | 
	
		
			
			|  | 84 | +                text: 'Image',
 | 
	
		
			
			|  | 85 | +                icon: false,
 | 
	
		
			
			|  | 86 | +                onclick: function () {
 | 
	
		
			
			|  | 87 | +                  if ($('#hidden_tinymce_fileinput').length > 0) $('#hidden_tinymce_fileinput').remove()
 | 
	
		
			
			|  | 88 | +
 | 
	
		
			
			|  | 89 | +                  fileTag = document.createElement('input')
 | 
	
		
			
			|  | 90 | +                  fileTag.id = 'hidden_tinymce_fileinput'
 | 
	
		
			
			|  | 91 | +                  fileTag.type = 'file'
 | 
	
		
			
			|  | 92 | +                  $('body').append(fileTag)
 | 
	
		
			
			|  | 93 | +
 | 
	
		
			
			|  | 94 | +                  $('#hidden_tinymce_fileinput').on('change', function () {
 | 
	
		
			
			|  | 95 | +                    base64EncodeAndTinyMceInsert($(this)[0].files)
 | 
	
		
			
			|  | 96 | +                  })
 | 
	
		
			
			|  | 97 | +
 | 
	
		
			
			|  | 98 | +                  $('#hidden_tinymce_fileinput').click()
 | 
	
		
			
			|  | 99 | +                }
 | 
	
		
			
			|  | 100 | +              })
 | 
	
		
			
			| 58 | 101 |  
 | 
	
		
			
			|  | 102 | +              //////////////////////////////////////////////
 | 
	
		
			
			|  | 103 | +              // Handle drag & drop image into TinyMce by encoding them in base64 (to avoid uploading them somewhere and keep saving comment in string format)
 | 
	
		
			
			|  | 104 | +              $editor
 | 
	
		
			
			|  | 105 | +              .on('drag dragstart dragend dragover dragenter dragleave drop', function (e) {
 | 
	
		
			
			|  | 106 | +                e.preventDefault()
 | 
	
		
			
			|  | 107 | +                e.stopPropagation()
 | 
	
		
			
			|  | 108 | +              })
 | 
	
		
			
			|  | 109 | +              .on('drop', function(e) {
 | 
	
		
			
			|  | 110 | +                base64EncodeAndTinyMceInsert(e.dataTransfer.files)
 | 
	
		
			
			|  | 111 | +              })
 | 
	
		
			
			|  | 112 | +            }
 | 
	
		
			
			| 59 | 113 |          });
 | 
	
		
			
			| 60 | 114 |      </script>
 | 
	
		
			
			| 61 | 115 |  </%def>
 |