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