/* * 2017-2019 Zemez * * JX Wishlist * * 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) */ jxwishlist = { list: function(){ this.init = function(json) { if (json == '') { json = '[]'; } this.array = JSON.parse(json); }; this.extend = function(json) { var products = JSON.parse(json); for (var i = 0; i < products.length; i++) { this.array[this.array.length] = products[i]; } return JSON.stringify(this.array); }; this.add = function(elem){ if (this.array.indexOf(elem) == -1) { this.array[this.array.length] = elem; } return JSON.stringify(this.array); }; this.remove = function(elem){ var index = this.array.indexOf(elem); this.array.splice(index, 1); return JSON.stringify(this.array); } } }; $(document).ready(function(){ $(':input','#form_wishlist') .not(':button, :submit, :reset, :hidden') .val('') .removeAttr('checked') .removeAttr('selected'); $(".edit-wishlist").click(function(){ $('html, body').animate({scrollTop : 0},800); return false; }); $("#wishlist_button").popover({ html: true, content: function(){ return $("#popover-content-wishlist").html(); } }); $('.btn-product-wishlist').click(function() { $(this).parent().prev().fadeToggle( "slow", "linear" ); $(this).addClass('active'); }); $("#change_wishlist").hide(); jxwl_layouts = new Array(); $(document).on('click', '#add-new-layout', function() { var wishlist_name = $(this).parent().parent().attr('data-wishlist-name'); layouts_popup(wishlist_name); var wishlist_id = $(this).parent().parent().attr('data-wishlist-id'); $('#id_wishlist_popup').attr('value', wishlist_id); $('#name_wishlist_popup').attr('value', wishlist_name); $('.jxwl-step-2').hide(); }); $(document).on('click', '#back_button', function() { $('.block-container-row').remove(); $('#jxwl-layouts-popup > .jxwl_popup_item, .jxwl-step-1').show(); $('.jxwl-step-2').hide(); }); $(document).on('click', '#jxwl-layouts-popup > .jxwl_popup_item > .items', function() { layout_type = $(this).attr('id'); addNewRow(layout_type); $('#jxwl-layouts-popup > .jxwl_popup_item, .jxwl-step-1').hide(); $('.jxwl-step-2').show(); $("#back_button_step_2").hide(); }); $(document).on('click', '.block-container-row .jxwl_popup_item li', function() { $(this).addClass('active'); $('.block-container-row .jxwl_popup_item, .block-container-row .share_button, .block-container-row #back_button').hide(); $('.block-container-product, .block-container-row .alert-warning, #clear-item').show(); if($('.block-container-product > div.done').length <= 0) { $('.block-container-row .block-container-product').append('

' + wishlist_no_product + '

'); } $("#back_button_step_2").show(); }); $(document).on('click', '.block-container-row .jxwl_popup_item li .jxwl-content-image', function() { $('.block-container-product .alert').hide(); var products = new jxwishlist.list() data_product_id = $(this).attr('data-product-id'); products.init($('#popup_selected_products').attr('value')); $('#popup_selected_products').attr('value', products.remove(data_product_id)); $('.block-container-product .product').filter('[data-product-id="'+data_product_id+'"]').removeClass('active'); $('.block-container-product .product').filter('[data-product-id="'+data_product_id+'"]').addClass('done'); }); $(document).on('click', '.block-container-product .product', function(e){ image_src = $(this).find('img').attr('src'); current_block = $('.block-container-row .jxwl_popup_item li.active .content'); current_block.find('.content-inner').remove(); current_block.append('
'); current_block.addClass('current'); $('.block-container-row .jxwl_popup_item li.active .content .jxwl-content-image').attr('data-product-id', $(this).attr("data-product-id")); $(this).addClass('active'); $(this).removeClass('done'); $('.block-container-row .share_button').show(); var products = new jxwishlist.list(); products.init($('#popup_selected_products').attr('value')); var product_id = $(this).attr('data-product-id'); $('#popup_selected_products').attr('value', products.add(product_id)); $('.block-container-product, #back_button_step_2').hide(); $('.block-container-row .jxwl_popup_item, .block-container-row #share_button, .block-container-row #back_button').show(); $('.block-container-row .jxwl_popup_item li').removeClass('active'); }); $(document).on('click', '#back_button_step_2', function() { $('.block-container-row .share_button, .block-container-row .jxwl_popup_item, #back_button').show(); $('.block-container-product, #back_button_step_2').hide(); $('.block-container-row .jxwl_popup_item li').removeClass('active'); $('.block-container-product .alert').remove(); var products = new jxwishlist.list(); products.init($('#popup_selected_products').attr('value')); if (typeof(data_product_id) != 'undefined' && data_product_id.length) { $('#popup_selected_products').attr('value', products.add(data_product_id)); $('.block-container-product .product').filter('[data-product-id="' + data_product_id + '"]').removeClass('done'); $('.block-container-product .product').filter('[data-product-id="' + data_product_id + '"]').addClass('active'); } }); $(document).on('click', '.clear-item', function(e){ e.stopPropagation(); $(this).parent().parent().parent().removeClass('current'); var products = new jxwishlist.list(), product_id = $(this).parent().attr('data-product-id'); products.init($('#popup_selected_products').attr('value')); $('#popup_selected_products').attr('value', products.remove(product_id)); $('.block-container-product .product').filter('[data-product-id="'+product_id+'"]').removeClass('active'); $('.block-container-product .product').filter('[data-product-id="'+product_id+'"]').addClass('done'); element = $(this).closest('li'); $(this).remove(); element.find('.content-inner').remove(); }); }); function layouts_popup(wishlist_name){ jxwl_lp_content = ''; if (jxwl_layouts.length) { for (i = 0; i < jxwl_layouts.length; i++) { jxwl_lp_content += jxwl_layouts[i].value; } } $('body').append(''); $('#wishlistModal').modal(); $('[id^="quickview-modal-"]').modal('hide'); $('#wishlistModal').on('hidden.bs.modal', function (e) { $('#wishlistModal').remove(); }); $('.jxwl_popup_item h5').append(wishlist_name); return false; } function getProductsByWishlistId(id_wishlist){ result = ''; $.ajax({ type:'POST', url: mywishlists_url, headers: { "cache-control": "no-cache" }, dataType: 'json', async:false, data: { rand: new Date().getTime(), myajax: 1, id_wishlist: id_wishlist, action: 'getProductsById', }, success: function(msg){ result = msg.response; } }); return result; } function addNewRow(layout_type){ layout = ''; var id_wishlist = $('#id_wishlist_popup[name=id_wishlist]').attr('value'); switch (layout_type) { case 'jxwl_row_1' : layout = jxwl_row_1; break; case 'jxwl_row_2' : layout = jxwl_row_2; break; case 'jxwl_row_3' : layout = jxwl_row_3; break; case 'jxwl_row_4' : layout = jxwl_row_4; break; default : layout = layout; } jxwl_new_row = ''; jxwl_new_row += '