custom-javascript.js 9.52 KB


import './vendor/jquery-cookie-1.4.1.min';
import './vendor/jquery-colorbox-1.6.4';
import './vendor/bootstrap-3.2.0.min';
import './vendor/jquery-ui.min';
import './vendor/tooltipster.bundle.min';
import "./vendor/icheck.min";

import "./moblie_menu";
import './show-more';
import './accessibility';
import "./_resources_list";
import "./_custom_select";
import "./_accordion";
import "./_responsive";
import "./_postal_search";

function checkOffsetForTopper() {
    if(jQuery('.the-toppe').length > 0) {
        if(jQuery('.the-topper a').offset().top + jQuery('.the-topper a').height() 
                                            >= jQuery('#new-footer').offset().top - 300)
            jQuery('.the-topper').addClass('stopper');
        if(jQuery(document).scrollTop() + window.innerHeight < jQuery('#new-footer').offset().top)
            jQuery('.the-topper').removeClass('stopper');
    }
}

function getIsExternLink($link) {
    $link = $link.trim();
    if($link.indexOf('brokers') === -1 && $link.indexOf('broker') === -1 &&
    $link.indexOf('localhost') === -1 && $link.indexOf('mailto:') === -1 && $link.indexOf('tel:') === -1 
    && $link.indexOf('#') !== 0) {
        if($link !== "/" && $link !== "#" && $link.indexOf('/') !== 0) {
            return true;
        }
    }
  }

jQuery(document).ready(function($) {

    if($('#page-content').outerHeight() >= 1000) {
        $('#page-content').addClass('topper');
        $('.the-topper').removeClass('hide');
    }

    $('.the-topper a').on('click', function(e) {
        e.preventDefault();
        $(window).scrollTop(0);
    });

    $('#page-content a').each(function() {
        if(jQuery(this).is("a") && jQuery(this).find('.download-bar').length == 0 
        && jQuery(this).text().length > 4) {
            var _href = jQuery(this).attr('href');
            if(_href) {
              if(_href.indexOf('.pdf') !== -1) {
                  jQuery(this).addClass('pdf');
              } else if(_href.indexOf('.xls') !== -1) {
                jQuery(this).addClass('xls');
              } else if(_href.indexOf('mailto:') !== -1) {
                jQuery(this).addClass('mailto');
              } else if(_href.indexOf('tel:') !== -1) {
                jQuery(this).addClass('tel');
              } else if(getIsExternLink(_href)) {
                console.log(jQuery(this).parent())
                if(jQuery(this).parents('.entry-content').length > 0) {
                  jQuery(this).html(jQuery(this).html() + "&nbsp;")
                }
                jQuery(this).addClass('extern');
                if(jQuery(this).is('a')) {
                  jQuery(this).attr('target','_blank');
                }
              }
            }
        }
    });

    $(document).on('click', '.favourite', function(e) {
        e.preventDefault();
        console.log("PREVENTED DEFAULT?");
        if($(this).attr('disabled')) {
            return;
        }
        $(this).attr('disabled', true).addClass('loading');
        var _request = $(this).attr('href'),
        _other_request = $(this).data('other-request');
        var that = this;
        if($(this).hasClass('fav')) {
            $(this).removeClass('fav'); 
        } else {
            $(this).addClass('fav'); 
        }
        $.get(_request, function(response) {
            if(response.response === true) {
                var _href = _request;
                $(that).attr('href',_other_request);
                $(that).data('other-request', _href);
            }
        }).done(function() {
            $(that).attr('disabled', false).removeClass('loading');
        });
    });

    function scrollScripts() {
        checkOffsetForTopper();
        if(!jQuery('#content-wrap').hasClass('retract')) {
          if(jQuery(window).scrollTop() >= 50) {
             jQuery('body').addClass('retract');
              jQuery('#content-wrap').addClass('retract');
          }
        } else {
            if(jQuery(window).scrollTop() < 50) {
                jQuery('#content-wrap').removeClass('retract');
                jQuery('body').removeClass('retract');
            }
        }
      }
    
      var scrolling = false;
     
      jQuery( window ).scroll( function() {
          scrolling = true;
      });
    
      jQuery('#side-window').scroll(function() {
          scrolling = true;
      });
      
      setInterval( function() {
          if ( scrolling ) {
              scrolling = false;
              scrollScripts();
          }
      }, 50 );
      
      // or for modern browsers
      document.addEventListener( 'wheel', function( evt ) {
          scrolling = true;
      }, { capture: false, passive: true });
    
      scrollScripts();

    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://brokers.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 ));