Advertisement
Guest User

Untitled

a guest
Oct 25th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.00 KB | None | 0 0
  1. /* global $, prestashop */
  2.  
  3. /**
  4.  * This module exposes an extension point in the form of the `showModal` function.
  5.  *
  6.  * If you want to override the way the modal window is displayed, simply define:
  7.  *
  8.  * prestashop.blockcart = prestashop.blockcart || {};
  9.  * prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) {
  10.  *   // your own code
  11.  *   // please not that it is your responsibility to handle closing the modal too
  12.  * };
  13.  *
  14.  * Attention: your "override" JS needs to be included **before** this file.
  15.  * The safest way to do so is to place your "override" inside the theme's main JS file.
  16.  *
  17.  */
  18.  
  19. $(document).ready(function () {
  20.     HoverCart();
  21.     prestashop.blockcart = prestashop.blockcart || {};
  22.  
  23.     var showModal = prestashop.blockcart.showModal || function (modal) {
  24.       var $body = $('body');
  25.       $body.append(modal);
  26.       $body.one('click', '#blockcart-modal', function (event) {
  27.         if (event.target.id === 'blockcart-modal') {
  28.           $(event.target).remove();
  29.         }
  30.  
  31.         $(".add-to-cart").click(function () {
  32.           $(this).html('PLEASE WAIT..').fadein();
  33.           window.open("https://pressurized.ma/cart?action=show", "_self");
  34.       });
  35.     });
  36.  
  37.   prestashop.on(
  38.     'updateCart',
  39.     function (event) {
  40.       var refreshURL = $('.blockcart').data('refresh-url');
  41.       var requestData = {};
  42.  
  43.       if (event && event.reason) {
  44.         requestData = {
  45.           id_product_attribute: event.reason.idProductAttribute,
  46.           id_product: event.reason.idProduct,
  47.           action: event.reason.linkAction
  48.         };
  49.       }
  50.  
  51.       $.post(refreshURL, requestData).then(function (resp) {
  52.         $('.blockcart').replaceWith(resp.preview);
  53.         HoverCart();
  54.         if (resp.modal) {
  55.           showModal(resp.modal);
  56.         }
  57.        
  58.       }).fail(function (resp) {
  59.         prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp});
  60.       });
  61.     }
  62.   );
  63. };
  64. function HoverCart(){
  65.   var cart_block = new HoverWatcher('.blockcart .header');
  66.   var shopping_cart = new HoverWatcher('.blockcart .body');
  67.   $(".blockcart .header").hover(
  68.     function(){
  69.       if (parseInt($('.blockcart').attr('data-cartitems')) > 0)
  70.         $(".blockcart .body").stop(true, true).slideDown(450);
  71.     },
  72.     function(){
  73.       setTimeout(function(){
  74.         if (!shopping_cart.isHoveringOver() && !cart_block.isHoveringOver())
  75.           $(".blockcart .body").stop(true, true).slideUp(450);
  76.       }, 200);
  77.     }
  78.   );
  79.  
  80.   $(".blockcart .body").hover(
  81.     function(){
  82.     },
  83.     function(){
  84.       setTimeout(function(){
  85.         if (!shopping_cart.isHoveringOver())
  86.           $(".blockcart .body").stop(true, true).slideUp(450);
  87.       }, 200);
  88.     }
  89.   );
  90. }
  91. function HoverWatcher(selector)
  92. {
  93.   this.hovering = false;
  94.   var self = this;
  95.  
  96.   this.isHoveringOver = function(){
  97.     return self.hovering;
  98.   }
  99.  
  100.   $(selector).hover(function(){
  101.     self.hovering = true;
  102.   }, function(){
  103.     self.hovering = false;
  104.   })}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement