Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function collectPostBody(additional) {
- var post_body = {chars: 0, blocks: 0, images: 0, videos: 0};
- var body = [];
- if (additional && additional.tags) {
- post_body.tags = 0;
- $.each($('.tags-input select.tags option'), function(){
- post_body.tags++;
- });
- }
- $.each($('#list-media>li'), function() {
- var block = {};
- var type = $(this).data('type');
- block.type = type;
- if (type == 'image') {
- block.id = $(this).find('.input-image').data('id');
- if (!block.id) {
- $(this).remove();
- return true;
- }
- post_body.blocks++;
- post_body.images++;
- } else if (type == 'text') {
- $(this).find('.ck-content a').attr('rel', 'nofollow noopener');
- var html = $(this).find('.ck-content').html();
- var temp_el = document.createElement("div");
- temp_el.innerHTML = html;
- var text_printed = $.trim(temp_el.innerText);
- if (text_printed == "") {
- $(this).remove();
- return true;
- }
- block.content = $.trim($(this).find('.ck-content').html()).replace(/ /g, ' ');
- post_body.chars += text_printed.length;
- post_body.blocks++;
- } else if (type == 'video') {
- block.content = $(this).find('.input-video-js').val();
- block.source = $(this).find('.input-video-js').data('source');
- block.ratio = $(this).find('.input-video-js').data('ratio');
- block.thumb = $(this).find('.video_preview img').prop('src');
- if (!block.source) {
- $(this).remove();
- return true;
- }
- post_body.videos++;
- post_body.blocks++;
- }
- body.push(block);
- });
- if (validatePostBody(post_body, additional)) {
- var json_body = JSON.stringify(body);
- $('#track_input').val(e(json_body));
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement