/** * 2007-2020 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA * @copyright 2007-2020 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ $(document).on("click", ".datatext", function(e) { window.location.href = b64_to_utf8($(this).attr("datatext")); }); function b64_to_utf8(str) { return decodeURIComponent(escape(window.atob(str))); } $( document ).ready(function() { // Activar boton comentarios $(document).on('click', '.politica_privacidad', function(){ var checked = $("input[name=politica_privacidad]:checked", $(this).parents("form")).length; var nombre = $('input[name=nombre]', $(this).parents("form")).length; if(checked > 0 && nombre > 0){ $(".send_comment", $(this).parents("form")).removeAttr("disabled"); } else { $(".send_comment", $(this).parents("form")).attr( "disabled", "disabled" ); } }); // Enviar Comentario $(document).on('click', '.send_comment', function(){ var id_post = $('input[name=id_post]', $(this).parents("form")).val(); var id_comment = $('input[name=id_comment]', $(this).parents("form")).val(); var nombre = $('input[name=nombre]', $(this).parents("form")).val(); var comentario = $('textarea[name=comentario]', $(this).parents("form")).val(); var rating = $('input[name=rating]:checked', $(this).parents("form")).val(); // var url_comment = $('.form_comment_post').attr('action'); var checked = $("input[name=politica_privacidad]:checked", $(this).parents("form")).length; if(checked == 0){ alert('Debe de aceptar la politica de privacidad para comentar'); return; } requestData = { id_post: id_post, id_comment: id_comment, nombre: nombre, comentario: comentario, rating: rating, action: 'send_comment', }; $.ajax({ url: dbblog_ajax, type: 'POST', data: requestData, dataType: 'json', success: function(response) { if(response.result == 'OK'){ modal = ''; $('input[name=nombre]').val(''); $('textarea[name=comentario]').val(''); } else { modal = ''; } $('body').append(modal); $('#comment_created').modal('show'); } }); }); // Scroll infinito $(document).on('click', '.btn_db_inifinitescroll', function(){ var page = document.getElementById('btn_db_inifinitescroll').dataset.pag; var id_category = $('.btn_db_inifinitescroll').data('category'); console.log(page); requestData = { page: page, id_category: id_category, action: 'infinite_scroll', }; $.ajax({ url: dbblog_ajax, type: 'POST', data: requestData, dataType: 'json', success: function(response) { if(response.result == 'OK'){ // Calculamos la pagina siguiente page_plus = parseInt(page) + 1; $('.btn_db_inifinitescroll').attr('data-pag', page_plus); // Sacamos los post vistos hasta el momento sum_infinite_from = document.getElementById('sum_infinite_from').dataset.sumin; sum_infinite = parseInt(sum_infinite_from) + parseInt(response.sum); $('.sum_infinite_from').html(sum_infinite); $('.sum_infinite_from').attr('data-sumin', sum_infinite); // Calculamos el porcentaje de progreso total_posts = $('.total_posts').data('total'); porcent = (sum_infinite * 100 / total_posts).toFixed(2); $('.progress-bar').css('width', porcent+'%'); // Pintamos los posts llamados por ajax $('.post__grid').append(response.list_post); // Oculatmos el boton si ya no hay mas posts if(total_posts <= sum_infinite){ $('#btn_db_inifinitescroll').hide(); } } } }); }); // Scroll infinito Author $(document).on('click', '.btn_db_inifinitescroll_author', function(){ var page = document.getElementById('btn_db_inifinitescroll_author').dataset.pag; var id_author = $('.btn_db_inifinitescroll_author').data('author'); requestData = { page: page, id_author: id_author, action: 'infinite_scroll_author', }; $.ajax({ url: dbblog_ajax, type: 'POST', data: requestData, dataType: 'json', success: function(response) { if(response.result == 'OK'){ // Calculamos la pagina siguiente page_plus = parseInt(page) + 1; $('.btn_db_inifinitescroll_author').attr('data-pag', page_plus); // Sacamos los post vistos hasta el momento sum_infinite_from = document.getElementById('sum_infinite_from').dataset.sumin; sum_infinite = parseInt(sum_infinite_from) + parseInt(response.sum); $('.sum_infinite_from').html(sum_infinite); $('.sum_infinite_from').attr('data-sumin', sum_infinite); // Calculamos el porcentaje de progreso total_posts = $('.total_posts').data('total'); porcent = (sum_infinite * 100 / total_posts).toFixed(2); $('.progress-bar').css('width', porcent+'%'); // Pintamos los posts llamados por ajax $('.post__grid').append(response.list_post); // Oculatmos el boton si ya no hay mas posts if(total_posts <= sum_infinite){ $('#btn_db_inifinitescroll_author').hide(); } } } }); }); // Formulario respuesta $(document).on('click', '.btn_form_respond', function(){ var id_comment = $(this).data('id-comment'); var id_post = $(this).data('id-post'); if ($('.form_respond_' + id_comment + ':has(*)').length) { $('.form_respond_' + id_comment).empty(); return; } requestData = { id_comment: id_comment, id_post: id_post, action: 'form_respond', }; $.ajax({ url: dbblog_ajax, type: 'POST', data: requestData, dataType: 'json', success: function(response) { if(response.result == 'OK'){ $('.form_respond_' + id_comment).append(response.form); } } }); }); // Mostrar menu mobile $(document).on('click', '.dbblog_menu_mobile', function(){ $('.menu .list_category').css('opacity', '1'); $('.menu .list_category').css('visibility', 'visible'); $('.menu .menub__overlay').css('opacity', '1'); $('.menu .menub__overlay').css('visibility', 'visible'); $('body').css('overflow', 'hidden'); }); // Ocultar menu mobile $(document).on('click', '.close_menub', function(){ $('.menu .list_category').css('opacity', '0'); $('.menu .list_category').css('visibility', 'hidden'); $('.menu .menub__overlay').css('opacity', '0'); $('.menu .menub__overlay').css('visibility', 'hidden'); $('body').css('overflow', 'auto'); }); });