script.js 4.95 KB
jQuery(document).ready(function($) {

    if ($(window).width() > 720) {
        setTimeout(function() {
            var maxHeight = 0;
        $('.thumbnail.course').each(function() {
            console.log($(this));
                maxHeight = Math.max(maxHeight, $(this).height());
            
            });
        $('.thumbnail.course').css({height:maxHeight + 'px'});
        },100);
    }

    var mobile = window.matchMedia( "(max-width: 768px)" );
	var isMobile = false;

    mobile.addListener(checkMobile);

    function checkMobile(e) {
        if(e.matches) {
            isMobile = true;
            mobilize();
        } else {
            demobilize();
        }
    }

    checkMobile(mobile) 
    
    function demobilize() {
    }

	function mobilize(e) {

    }

    $('.menu-item-has-children').on('click', function() {
        $('.menu-item-has-children').removeClass('open-menu');
        if(isMobile) {
            $(this).toggleClass('open-menu');
        }
    });


    $('#mySidenav').css('top', -$('#mySidenav').height() - 200).addClass('ready');

    $('*').on('focus', function(e) {
        if(!isMobile) {
            if($(this).parents('.menu-item-has-children').length > 0) {
                $(this).parents('.menu-item-has-children').addClass('open-menu');
            } else {
                $('.menu-item-has-children').removeClass('open-menu');
            }
        }
    });
    $(".learning-cards .ugb-card__item .ugb-card__content:empty").parent().addClass('empty').removeClass('ugb--shadow-1');




    $(".badge_container").not('.cert').click(function () {
     var title =  $(this).data('title');
      
       // $("#dialog").dialog({modal: true, height: 590, width: 1005 });
        var w = window.open("https://thecommonwell.ca/badge-share/?badge="+title, "popupWindow", "width=400, height=400, scrollbars=no");

    });

    $('.background-img').each(function(index) {  
      
        $(this).parents('.background-img-cont').attr("style", 'background-image:url('+$(this).children('img').attr('src')+');')
        $(this).children('img').hide();
        
    });

    
});



function flipCard(event){
    var element = event.currentTarget;
    var link = event.currentTarget.getElementsByClassName('link');
   
    var ellipsis = event.currentTarget.getElementsByClassName('ellipsis');
    var after = event.currentTarget.getElementsByClassName('after');
    var translate = 'scale3d(1, 1, 9) rotateY(180deg) translate(0%, 0%)';
    if (jQuery(window).width() <= 768) {  
        translate = 'scale3d(1, 1, 9) rotateY(180deg) translate(0%, 0px)';
    }

    if (element.className === "badge-flip-card") {
  
      if(element.style.transform == translate) {
        element.style.transform = "";
        setTimeout(function(){
        jQuery(element).find('.card-content.back').delay(1000).css('backface-visibility', 'hidden');
          }, 300);
        if(element.className === "staff-flip-card"){
           setTimeout(function(){
            ellipsis[0].style.visibility='visible';
            element.style.zIndex = "1";
          }, 300);
        }
      }
      else {
        jQuery('.staff-flip-card').css('transform', '');
        jQuery('.staff-flip-card').css('z-index', '1');

      
        setTimeout(function(){
            jQuery(element).find('.card-content.back').css('backface-visibility', 'visible');
          jQuery('.linkedin').attr('style', 'display:block;');
          jQuery('.ellipsis').attr('style', 'display:block;');
   
        }, 200);
        
        element.style.transform =  translate;
        element.style.zIndex = "1000";
        if(element.className === "staff-flip-card"){
        setTimeout(function(){
          ellipsis[0].style.visibility='hidden';
       
          }, 200);
        }
      }
    }
  };


  document.addEventListener( 'wpcf7invalid', function( event ) {

    var is_leaf_submit = jQuery(event.target).parents('#wpcf7-f47761-o1');

    setTimeout(function() {
        if(is_leaf_submit.length > 0) {

            var first_err = jQuery('input[aria-invalid="true"]:first');
    
            if(first_err) {
    
                jQuery([document.documentElement, document.body]).animate({
                    scrollTop: first_err.offset().top - 200
                }, 500);
    
            }
    
        }
    }, 500);

  }, false );



  (function( $ ) {
    // the sameHeight functions makes all the selected elements of the same height
    $.fn.sameHeight = function() {
        var selector = this;
        var heights = [];

        // Save the heights of every element into an array
        selector.each(function(){
            var height = $(this).height();
            heights.push(height);
        });

        // Get the biggest height
        var maxHeight = Math.max.apply(null, heights);
        // Show in the console to verify
        console.log(heights,maxHeight);

        // Set the maxHeight to every selected element
        selector.each(function(){
            $(this).height(maxHeight);
        }); 
    };
 
}( jQuery ));