var jsSite = { // init, something like a constructor init: function() { $('body').addClass('js'); var bLazy = new Blazy({}); $('js-remove-dimensions-from-media').find('iframe,img').removeAttr('style').removeAttr('width').removeAttr('height'); if($('.packery').length > 0) { imagesLoaded('.packery', function() { $('.packery').packery({ itemSelector: '.packery-item', percentPosition: true }); }); } $('#cycle-2').on( 'DOMMouseScroll mousewheel', function ( event ) { if( event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0 ) { //alternative options for wheelData: wheelDeltaX & wheelDeltaY $('#cycle-2').cycle('next'); } else { $('#cycle-2').cycle('prev'); } //prevent page fom scrolling return false; }); $(document.documentElement).keyup(function (e) { if (e.keyCode == 39) { $('#cycle-1').cycle('next'); } if (e.keyCode == 37) { $('#cycle-1').cycle('prev'); } }); var slideshows = $('.cycle-slideshow').on('cycle-next cycle-prev', function(e, opts) { // advance the other slideshow slideshows.not(this).cycle('goto', opts.currSlide); }); $('#cycle-2 .cycle-slide').click(function(){ var index = $('#cycle-2').data('cycle.API').getSlideIndex(this); slideshows.cycle('goto', $(this).data('index')); }); $('#cycle-1').click(function(e){ var parentOffset = $(this).parent().offset(); //or $(this).offset(); if you really just want the current element's offset var relX = e.pageX - parentOffset.left; var relY = e.pageY - parentOffset.top; if(relX < $(this).width()/2){ $('#cycle-1').cycle('prev'); } else { $('#cycle-1').cycle('next'); } }); $("#cycle-1").mousemove(function(e){ var parentOffset = $(this).parent().offset(); }); jsSite.controls.init(); jsSite.contentFixes.init(); jsSite.forms.init(); jsSite.navigation.init(); } } // Check if on mobile var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; jsSite.controls = { // init, something like a constructor init: function() { jsSite.controls.bindTargetBlank(); }, // bind target blank bindTargetBlank: function() { $('a.js-target-blank').attr('target', '_blank'); } } jsSite.contentFixes = { // init, something like a constructor init: function() { jsSite.contentFixes.equalHeights(); }, equalHeights: function() { if ($('.js-equal-heights, .js-equal-height').length > 0) { imagesLoaded('.js-equal-heights, .js-equal-height', function() { $('.js-equal-heights, .js-equal-height').equalHeights(); }); $(window).on("resize", function(event) { $('.js-equal-heights, .js-equal-height').equalHeights(); }); } } } jsSite.socialShare = { // init, something like a constructor init: function() { var dimensions = 'width=626,height=436'; var $url = 'https://www.facebook.com/sharer/sharer.php' + '?u=' + encodeURIComponent(location.href) + '&src=sdkpreparse'; $('.js-facebook').click(function(e) { e.preventDefault(); window.open( $url, 'facebook_share_dialog', dimensions); return false; }); $(".js-twitter").click(function(e) { e.preventDefault(); if ($(this).attr('title')) { window.open('http://twitter.com/intent/tweet?text=' + $(this).attr('title') + ' ' + location.href, 'twitter', dimensions); } else { window.open('http://twitter.com/intent/tweet?text=' + location.href, 'twitter', dimensions); } }); // href="whatsapp://send?text=Content of text" $(function() { // Hide button on desktop if (!isMobile.any()) $('.js-whatsapp').css('display', 'none'); // Show button on desktop if (isMobile.any()) $('.js-whatsapp').css('display', 'block'); }); } } jsSite.forms = { // init, something like a constructor init: function() { jsSite.forms.bindFocus(); jsSite.forms.bindSubmit(); jsSite.forms.inlineLabels(); }, bindSubmit: function() { $('.js-submit-form').click(function() { $(this).closest('form').submit(); return false; }); }, inlineLabels: function() { $("label.js-inline-label + input.inputText").each(function(type) { // $(window).on('load', function () { // setTimeout(function(){ // if (!input.value.empty()) { // input.previous().addClassName('has-text'); // } // }, 200); // }); $(this).focus(function() { $(this).prev("label.js-inline-label").addClass("is-focused"); }); $(this).keypress(function() { $(this).prev("label.js-inline-label").addClass("has-text").removeClass("is-focused"); }); $(this).blur(function() { if ($(this).val() == "") { $(this).prev("label.js-inline-label").removeClass("has-text").removeClass("is-focused"); } }); }); }, bindFocus: function() { $('.js-focus').first().focus(); $('.js-focus-on-first').find("input:text, textarea").first().focus(); } } jsSite.navigation = { // init, something like a constructor init: function() { jsSite.navigation.responsive(); jsSite.navigation.tabs(); jsSite.navigation.language(); }, tabs: function() { var hash = window.location.hash; if (hash.indexOf('#tab-') != -1) { var tab = hash.slice(1); var target = $('.tab-content[data-tab-name=' + tab + ']'); if (target.length > 0) { $('.tab-content.tab-selected').removeClass('tab-selected'); target.addClass('tab-selected'); $('.js-tab').closest('li').parent().find('li.selected').removeClass('selected'); $('.js-tab[data-tab-name=' + tab + ']').closest('li').addClass('selected'); } } $('.js-tab').click(function() { var t = $(this).data('tab-name'); $(this).closest('li').parent().find('li.selected').removeClass('selected'); $(this).closest('li').addClass('selected'); $('.tab-content.tab-selected').removeClass('tab-selected'); $('.tab-content[data-tab-name=' + t + ']').addClass('tab-selected'); window.location.hash = t; return false; }) }, responsive: function() { $('.js-responsive-collapse-button').click(function() { $('body').toggleClass('responsive-collapse-is-open'); return false; }); }, language: function() { if (isMobile.any()) { $('.language-navigation ul').click(function(e){ e.preventDefault(); $('.language-navigation select').trigger('click'); }) } $('.language-navigation select').change(function() { window.location = $(this).val(); return false; }); } } $(jsSite.init);