$(document).ready(function(){ /* Windows Width Resize, Page Reload */ /*var tempWinWidth = $(window).width(); $(window).bind('resize', function(e){ if (window.RT) clearTimeout(window.RT); window.RT = setTimeout(function(){ var changes = ((tempWinWidth-$(window).width()) / tempWinWidth) ; if(changes < 0){ changes *= -1 } if(changes > 0.3){ window.location.reload(); } }, 100); });*/ //To trigger the # tag page anchor if(window.location.href.indexOf("#") > -1) { $(window).scrollTop(0); var topVal = 0; if($(window).width() > 767){ topVal = 90; } setTimeout(function(){ var target = $(location.hash); target = target.length ? target : $('[name=' + $(location).attr('hash').slice(1) + ']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top - topVal }, 1000, "easeInOutCubic"); } }, 100); } /* For anchor link start with # */ $(document).on('click','a[href^=#]:not([href=#])',function (e) { e.preventDefault(); e.stopPropagation(); var target = $($(this).attr('href')); if(target.length){ $($(this).attr('href')).get(0).scrollIntoView({ behavior: "smooth", // or "auto" or "instant" block: "start" // or "end" }); } }); /* =========== BG Parallex Effect - BOF =========== */ if($(window).width() > 767){ var hWindow = $(window).height(); $(window).scroll(function () { var st = $(window).scrollTop(); $(".parallex-fixed .middle-bg, .wrapper_middle.parallex-fixed, .parallex-fixed").each(function(){ var otElement = $(this).offset().top - st; if( otElement > 0 && otElement < hWindow ){ sh = ((otElement / hWindow) * 50 ); } if(otElement <= 0){ sh=0; } if(otElement >= hWindow){ sh=50; } $(this).css({ // 'background-attachment' : 'fixed', 'background-position' : 'center '+sh+'% ' }); }); $(".parallex").each(function(){ var otElement = $(this).offset().top - st; if( otElement > 0 && otElement < hWindow ){ sh = 50 - ((otElement / hWindow) * 50); } if(otElement <= 0){ sh=50; } if(otElement >= hWindow){ sh=0; } //console.log('test: ' + otElement); $(this).css({ 'background-position' : 'center '+sh+'% ' }); }); /* Apply parallex BG on float element */ $(".parallex-parent").each(function(){ var otElement = $(this).offset().top - st; if( otElement > 0 && otElement < hWindow ){ sh = 50 - ((otElement / hWindow) * 50); } if(otElement <= 0){ sh=50; } if(otElement >= hWindow){ sh=0; } //console.log('test: ' + otElement); $(this).find('.middle-bg').css({ 'background-position' : 'center '+sh+'% ' }); }); $(".wrapper_middle.fixed, .fixed-bg").each(function(){ //$(this).css('background-position', 'center ' + (st-$(this).offset().top) + 'px'); //console.log('test: ' + ($(this).offset().top - st) ); /* Fixed iOS Safari background fixed CSS issue, by using position fixed in DIV element */ // if( ($(this).offset().top - st - $(window).height() ) < 20){ // }else if( ($(this).offset().top - st - ($(window).height()*1.1) ) > 0 || (st+$(window).height()*0.8) >= ($(window).height()*1.2 + $(this).offset().top) ){ $(this).removeClass('active'); }else{ $(this).addClass('active'); } }); }); } /* =========== EOF - BG Parallex Effect =========== */ /* Bootstrap Accordian */ $(document).on('click','.panel-group a.accordion-toggle',function(e){ $parentDIV = $(this).parents('div.panel-group'); if( $(this).hasClass('closed') ){ $('.panel-group#'+$parentDIV.attr('id')+' a.accordion-toggle').addClass('closed'); $('.panel-group#'+$parentDIV.attr('id')+' .panel-heading').removeClass('opened'); $(this).parent('.panel-heading').addClass('opened'); $(this).removeClass('closed'); setTimeout(function(){ //$('html').animate({ scrollTop: $('.panel-group#'+$parentDIV.attr('id')+' .panel-heading.opened').offset().top }, 300); },500); }else{ $('.panel-group#'+$parentDIV.attr('id')+' a.accordion-toggle').addClass('closed'); $(this).parent('.panel-heading').removeClass('opened'); } return true; }); /* EOF - Bootstrap Accordian */ // ------ Convert Thickbox to BlueImp ------- $(document).on('click', 'a.thickbox', function (event) { event.preventDefault(); var target = event.target || event.srcElement, link = target.src ? target.parentNode : target, dataindex = $(this).attr('data-index') ? $(this).attr('data-index') : link, options = { index: dataindex, event: event, onopened: function(){ /* === BOL - Panzoom jQuery plugin === */ $('#blueimp-gallery .slide').panzoom(); var zoomLevel = 1; // Panzoom with Mouse Scroll $('#blueimp-gallery .slide').on('wheel', function(e) { var oEvent = e.originalEvent, delta = oEvent.deltaY || oEvent.wheelDelta; var valX = parseInt($(this).css('transform').split(',')[4]); var valY = parseInt($(this).css('transform').split(',')[5]); if (delta < 0) { // Scrolled up || zoom in if(zoomLevel < 2 ) { zoomLevel = zoomLevel *1.1; } } else { // Scrolled down || zoom out if(zoomLevel > 0.3 ){ zoomLevel = zoomLevel *0.9; } } $(this).css('transform', 'matrix('+zoomLevel+', 0, 0,'+zoomLevel+', '+valX+','+valY+')'); return false; }); /* === EOL - Panzoom jQuery plugin === */ }, onclosed: function () { //console.log('test2'); $('body:not(.noscroll)').css({'overflow-y':'auto'}); } }; //fullScreen: true, //When no group ID detect if($(this).attr('rel') === null){ blueimp.Gallery($(this),options); }else{ blueimp.Gallery($('a.thickbox[rel='+$(this).attr('rel')+']'),options); } }); // ------ EOF - Convert Thickbox to BlueImp ------- /*--- BOF - Append Current Link to Anchor ---*/ var currentLoc = $(location).attr('href'); $("a[href^='#']").each(function(){ var hashValue = $(this).attr('href'); $(this).attr('href', currentLoc + hashValue); }); /*--- EOF - Append Current Link to Anchor ---*/ /* Make Footer Stick at Bottom always */ if($('#morph-main > section.wrapper_middle.only').length == 1){ $minHeight = $(window).height() - $('.wrapper_header').height() - $('.wrapper_footer').height(); $('#morph-main > section.wrapper_middle.only').css({ 'min-height' : $minHeight }); } /* Detect anchor when click smooth scrolling */ scrollToElement(); /* Adding CSS3 Fading Effect on every buttons */ $('.btn').addClass('fadeBG'); // HEADER SCROLLING var didScroll; var lastScrollTop = 0; var delta = 160; var navbarHeight = $('header').outerHeight(); $(window).scroll(function(event){ didScroll = true; }); setInterval(function() { if (didScroll) { hasScrolled(); didScroll = false; } }, delta); function hasScrolled() { var st = $(this).scrollTop(); // Make sure they scroll more than delta if(Math.abs(lastScrollTop - st) <= delta) return; if (st > lastScrollTop && st > navbarHeight){ // Scroll Down $('html').removeClass('nav-down').addClass('nav-up'); } else { // Scroll Up $('html').addClass('nav-down').removeClass('nav-up'); } lastScrollTop = st; } // FIXED HEADER $(window).scroll(function() { var scroll = $(window).scrollTop(); if (scroll >= 160) { $("html").removeClass("reached-top"); } else { $("html").addClass("reached-top"); } if ( $(window).scrollTop() + $(window).height() > $(document).height()-10 ) { $("html").addClass("reached-bottom"); } else { $("html").removeClass("reached-bottom"); } }); }); function elementScrolled(elem, withBody){ withBody = withBody || 0; var docViewTop = $(window).scrollTop(); var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top + withBody; return ((elemTop <= docViewBottom) && (elemTop >= docViewTop)); } function scrollToElement() { var headerH = $('.wrapper_header.bottom').outerHeight(true); var headerFH = $('.wrapper_header.bottom').outerHeight(true); if($(window).width() > 767){ topVal = ( $(this).scrollTop() > $(window).height()) ? headerFH : headerH; $(window).scroll(function() { var topVal = $('.sticky-wrapper.sticked').length ? $('.wrapper_header.bottom').height()*2 : $('.wrapper_header.bottom').height(); }); } $(document).on('click','a[href*=#]:not([href=#])',function (e) { // console.log('location.pathname: ' + location.pathname); // console.log('this.pathname: ' + this.pathname); // console.log('test: ' + this.hostname); if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : (this.hash.slice(1).trim() ? $('[name=' + this.hash.slice(1) + ']') : '') ; //console.log('test: ' + this.hash.slice(1)); if (target.length) { //console.log('test: ' + target.offset().top); $('html,body').animate({ scrollTop: target.offset().top - topVal }, 800, "easeInOutCubic"); return false; } } }); } /** * Protect window.console method calls, e.g. console is not defined on IE * unless dev tools are open, and IE doesn't define console.debug */ (function() { if (!window.console) { window.console = {}; } // union of Chrome, FF, IE, and Safari console methods var m = [ "log", "info", "warn", "error", "debug", "trace", "dir", "group", "groupCollapsed", "groupEnd", "time", "timeEnd", "profile", "profileEnd", "dirxml", "assert", "count", "markTimeline", "timeStamp", "clear" ]; // define undefined methods as noops to prevent errors for (var i = 0; i < m.length; i++) { if (!window.console[m[i]]) { window.console[m[i]] = function() {}; } } })(); /* ================= Add Classname Touchscreen Detection into HTML - BOF ================= Reference: http://jonwallsten.com/2015/03/02/how-to-handle-hover-on-touch-devices-in-simple-way-javascript-css/ ======================================================================================= */ (function() { //I use jQuery for simplicity var preliminaryTouch = false; //Assume all devices are no touch device $('html').addClass('no-touch-device'); //Check the user agent string if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { preliminaryTouch = true; } if( preliminaryTouch ) { //Do something for touch devices and //Add a preliminary touch class $('html').addClass('prel-touch-device'); } })(); $(document).on('touchstart', function() { //Now we can safely remove the the no-touch-device and prel-touch-device classes $('html').removeClass('no-touch-device prel-touch-device').addClass('touch-device'); }); //Do something later somewhere in your code if( $('html').hasClass('touch-device') ) { //$('body').prepend('

Touch Screen Device Detected ...

'); } /*================= EOF - Add Classname Touchscreen Detection into HTML ================= */