vendor/uvdesk/support-center-bundle/Resources/views/Templates/tinyMCE.html.twig line 1

Open in your IDE?
  1. <script src="{{ asset('bundles/uvdeskcoreframework/js/tinymce/tinymce.min.js') }}"></script>
  2. <script src="{{ asset('bundles/uvdeskcoreframework/js/tinymce/themes/modern/theme.min.js')}}"></script>
  3. <script scr="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  4. <script type="text/javascript">
  5. var sfTinyMce = {
  6. tinymce : tinymce,
  7. options : {
  8. browser_spellcheck : true,
  9. selector: '.uv-view textarea',
  10. branding: false,
  11. relative_urls : false,
  12. remove_script_host : false,
  13. convert_urls: true,
  14. image_title: true,
  15. autoresize_max_height: 350,
  16. theme: 'modern',
  17. menubar: false,
  18. height: 150,
  19. toolbar: '| undo redo | bold italic forecolor | bullist numlist | link image',
  20. spellchecker_languages: 'English=en',
  21. plugins: [
  22. 'spellchecker autolink lists link charmap print preview hr anchor pagebreak',
  23. 'searchreplace wordcount visualblocks visualchars code fullscreen',
  24. 'media nonbreaking table directionality',
  25. 'emoticons template paste textcolor colorpicker textpattern codesample toc',
  26. 'autoresize image imagetools',
  27. 'mention',
  28. ],
  29. invalid_elements : 'script,style,input,textarea,form,onmouseover,onmouseout,onclick',
  30. // paste_as_text: true,
  31. paste_data_images: true,
  32. image_advtab: true,
  33. mentions : {
  34. source: function(){
  35. return [];
  36. },
  37. },
  38. },
  39. init : function (options){
  40. if(typeof(options.setup) === 'function'){
  41. let optionsSetup = options.setup;
  42. this.options.setup = function(editor){
  43. sfTinyMce.initImageUpload(editor);
  44. optionsSetup(editor);
  45. }
  46. delete options.setup;
  47. }else{
  48. this.options.setup = function(editor){
  49. sfTinyMce.initImageUpload(editor);
  50. }
  51. delete options.setup;
  52. }
  53. this.options = $.extend({}, this.options, options)
  54. window.tinymce.dom.Event.domLoaded = true;
  55. tinymce.init(this.options);
  56. },
  57. html : function(selector, html){
  58. tinymce.get(selector).setContent(html);
  59. },
  60. initImageUpload : function(editor) {
  61. // create input and insert in the DOM
  62. var inp = $('<input id="tinymce-uploader" type="file" name="pic" accept="image/*" style="display:none">');
  63. $(editor.getElement()).parent().append(inp);
  64. // add the image upload button to the editor toolbar
  65. editor.addButton('imageupload', {
  66. text: '',
  67. icon: 'image',
  68. onclick: function(e) { // when toolbar button is clicked, open file select modal
  69. inp.trigger('click');
  70. }
  71. });
  72. // when a file is selected, upload it to the server
  73. inp.on("change", function(e){
  74. sfTinyMce.uploadFile($(this), editor);
  75. });
  76. },
  77. uploadFile : function(input, editor) {
  78. sendFile(input.get(0).files).done(function(json){
  79. //remove loading image
  80. if(json['error'] != ''){
  81. var response = {
  82. 'alertClass' : 'danger',
  83. 'alertMessage' : json['error'],
  84. };
  85. app.appView.hideLoader();
  86. app.appView.renderResponseAlert(response);
  87. }else if(json['fileNames']){
  88. $.each(json['fileNames'], function(key, path){
  89. editor.insertContent('<img class="content-img" src="' + path + '"/>');
  90. });
  91. }
  92. if(json.location != undefined)
  93. window.location = json.location;
  94. })
  95. .fail(function(xhr) {
  96. if(url = xhr.getResponseHeader('Location'))
  97. window.location = url;
  98. app.appView.hideLoader();
  99. app.appView.renderResponseAlert(warningResponse);
  100. })
  101. ;
  102. },
  103. }
  104. function sendFile(files) {
  105. var data = new FormData();
  106. var nonEmptyFlag;
  107. $.each(files, function(key, file){
  108. var patt = new RegExp("(image/)(?!tif)");
  109. if(file.type && patt.test(file.type)) {
  110. data.append("attachments[]", file);
  111. nonEmptyFlag = true;
  112. }
  113. });
  114. {# var path = "{{ '/customer/' in app.request.requestUri ? path('ajax_file_upload_customer') : path('ajax_file_upload') }}";
  115. if(nonEmptyFlag) {
  116. return $.ajax({
  117. data: data,
  118. type: "POST",
  119. enctype: 'multipart/form-data',
  120. url: path,
  121. processData: false,
  122. contentType: false,
  123. cache: false,
  124. });
  125. } else {
  126. app.appView.renderResponseAlert({'alertClass': 'danger', 'alertMessage': '{{ "Warning! Select valid image file."|trans }}' });
  127. } #}
  128. }
  129. function sendUrls(url) {
  130. {# var path = "{{ '/customer/' in app.request.requestUri ? path('ajax_url_file_customer') : path('ajax_url_file') }}";
  131. return $.ajax({
  132. data: {'url': url},
  133. type: "POST",
  134. url: path,
  135. dataType: 'json'
  136. }); #}
  137. }
  138. function removeFile(file) {
  139. {# var path = "{{ '/customer/' in app.request.requestUri ? path('ajax_file_remove_customer') : path('ajax_file_remove') }}";
  140. return $.ajax({
  141. data: {'path': file},
  142. type: "POST",
  143. url: path,
  144. dataType: 'json'
  145. }); #}
  146. }
  147. addTranslateButton = function(editor) {
  148. {# editor.addButton('translate', {
  149. type: 'listbox',
  150. title : 'selectContentAndTranslate',
  151. text: '{{ "Translate"|trans }}',
  152. onselect: function (e) {
  153. this.text('{{ "Translate"|trans }}');
  154. if(editor.selection.getContent({format : 'html'})) {
  155. ajaxData = {
  156. 'lang': this.value(),
  157. 'content': editor.selection.getContent({format : 'html'}),
  158. };
  159. tinyMCE.activeEditor.setProgressState(true);
  160. } else {
  161. editor.notificationManager.close();
  162. editor.notificationManager.open({
  163. text: '{{ "Select text then select language to translate text."|trans }}',
  164. type: 'info',
  165. timeout: 3000,
  166. closeButton: true
  167. });
  168. }
  169. },
  170. values: [
  171. {% for value, text in application_service.getTranslationSupportedLanguages() %}
  172. { text: '{{ text }}', value: '{{ value }}' },
  173. {% endfor %}
  174. { text: '“Powered by Yandex.Translate”', value: '', disabled: true },
  175. ],
  176. }); #}
  177. }
  178. </script>