script-leaf.js 7.24 KB
jQuery(document).ready( function($) {

  // in case of bootstrap modal example:
$('.modal').on('shown.bs.modal', function () {
  
  var documentScrollTop = $(document).scrollTop();
  $(document).on('scroll.noScroll', function() {
     $(document).scrollTop(documentScrollTop);
     return false;
  });

}).on('hidden.bs.modal', function() {

  $(document).off('scroll.noScroll');

});

    $('input').iCheck({
        checkboxClass: 'icheckbox_square-green',
          radioClass: 'iradio_square-green',
          increaseArea: '20%' // optional
        });
        
    function scrollScripts() {
  
      if(!jQuery('#content-wrap').hasClass('retract')) {
        if(jQuery(window).scrollTop() >= 150) {
            jQuery('#content-wrap').addClass('retract');
            jQuery('#page-header-seedit').addClass('retract');
            jQuery('#mySidenav').addClass('retract');
            jQuery('#page-header-part').addClass('retract');
            jQuery('#myTopnav').css('top', '40px');
            jQuery('#menu-seedit-main').css('margin-top', '15px');
            jQuery('.tag-line').hide();
                     
        }
      } else {
          if(jQuery(window).scrollTop() < 170) {
              jQuery('#content-wrap').removeClass('retract');
              jQuery('#page-header-seedit').removeClass('retract');
              jQuery('#mySidenav').removeClass('retract');
              jQuery('#page-header-part').removeClass('retract');
              jQuery('#menu-seedit-main').css('margin-top', '50px');
              jQuery('.tag-line').show();
              jQuery('#myTopnav').css('top', '100px');
                     
          }
      }
    }
 

    jQuery( ".rect" ).each(function( index ) {

        var rec = $(this);
             setTimeout(function() {
                $(rec).css('visibility','visible');
    
            }, index * 500);

      });


      


      $(document).on("click",".btn.story",function() {
        $('.sub-header').show();
        $('.modal-title').show();
        $('.modal-thanks').hide(); 
        $('.form').children().show();
        $('.load').hide();
        $('[name="project_id"]').val($('[name="post_id"]').val());
        $('[name="post_date"]').val( $('#date').val());
        $('#exampleModalAddStory').modal('show');
      });
      $(document).on("click",".btn.photo",function() {
        $('.sub-header').show();
        $('.modal-title').show();
        $('.modal-thanks').hide(); 
        $('.form').children().show();
        $('.load').hide();
        $('[name="project_id"]').val($('[name="post_id"]').val());
        $('[name="post_date"]').val( $('#date').val());
        $('#exampleModalAddPhoto').modal('show');
      });
      $(document).on("click",".btn.comment",function() {
        $('.sub-header').show();
        $('.modal-title').show();
        $('.modal-thanks').hide(); 
        $('.form').children().show();
        $('.load').hide();
        $('[name="project_id"]').val($('[name="post_id"]').val());
        $('[name="post_date"]').val( $('#date').val());
        $('#exampleModalAddComment').modal('show');
       
      });

      $(document).on("click",".wpcf7-submit",function() {
        $('.load').show();
      });   

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

        setTimeout(function(){
          if(jQuery('.wpcf7-not-valid').length > 0) {
            jQuery('html,body').animate({scrollTop: jQuery('.wpcf7-not-valid').first().offset().top -150}, 'linear')
          }
        }, 1000);

        setTimeout(function(){
          $('.load').hide();
        }, 1000);

      }, false ); 

      document.addEventListener( 'wpcf7mailsent', function( event ) {
        $('.load').hide();
        $('.sub-header').hide();
        $('.modal-title').hide();
        $('.form').children().hide();
        $('.modal-thanks').show(); 
  
        $('.wpcf7-response-output').show();
        if($('.modal.fade.in').length == 0) {
          setTimeout(function(){
            $([document.documentElement, document.body]).animate({
              scrollTop:  $('.wpcf7-response-output').offset().top - 150
            }, 2000);
        }, 1000);
        }

      });   

        $(".moreBox").slice(0, 3).show();
        if ($(".blogBox:hidden").length != 0) {
          $("#loadMore").show();
        }   

        jQuery(document).on("click", "#loadMore", function(e) {
          e.preventDefault();
          $(".moreBox:hidden").slice(0, 3).slideDown();
          if ($(".moreBox:hidden").length == 0) {
            $("#loadMore").fadeOut('slow');
          }
        });
  
        $(document).on("click",".btn.fb",function() {
            window.open('http://facebook.com/sharer/sharer.php?u='+encodeURIComponent(window.location.href), '', 'left=0,top=0,width=650,height=420,personalbar=0,toolbar=0,scrollbars=0,resizable=0');
        });

    jQuery(document).on("click",".share_read_more",function(evt) {
        evt.preventDefault();

        $(".modal-body.story").html('<img class="loading"  src="https://thecommonwell.ca/wp-content/themes/commonwell-corp/images/loading.svg"/>');
        $('.sub-header').show();
        $('.modal-title').show();
        $("#exampleModalLong").modal("show");
            var id = $(this).data('id');
        console.log(id);
        $.ajax({
            type: 'POST',
            url: '../../wp-admin/admin-ajax.php',
            dataType: 'json',
            data: {
                'post_id': id,
                'action': 'ajax_request' //this is the name of the AJAX method called in WordPress
            }, success: function (data) {
                $(".sub-header.story").html(data['date']+'<br/>Submitted by '+data['post'].post_title);
                $(".modal-body.story").html(data['post'].post_content);
    
               console.log(data['post']);
            },
            error: function () {
                alert("error");
            }
        });
    
    
        return false;
      });

      jQuery(document).on("click","#menu-seedit-main li a",function(evt) {
        jQuery('#mySidenav').removeClass('mobile-open');
    });
      
      document.addEventListener('dblclick', (event) => {
        event.preventDefault()
    }, { passive: false });
    
    var scrolling = false;
   
    jQuery( window ).scroll( function() {
        scrolling = true;
    });
  
    jQuery('#side-window').scroll(function() {
        scrolling = true;
    });
    
    setInterval( function() {
        if ( scrolling ) {
            scrolling = false;
            scrollScripts();
        }
    }, 250 );
    
    // or for modern browsers
    document.addEventListener( 'wheel', function( evt ) {
        scrolling = true;
    }, { capture: false, passive: true });
  
    scrollScripts();

    var el = document.getElementById('commonwell-link');
var style = window.getComputedStyle(el, null).getPropertyValue('font-size');
var fontSize = style;
var fontSizePercentage = parseFloat(style) / 12 * 100;
if( fontSizePercentage > 100){
  document.body.className += ' large_font';
 // $('.menu-item-220  a').attr('href','/news/');
}
if( fontSizePercentage > 125){
    document.body.className += ' xlarge_font';
  }

console.log(style, fontSizePercentage);

  });

jQuery(window).load(function() {
  if(location.hash) {
    var id = jQuery(location.hash);
    jQuery('html,body').animate({scrollTop: id.offset().top -150}, 'linear')
  }
});