// global JS object VHA_Global = function(){ //global vars var _this, orientationSupport, textVal; return{ /************************ Init function -- attach event handlers ************************/ init: function(){ _this = this; //mobile hack if(!$.browser.msie){ document.addEventListener("touchstart", function() {},false); } //console.log('yo'); $('#vha-vca .vha-mobile .vha-mod-kms-mobile .mod-hd').live('click',_this.openMobileMod); $('#vha-vca .mod-support-article-snippet .mod-hd').live('click',_this.openMobileMod); $('#toggle-btn').click(_this.toggleLayout); //Email us form $('.vha-vca-email-us .mod-kms-email-resolve .solve_yes').click(_this.showThanks); $('.vha-vca-email-us .mod-kms-email-resolve .solve_no').click(_this.showCust); $('.vha-vca-email-us .mod-kms-email-cust .cust_yes').click(_this.showForm); $('.vha-vca-email-us .mod-kms-email-cust .cust_no').click(_this.showNonCust); $('.vha-vca-email-us .mod-kms-email-form .id-proof').click(_this.showIDProof); var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; //alert(supportsOrientationChange); //alert(orientationEvent); orientationSupport = orientationEvent; //alert(orientationSupport); $(window).bind(orientationEvent, _this.deviceOrientation) //run device hook _this.deviceOrientation(); //handle menu run only if we're in mobile view _this.checkDevice(); $(window).resize(_this.checkDevice); $('#vha-vca .vha-mobile #menu .nav-item-home').live('click', _this.toggleMenu) $('#vha-vca .vha-mobile #vha-search-results .sr-bd .no-results dl dt:first-child').live('click',_this.openSubNav) //clear input boxes $('.vha-kms-form-breakout input[type=text],.vha-mod-landing-breakout input[type=text], .vha-mod-kms-ask-us input[type=text], .vha-mod-kms-error .input-cont :input').live('focus', _this.inputHandler) $('.vha-kms-form-breakout input[type=text],.vha-mod-landing-breakout input[type=text], .vha-mod-kms-ask-us input[type=text], .vha-mod-kms-error .input-cont :input').live('blur', _this.inputHandler) }, inputHandler : function(e){ //get the event var whichEvent = e.type; //console.log(e); if(whichEvent == 'focusin'){ //input focus //console.log('focus') textVal = $(this).attr('value'); //console.log(textVal); $(this).attr('default-text', textVal); //clear it out $(this).val(""); }else if(whichEvent == 'focusout'){ //inputblur //console.log('blur') //$(this).attr('value',textVal); //$(this).val(textVal); } }, showThanks : function(){ $('.mod-kms-email-thanks').show(); $('.mod-kms-email-cust').hide(); $('.mod-kms-email-form').hide(); }, showCust : function(){ $('.mod-kms-email-thanks').hide(); $('.mod-kms-email-cust').show(); }, showNonCust : function(){ $('.mod-kms-email-noncust').show(); $('.mod-kms-email-form').hide(); }, showForm : function(){ $('.mod-kms-email-noncust').hide(); $('.mod-kms-email-form').show(); }, showIDProof : function(){ $('.mod-kms-email-form .form-cont .extra-info .id-points').toggle(); }, checkDevice : function(){ //console.log("check"); //check screen size if($(window).width() < 560){ //console.log('unbind'); $("#menu li.top-level, #top-globalnav li, #top-quicklinks li").unbind(); $('#vha-device-hook').addClass('vha-mobile'); $('#vha-vca .vha-mobile #menu .nav-item-home').attr('onclick','void(0)'); $('#vha-vca #vha-search-results .sr-bd .no-results dl dt').live('click',function(e){ e.preventDefault(); var thisTarg = $(this).children('a'); if(!$(thisTarg).hasClass('first-item')){ //console.log($(thisTarg).attr('href')) document.location.href = $(thisTarg).attr('href'); } }) } else { //console.log('bind'); // nasty hack $('#vha-device-hook').removeClass('vha-mobile'); $('#vha-vca #menu .nav-item-home').removeAttr('onclick'); $('#top-nav').removeClass('menu-closed').addClass('menu-open').height('auto'); $('#vha-vca #vha-search-results .sr-bd .no-results dl dt').live('click',function(e){ e.preventDefault(); return false; }) //Mega Menu Hover States $("#menu li.top-level, #top-globalnav li, #top-quicklinks li").hover( function(){ $(this).addClass("nav-item-on"); //normalise height for support panel if($(this).hasClass("top-level") && !$(this).hasClass("nav-item-home")){ VHA_MegaMenu.setPanelHeight($(this)); } }, function(){ $(this).removeClass("nav-item-on"); } ) if ((navigator.userAgent.indexOf('iPad') != -1)){ $("#menu li.top-level, #top-globalnav li, #top-quicklinks li").click(VHA_MegaMenu.mobileDevice); } } }, toggleMenu : function(e){ //console.log(e); //console.log(e.target); var clickTarget = e.target; if($(clickTarget).is('a')){ //console.log('clicked home') return; } else { e.preventDefault(); //console.log($('#menu').height()); var menuHeight = $('#menu').height(); if($('#top-nav').hasClass('menu-open')){ $('#top-nav').animate({ height:50 }, 500, function(){ //console.log('should be closed') $('#top-nav').removeClass('menu-open').addClass('menu-closed'); $('#top-globalnav').slideUp(); }) }else{ $('#top-nav').animate({ height:menuHeight }, 500, function(){ //console.log('should be open') $('#top-nav').removeClass('menu-closed').addClass('menu-open'); $('#top-globalnav').slideDown(); }) } } }, openSubNav : function(e){ e.preventDefault(); //console.log('yo'); var thisNav = $(this).parent(); var thisHeight = 0; //console.log(thisNav); var children = $(thisNav).children('dt'); //console.log(children); $(children).each(function(){ //console.log($(this).height()) thisHeight += $(this).height() + 20; }) //console.log(thisHeight); thisHeight = thisHeight - 10; if(!$(thisNav).hasClass('nav-open')){ $(thisNav).animate({ height:thisHeight }, 500, function(){ $(thisNav).addClass('nav-open') }) } else { $(thisNav).animate({ height:55 }, 500, function(){ $(thisNav).removeClass('nav-open') }) } }, openMobileMod : function(e){ var thisHd = $(this); //console.log(thisHd); var thisParent = $(this).parents('.vha-mod-kms-mobile') var thisBody = $(this).next(); var thisFt = $(thisBody).next(); var bdHeight = $(thisBody).height(); var ftHeight = $(thisFt).height() //console.log(thisHd); //console.log(thisParent); //console.log(thisBody); //console.log(thisFt); //console.log(bdHeight); //console.log(ftHeight); if($(thisParent).hasClass('mod-support-article-snippet')){ var whichHeight = bdHeight + ftHeight + 53 + 40; $(thisParent).siblings().not('.mod-kms-email-resolve').animate({ height: 53+'px' }, 500, function(){ $(thisParent).siblings().not('.mod-kms-email-resolve').removeClass('mod-mobile-open'); }) } else if($(thisParent).hasClass('vha-mod-kms-article-footer')) { var whichHeight = bdHeight + ftHeight + 53 + 20; } else { var whichHeight = bdHeight + ftHeight + 53; } //console.log(whichHeight); if(!$(thisParent).hasClass('mod-mobile-open')){ //console.log('is closed'); $(thisParent).animate({ height: whichHeight }, 500, function(){ $(thisParent).addClass('mod-mobile-open'); }) } else { //console.log('is open'); $(thisParent).animate({ height: 53+'px' }, 500, function(){ $(thisParent).removeClass('mod-mobile-open'); }) } }, toggleLayout : function(e){ if($(this).hasClass('desktop')){ $('#toggle').removeClass('vha-desktop').addClass('vha-mobile'); $(this).addClass('mobile').removeClass('desktop'); }else{ $('#toggle').removeClass('vha-mobile').addClass('vha-desktop'); $(this).addClass('desktop').removeClass('mobile'); } }, deviceOrientation : function(e){ //alert('change '+orientationSupport); if(orientationSupport == 'orientationchange'){ //alert('true'); var orientation = window.orientation; } else { //alert('false'); var orientation = screen.size; } //alert(orientation); var layout; //alert(orientation); if(orientation != 0){ if(orientationSupport == 'orientationchange'){ layout = orientation == 90 || orientation == -90 ? "land" : "port"; }else{ layout = orientation > 320 || orientation < 320 ? "land" : "port"; } //alert(layout); if(layout == 'land'){ $('#vha-device-hook').removeClass('vha-mobile-port').addClass('vha-mobile-land'); //alert($('#vha-device-hook').width()); } else { $('#vha-device-hook').removeClass('vha-mobile-land').addClass('vha-mobile-port'); //alert($('#vha-device-hook').width()); } } else { $('#vha-device-hook').removeClass('vha-mobile-land').addClass('vha-mobile-port'); //alert($('#vha-device-hook').width()); } } } }(); // load on document ready $(function() { VHA_Global.init(); })