Advertisement
Guest User

Untitled

a guest
May 6th, 2017
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * 2007-2016 PrestaShop
  3. *
  4. * NOTICE OF LICENSE
  5. *
  6. * This source file is subject to the Academic Free License (AFL 3.0)
  7. * that is bundled with this package in the file LICENSE.txt.
  8. * It is also available through the world-wide-web at this URL:
  9. * http://opensource.org/licenses/afl-3.0.php
  10. * If you did not receive a copy of the license and are unable to
  11. * obtain it through the world-wide-web, please send an email
  12. * to license@prestashop.com so we can send you a copy immediately.
  13. *
  14. * DISCLAIMER
  15. *
  16. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  17. * versions in the future. If you wish to customize PrestaShop for your
  18. * needs please refer to http://www.prestashop.com for more information.
  19. *
  20. *  @author PrestaShop SA <contact@prestashop.com>
  21. *  @copyright  2007-2016 PrestaShop SA
  22. *  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  23. *  International Registered Trademark & Property of PrestaShop SA
  24. */
  25. //global variables
  26. var responsiveflag = false;
  27.  
  28. $(document).ready(function(){
  29.     highdpiInit();
  30.     responsiveResize();
  31.     $(window).resize(responsiveResize);
  32.     if (navigator.userAgent.match(/Android/i))
  33.     {
  34.         var viewport = document.querySelector('meta[name="viewport"]');
  35.         viewport.setAttribute('content', 'initial-scale=1.0,maximum-scale=1.0,user-scalable=0,width=device-width,height=device-height');
  36.         window.scrollTo(0, 1);
  37.     }
  38.     if (typeof quickView !== 'undefined' && quickView)
  39.         quick_view();
  40.     dropDown();
  41.  
  42.     if (typeof page_name != 'undefined' && !in_array(page_name, ['index', 'product']))
  43.     {
  44.         bindGrid();
  45.  
  46.         $(document).on('change', '.selectProductSort', function(e){
  47.             if (typeof request != 'undefined' && request)
  48.                 var requestSortProducts = request;
  49.             var splitData = $(this).val().split(':');
  50.             var url = '';
  51.             if (typeof requestSortProducts != 'undefined' && requestSortProducts)
  52.             {
  53.                 url += requestSortProducts ;
  54.                 if (typeof splitData[0] !== 'undefined' && splitData[0])
  55.                 {
  56.                     url += ( requestSortProducts.indexOf('?') < 0 ? '?' : '&') + 'orderby=' + splitData[0];
  57.                     if (typeof splitData[1] !== 'undefined' && splitData[1])
  58.                         url += '&orderway=' + splitData[1];
  59.                 }
  60.                 document.location.href = url;
  61.             }
  62.         });
  63.  
  64.         $(document).on('change', 'select[name="n"]', function(){
  65.             $(this.form).submit();
  66.         });
  67.  
  68.         $(document).on('change', 'select[name="currency_payment"]', function(){
  69.             setCurrency($(this).val());
  70.         });
  71.     }
  72.  
  73.     $(document).on('change', 'select[name="manufacturer_list"], select[name="supplier_list"]', function(){
  74.         if (this.value != '')
  75.             location.href = this.value;
  76.     });
  77.  
  78.     $(document).on('click', '.back', function(e){
  79.         e.preventDefault();
  80.         history.back();
  81.     });
  82.  
  83.     jQuery.curCSS = jQuery.css;
  84.     if (!!$.prototype.cluetip)
  85.         $('a.cluetip').cluetip({
  86.             local:true,
  87.             cursor: 'pointer',
  88.             dropShadow: false,
  89.             dropShadowSteps: 0,
  90.             showTitle: false,
  91.             tracking: true,
  92.             sticky: false,
  93.             mouseOutClose: true,
  94.             fx: {
  95.                 open:       'fadeIn',
  96.                 openSpeed:  'fast'
  97.             }
  98.         }).css('opacity', 0.8);
  99.  
  100.     if (typeof(FancyboxI18nClose) !== 'undefined' && typeof(FancyboxI18nNext) !== 'undefined' && typeof(FancyboxI18nPrev) !== 'undefined' && !!$.prototype.fancybox)
  101.         $.extend($.fancybox.defaults.tpl, {
  102.             closeBtn : '<a title="' + FancyboxI18nClose + '" class="fancybox-item fancybox-close" href="javascript:;"></a>',
  103.             next     : '<a title="' + FancyboxI18nNext + '" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
  104.             prev     : '<a title="' + FancyboxI18nPrev + '" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
  105.         });
  106.  
  107.     // Close Alert messages
  108.     $(".alert.alert-danger").on('click', this, function(e){
  109.         if (e.offsetX >= 16 && e.offsetX <= 39 && e.offsetY >= 16 && e.offsetY <= 34)
  110.             $(this).fadeOut();
  111.     });
  112. });
  113.  
  114. function highdpiInit()
  115. {
  116.     if (typeof highDPI === 'undefined')
  117.         return;
  118.     if(highDPI && $('.replace-2x').css('font-size') == "1px")
  119.     {
  120.         var els = $("img.replace-2x").get();
  121.         for(var i = 0; i < els.length; i++)
  122.         {
  123.             src = els[i].src;
  124.             extension = src.substr( (src.lastIndexOf('.') +1) );
  125.             src = src.replace("." + extension, "2x." + extension);
  126.  
  127.             var img = new Image();
  128.             img.src = src;
  129.             img.height != 0 ? els[i].src = src : els[i].src = els[i].src;
  130.         }
  131.     }
  132. }
  133.  
  134.  
  135. // Used to compensante Chrome/Safari bug (they don't care about scroll bar for width)
  136. function scrollCompensate()
  137. {
  138.     var inner = document.createElement('p');
  139.     inner.style.width = "100%";
  140.     inner.style.height = "200px";
  141.  
  142.     var outer = document.createElement('div');
  143.     outer.style.position = "absolute";
  144.     outer.style.top = "0px";
  145.     outer.style.left = "0px";
  146.     outer.style.visibility = "hidden";
  147.     outer.style.width = "200px";
  148.     outer.style.height = "150px";
  149.     outer.style.overflow = "hidden";
  150.     outer.appendChild(inner);
  151.  
  152.     document.body.appendChild(outer);
  153.     var w1 = inner.offsetWidth;
  154.     outer.style.overflow = 'scroll';
  155.     var w2 = inner.offsetWidth;
  156.     if (w1 == w2) w2 = outer.clientWidth;
  157.  
  158.     document.body.removeChild(outer);
  159.  
  160.     return (w1 - w2);
  161. }
  162.  
  163. function responsiveResize()
  164. {
  165.     compensante = scrollCompensate();
  166.     if (($(window).width()+scrollCompensate()) <= 767 && responsiveflag == false)
  167.     {
  168.         accordion('enable');
  169.         accordionFooter('enable');
  170.         responsiveflag = true;
  171.     }
  172.     else if (($(window).width()+scrollCompensate()) >= 768)
  173.     {
  174.         accordion('disable');
  175.         accordionFooter('disable');
  176.         responsiveflag = false;
  177.         if (typeof bindUniform !=='undefined')
  178.             bindUniform();
  179.     }
  180.     blockHover();
  181. }
  182.  
  183. function blockHover(status)
  184. {
  185.     var screenLg = $('body').find('.container').width() == 1170;
  186.  
  187.     if ($('.product_list').is('.grid'))
  188.         if (screenLg)
  189.             $('.product_list .button-container').hide();
  190.         else
  191.             $('.product_list .button-container').show();
  192.  
  193.     $(document).off('mouseenter').on('mouseenter', '.product_list.grid li.ajax_block_product .product-container', function(e){
  194.         if (screenLg)
  195.         {
  196.             var pcHeight = $(this).parent().outerHeight();
  197.             var pcPHeight = $(this).parent().find('.button-container').outerHeight() + $(this).parent().find('.comments_note').outerHeight() + $(this).parent().find('.functional-buttons').outerHeight();
  198.             $(this).parent().addClass('hovered').css({'height':pcHeight + pcPHeight, 'margin-bottom':pcPHeight * (-1)});
  199.             $(this).find('.button-container').show();
  200.         }
  201.     });
  202.  
  203.     $(document).off('mouseleave').on('mouseleave', '.product_list.grid li.ajax_block_product .product-container', function(e){
  204.         if (screenLg)
  205.         {
  206.             $(this).parent().removeClass('hovered').css({'height':'auto', 'margin-bottom':'0'});
  207.             $(this).find('.button-container').hide();
  208.         }
  209.     });
  210. }
  211.  
  212. function quick_view()
  213. {
  214.     $(document).on('click', '.quick-view:visible, .quick-view-mobile:visible', function(e){
  215.         e.preventDefault();
  216.         var url = this.rel;
  217.         var anchor = '';
  218.  
  219.         if (url.indexOf('#') != -1)
  220.         {
  221.             anchor = url.substring(url.indexOf('#'), url.length);
  222.             url = url.substring(0, url.indexOf('#'));
  223.         }
  224.  
  225.         if (url.indexOf('?') != -1)
  226.             url += '&';
  227.         else
  228.             url += '?';
  229.  
  230.         if (!!$.prototype.fancybox)
  231.             $.fancybox({
  232.                 'padding':  0,
  233.                 'width':    1087,
  234.                 'height':   610,
  235.                 'type':     'iframe',
  236.                 'href':     url + 'content_only=1' + anchor
  237.             });
  238.     });
  239. }
  240.  
  241. function bindGrid()
  242. {
  243.     var storage = false;
  244.     if (typeof(getStorageAvailable) !== 'undefined') {
  245.         storage = getStorageAvailable();
  246.     }
  247.     if (!storage) {
  248.         return;
  249.     }
  250.  
  251.     var view = $.totalStorage('display');
  252.  
  253.     if (!view && (typeof displayList != 'undefined') && displayList)
  254.         view = 'list';
  255.  
  256.     if (view && view != 'grid')
  257.         display(view);
  258.     else
  259.         $('.display').find('li#grid').addClass('selected');
  260.  
  261.     $(document).on('click', '#grid', function(e){
  262.         e.preventDefault();
  263.         display('grid');
  264.     });
  265.  
  266.     $(document).on('click', '#list', function(e){
  267.         e.preventDefault();
  268.         display('list');
  269.     });
  270. }
  271.  
  272. function display(view)
  273. {
  274.  if (view == 'list')
  275.  {
  276. $('.product_list > li').removeClass('col-xs-12 col-sm-6 col-md-4')
  277. .addClass('col-xs-12 col-sm-6 col-md-12');
  278. }
  279.  else
  280.  {
  281.  $('.product_list > li').removeClass('col-xs-12 col-md-12').addClass('col-xs-12 col-sm-6 col-md-4');
  282. }}
  283.  
  284.  
  285. function dropDown()
  286. {
  287.     elementClick = '#header .current';
  288.     elementSlide =  'ul.toogle_content';
  289.     activeClass = 'active';
  290.  
  291.     $(elementClick).on('click', function(e){
  292.         e.stopPropagation();
  293.         var subUl = $(this).next(elementSlide);
  294.         if(subUl.is(':hidden'))
  295.         {
  296.             subUl.slideDown();
  297.             $(this).addClass(activeClass);
  298.         }
  299.         else
  300.         {
  301.             subUl.slideUp();
  302.             $(this).removeClass(activeClass);
  303.         }
  304.         $(elementClick).not(this).next(elementSlide).slideUp();
  305.         $(elementClick).not(this).removeClass(activeClass);
  306.         e.preventDefault();
  307.     });
  308.  
  309.     $(elementSlide).on('click', function(e){
  310.         e.stopPropagation();
  311.     });
  312.  
  313.     $(document).on('click', function(e){
  314.         e.stopPropagation();
  315.         var elementHide = $(elementClick).next(elementSlide);
  316.         $(elementHide).slideUp();
  317.         $(elementClick).removeClass('active');
  318.     });
  319. }
  320.  
  321. function accordionFooter(status)
  322. {
  323.     if(status == 'enable')
  324.     {
  325.         $('#footer .footer-block h4').on('click', function(e){
  326.             $(this).toggleClass('active').parent().find('.toggle-footer').stop().slideToggle('medium');
  327.             e.preventDefault();
  328.         })
  329.         $('#footer').addClass('accordion').find('.toggle-footer').slideUp('fast');
  330.     }
  331.     else
  332.     {
  333.         $('.footer-block h4').removeClass('active').off().parent().find('.toggle-footer').removeAttr('style').slideDown('fast');
  334.         $('#footer').removeClass('accordion');
  335.     }
  336. }
  337.  
  338. function accordion(status)
  339. {
  340.     if(status == 'enable')
  341.     {
  342.         var accordion_selector = '#right_column .block .title_block, #left_column .block .title_block, #left_column #newsletter_block_left h4,' +
  343.                                 '#left_column .shopping_cart > a:first-child, #right_column .shopping_cart > a:first-child';
  344.  
  345.         $(accordion_selector).on('click', function(e){
  346.             $(this).toggleClass('active').parent().find('.block_content').stop().slideToggle('medium');
  347.         });
  348.         $('#right_column, #left_column').addClass('accordion').find('.block .block_content').slideUp('fast');
  349.         if (typeof(ajaxCart) !== 'undefined')
  350.             ajaxCart.collapse();
  351.     }
  352.     else
  353.     {
  354.         $('#right_column .block .title_block, #left_column .block .title_block, #left_column #newsletter_block_left h4').removeClass('active').off().parent().find('.block_content').removeAttr('style').slideDown('fast');
  355.         $('#left_column, #right_column').removeClass('accordion');
  356.     }
  357. }
  358.  
  359. function bindUniform()
  360. {
  361.     if (!!$.prototype.uniform)
  362.         $("select.form-control,input[type='radio'],input[type='checkbox']").not(".not_uniform").uniform();
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement