Advertisement
Guest User

Untitled

a guest
Oct 6th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.91 KB | None | 0 0
  1. FrEditor[idDomPostId] = new FroalaEditor('#'+idDomPostId,
  2.                 {
  3.                  saveURL: '/contents/publish/post_save/' + suffix,
  4.                  language: 'ru',
  5.                  requestHeaders: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
  6.                  toolbarSticky: false,
  7.                  saveInterval: 0,
  8.                  videoUpload: false,
  9.                  imageUploadRemoteUrls: false,
  10.                  enter: FroalaEditor.ENTER_DIV,
  11.                  toolbarButtons: {
  12.                                   moreText: {
  13.                                               buttons: [ //'bold', 'italic', 'underline', 'fontSize', 'textColor', 'paragraphFormat', 'formatOL', 'formatUL',
  14.                                                         'insertLink', 'insertImage', 'insertVideo', 'insertAudio', 'specialCharacters',
  15.                                                         'html',  'selectAll', 'undo', 'redo','myButton'
  16.                                                        ],
  17.                                               align: 'left',
  18.                                               buttonsVisible: 10
  19.                                             },
  20.                                   moreMisc: {
  21.                                              buttons: is_new ? [ 'saveOrig', 'print', 'fullscreen' ] :
  22.                                                                [ 'saveOrig', 'saveCopy', 'print', 'fullscreen', 'cancelEdit' ],
  23.                                              align: 'right',
  24.                                              buttonsVisible: 5
  25.                                             }
  26.                                  },
  27.                   pluginsEnabled: ['align', 'charCounter', 'codeBeautifier', 'codeView', 'colors', 'draggable', 'embedly', 'emoticons', 'entities', 'file', 'fontAwesome', 'fontFamily', 'fontSize', 'fullscreen', 'image', 'imageTUI', 'imageManager', 'inlineStyle', 'inlineClass', 'lineBreaker', 'lineHeight', 'link', 'lists', 'paragraphFormat', 'paragraphStyle', 'quickInsert', 'quote', 'save', 'table', 'url', 'video', 'wordPaste'],
  28.  
  29.                  events: {'image.beforeUpload': function (files) {
  30.                           var editor = this;
  31.                           for(var file_i in files){
  32.                             // Create a File Reader.
  33.                               var reader = new FileReader();
  34.  
  35.                               // Set the reader to insert images when they are loaded.
  36.                               reader.onload = function (e) {
  37.                                var result = e.target.result;
  38.                                editor.image.insert(result, null, null, editor.image.get());
  39.                               };
  40.  
  41.                               // Read image as base64.
  42.                               reader.readAsDataURL(files[file_i]);
  43.                           }
  44.                           editor.popups.hideAll();
  45.  
  46.                           // Stop default upload chain.
  47.                           return false;
  48.                          },
  49.                           'save.after': function (data)
  50.                                         {
  51.                                          var obj = $.parseJSON(data);
  52.                                          var orig_id  = obj.original_id;
  53.                                          var saved_id = obj.saved_id;
  54.                                          var is_manual= obj.is_manual;
  55.                                          var author = obj.author;
  56.                                          var change_time = obj.change_time;
  57.                                          var postId = orig_id;
  58.                                          var idDomPostId = 'idPost_' + postId;
  59.                                          var thread_id = obj.thread_id;
  60.                                          var current_media_body = FrEditor[idDomPostId].html.get();
  61.  
  62.                                          console.log('[save.after]: ', orig_id, saved_id);
  63.                                          // console.log('[save.after]: current_media_body', current_media_body);
  64.                                          if (orig_id == saved_id)
  65.                                             {
  66.                                              MediaBodyCopy[idDomPostId].html(current_media_body);
  67.                                             }
  68.                                            else
  69.                                             { // была сохранена новая публикация
  70.                                               $(PanelCopy[orig_id]).data('publication-id',saved_id).attr('data-publication-id',saved_id);
  71.                                               $(PanelCopy[orig_id]).prop('id','idPost_' + saved_id + '_panel');
  72.  
  73.                                               var a_author = PanelCopy[orig_id].find('#id' + orig_id + '_author')[0];
  74.                                               $(a_author).prop('id', 'id' + saved_id + '_author');
  75.                                               $(a_author).children('b').text(author);
  76.  
  77.                                               var div_right = PanelCopy[orig_id].find('#idPost_' + orig_id + '_right')[0];
  78.                                               $(div_right).data('id',saved_id).attr('data-id',saved_id);
  79.                                               $(div_right).data('thread-id',thread_id).attr('data-thread-id',thread_id);
  80.                                               $(div_right).data('author',thread_id).attr('data-author',author);
  81.                                               $(div_right).prop('id', 'idPost_' + saved_id + '_right');
  82.                                               $($(div_right).find('.uk_change_time')[0]).text(change_time);
  83.                                               $(div_right).find('div.uk_publish_button').css('display', 'inline-block');
  84.  
  85.                                               var new_media_body = MediaBodyCopy[idDomPostId].clone();
  86.                                               // console.log('[save.after]: new_media_body', new_media_body);
  87.                                               new_media_body.html(current_media_body);
  88.                                               $(new_media_body).data('id',saved_id).attr('data-id',saved_id);
  89.                                               $(new_media_body).data('new', false).attr('data-new', false);
  90.                                               $(new_media_body).prop('id', 'idPost_' + saved_id);
  91.                                               // console.log('new_media_body', new_media_body);
  92.  
  93.                                               var old_media_body = PanelCopy[orig_id].find('#idPost_' + orig_id)[0];
  94.                                               $(old_media_body).replaceWith(new_media_body);
  95.                                               var old_panel = PanelCopy[orig_id].find('div.v5_panel_heading > div')[0];
  96.  
  97.                                               $(old_panel).text('*');
  98.                                               $('#idPost_' + orig_id + '_panel').before(PanelCopy[orig_id].clone());
  99.  
  100.                                               if (is_manual == true) $('#' + idDomPostId + '_panel').remove();
  101.                                             }
  102.  
  103.                                          $('#' + idDomPostId).removeClass('display_block');
  104.                                          $('#' + idDomPostId + '_right').fadeIn();
  105.                                          FrEditor[idDomPostId].destroy();
  106.                                          delete FrEditor[idDomPostId];
  107.                                          $('#' + idDomPostId).replaceWith(MediaBodyCopy[idDomPostId].clone(true));
  108.                                          delete MediaBodyCopy[idDomPostId];
  109.                                          delete PanelCopy[postId];
  110.                                         }
  111.                          }
  112.                 },
  113.                 function () { FrEditor[idDomPostId].charCounter.count(); });
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement