Shoora
10/8/2018 - 4:53 PM

segalCustomScripts.js

segalCustomScripts

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};

/* querystring code */
function GetQueryStringParams(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++)
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam)
        {
            return sParameterName[1];
        }
    }
}

/// <reference path="../typings/index.d.ts" />
(function (_$, _location) {
    "use strict";
    var decode = decodeURIComponent;
    function _queryStringParser(url) {
        var result = new Array();
        try {
            var parts = (url.split("?")[1]).split("#");
            url = parts[0];
            if (parts[1]) {
                result["#"] = decode(parts[1]);
            }
            var args = url.split("&");
            var len = args.length;
            for (var i = 0; i < len; i++) {
                var param = args[i].split("=");
                result[param[0]] = decode(param[1]);
            }
        }
        catch (e) {
        }
        return result;
    }
    var _queryString = _queryStringParser(_location.search);
    _$.Querystring = function (key) {
        if (key === "#") {
            if (_location.hash) {
                return _location.hash.substr(1);
            }
        }
        else {
            return _queryString[key];
        }
    };
    _$.QueryStringParser = _queryStringParser;
})(jQuery, window.location);

/* Float Label Pattern Plugin for Bootstrap 3.1.0 by Travis Wilson
**************************************************/
(function ($) {
    $.fn.floatLabels = function (options) {

        // Settings
        var self = this;
        var settings = $.extend({}, options);


        // Event Handlers
        function registerEventHandlers() {
            self.on('input keyup change', 'input, textarea', function () {
                actions.swapLabels(this);
            });
        }


        // Actions
        var actions = {
            initialize: function() {
                self.each(function () {
                    var $this = $(this);
                    var $label = $this.children('label');
                    var $field = $this.find('input,textarea').first();
					

                    if ($this.children().first().is('label')) {
                        $this.children().first().remove();
                        $this.append($label);
                    }

                    var placeholderText = ($field.attr('placeholder') && $field.attr('placeholder') != $label.text()) ? $field.attr('placeholder') : $label.text();

                    $label.data('placeholder-text', placeholderText);
                    $label.data('original-text', $label.text());

                    if ($field.val() == '') {
                        $field.addClass('empty')
                    }
                });
            },
            swapLabels: function (field) {
                var $field = $(field);
                var $label = $(field).siblings('label').first();
                var isEmpty = Boolean($field.val());
				var $isError = $(this).siblings('valid-error').first();
				

                if (isEmpty) {
                    $field.removeClass('empty');
                    $label.text($label.data('original-text'));
					$field.closest('.col-sm-4, .col-sm-6').find('.valid-error').removeClass("text-danger").html("");
					$label.removeClass("text-danger");
                }
                else {
                    $field.addClass('empty');
                    $label.text($label.data('placeholder-text'));
                }
            }
        }


        // Initialization
        function init() {
            registerEventHandlers();

            actions.initialize();
            self.each(function () {
                actions.swapLabels($(this).find('input,textarea').first());
            });
        }
        init();


        return this;
    };

    $(function () {
        $('.float-label-control').floatLabels();
    });
})(jQuery);

function recaptchaCallback(response) {
    //$('#submitBtn').removeAttr('disabled');
	$(".captcha-error").removeClass("text-danger").html("");
	$(".submitBTN").removeAttr("disabled");
};

$(window).on('load', function () {
   if (window.navigator.standalone == true) {
   //not in safari
	   var deviceAgent = window.navigator.userAgent.toLowerCase();
	   var ipad = /ipad/.test( deviceAgent );
	   var iphone = /iphone/.test( deviceAgent );
	   if(ipad){
		  var eventString = "ipad standalone"; 
	   } 
	   
	   if(iphone){
		   var eventString = "iphone standalone"; 
	   }
	   
	  ga('send', 'event', eventString, 'Launch', 'Standalone Mode');
        
   } else { 
	   var deviceAgent = window.navigator.userAgent.toLowerCase();
	   var android = /android/.test(deviceAgent);
	   if(android){
		   var eventString = "android use";
		   ga('send', 'event', eventString, 'Launch', 'Android Usage');
	   }
   }
	
	if( isMobile.Windows() ) {
		ga('send', 'event', 'Windows Phone', 'Launch', 'Windows Phone');
	}

    
});

$(document).ready(function () {
  // this variable is just very helpful for trackign the current page path in your javascript functions
   var pathname = window.location.pathname;
   
  //add icons based on link type
  //if you add a class of noExt to a link, it will NOT have an icon
  $("a:not(.noExt)").filter(function() {
    return this.hostname && this.hostname !== location.hostname;
	}).prepend( "<i class='fa fa-share-square-o' aria-hidden='true'></i>&nbsp;" ).attr('title','This link will take you to a new website.').addClass("text-nowrap");
	
	$("a[href$='.pdf']").addClass("pdf").prepend( "<i class='fa fa-file-pdf-o fa-fw'></i>" ).attr('target', '_blank').attr('title','This link will open in a new window.').addClass("text-nowrap");
	$("a[href$='.docx']").addClass("doc").prepend( "<i class='fa fa-file-doc-o fa-fw'></i>" ).attr('target', '_blank').attr('title','This link will open in a new window.').addClass("text-nowrap");
	
	//swap icon on accordion toggle in bootstrap 3.x
	//note the actual icons used, you may have to update to reflect your icon choice
	$('a.accordion-toggle').click(function() {
			$(this).children('i').toggleClass('fa-plus-circle fa-minus-circle', 200);
		});
		
	//go back function for our 404 page
	$("#goBack").click(function(event) {
		 event.preventDefault();
    		history.back(1);
	});
	
	//go to an anchor and open a hide show region (accordion) in bootstrap 3.x and scroll to it
	// just place the ID of the desired hide show region as a hash at end of url
	// example: https://western-states-office-professional-employees-pension-trust.s1.umbraco.io/pension-recovery-plan#collapse1095
	if(location.hash != null && location.hash != ""){
        $('.collapse').removeClass('in');
        $(location.hash + '.collapse').collapse('show');
	// what if this hide show is nested inside another? this line will expand the hide show it is nested in
	// if you are nesting deeper than that, shame on you!
	$(location.hash).closest('.collapse').collapse('show');
		$('html, body').animate({
    		scrollTop: ($(location.hash).offset().top)
		},500);
    }
    
  	//if you add refrence to jquery mobile this will make the carousel touch sensitive [http://jquerymobile.com/]
  	// obviously replace #myCarousel with the ID of your carousel
  	$("#myCarousel").swiperight(function() {
      		$(this).carousel('prev');
    	});
   	$("#myCarousel").swipeleft(function() {
      		$(this).carousel('next');
   	});
   	
   	// google analytics event tracking example
   	// this will add an event to GA when a pdf link is clicked
   	
   	$('a[href$=".pdf"],a[href$=".PDF"]').on('click', function() {
                                   ga('send', 'event', 'Download', 'PDF File', $(this).attr("href"));
                        });
         
         // add class to the links in search results of searchResult               
        $('.searchResult').on('click', function () {
		var pageNo = $(this).data("resultPage");
	    ga('send', 'event', 'Search Result Page -' + pageNo, 'Click', $(this).attr("href"));
	});

	// add ids to your search forms to match the ids below - also add class to the input field
	$('#topSearchForm').on('submit', function () {
	    ga('send', 'event', 'Search Initiated-Header', pathname, $('.searchText').val());
	});
	
	$('#bottomSearchForm').on('submit', function () {
	    ga('send', 'event', 'Search Initiated-Footer', pathname, $('.searchText').val());
	});
	
	$('.heroAction').on('click', function() {
        ga('send', 'event', 'Hero Action Click', pathname, $(this).attr("href"));
    });
	
	$('#eyebrow a').on('click', function() {
        ga('send', 'event', 'Eyebrow Click', pathname, $(this).attr("href"));
    });
	
	$('#footerNav a').on('click', function() {
        ga('send', 'event', 'Footer Nav Click', pathname, $(this).attr("href"));
    });
	
	$('#headerLogo').on('click', function() {
        ga('send', 'event', 'Header Logo Click', pathname, $(this).attr("href"));
    });
	
	$('#maincontent a').on('click', function() {
        ga('send', 'event', 'Main Body Link Click', pathname, $(this).attr("href"));
    });
	
	$('#relatedDocs a').on('click', function() {
        ga('send', 'event', 'Related Docs Link Click', pathname, $(this).attr("href"));
    });
	
	$('#formsDocsArea a').on('click', function() {
        ga('send', 'event', 'Forms and Docs Link Click', pathname, $(this).attr("href"));
    });
	
	
	// these snippets can be used to reveal info based on mobile devices
	if( isMobile.iOS() && !navigator.standalone) { 
		$(".ios").show();
	}
	
	
	if( isMobile.Android() ) {
		$(".android").show();
	}
	
	if( isMobile.Windows() ) {
		$(".windows").show();
	}	
	
	if(isMobile.any() && !navigator.standalone){ 
		$(".mobileAny").show();
	}
  
});