/* * 2019 Areama * * 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@areama.net so we can send you a copy immediately. * * * @author Areama * @copyright 2019 Areama * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of Areama */ var arPL = { currentProduct: null, ajaxTabs: [], ps: 17, init: function(){ jQuery('.ar-pl-promotions').on('click', '.ar-pl-promo-total-add-to-cart', function(){ var promoId = jQuery(this).data('promo-id'); arPL.addToCart(promoId); }); jQuery('.arpl-group-tabbed').on('click', '.arpl-tab-ajax', function(){ var id = jQuery(this).data('id'); var group_id = jQuery(this).data('group'); arPL.loadAjaxTab(group_id, id); }); jQuery('.arpl-group-tabbed').on('click', '.arpl-tab-header a', function(){ var $this = $(this); setTimeout(function(){ $this.get(0).scrollIntoView({ block: "start", behavior: "smooth" }); }, 100); }); jQuery('.arpl-tab-header a').click(function(e){ jQuery(this).parents('.arpl-tab-content').find('.arpl-tab-header a.active').removeClass('active'); }); if (arPL.ps == 16){ arPL.init16(); } }, init16: function(){ jQuery('.arpl-group-tabbed').on('click', '.nav-link', function(){ jQuery('.arpl-group-tabbed .nav-link.active').removeClass('active'); }); }, initOWLSlider: function(group_id, id, list, breakdowns){ jQuery('#arpl-section-' + group_id + '-' + id + '-carousel').arplOwlCarousel({ loop: list.loop, margin: 0, nav: list.controls, dots: list.dots, responsiveClass: 'arpl-responsive', responsiveBaseElement: list.responsiveBaseElement == 'window'? window : jQuery('#arpl-section-' + group_id + '-' + id + '-carousel').parent(), center: false, lazyLoad: false, autoplay: list.autoplay, autoplayTimeout: list.autoplayTimeout, autoplayHoverPause: true, mouseDrag: list.drag, touchDrag: list.drag, navText: [ '', '' ], responsive:breakdowns }); }, loadAjaxTab: function(group_id, id){ if (arPL.ajaxTabs.indexOf(id) !== -1){ return false; } jQuery('#arpl-tab-' + id).addClass('arpl-ajax-loading'); jQuery.ajax({ type: 'POST', url: arplAjaxURL, dataType: 'json', data: { action: 'loadTab', ajax : true, id: id, group_id: group_id, product_id: arPL.currentProduct }, success: function(data){ jQuery('#arpl-tab-' + id).html(data.content); if (data.model.list.view == 1) { arPL.initOWLSlider(group_id, id, data.model.list, data.responsiveBreakdowns); } jQuery('#arpl-tab-' + id).removeClass('arpl-ajax-loading').addClass('arpl-ajax-loaded'); if (arPL.ps == 17) { prestashop.emit('updateProductList', {}); } arPL.ajaxTabs.push(id); } }).fail(function(){ jQuery('#arpl-tab-' + id).removeClass('arpl-ajax-loading').addClass('arpl-ajax-loaded').addClass('arpl-ajax-error'); console.log('fail'); }); }, showModal: function(promoId, ids){ console.log('arPL.showModal'); jQuery.ajax({ type: 'POST', url: arplAjaxURL, dataType: 'json', data: { action: 'showModal', ajax : true, ids: ids, cartRuleId: promoId }, success: function(data){ jQuery('#blockcart-modal').remove(); jQuery('body').append(data.content); jQuery('#blockcart-modal').modal('show'); } }).fail(function(){ console.log('fail'); }); }, addToCart: function(promoId){ var token = jQuery('#arpl-promo-token-' + promoId).val(); var ids = []; $('#arpl-promo-' + promoId).find('.ar-pl-promo-product.active').each(function(){ ids.push($(this).data('id')); }); $('#arpl-promo-' + promoId).find('.ar-pl-promo-total-add-to-cart').prop('disabled', 'disabled'); var idsClone = ids.slice(0); var lastId = idsClone.pop(); jQuery.each(ids, function(index){ jQuery.ajax({ type: 'POST', url: arplCartURL, dataType: 'json', data: { controller: 'cart', token: token, action: 'update', ajax : true, qty: 1, add: 1, id_product: this, id_customization: 0 }, success: function(data){ if (data.id_product == lastId){ if (arPL.ps == 17){ prestashop.emit('updateCart', {reason:data}); } arPL.showModal(promoId, ids); $('#arpl-promo-' + promoId).find('.ar-pl-promo-total-add-to-cart').removeAttr('disabled'); } } }).fail(function(){ console.log('fail'); }); }); } };