1/** 2 * 2007-2017 Leotheme 3 * 4 * NOTICE OF LICENSE 5 * 6 * Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list 7 * 8 * DISCLAIMER 9 * 10 * @Module Name: Leo Feature 11 * @author leotheme <[email protected]> 12 * @copyright 2007-2017 Leotheme 13 * @license http://leotheme.com - prestashop template provider 14 */ 15$(document).ready(function(){ 16 createLeoWishlistModalPopup(); 17 LeoWishlistButtonAction(); 18 prestashop.on('updateProductList', function() { 19 LeoWishlistButtonAction(); 20 }); 21 //DONGND:: recall button action if need when change attribute at product page 22 prestashop.on('updatedProduct', function() { 23 LeoWishlistButtonAction(); 24 }); 25 prestashop.on('clickQuickView', function() { 26 check_active_wishlist = setInterval(function(){ 27 if($('.quickview.modal').length) 28 { 29 $('.quickview.modal').on('shown.bs.modal', function (e) { 30 LeoWishlistButtonAction(); 31 }) 32 clearInterval(check_active_wishlist); 33 } 34 35 }, 300); 36 37 }); 38 39 // $('.quickview.modal').on('shown.bs.modal', function (e) { 40 // console.log('aaa'); 41 // }) 42 activeEventModalWishlist(); 43 LeoListWishlistAction(); 44 $('.leo-save-wishlist-bt').click(function(){ 45 if (!$(this).hasClass('active')) 46 { 47 $(this).addClass('active'); 48 $('.new-wishlist .has-danger .form-control-feedback').html(''); 49 $('.new-wishlist .has-success .form-control-feedback').html(''); 50 var name_wishlist = $.trim($('#wishlist_name').val()); 51 if (!name_wishlist) 52 { 53 $('#wishlist_name').parent().addClass('has-error'); 54 $(this).removeClass('active'); 55 } 56 else 57 { 58 var object_e = $(this); 59 $('#wishlist_name').parent().removeClass('has-error'); 60 $('.leo-save-wishlist-bt-text').hide(); 61 $('.leo-save-wishlist-loading').css({'display':'block'}); 62 $.ajax({ 63 type: 'POST', 64 headers: {"cache-control": "no-cache"}, 65 url: wishlist_url+ '?rand=' + new Date().getTime(), 66 async: true, 67 cache: false, 68 data: { 69 "ajax": 1, 70 "action": "add-wishlist", 71 "name_wishlist": name_wishlist, 72 "token": leo_token 73 }, 74 success: function (result) 75 { 76 var object_result = $.parseJSON(result); 77 if (object_result.errors.length) 78 { 79 // console.log(object_result.errors); 80 $('.new-wishlist .has-success .form-control-feedback').html(''); 81 $('.new-wishlist .has-danger .form-control-feedback').html(object_result.errors).fadeIn(); 82 } 83 else 84 { 85 $('.new-wishlist .has-danger .form-control-feedback').html(''); 86 $('.new-wishlist .has-success .form-control-feedback').html(object_result.result.message).fadeIn(); 87 setTimeout(function() { 88 $('.new-wishlist .has-success .form-control-feedback').fadeOut(); 89 }, 3000); 90 $('#wishlist_name').val(''); 91 92 $('.list-wishlist table tbody').append(object_result.result.wishlist); 93 $('html, body').animate({ 94 scrollTop: $('.list-wishlist table tr.new').offset().top 95 }, 500, function (){ 96 $('.list-wishlist table tr.new').removeClass('new'); 97 }); 98 LeoListWishlistAction(); 99 //DONGND:: reload list product if a wishlist current view 100 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 101 } 102 $('.leo-save-wishlist-bt-text').show(); 103 $('.leo-save-wishlist-loading').hide(); 104 object_e.removeClass('active'); 105 }, 106 error: function (XMLHttpRequest, textStatus, errorThrown) { 107 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 108 } 109 }); 110 111 } 112 } 113 return false; 114 }) 115}); 116 117function createLeoWishlistModalPopup() 118{ 119 var leoWishlistModalPopup = ''; 120 leoWishlistModalPopup += '<div class="modal leo-modal leo-modal-wishlist fade" tabindex="-1" role="dialog" aria-hidden="true">'; 121 leoWishlistModalPopup += '<div class="modal-dialog" role="document">'; 122 leoWishlistModalPopup += '<div class="modal-content">'; 123 leoWishlistModalPopup += '<div class="modal-header">'; 124 leoWishlistModalPopup += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'; 125 leoWishlistModalPopup += '<span aria-hidden="true">×</span>'; 126 leoWishlistModalPopup += '</button>'; 127 leoWishlistModalPopup += '<h5 class="modal-title text-xs-center">'; 128 leoWishlistModalPopup += '</h5>'; 129 leoWishlistModalPopup += '</div>'; 130 leoWishlistModalPopup += '<div class="modal-footer">'; 131 leoWishlistModalPopup += '<button type="button" class="btn btn-secondary" data-dismiss="modal">'+wishlist_cancel_txt+'</button>'; 132 leoWishlistModalPopup += '<button type="button" class="leo-modal-wishlist-bt btn btn-primary">'; 133 leoWishlistModalPopup += '<span class="leo-modal-wishlist-loading cssload-speeding-wheel"></span>'; 134 leoWishlistModalPopup += '<span class="leo-modal-wishlist-bt-text">'; 135 leoWishlistModalPopup += wishlist_ok_txt; 136 leoWishlistModalPopup += '</span>'; 137 leoWishlistModalPopup += '</button>'; 138 leoWishlistModalPopup += '</div>'; 139 leoWishlistModalPopup += '</div>'; 140 leoWishlistModalPopup += '</div>'; 141 leoWishlistModalPopup += '</div>'; 142 $('body').append(leoWishlistModalPopup); 143} 144 145function LeoWishlistButtonAction() 146{ 147 if (!$('.leo-wishlist-button').hasClass('show-list')) 148 { 149 $('.leo-wishlist-button').click(function(){ 150 if (!$('.leo-wishlist-button.active').length) 151 { 152 var id_product = $(this).data('id-product'); 153 var id_wishlist = $(this).data('id-wishlist'); 154 var id_product_attribute = $(this).data('id-product-attribute'); 155 var content_wishlist_mess_remove = wishlist_remove+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 156 var content_wishlist_mess_add = wishlist_add+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 157 158 $(this).addClass('active'); 159 160 if (!isLogged) 161 { 162 //DONGND:: display quicklogin if enable 163 // if ($('.leo-quicklogin').length) 164 // { 165 // $('.leo-quicklogin').first().trigger('click'); 166 // resetButtonAction(); 167 // } 168 // else 169 // {
170 $('.leo-modal-wishlist .modal-title').html(wishlist_loggin_required); 171 $('.leo-modal-wishlist').modal('show'); 172 // } 173 return false; 174 } 175 176 var object_e = $(this); 177 object_e.find('.leo-wishlist-bt-loading').css({'display':'block'}); 178 object_e.find('.leo-wishlist-bt-content').hide(); 179 if ($(this).hasClass('added') || $(this).hasClass('delete')) 180 { 181 //DONGND:: remove product form wishlist 182 $.ajax({ 183 type: 'POST', 184 headers: {"cache-control": "no-cache"}, 185 url: wishlist_url+ '?rand=' + new Date().getTime(), 186 async: true, 187 cache: false, 188 data: { 189 "ajax": 1, 190 "action": "remove", 191 "id_product": id_product, 192 "id_wishlist": id_wishlist, 193 "id_product_attribute": id_product_attribute, 194 "quantity": 1, 195 "token": leo_token 196 }, 197 success: function (result) 198 { 199 var object_result = $.parseJSON(result); 200 if (object_result.errors.length) 201 { 202 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 203 $('.leo-modal-wishlist').modal('show'); 204 } 205 else 206 { 207 //Leotheme add: update number product on icon wishlist after remove from wishlist 208 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 209 { 210 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 211 var new_num_wishlist = old_num_wishlist-1; 212 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 213 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 214 } 215 216 // compared_products.splice($.inArray(parseInt(id_product), compared_products), 1); 217 if (object_e.hasClass('delete')) 218 { 219 //DONGND:: remove from page wishlist 220 $('td.product-'+id_product).fadeOut(function(){ 221 $(this).remove(); 222 }); 223 } 224 else 225 { 226 //DONGND:: remove from page product list 227 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_remove); 228 $('.leo-modal-wishlist').modal('show'); 229 $('.leo-wishlist-button[data-id-product='+id_product+']').removeClass('added'); 230 $('.leo-wishlist-button[data-id-product='+id_product+']').attr('title',buttonwishlist_title_add); 231 object_e.find('.leo-wishlist-bt-loading').hide(); 232 object_e.find('.leo-wishlist-bt-content').show(); 233 } 234 } 235 }, 236 error: function (XMLHttpRequest, textStatus, errorThrown) { 237 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 238 } 239 }); 240 } 241 else 242 { 243 244 //DONGND:: add product to list product wishlist 245 $.ajax({ 246 type: 'POST', 247 headers: {"cache-control": "no-cache"}, 248 url: wishlist_url+ '?rand=' + new Date().getTime(), 249 async: true, 250 cache: false, 251 data: { 252 "ajax": 1, 253 "action": "add", 254 "id_product": id_product, 255 "id_wishlist": id_wishlist, 256 "id_product_attribute": id_product_attribute, 257 "quantity": 1, 258 "token": leo_token 259 }, 260 success: function (result) 261 { 262 // console.log(result); 263 var object_result = $.parseJSON(result); 264 if (object_result.errors.length) 265 { 266 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 267 $('.leo-modal-wishlist').modal('show'); 268 } 269 else 270 { 271 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_add); 272 $('.leo-modal-wishlist').modal('show'); 273 //Leotheme add: update number product on icon wishlist after add from wishlist 274 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 275 { 276 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 277 var new_num_wishlist = old_num_wishlist+1; 278 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 279 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 280 } 281 282 // console.log(object_result.result.id_wishlist); 283 //DONGND:: update id wishlist if the first add of user 284 if (id_wishlist == '') 285 { 286 $('.leo-wishlist-button').data('id-wishlist', object_result.result.id_wishlist); 287 // wishlist_products[object_result.result.id_wishlist].push(id_product); 288 } 289 // else 290 // { 291 // wishlist_products[id_wishlist].push(id_product); 292 // } 293 294 $('.leo-wishlist-button[data-id-product='+id_product+']').addClass('added'); 295 $('.leo-wishlist-button[data-id-product='+id_product+']').attr('title',buttonwishlist_title_remove); 296 object_e.find('.leo-wishlist-bt-loading').hide(); 297 object_e.find('.leo-wishlist-bt-content').show(); 298 } 299 300 }, 301 error: function (XMLHttpRequest, textStatus, errorThrown) { 302 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 303 } 304 }); 305 } 306 } 307 return false;
308 }) 309 } 310 else 311 { 312 // $('.leo-wishlist-button').each(function(){ 313 314 // $(this).click(function(e){ 315 316 // e.preventDefault(); 317 // }); 318 // var htmlContent = $(this).next().html(); 319 // $(this).popover({ 320 // placement : 'bottom', //placement of the popover. also can use top, bottom, left or right 321 // title : '', //this is the top title bar of the popover. add some basic css 322 // html: true, //needed to show html of course 323 // content : htmlContent, //this is the content of the html box. add the image here or anything you want really. 324 // template: '<div class="popover popover-list-wishlist" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>' 325 // }); 326 327 // }); 328 329 // $('.popover').popover('hide'); 330 331 // $('.leo-wishlist-button').click(function(){ 332 // if ($(this).hasClass('active')) 333 // { 334 // $(this).next().fadeOut(); 335 // $(this).removeClass('active'); 336 // } 337 // else 338 // { 339 // $('.leo-wishlist-button.active').next().fadeOut(); 340 // $('.leo-wishlist-button.active').removeClass('active'); 341 // $(this).addClass('active'); 342 // $(this).next().fadeIn(); 343 // } 344 345 // return false; 346 // }); 347 348 // $('.popover').on('show.bs.popover' , function () { 349 //DONGND:: add/remove wishlist with list wishlist 350 $('.wishlist-item').click(function(){ 351 if (!$('.wishlist-item.active-add').length) 352 { 353 var id_product = $(this).data('id-product'); 354 var id_wishlist = $(this).data('id-wishlist'); 355 var id_product_attribute = $(this).data('id-product-attribute'); 356 var content_wishlist_mess_remove = wishlist_remove+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 357 var content_wishlist_mess_add = wishlist_add+'. <a href="'+wishlist_url+'" target="_blank"><strong>'+wishlist_viewwishlist+'.</strong></a>'; 358 359 $(this).addClass('active-add'); 360 361 if (!isLogged) 362 { 363 //DONGND:: display quicklogin if enable 364 // if ($('.leo-quicklogin').length) 365 // { 366 // $('.leo-quicklogin').first().trigger('click'); 367 // resetButtonAction(); 368 // } 369 // else 370 // { 371 $('.leo-modal-wishlist .modal-title').html(wishlist_loggin_required); 372 $('.leo-modal-wishlist').modal('show'); 373 // } 374 return false; 375 } 376 377 var object_e = $(this); 378 var parents_e = object_e.parents('.leo-wishlist-button-dropdown'); 379 parents_e.find('.leo-wishlist-button').addClass('active'); 380 parents_e.find('.leo-wishlist-bt-loading').css({'display':'block'}); 381 parents_e.find('.leo-wishlist-bt-content').hide(); 382 if ($(this).hasClass('added') || $(this).hasClass('delete')) 383 { 384 //DONGND:: remove product form wishlist 385 $.ajax({ 386 type: 'POST', 387 headers: {"cache-control": "no-cache"}, 388 url: wishlist_url+ '?rand=' + new Date().getTime(), 389 async: true, 390 cache: false, 391 data: { 392 "ajax": 1, 393 "action": "remove", 394 "id_product": id_product, 395 "id_wishlist": id_wishlist, 396 "id_product_attribute": id_product_attribute, 397 "quantity": 1, 398 "token": leo_token 399 }, 400 success: function (result) 401 { 402 var object_result = $.parseJSON(result); 403 if (object_result.errors.length) 404 { 405 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 406 $('.leo-modal-wishlist').modal('show'); 407 } 408 else 409 { 410 //Leotheme add: update number product on icon wishlist after remove from wishlist 411 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 412 { 413 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 414 var new_num_wishlist = old_num_wishlist-1; 415 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 416 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 417 } 418 419 // compared_products.splice($.inArray(parseInt(id_product), compared_products), 1); 420 if (object_e.hasClass('delete')) 421 { 422 //DONGND:: remove from page wishlist 423 $('td.product-'+id_product).fadeOut(function(){ 424 $(this).remove(); 425 }); 426 } 427 else 428 { 429 //DONGND:: remove from page product list
430 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_remove); 431 $('.leo-modal-wishlist').modal('show'); 432 433 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').removeClass('added'); 434 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').attr('title',buttonwishlist_title_add); 435 if (!$('.wishlist-item[data-id-product='+id_product+']').hasClass('added')) 436 { 437 $('.leo-wishlist-button[data-id-product='+id_product+']').removeClass('added'); 438 } 439 440 parents_e.find('.leo-wishlist-bt-loading').hide(); 441 parents_e.find('.leo-wishlist-bt-content').show(); 442 parents_e.find('.leo-wishlist-button').removeClass('active'); 443 } 444 } 445 }, 446 error: function (XMLHttpRequest, textStatus, errorThrown) { 447 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 448 } 449 }); 450 } 451 else 452 { 453 454 //DONGND:: add product to list product wishlist 455 $.ajax({ 456 type: 'POST', 457 headers: {"cache-control": "no-cache"}, 458 url: wishlist_url+ '?rand=' + new Date().getTime(), 459 async: true, 460 cache: false, 461 data: { 462 "ajax": 1, 463 "action": "add", 464 "id_product": id_product, 465 "id_wishlist": id_wishlist, 466 "id_product_attribute": id_product_attribute, 467 "quantity": 1, 468 "token": leo_token 469 }, 470 success: function (result) 471 { 472 // console.log(result); 473 var object_result = $.parseJSON(result); 474 if (object_result.errors.length) 475 { 476 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 477 $('.leo-modal-wishlist').modal('show'); 478 } 479 else 480 { 481 $('.leo-modal-wishlist .modal-title').html(content_wishlist_mess_add); 482 $('.leo-modal-wishlist').modal('show'); 483 //Leotheme add: update number product on icon wishlist after add from wishlist 484 if ($('.ap-btn-wishlist .ap-total-wishlist').length) 485 { 486 var old_num_wishlist = parseInt($('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total')); 487 var new_num_wishlist = old_num_wishlist+1; 488 $('.ap-btn-wishlist .ap-total-wishlist').data('wishlist-total',new_num_wishlist); 489 $('.ap-btn-wishlist .ap-total-wishlist').text(new_num_wishlist); 490 } 491 492 // console.log(object_result.result.id_wishlist); 493 494 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').addClass('added'); 495 $('.wishlist-item[data-id-wishlist='+id_wishlist+'][data-id-product='+id_product+']').attr('title',buttonwishlist_title_remove); 496 if (!$('.leo-wishlist-button[data-id-product='+id_product+']').hasClass('added')) 497 { 498 $('.leo-wishlist-button[data-id-product='+id_product+']').addClass('added'); 499 } 500 501 parents_e.find('.leo-wishlist-bt-loading').hide(); 502 parents_e.find('.leo-wishlist-bt-content').show(); 503 parents_e.find('.leo-wishlist-button').removeClass('active'); 504 } 505 506 }, 507 error: function (XMLHttpRequest, textStatus, errorThrown) { 508 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 509 } 510 }); 511 } 512 } 513 return false; 514 }); 515 // }); 516 517 } 518 519} 520 521function LeoListWishlistAction() 522{ 523 //DONGND:: click delete wishlist 524 $('.delete-wishlist').click(function(){ 525 if (!$(this).hasClass('active')) 526 { 527 $(this).addClass('active'); 528 $(this).parents('tr').addClass('active'); 529 if ($('.list-wishlist tr.active .default-wishlist').is(":checked")) 530 { 531 $('.leo-modal-wishlist .modal-title').html(wishlist_del_default_txt); 532 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 533 } 534 else 535 { 536 $('.leo-modal-wishlist .modal-title').html(wishlist_confirm_del_txt); 537 $('.leo-modal-wishlist').addClass('enable-action').modal('show'); 538 } 539 } 540 541 return false;
542 }); 543 544 //DONGND:: confirm delete wishlist 545 $('.leo-modal-wishlist-bt').click(function(){ 546 if (!$(this).hasClass('active')) 547 { 548 // console.log('test'); 549 $(this).addClass('active'); 550 var object_e = $(this); 551 var id_wishlist = $('.delete-wishlist.active').data('id-wishlist'); 552 $('.leo-modal-wishlist-bt-text').hide(); 553 $('.leo-modal-wishlist-loading').css({'display':'block'}); 554 555 $.ajax({ 556 type: 'POST', 557 headers: {"cache-control": "no-cache"}, 558 url: wishlist_url+ '?rand=' + new Date().getTime(), 559 async: true, 560 cache: false, 561 data: { 562 "ajax": 1, 563 "action": "delete-wishlist", 564 "id_wishlist": id_wishlist, 565 "token": leo_token 566 }, 567 success: function (result) 568 { 569 var object_result = $.parseJSON(result); 570 if (object_result.errors.length) 571 { 572 573 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 574 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 575 } 576 else 577 { 578 var object_delete = $('.list-wishlist tr.active'); 579 $('.leo-modal-wishlist').modal('hide'); 580 object_delete.fadeOut(function(){ 581 if ($(this).hasClass('show')) 582 { 583 $('.leo-wishlist-product').fadeOut().html(''); 584 } 585 else 586 { 587 //DONGND:: reload list product if a wishlist current view 588 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 589 } 590 $(this).remove(); 591 }) 592 593 } 594 $('.leo-modal-wishlist-loading').hide(); 595 $('.leo-modal-wishlist-bt-text').show(); 596 object_e.removeClass('active'); 597 598 }, 599 error: function (XMLHttpRequest, textStatus, errorThrown) { 600 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 601 } 602 }); 603 } 604 }) 605 606 //DONGND:: change default wishlist 607 $('.default-wishlist').click(function(){ 608 if ($(this).is(":checked")) 609 { 610 // console.log('test'); 611 if (!$('.default-wishlist.active').length) 612 { 613 $(this).addClass('active'); 614 var object_e = $(this); 615 var id_wishlist = $('.default-wishlist.active').data('id-wishlist'); 616 $.ajax({ 617 type: 'POST', 618 headers: {"cache-control": "no-cache"}, 619 url: wishlist_url+ '?rand=' + new Date().getTime(), 620 async: true, 621 cache: false, 622 data: { 623 "ajax": 1, 624 "action": "default-wishlist", 625 "id_wishlist": id_wishlist, 626 "token": leo_token 627 }, 628 success: function (result) 629 { 630 var object_result = $.parseJSON(result); 631 if (object_result.errors.length) 632 { 633 634 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 635 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 636 } 637 else 638 { 639 $('.default-wishlist:checked').removeAttr('checked'); 640 object_e.prop('checked', true); 641 } 642 643 object_e.removeClass('active'); 644 645 }, 646 error: function (XMLHttpRequest, textStatus, errorThrown) { 647 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 648 } 649 }); 650 } 651 } 652 // else 653 // { 654 // console.log('test1'); 655 656 // } 657 return false; 658 }) 659 660 //DONGND:: show list product of wishlist 661 $('.view-wishlist-product').click(function(){ 662 if (!$('.view-wishlist-product.active').length) 663 { 664 $(this).addClass('active'); 665 $(this).next('.leo-view-wishlist-product-loading').show(); 666 $('.list-wishlist tr.show').removeClass('show'); 667 $(this).parents('tr').addClass('show'); 668 var object_e = $(this); 669 var id_wishlist = $(this).data('id-wishlist'); 670 // $('.send-wishlist').fadeOut(); 671 // $('.leo-wishlist-product').fadeOut(function(){ 672 //$('.leo-wishlist-product').html(''); 673 $.ajax({ 674 type: 'POST', 675 headers: {"cache-control": "no-cache"}, 676 url: wishlist_url+ '?rand=' + new Date().getTime(), 677 async: true, 678 cache: false, 679 data: { 680 "ajax": 1, 681 "action": "show-wishlist-product", 682 "id_wishlist": id_wishlist, 683 "token": leo_token 684 }, 685 success: function (result) 686 { 687 var object_result = $.parseJSON(result); 688 if (object_result.errors.length) 689 { 690
691 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 692 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 693 } 694 else 695 { 696 $('.leo-wishlist-product').hide(); 697 $('.leo-wishlist-product').html(object_result.result.html).fadeIn(); 698 if (object_result.result.show_send_wishlist) 699 { 700 $('.send-wishlist').fadeIn(); 701 // LeoWishlistButtonAction(); 702 if (!$('.leo-modal-send-wishlist').length) 703 { 704 createLeoSendWishlistModalPopup(); 705 LeoListWishlistProductModalAction(); 706 } 707 else 708 { 709 $('.leo-modal-reset-send-wishlist-bt').trigger('click'); 710 } 711 LeoListWishlistProductAction(); 712 713 } 714 else 715 { 716 $('.send-wishlist').hide(); 717 } 718 refeshWishlist(id_wishlist); 719 720 } 721 722 object_e.removeClass('active'); 723 object_e.next('.leo-view-wishlist-product-loading').hide(); 724 725 }, 726 error: function (XMLHttpRequest, textStatus, errorThrown) { 727 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 728 } 729 }); 730 // }) 731 } 732 return false; 733 }) 734} 735function LeoListWishlistProductModalAction() 736{ 737 //DONGND:: send wishlist 738 $('.leo-send-wishlist-button').click(function(){ 739 var name_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('name-wishlist'); 740 $('.leo-modal-send-wishlist .modal-title').html(wishlist_send_wishlist_txt+' "'+name_wishlist+'"'); 741 $('.leo-modal-send-wishlist').modal('show'); 742 743 return false; 744 }) 745 746 $('.leo-modal-send-wishlist').submit(function(){ 747 // if ($(this).find('.form-group.leo-has-error').length) 748 if ($('.leo-fake-send-wishlist-button').hasClass('validate-ok')) 749 { 750 return false; 751 } 752 }); 753 754 //DONGND:: submit send wishlist 755 $('.leo-modal-send-wishlist-bt').click(function(){ 756 if (!$(this).hasClass('active')) 757 { 758 var check_submit_wishlist = true; 759 var list_email = []; 760 $(this).addClass('active'); 761 var object_e = $(this); 762 $('.leo-modal-reset-send-wishlist-bt').fadeOut(); 763 764 $('.wishlist_email').each(function(key, val){ 765 if ($(this).val() !== '' && !$(this).parents('.form-group').hasClass('has-success') && !$(this).parents('.form-group').hasClass('has-warning')) 766 { 767 if (!validateEmail($(this).val())) 768 { 769 $(this).parents('.form-group').addClass('leo-has-error'); 770 check_submit_wishlist = false; 771 } 772 else 773 { 774 $(this).parents('.form-group').removeClass('leo-has-error'); 775 list_email.push(key); 776 } 777 } 778 779 }) 780 // console.log(check_submit_wishlist); 781 if (check_submit_wishlist) 782 { 783 // if (list_email.length == 0) 784 // console.log(list_email.length); 785 // console.log(list_email); 786 if (list_email.length == 0) 787 { 788 $('.wishlist_email').each(function(key, val){ 789 if ($(this).val() == '') 790 { 791 $(this).parents('.form-group').addClass('leo-has-error'); 792 $(this).attr("required", ""); 793 return false; 794 } 795 }) 796 object_e.removeClass('active'); 797 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 798 } 799 else 800 { 801 $('.leo-fake-send-wishlist-button').addClass('validate-ok'); 802 var id_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('id-wishlist'); 803 // console.log(list_email); 804 805 $('.leo-modal-send-wishlist-bt-text').hide(); 806 $('.leo-modal-send-wishlist-loading').css({'display':'block'}); 807 808 $.each(list_email,function(key, val){ 809 var index_wishlist_email = val + 1; 810 var email = $('#wishlist_email_'+index_wishlist_email).val(); 811 var object_parent_e = $('#wishlist_email_'+index_wishlist_email).parents('.form-group'); 812 object_parent_e.find('.wishlist_email_status_loading').show(); 813 814 $.ajax({ 815 type: 'POST', 816 headers: {"cache-control": "no-cache"}, 817 url: wishlist_url+ '?rand=' + new Date().getTime(), 818 async: true, 819 cache: false, 820 data: { 821 "ajax": 1, 822 "action": "send-wishlist", 823 "id_wishlist": id_wishlist, 824 "email": email, 825 "token": leo_token 826 }, 827 success: function (result) 828 { 829 object_parent_e.find('.wishlist_email_status_loading').hide(); 830 var object_result = $.parseJSON(result); 831 if (object_result.errors.length) 832 { 833 object_parent_e.addClass('has-warning').find('.send_wishlist_error').fadeIn(); 834 } 835 else 836 { 837 object_parent_e.addClass('has-success').find('.send_wishlist_success').fadeIn(); 838 } 839 840 }, 841 error: function (XMLHttpRequest, textStatus, errorThrown) { 842 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 843 } 844 }); 845 846 }); 847 $(document).ajaxStop(function() { 848 // console.log('test'); 849 $('.leo-modal-send-wishlist-loading').hide(); 850 $('.leo-modal-send-wishlist-bt-text').show(); 851 $('.leo-fake-send-wishlist-button').removeClass('validate-ok'); 852 object_e.removeClass('active'); 853 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 854 }); 855 856 } 857 if ($('.form-send-wishlist .form-group.leo-has-error').length) 858 { 859 $('.leo-fake-send-wishlist-button').trigger('click'); 860 } 861 } 862 else 863 {
864 object_e.removeClass('active'); 865 $('.leo-modal-reset-send-wishlist-bt').fadeIn(); 866 $('.leo-fake-send-wishlist-button').trigger('click'); 867 } 868 869 } 870 }) 871 872 //DONGND:: reset from send wishlist 873 $('.leo-modal-reset-send-wishlist-bt').click(function(){ 874 $('.wishlist_email').val('').removeAttr('required'); 875 $('.send_wishlist_form_content .form-group').removeClass('leo-has-error has-success has-warning'); 876 $('.wishlist_email_status_loading').fadeOut(); 877 $('.send_wishlist_msg').fadeOut(); 878 }) 879} 880 881function LeoListWishlistProductAction() 882{ 883 //DONGND:: delete product of wishlist 884 $('.leo-wishlist-button-delete').click(function(){ 885 if (!$(this).hasClass('active')) 886 { 887 $(this).addClass('active'); 888 var object_e = $(this); 889 var object_parent_e = object_e.parents('.leo-wishlist-product'); 890 var id_wishlist_product = $(this).data('id-wishlist-product'); 891 var id_wishlist = $(this).data('id-wishlist'); 892 $.ajax({ 893 type: 'POST', 894 headers: {"cache-control": "no-cache"}, 895 url: wishlist_url+ '?rand=' + new Date().getTime(), 896 async: true, 897 cache: false, 898 data: { 899 "ajax": 1, 900 "action": "delete-wishlist-product", 901 "id_wishlist": id_wishlist, 902 "id_wishlist_product": id_wishlist_product, 903 "token": leo_token 904 }, 905 success: function (result) 906 { 907 var object_result = $.parseJSON(result); 908 if (object_result.errors.length) 909 { 910 911 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 912 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 913 } 914 else 915 { 916 object_e.parents('.leo-wishlistproduct-item').fadeOut(function(){ 917 $(this).remove(); 918 // console.log(object_parent_e); 919 // console.log(object_parent_e.find('.leo-wishlistproduct-item')); 920 // console.log(object_parent_e.find('.leo-wishlistproduct-item').length); 921 if (!object_parent_e.find('.leo-wishlistproduct-item').length) 922 { 923 $('.send-wishlist').hide(); 924 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 925 } 926 }) 927 refeshWishlist(id_wishlist); 928 } 929 930 object_e.removeClass('active'); 931 932 }, 933 error: function (XMLHttpRequest, textStatus, errorThrown) { 934 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 935 } 936 }); 937 } 938 return false; 939 }) 940 941 //DONGND:: 942 $('.leo-wishlist-product-save-button').click(function(){ 943 if (!$(this).hasClass('active')) 944 { 945 $(this).addClass('active'); 946 var object_e = $(this); 947 var id_wishlist_product = $(this).data('id-wishlist-product'); 948 var id_wishlist = $(this).data('id-wishlist'); 949 // $('.leo-wishlistproduct-item-'+id_wishlist_product).addClass('update'); 950 var quantity = $('.wishlist-product-quantity-'+id_wishlist_product).val(); 951 var priority = $('.wishlist-product-priority-'+id_wishlist_product).val(); 952 953 if(Math.floor(quantity) == quantity && $.isNumeric(quantity) && quantity > 0) 954 { 955 $('.wishlist-product-quantity-'+id_wishlist_product).parents('.form-group').removeClass('has-error'); 956 $.ajax({ 957 type: 'POST', 958 headers: {"cache-control": "no-cache"}, 959 url: wishlist_url+ '?rand=' + new Date().getTime(), 960 async: true, 961 cache: false, 962 data: { 963 "ajax": 1, 964 "action": "update-wishlist-product", 965 "id_wishlist": id_wishlist, 966 "id_wishlist_product": id_wishlist_product, 967 "quantity": quantity, 968 "priority": priority, 969 "token": leo_token 970 }, 971 success: function (result) 972 { 973 var object_result = $.parseJSON(result); 974 if (object_result.errors.length) 975 { 976 977 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 978 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 979 } 980 else 981 { 982 $('.leo-wishlistproduct-item-'+id_wishlist_product).hide(); 983 $('.leo-wishlistproduct-item-'+id_wishlist_product).fadeIn(); 984 refeshWishlist(id_wishlist); 985 } 986 987 object_e.removeClass('active'); 988 989 }, 990 error: function (XMLHttpRequest, textStatus, errorThrown) { 991 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 992 } 993 }); 994 } 995 else 996 {
997 $('.wishlist-product-quantity-'+id_wishlist_product).parents('.form-group').addClass('has-error'); 998 $('.leo-modal-wishlist .modal-title').html(wishlist_quantity_required); 999 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1000 object_e.removeClass('active'); 1001 } 1002 } 1003 return false; 1004 }) 1005 1006 $('.move-wishlist-item').click(function(){ 1007 if (!$(this).hasClass('active')) 1008 { 1009 $(this).addClass('active'); 1010 var object_e = $(this); 1011 var object_parent_e = object_e.parents('.leo-wishlist-product'); 1012 var id_wishlist_product = $(this).data('id-wishlist-product'); 1013 var id_product = $(this).data('id-product'); 1014 var id_product_attribute = $(this).data('id-product-attribute'); 1015 var id_old_wishlist = $('.list-wishlist tr.show .view-wishlist-product').data('id-wishlist'); 1016 var id_new_wishlist = $(this).data('id-wishlist'); 1017 var priority = $('.wishlist-product-priority-'+id_wishlist_product).val(); 1018 var quantity = $('.wishlist-product-quantity-'+id_wishlist_product).val(); 1019 $.ajax({ 1020 type: 'POST', 1021 headers: {"cache-control": "no-cache"}, 1022 url: wishlist_url+ '?rand=' + new Date().getTime(), 1023 async: true, 1024 cache: false, 1025 data: { 1026 "ajax": 1, 1027 "action": "move-wishlist-product", 1028 "id_new_wishlist": id_new_wishlist, 1029 "id_wishlist_product": id_wishlist_product, 1030 "id_old_wishlist": id_old_wishlist, 1031 "id_product" : id_product, 1032 "id_product_attribute": id_product_attribute, 1033 "quantity": quantity, 1034 "priority": priority, 1035 "token": leo_token 1036 }, 1037 success: function (result) 1038 { 1039 var object_result = $.parseJSON(result); 1040 if (object_result.errors.length) 1041 { 1042 1043 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 1044 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1045 } 1046 else 1047 { 1048 object_e.parents('.leo-wishlistproduct-item').fadeOut(function(){ 1049 $(this).remove(); 1050 if (!object_parent_e.find('.leo-wishlistproduct-item').length) 1051 { 1052 $('.send-wishlist').hide(); 1053 $('.list-wishlist tr.show .view-wishlist-product').trigger('click'); 1054 } 1055 }); 1056 refeshWishlist(id_new_wishlist); 1057 refeshWishlist(id_old_wishlist); 1058 } 1059 1060 object_e.removeClass('active'); 1061 1062 }, 1063 error: function (XMLHttpRequest, textStatus, errorThrown) { 1064 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 1065 } 1066 }); 1067 } 1068 return false; 1069 }) 1070} 1071 1072function activeEventModalWishlist() 1073{ 1074 $('.leo-modal-wishlist').on('hide.bs.modal', function (e) { 1075 resetButtonAction(); 1076 }) 1077 1078 $('.leo-modal-wishlist').on('hidden.bs.modal', function (e) { 1079 $('body').css('padding-right', ''); 1080 }) 1081 $('.leo-modal-wishlist').on('show.bs.modal', function (e) { 1082 if ($('.quickview.modal').length) 1083 { 1084 $('.quickview.modal').modal('hide'); 1085 } 1086 1087 }); 1088} 1089 1090//DONGND:: reset button add wishlist after click 1091function resetButtonAction(){ 1092 // console.log($('.leo-modal-review-bt').length); 1093 if ($('.leo-wishlist-button.active').length) 1094 { 1095 // console.log('aaa'); 1096 $('.leo-wishlist-button.active').removeClass('active'); 1097 } 1098 1099 if ($('.wishlist-item.active-add').length) 1100 { 1101 // console.log('aaa'); 1102 $('.wishlist-item.active-add').removeClass('active-add'); 1103 } 1104 // $('.leo-list-wishlist').fadeOut(); 1105 $('.default-wishlist.active').removeClass('active'); 1106 $('.delete-wishlist.active').removeClass('active'); 1107 1108 $('.list-wishlist tr.active').removeClass('active'); 1109 1110 // $('.leo-modal-wishlist').removeClass('enable-action'); 1111} 1112 1113function createLeoSendWishlistModalPopup() 1114{ 1115 var leoSendWishlistModalPopup = ''; 1116 leoSendWishlistModalPopup += '<div class="modal leo-modal leo-modal-send-wishlist fade" tabindex="-1" role="dialog" aria-hidden="true">'; 1117 leoSendWishlistModalPopup += '<div class="modal-dialog" role="document">'; 1118 leoSendWishlistModalPopup += '<div class="modal-content">'; 1119 leoSendWishlistModalPopup += '<div class="modal-header">'; 1120 leoSendWishlistModalPopup += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'; 1121 leoSendWishlistModalPopup += '<span aria-hidden="true">×</span>'; 1122 leoSendWishlistModalPopup += '</button>'; 1123 leoSendWishlistModalPopup += '<h5 class="modal-title text-xs-center">'; 1124 leoSendWishlistModalPopup += '</h5>'; 1125 leoSendWishlistModalPopup += '</div>'; 1126 leoSendWishlistModalPopup += '<div class="modal-body">'; 1127 leoSendWishlistModalPopup += '<div class="send_wishlist_form_content">'; 1128 leoSendWishlistModalPopup += '<form class="form-send-wishlist" action="#" method="post">' 1129 for (var $i=1; $i<= 10; $i++) 1130 { 1131 leoSendWishlistModalPopup += '<div class="form-group row">'; 1132 leoSendWishlistModalPopup += '<label class="col-form-label col-sm-2 text-sm-left" for="wishlist_email_'+$i+'">'+wishlist_email_txt+' '+$i+'</label>'; 1133 leoSendWishlistModalPopup += '<div class="wishlist_email_status col-sm-1">'; 1134 leoSendWishlistModalPopup += '<div class="wishlist_email_status_loading cssload-speeding-wheel">'; 1135 leoSendWishlistModalPopup += '</div>'; 1136 leoSendWishlistModalPopup += '<i class="send_wishlist_msg send_wishlist_success material-icons"></i>'; 1137 leoSendWishlistModalPopup += '<i class="send_wishlist_msg send_wishlist_error material-icons"></i>'; 1138 leoSendWishlistModalPopup += '</div>'; 1139 leoSendWishlistModalPopup += '<div class="col-sm-9">'; 1140 leoSendWishlistModalPopup += '<input class="form-control wishlist_email" id="wishlist_email_'+$i+'" name="wishlist_email_'+$i+'" type="email">'; 1141 leoSendWishlistModalPopup += '</div>'; 1142 leoSendWishlistModalPopup += '</div>'; 1143 } 1144 leoSendWishlistModalPopup += '<button class="btn btn-primary form-control-submit leo-fake-send-wishlist-button pull-xs-right" type="submit"></button>'; 1145 leoSendWishlistModalPopup += '</form>'; 1146 leoSendWishlistModalPopup += '</div>'; 1147 leoSendWishlistModalPopup += '</div>'; 1148 leoSendWishlistModalPopup += '<div class="modal-footer">'; 1149 leoSendWishlistModalPopup += '<button type="button" class="btn btn-primary leo-modal-reset-send-wishlist-bt">'+wishlist_reset_txt+'</button>'; 1150 leoSendWishlistModalPopup += '<button type="button" class="btn btn-secondary" data-dismiss="modal">'+wishlist_cancel_txt+'</button>'; 1151 leoSendWishlistModalPopup += '<button type="button" class="leo-modal-send-wishlist-bt btn btn-primary">'; 1152 leoSendWishlistModalPopup += '<span class="leo-modal-send-wishlist-loading cssload-speeding-wheel"></span>'; 1153 leoSendWishlistModalPopup += '<span class="leo-modal-send-wishlist-bt-text">'; 1154 leoSendWishlistModalPopup += wishlist_send_txt; 1155 leoSendWishlistModalPopup += '</span>'; 1156 leoSendWishlistModalPopup += '</button>'; 1157 leoSendWishlistModalPopup += '</div>'; 1158 leoSendWishlistModalPopup += '</div>'; 1159 leoSendWishlistModalPopup += '</div>'; 1160 leoSendWishlistModalPopup += '</div>';
1161 $('body').append(leoSendWishlistModalPopup); 1162} 1163 1164function validateEmail(email) { 1165 // var regex = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 1166 // return regex.test(email); 1167 var reg = /^[a-z\p{L}0-9!#$%&'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+[._a-z\p{L}0-9-]*\.[a-z\p{L}0-9]+$/i; 1168 return reg.test(email); 1169} 1170 1171//DONGND:: update quantity of wishlist 1172function refeshWishlist(id_wishlist) 1173{ 1174 $('.leo-view-wishlist-product-loading-'+id_wishlist).show(); 1175 $.ajax({ 1176 type: 'POST', 1177 headers: {"cache-control": "no-cache"}, 1178 url: wishlist_url+ '?rand=' + new Date().getTime(), 1179 async: true, 1180 cache: false, 1181 data: { 1182 "ajax": 1, 1183 "action": "get-wishlist-info", 1184 "id_wishlist": id_wishlist, 1185 "token": leo_token 1186 }, 1187 success: function (result) 1188 { 1189 var object_result = $.parseJSON(result); 1190 if (object_result.errors.length) 1191 { 1192 1193 $('.leo-modal-wishlist .modal-title').html(object_result.errors); 1194 $('.leo-modal-wishlist').removeClass('enable-action').modal('show'); 1195 } 1196 else 1197 { 1198 $('.wishlist-numberproduct-'+id_wishlist).html(object_result.result.number_product); 1199 } 1200 $('.leo-view-wishlist-product-loading-'+id_wishlist).hide(); 1201 }, 1202 error: function (XMLHttpRequest, textStatus, errorThrown) { 1203 alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 1204 } 1205 }); 1206}
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.