Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function collectPostBody(additional) {
  2.     var post_body = {chars: 0, blocks: 0, images: 0, videos: 0};
  3.     var body = [];
  4.  
  5.     if (additional && additional.tags) {
  6.         post_body.tags = 0;
  7.         $.each($('.tags-input select.tags option'), function(){
  8.             post_body.tags++;
  9.         });
  10.     }
  11.  
  12.     $.each($('#list-media>li'), function() {
  13.         var block = {};
  14.         var type = $(this).data('type');
  15.         block.type = type;
  16.         if (type == 'image') {
  17.             block.id = $(this).find('.input-image').data('id');
  18.             if (!block.id) {
  19.                 $(this).remove();
  20.                 return true;
  21.             }
  22.             post_body.blocks++;
  23.             post_body.images++;
  24.         } else if (type == 'text') {
  25.             $(this).find('.ck-content a').attr('rel', 'nofollow noopener');
  26.             var html = $(this).find('.ck-content').html();
  27.             var temp_el = document.createElement("div");
  28.             temp_el.innerHTML = html;
  29.             var text_printed = $.trim(temp_el.innerText);
  30.             if (text_printed == "") {
  31.                 $(this).remove();
  32.                 return true;
  33.             }
  34.             block.content = $.trim($(this).find('.ck-content').html()).replace(/ /g, ' ');
  35.             post_body.chars += text_printed.length;
  36.             post_body.blocks++;
  37.         } else if (type == 'video') {
  38.             block.content = $(this).find('.input-video-js').val();
  39.             block.source = $(this).find('.input-video-js').data('source');
  40.             block.ratio = $(this).find('.input-video-js').data('ratio');
  41.             block.thumb = $(this).find('.video_preview img').prop('src');
  42.             if (!block.source) {
  43.                 $(this).remove();
  44.                 return true;
  45.             }
  46.             post_body.videos++;
  47.             post_body.blocks++;
  48.         }
  49.         body.push(block);
  50.     });
  51.  
  52.     if (validatePostBody(post_body, additional)) {
  53.         var json_body = JSON.stringify(body);
  54.         $('#track_input').val(e(json_body));
  55.         return true;
  56.     }
  57.  
  58.     return false;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement