//é jQuery(document).ready(function () { customFunctions.enhanceBehaviour(); // Gets the video src from the data-src on each button var $videoSrc; jQuery('#videoHome a').click(function () { $videoSrc = jQuery(this).data("src"); }); // when the modal is opened autoplay it jQuery('#myModal').on('shown.bs.modal', function (e) { // set the video src to autoplay and not to show related video. Youtube related video is like a box of chocolates... you never know what you're gonna get jQuery("#video").attr('src', $videoSrc + "?autoplay=1&modestbranding=1&showinfo=0"); }) // stop playing the youtube video when I close the modal jQuery('#myModal').on('hide.bs.modal', function (e) { // a poor man's stop video jQuery("#video").attr('src', $videoSrc); }) }); jQuery(window).load(function () { customFunctions.finishDesign(); customFunctions.jQueryPlugins.initPrettyPhoto(); }); jQuery(window).scroll(function () { scrollTop = jQuery(this).scrollTop(); customFunctions.fakeParallax(); }); var customData = {}, hDispo = jQuery(window).height(), lDispo = jQuery(window).width(), customFunctions = function () { /* Basic texts in various languages... */ var trads = { 'fr': { 'expand': 'Agrandir / Réduire l\'image' }, 'en': { 'expand': 'Enlarge / Shrink the image' }, 'de': { 'expand': '' } } /* This function finishes design */ , finishDesign = function () { var design = '' // Egalisation de la taille des listes dans les vidéos if (!de0a640) { base.columnizer('.videos', 'li'); } // Egalisation de la taille des points de vente base.columnizer('#listeDistributeurs > div', '.distributeur'); // Centrage vertical des images produit /* jQuery('#visuels').find('li').each(function () { var hImg = jQuery('img', jQuery(this)).attr('data-h'); if (hImg < 415) { jQuery('img', jQuery(this)).css('margin-top', parseInt((415 - hImg) / 2) + 'px'); } }); */ // Egalisation de la taille des adresses if (!de0a640) { base.columnizer('#adrRecap', 'div'); } // Egalisation de la taille des modes de paiement if (!de0a640) { base.columnizer('#choixPaiement > div', '.paiement'); } // Si inférieur à 640 /*if (de0a640) { // Remplacement du logo d'entete jQuery('#logo').find('img').attr('src', 'img/le-galion-640.png'); jQuery('#video1').find('.iframeCtnr, iframe').width(610).height(346); }*/ // Egalisation de la taille des points de vente base.columnizer('#docs', 'li'); /* if (jQuery.browser.msie == true && jQuery.browser.version == 7) { initIE7(); } */ return true; } /* Faux parallax */ , fakeParallax = function () { if (!touchDevice) { // Cas des bandeaux hauts jQuery('.soloImg').each(function () { if (!de0a640 || jQuery(this).parents('.fullW').length == 0) { var lImg = jQuery(this).find('.bandeau'); if (jQuery(this).parent('.fullW').length == 0) { lImg.css('top', -scrollTop * .33); } else { lImg.css('top', -scrollTop * .33); // lImg.css('top', -(scrollTop - (jQuery(this).offset().top / 2)) * .33 ); } /* console.log(lImg.height(), parseInt(lImg.css('top')), jQuery(this).height()); if (lImg.height() + parseInt(lImg.css('top')) >= jQuery(this).height()) { if (jQuery(this).parent('.fullW').length == 0) { lImg.css('top', -scrollTop * .33); } else if (jQuery(this).offset().top < (scrollTop + jQuery(window).height())) { //console.log(jQuery(this).find('> img').attr('src'), jQuery(this).offset().top, (scrollTop + jQuery(window).height())); newPos = -(scrollTop - (jQuery(this).offset().top / 2.1)) * .33; if (newPos > jQuery(this).height() - lImg.height() + 5) { lImg.css('top', -(scrollTop - (jQuery(this).offset().top / 2.5)) * .33 ); } } } else { // lImg.css('top', lImg.height() - jQuery(this).height() ); } /* console.log(jQuery(this).find('.bandeau').height(), jQuery(this).height()); if (jQuery(this).parent('.fullW').length == 0) { jQuery(this).find('.bandeau').css('top', -scrollTop * .33 ); } else if (jQuery(this).offset().top < (scrollTop + jQuery(window).height())) { //console.log(jQuery(this).find('> img').attr('src'), jQuery(this).offset().top, (scrollTop + jQuery(window).height())); jQuery(this).find('.bandeau').css('top', -(scrollTop - (jQuery(this).offset().top / 2.5)) * .33 ); } */ } }); } } /* This function intercepts natural behaviour to enhance user experience */ , enhanceBehaviour = function () { // Rend le LI contenant le A réactif // base.enlargeClick('nav > ul > li'); // Navigation principale if (!de0a640) { // Apparition/disparition du sous-menu de langue sauf en 640 jQuery('header').find('#btnMenu').remove(); jQuery('#mainNav').find('nav > ul > li').on('mouseenter', function () { jQuery('#mainNav') .find('.sNav').hide() .end() .find('li').removeClass('focus'); jQuery(this).addClass('focus'); jQuery(this).find('.sNav').slideDown(250, function () { // base.columnizer(jQuery(this), 'ul'); }); }).on('mouseleave', function () { jQuery(this).removeClass('focus'); jQuery(this).find('.sNav').delay(200).slideUp(150); }); } else { // Gestion du bouton Menu en 640 jQuery('#btnMenu').on('click', function (e) { jQuery('#mainNav').slideToggle(400, function () { jQuery('#btnMenu').toggleClass('open'); }).find('.sNav').slideUp(); e.preventDefault(); }); jQuery('#mainNav').find('nav > ul > li').on('click', function () { jQuery('#mainNav') .find('.sNav').slideUp() .end() .find('li').removeClass('focus'); jQuery(this).addClass('focus'); jQuery(this).find('.sNav').slideDown(500); }); } // Nav secondaire jQuery('#floatingBar').find('li').each(function () { var monLi = jQuery(this), monLnk = monLi.find('a').attr('href'); }); var scrollToElt = function (elt, delay) { jQuery(document).on('mousewheel DOMMouseScroll', function (e) { e.preventDefault(); }); var documentBody = jQuery.browser.chrome || jQuery.browser.safari ? document.body : document.documentElement, decalage = jQuery('header').height() + jQuery('#floatingBar').height() - 1; jQuery('html, body').animate({ scrollTop: jQuery(elt).offset().top - decalage }, delay, 'linear', function () { jQuery(document) .off('mousewheel DOMMouseScroll') }); } // ByPass du clic sur une ancre par un scroll jQuery('.scrollToElt').on('click', function (e) { var elt = jQuery(this), lAncre = elt.attr('href'); elt.parents('ul').find('li').removeClass('current'); elt.parent('li').addClass('current'); // scrollToElt(lAncre, 2000); // e.preventDefault(); }); // Filtre des produits jQuery('#filtreSelect').on('change', function () { if (jQuery('#filtreSelect').val() != '') { jQuery('#catalogue li').not('.' + jQuery('#filtreSelect').val()).hide(); jQuery('#catalogue li.mixte, #catalogue li.' + jQuery('#filtreSelect').val()).show(); } else { jQuery('#catalogue li').show(); } }); // Changement de produit par le format jQuery('#ajoutpanierformat').on('change', function () { location.href = jQuery(this).val(); }); jQuery('.woocommerce').on('change', 'input.qte', function () { if (timeout !== undefined) { clearTimeout(timeout); } var timeout = setTimeout(function () { jQuery("[name='update_cart']").trigger("click"); }, 1000); // 1 second delay, half a second (500) seems comfortable too }); // Actions Panier et parcours jQuery('#top') // Retrait d'une unité d'un article .on('click', '.modifMoins', function (e) { if (!jQuery(this).hasClass('disabled')) { //base.sablier(); var leMin = +jQuery(this).siblings('.qte').attr("min"); var leMax = +jQuery(this).siblings('.qte').attr("max"); if(!leMin){ jQuery(this).attr('data-min'); } if(!leMax){ leMax = jQuery(this).siblings('.modifPlus').attr('data-max'); } var lIncrement = jQuery(this).attr('data-qte'), laQte = jQuery(this).siblings('.qte').val(); var newVal = laQte - lIncrement; if (newVal >= leMin) { jQuery(this).siblings('.qte').val(newVal); jQuery(this).siblings('.qte').trigger('change'); // jQuery(this).parents('form').submit(); } if(newVal <= leMin){ jQuery(this).addClass('disabled'); }else{ jQuery(this).removeClass('disabled'); } if (newVal >= leMax) { jQuery(this).siblings('.modifPlus').addClass('disabled'); }else{ jQuery(this).siblings('.modifPlus').removeClass('disabled'); } } e.preventDefault(); }); jQuery('#top') // Ajout d'une unité d'un article .on('click', '.modifPlus', function (e) { if (!jQuery(this).hasClass('disabled')) { //base.sablier(); var leMin = +jQuery(this).siblings('.qte').attr("min"); var leMax = +jQuery(this).siblings('.qte').attr("max"); if(!leMin){ leMin = jQuery(this).siblings('.modifMoins').attr('data-min'); } if(!leMax){ leMax = jQuery(this).attr('data-max'); } var lIncrement = jQuery(this).attr('data-qte'), laQte = jQuery(this).siblings('.qte').val(); console.log(leMax,lIncrement,laQte); var newVal = parseInt(laQte) + parseInt(lIncrement); if (newVal <= leMax) { jQuery(this).siblings('.qte').val(newVal); jQuery(this).siblings('.qte').trigger('change'); // jQuery(this).parents('form').submit(); } if(newVal <= leMin){ jQuery(this).siblings('.modifMoins').addClass('disabled'); }else{ jQuery(this).siblings('.modifMoins').removeClass('disabled'); } if (newVal >= leMax) { jQuery(this).addClass('disabled'); }else{ jQuery(this).removeClass('disabled'); } } e.preventDefault(); }); // Rollover images paiement jQuery('#paiementCB').each(function () { var oldCB = jQuery(this).find('input[name=CB]').attr('src'), newCB = oldCB.replace('.gif', '-on.gif'), oldVISA = jQuery(this).find('input[name=VISA]').attr('src'), newVISA = oldVISA.replace('.gif', '-on.gif'), oldMC = jQuery(this).find('input[name=MASTERCARD]').attr('src'), newMC = oldMC.replace('.gif', '-on.gif'); jQuery(this).find('input[name=CB]').on('mouseover', function () { jQuery(this).attr('src', newCB); }).on('mouseout', function () { jQuery(this).attr('src', oldCB); }); jQuery(this).find('input[name=VISA]').on('mouseover', function () { jQuery(this).attr('src', newVISA); }).on('mouseout', function () { jQuery(this).attr('src', oldVISA); }); jQuery(this).find('input[name=MASTERCARD]').on('mouseover', function () { jQuery(this).attr('src', newMC); }).on('mouseout', function () { jQuery(this).attr('src', oldMC); }); }); return true; } , initIE7 = function () { return true; } /* This function handles the current position of the floating nav */ , windowHeight = jQuery(window).height(), docHeight = jQuery(document).height(), laSNav = jQuery('#floatingBar li').children(), activeSNavLnks = new Array(); // Liste des blocs liés for (var i = 0; i < laSNav.length; i++) { var leHref = jQuery(laSNav[i]).attr('href'); activeSNavLnks.push(leHref); } var activeSNav = function () { for (var i = 0; i < activeSNavLnks.length; i++) { var leId = activeSNavLnks[i], divPos = jQuery(leId).offset().top - (jQuery('header').height() + jQuery('#floatingBar').height()), divH = jQuery(leId).height(); console.log(scrollTop, divPos, divH); if (scrollTop >= (divPos - (divH/2)) && scrollTop < (divPos + divH)) { // Si bloc calé en haut, activation de l'item correspondant jQuery('a[href=' + leId + ']').parent('li').addClass('current'); if (leId == '#anchor1') { animScreen(1); } else if (leId == '#anchor2') { animScreen(2); } else if (leId == '#anchor3') { animScreen(3); } else if (leId == '#anchor4') { animScreen(4); } else if (leId == '#anchor5') { animScreen(5); } else if (leId == '#anchor6') { animScreen(6); } else if (leId == '#anchor7') { animScreen(7); } else if (leId == '#anchor8') { animScreen(8); } else if (leId == '#anchor9') { animScreen(9); } else if (leId == '#anchor10') { animScreen(10); } else if (leId == '#anchor11') { animScreen(11); } } else { jQuery('a[href=' + leId + ']').parent('li').removeClass('current'); } } // Si bas de page, activation du dernier item if (scrollTop + windowHeight == docHeight) { if (!jQuery('#floatingBar li:last-child').hasClass('current')) { var navCurrent = jQuery('#floatingBar .current').find('a').attr('href'); jQuery('#floatingBar li:last-child').addClass('current'); } } } /* This function inits animations on Savoir-Faire and Saga pages */ , initiatedScreens = new Array(), eraseAnimatedScreen = function (leScreen) { for (var i = 0; i < initiatedScreens.length; i++) { if (initiatedScreens[i] == leScreen) { initiatedScreens.splice(i, 1); break; } } } /* This function unmask the page */ , unMask = function () { jQuery('#mask').delay(250).fadeOut(250); } /* This function inits PrettyPhoto plugin */ , initPrettyPhoto = function () { if (typeof jQuery.prettyPhoto != "undefined") { jQuery(".gallery a[data-rel^='prettyPhoto']") .prettyPhoto({ theme: 'galion', opacity: 0.8, overlay_gallery: false, default_width: '100%', default_height: '100%', show_title: false, changepicturecallback: function () { // Fires at pop-in opening, kinda callback... // return true; }, callback: function () { return true; }, social_tools: '', deeplinking: false // to avoid #!prettyPhoto/0/ in the url }).on('click', function () { if (jQuery(this).attr('href') == '#popInCercle' || jQuery(this).attr('href') == '#popInNewsletter') { setTimeout(base.handleAjax, 1000); setTimeout(function () { jQuery('.pp_pic_holder').css({ left: '50%', 'margin-left': '-512px', 'max-width': '1024px' }); jQuery('.pp_content, .pp_details').css({ 'max-width': '1024px' }); jQuery('.pp_left').css({ padding: 0 }); }, 1000); } }); } } /* This function inits Cycle plugin */ , initCycle = function () { if (typeof jQuery.fn.cycle != "undefined") { jQuery('.cycle').cycle({ fx: 'turnUp', speed: 1500, timeout: 5000, pause: 1 }); } } /* This function inits MagnificPopUp plugin */ , initMFP = function () { if (typeof jQuery.fn.magnificPopup != "undefined") { jQuery('.mfp').magnificPopup({ type: 'iframe', delegate: 'a', gallery: { enabled: true }, iframe: { patterns: { dailymotion: { index: 'dailymotion.com', id: function (url) { var m = url.match(/^.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/); if (m !== null) { if (m[4] !== undefined) { return m[4]; } return m[2]; } return null; }, src: 'http://www.dailymotion.com/embed/video/%id%' } } } }); } } // Public elements : return { finishDesign: finishDesign, enhanceBehaviour: enhanceBehaviour, fakeParallax: fakeParallax, activeSNav: activeSNav, eraseAnimatedScreen: eraseAnimatedScreen, initiatedScreens: initiatedScreens, unMask: unMask, trads: trads, jQueryPlugins: { initPrettyPhoto: initPrettyPhoto, initCycle: initCycle, initMFP: initMFP } } }(); /* http://stackoverflow.com/questions/15191058/css-rotation-cross-browser-with-jquery-animate */ jQuery.fn.animateRotate = function (angle, duration, easing, complete) { var args = jQuery.speed(duration, easing, complete); var step = args.step; return this.each(function (i, e) { args.step = function (now) { jQuery.style(e, 'transform', 'rotate(' + now + 'deg)'); if (step) return step.apply(this, arguments); }; jQuery({ deg: 0 }).animate({ deg: angle }, args); }); };