/** * 2017-2019 Zemez * * JX Compare Product * * NOTICE OF LICENSE * * This source file is subject to the General Public License (GPL 2.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/GPL-2.0 * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade the module to newer * versions in the future. * * @author Zemez * @copyright 2017-2019 Zemez * @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0) */ $(document).ready(function(){ prestashop.jxcompare = prestashop.jxcompare || {}; var noComparingPreview = true; var $body = $('body'); var $header_info = $body.find('.compare-header'); var $container = $body.find('#compare-footer').length ? $body.find('#compare-footer') : $header_info; var $compareCounter = $body.find('.compare-counter'); var $containerList = $body.find('#compare-list-footer'); var refresh_url = $body.find('#compare-footer').attr('data-refresh-url'); if (refresh_url === undefined) { var refresh_url = $header_info.attr('data-refresh-url'); } var $compareMax = $container.attr('data-compare-max'); prestashop.urls.jxcompare = refresh_url; var setProducts = function() { if (localStorage.compareProducts) { var available = localStorage.compareProducts.split(','); if (available.length) { prestashop.jxcompare.products = available; $compareCounter.text(available.length); } } else { $compareCounter.text(0); prestashop.jxcompare.products = []; } }; setProducts(); var checkProductStatus = function() { $body.find('.js-compare-button').each(function() { var id_product = $(this).attr('data-id-product'); if (prestashop.jxcompare.products.indexOf(id_product) !== -1) { $(this).addClass('selected'); } else { $(this).removeClass('selected'); } }); }; checkProductStatus(); var showModal = prestashop.jxcompare.showModal || function(modal) { $.ajax({ type: 'GET', async: true, dataType: "json", headers: {"cache-control": "no-cache"}, url: refresh_url, cache: false, data: { rand: new Date().getTime(), action : 'show-modal', products : prestashop.jxcompare.products }, beforeSend: function() { $('.modal-compare').remove(); }, success: function (data) { $body.append(data.response); $('#modal-compare').modal('show'); $('#modal-compare').on('hidden.bs.modal', function (e) { $('#modal-compare').remove(); }); } }); }; var clearCompare = prestashop.jxcompare.clearCompare || function() { prestashop.jxcompare.products = []; localStorage.setItem('compareProducts', ''); $containerList.find('.compare-product-element').each(function() {$(this).remove()}); $compareCounter.text(0); $containerList.find('.no-products').remove(); $containerList.append('
'+$container.attr('data-empty-text')+'