1function stCompareAddProduct(dom) 2{ 3 var $dom = $(dom); 4 var id_product = $dom.data('id-product'); 5 if(!id_product) 6 return false; 7 var remove = $dom.hasClass('st_added');//in gird the first click is alawys adding, being ingored if added, the sccond does jian shao 8 $dom.toggleClass('st_added').addClass('active'); 9 $.ajax({ 10 type: 'GET', 11 url: stcompare.url, 12 headers: { "cache-control": "no-cache" }, 13 async: true, 14 cache: false, 15 dataType: "json", 16 data: { 17 id_product:id_product, 18 ajax: 1, 19 action: remove ? 'deleteCompareProduct' : 'addCompareProduct' 20 }, 21 success: function (resp) 22 { 23 $('.stcompare_add.active').removeClass('active'); 24 //improve this 25 $('.stcompare_quantity').toggleClass('lingge', resp.total==0).html(resp.total);//.toggle(resp.total>0) 26 27 if(resp.success){ 28 // $('stcompare_'+id_product).addClass('st_added'); 29 stComparePopup(resp.message, 2); 30 }else{ 31 stComparePopup(resp.message, 0); 32 $(dom).toggleClass('st_added'); 33 } 34 }, 35 error: function(XMLHttpRequest, textStatus, errorThrown) 36 { 37 $('.stcompare_add.active').removeClass('active'); 38 $(dom).toggleClass('st_added'); 39 } 40 }); 41 42} 43function stCompareProductRemove(dom, action) 44{ 45 var $dom = $(dom); 46 var id_product = $dom.data('id-product'); 47 if(!id_product && !action) 48 return false; 49 $dom.addClass('active'); 50 $.ajax({ 51 type: 'GET', 52 url: stcompare.url, 53 headers: { "cache-control": "no-cache" }, 54 async: true, 55 cache: false, 56 dataType: "json", 57 data: { 58 id_product:id_product, 59 ajax: 1, 60 action: action ? 'deleteAllCompareProducts' : 'deleteCompareProduct' 61 }, 62 success: function (resp) 63 { 64 $('.remove_compare_product.active').removeClass('active'); 65 if (resp.success==1) { 66 if(!resp.total) 67 stCompareShowInformation(); 68 $('.stcompare_td_'+id_product).remove(); 69 $('.stcompare_quantity').toggleClass('lingge', resp.total==0).html(resp.total);//.toggle(resp.total>0) 70 } 71 else if(!resp.success) 72 { 73 stComparePopup(resp.message, 0); 74 } 75 }, 76 error: function(XMLHttpRequest, textStatus, errorThrown) 77 { 78 $('.remove_compare_product.active').removeClass('active'); 79 } 80 }); 81} 82function stCompareShowInformation() 83{ 84 $('.stcompare_table').addClass('d-none'); 85 $('.stcompare_no_products').removeClass('d-none'); 86} 87function stComparePopup(msg, autoclose) 88{ 89 $.magnificPopup.open({ 90 removalDelay: 500, 91 showCloseBtn: autoclose ? false : true, 92 callbacks: { 93 beforeOpen: function() { 94 this.st.mainClass = 'mfp-zoom-in'+(autoclose ? ' mfp-modal-noti ' : ''); 95 }, 96 open: function(){ 97 var persist=this; 98 if(autoclose) 99 setTimeout(function(){ 100 persist.close(); 101 }, autoclose*1000); 102 } 103 }, 104 items: { 105 src: '<div class="inline_popup_content small_popup mfp-with-anim text-center">'+stCompareHtmlDecode(msg)+'</div>', 106 type: 'inline' 107 } 108 }); 109} 110function stCompareHtmlDecode(input){ 111 var e = document.createElement('div'); 112 e.innerHTML = input; 113 return e.childNodes[0].nodeValue; 114} 115 116function stCompareUpdateInCache(){ 117 var selector = ''; 118 if(typeof(stcompare.ids)!='undefined' && stcompare.ids.length){ 119 selector += '.stcompare_'+stcompare.ids.join(',.stcompare_'); 120 } 121 if(selector) 122 $(selector).addClass('st_added'); 123} 124$(document).ready(function () { 125 if(typeof(stcompare)!='undefined'){ 126 $('body').on('click', '.remove_compare_product', function (event) { 127 event.preventDefault(); 128 stCompareProductRemove(this,0); 129 return false; 130 }); 131 $('body').on('click', '.stcompare_remove_all', function (event) { 132 event.preventDefault(); 133 stCompareProductRemove(this,1); 134 return false; 135 }); 136 $('body').on('click', '.stcompare_add', function (event) { 137 event.preventDefault(); 138 stCompareAddProduct(this); 139 return false;
140 }); 141 stCompareUpdateInCache(); 142 } 143});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.