admin.js
7 years ago
colpick.js
7 years ago
jquery.cookie.js
7 years ago
jquery.mousewheel.min.js
7 years ago
products_compare.js
7 years ago
products_compare.js
144 lines
| 1 | (function ($){ |
| 2 | $(document).ready( function () { |
| 3 | $(document).on( 'click', '.br_compare_button .fa', function ( event ) { |
| 4 | $button = $(this).parent(); |
| 5 | event.preventDefault(); |
| 6 | event.stopPropagation(); |
| 7 | var id = $button.data('id'); |
| 8 | toggle_products_compare(id); |
| 9 | load_selected_list(); |
| 10 | }); |
| 11 | $(document).on( 'click', '.br_compare_button', function ( event ) { |
| 12 | if ( add_products_compare($(this).data('id')) ) { |
| 13 | event.preventDefault(); |
| 14 | load_selected_list(); |
| 15 | } |
| 16 | }); |
| 17 | $(document).on( 'click', '.br_remove_compare_product', function ( event ) { |
| 18 | event.preventDefault(); |
| 19 | compare_products_execute_func( the_compare_products_data.user_func.before_remove ); |
| 20 | var $parent = $(this).parents('.berocket_compare_widget'); |
| 21 | remove_products_compare($(this).data('id')); |
| 22 | $('.br_widget_compare_product_'+$(this).data('id')).remove(); |
| 23 | has_compared_products( $parent.find('ul li').length ); |
| 24 | compare_products_execute_func( the_compare_products_data.user_func.after_remove ); |
| 25 | if( typeof(br_compare_page) != 'undefined' ) { |
| 26 | location.replace(br_compare_page); |
| 27 | } |
| 28 | }); |
| 29 | $(document).on( 'click', '.br_remove_compare_product_reload', function ( event ) { |
| 30 | event.preventDefault(); |
| 31 | remove_products_compare($(this).data('id')); |
| 32 | if($(this).parents('.br_compare_popup').length > 0) { |
| 33 | $('.br_compare_popup').remove(); |
| 34 | load_selected_list(); |
| 35 | $('.berocket_open_compare').click(); |
| 36 | } else { |
| 37 | location.replace(br_compare_page); |
| 38 | } |
| 39 | }); |
| 40 | function load_selected_list() { |
| 41 | if ( $('.berocket_compare_widget').length > 0 ) { |
| 42 | compare_products_execute_func( the_compare_products_data.user_func.before_load ); |
| 43 | var data = {action: 'br_get_compare_products'}; |
| 44 | $.post( the_compare_products_data.ajax_url, data, function ( data ) { |
| 45 | var $data = $(data).find('.berocket_compare_widget'); |
| 46 | var $data_text = $(data).find('.berocket_compare_widget'); |
| 47 | $data_text.find('img').remove(); |
| 48 | $('.berocket_compare_widget').each( function ( i, o ) { |
| 49 | if ( $(o).data('type') == 'text' ) { |
| 50 | $(o).html($data_text.html()); |
| 51 | } else { |
| 52 | $(o).html($data.html()); |
| 53 | } |
| 54 | if( $(o).data('fast_compare') ) { |
| 55 | $(o).find('.berocket_open_compare').addClass('berocket_open_smart_compare'); |
| 56 | } |
| 57 | }); |
| 58 | has_compared_products( $data.find('ul li').length ); |
| 59 | compare_products_execute_func( the_compare_products_data.user_func.after_load ); |
| 60 | }); |
| 61 | } |
| 62 | } |
| 63 | function has_compared_products( count ) { |
| 64 | if ( count > 0 ) { |
| 65 | $('.berocket_show_compare_toolbar').show(); |
| 66 | } else { |
| 67 | $('.berocket_compare_widget_toolbar').hide(); |
| 68 | $('.berocket_show_compare_toolbar').hide(); |
| 69 | $('.berocket_open_compare').remove(); |
| 70 | } |
| 71 | } |
| 72 | }); |
| 73 | })(jQuery); |
| 74 | function toggle_products_compare( product ) { |
| 75 | var products = set_get_products_compare_cookie(); |
| 76 | if ( ! products || products.search( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)|(," + product + ",)") ) == -1 ) { |
| 77 | add_products_compare( product ); |
| 78 | return true; |
| 79 | } else { |
| 80 | remove_products_compare( product ); |
| 81 | return false; |
| 82 | } |
| 83 | } |
| 84 | function add_products_compare( product ) { |
| 85 | var products = set_get_products_compare_cookie(); |
| 86 | jQuery('.br_product_' + product).addClass('br_compare_added'); |
| 87 | jQuery('.br_product_' + product).find('span.br_compare_button_text').text(jQuery('.br_product_' + product).find('span.br_compare_button_text').data('added')); |
| 88 | if ( ! products || products.search( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)|(," + product + ",)") ) == -1 ) { |
| 89 | if ( products !== false && products ) { |
| 90 | products = products + ',' + product; |
| 91 | } else { |
| 92 | products = '' + product; |
| 93 | } |
| 94 | set_get_products_compare_cookie( products ); |
| 95 | return true; |
| 96 | } else { |
| 97 | set_get_products_compare_cookie( products ); |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | function remove_products_compare( product ) { |
| 102 | var products = set_get_products_compare_cookie(); |
| 103 | if ( products !== false && products ) { |
| 104 | products = products.replace( new RegExp("(^" + product + "$)|(^" + product + ",)|(," + product + "$)"), '' ); |
| 105 | products = products.replace( new RegExp("," + product + ","), ',' ); |
| 106 | } |
| 107 | jQuery('.br_product_' + product).removeClass('br_compare_added'); |
| 108 | jQuery('.br_product_' + product).find('span.br_compare_button_text').text(jQuery('.br_product_' + product).find('span.br_compare_button_text').data('not_added')); |
| 109 | set_get_products_compare_cookie(products); |
| 110 | return products; |
| 111 | } |
| 112 | function set_get_products_compare_cookie ( value ) { |
| 113 | if ( typeof value === "undefined" ) { |
| 114 | value = false; |
| 115 | } |
| 116 | if ( value === false ) { |
| 117 | if ( jQuery.cookie( 'br_products_compare' ) ) { |
| 118 | return jQuery.cookie( 'br_products_compare' ); |
| 119 | } else { |
| 120 | return false; |
| 121 | } |
| 122 | } else { |
| 123 | var path = the_compare_products_data.home_url; |
| 124 | path = path.split(document.domain); |
| 125 | path = path[1]; |
| 126 | if ( path == '' ) { |
| 127 | path = '/'; |
| 128 | } |
| 129 | jQuery.cookie( 'br_products_compare', value, { path: path, domain: document.domain } ); |
| 130 | } |
| 131 | } |
| 132 | function compare_products_execute_func ( func ) { |
| 133 | if( the_compare_products_data.user_func != 'undefined' |
| 134 | && the_compare_products_data.user_func != null |
| 135 | && typeof func != 'undefined' |
| 136 | && func.length > 0 ) { |
| 137 | try{ |
| 138 | eval( func ); |
| 139 | } catch(err){ |
| 140 | alert('You have some incorrect JavaScript code (Product Compare)'); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 |