// Smartresize
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
};
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
})(jQuery,'smartresize');
jQuery(document).ready(function(){
var $searchForm = jQuery('.search-wrap'),
$menuWrap = jQuery('.menu-wrap'),
$body = jQuery('body'),
$mobileDropdown = jQuery('.mobile-dropdown-wrap'),
$mobileDropdownTimeout,
shuffledUFStats;
// Run svgforeverybody
svg4everybody();
// Nicely scroll to anchors on the same page
jQuery('a[href^="#"]:not([href="#"])').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $target = jQuery(target);
jQuery('html, body').stop().animate({
'scrollTop': $target.offset().top-150
}, 900, 'swing', function () {
window.location.hash = target;
});
});
// Load randomized bio scroll features
if (typeof biosjson !== 'undefined') {
jQuery('[id^=bio_]').each(function(){
bioScrollPopulator( jQuery(this).attr('id'), jQuery(this).data('bio-affiliation'), biosjson );
});
}
// Shuffle around stats for stat areas
if (typeof statsjson !== 'undefined') {
randomizeStats(statsjson);
}
// Hide alert modal via cookies
ufl_site_alert_cookie();
// Main menu mobile
jQuery('.btn-menu').on('click',function(e){
e.preventDefault();
jQuery('.aux-menu-wrap a').off('click.mobileNoClick');
if($body.hasClass('open-mobile-dropdown')){
$body.removeClass('open-mobile-dropdown');
} else {
$body.toggleClass('open-menu');
}
// Mobile dropdown height if VH isn't supported
if(!Modernizr.cssvhunit){
$menuWrap.height(jQuery(window).height() - 60);
}
});
// Apply CSS class based on stat length
statLengthClassifier( '.stat-block .stat', 4 );
statLengthClassifier( '.homepage-stat-wrap .stat', 3 );
// -- T4 Helpers --
// Copy audience nav menu items to auxiliary menu
jQuery(".audience-nav-wrap ul li").each(function(){jQuery(this).children('a').attr('data-ufl-audience-preference',jQuery(this).text().replace(/\s+/g, '-').replace('&', '').replace('--', '-').toLowerCase()).addClass('audience-link');}).clone().prependTo(".aux-menu-wrap>ul").addClass("audience-link").find("a").removeClass("audience-link").parents(".aux-menu-wrap ul").addClass("aux-nav");
// Dropdown helper
jQuery(".main-menu-wrap .dropdown>ul").addClass("col-md-4");
// Big List helpers
jQuery(".gal-list-wrap ul").addClass("big-list").prepend('
Additional Links ').find("a").append('');
jQuery(".t4-help-big-list ul").addClass("big-list show-mobile").find("a").append('');
jQuery(".t4-ul-classifier ul").prepend('Filter ')
// Homepage Hero helper
jQuery(".featured-story-content-wrap>.featured-story").each(function(i){if(0==i){jQuery(this).addClass("active");}jQuery(this).attr("data-number",i+1);jQuery(this).children("h2").attr("data-index",i+1);});
// Alphabetical List helper
jQuery('.t4-alpha-list ul').addClass('majors-list').each(function(){var alpha = jQuery(this).parent('div').attr('data-category');jQuery(this).attr('data-category',alpha);});
// UL Classifier
jQuery(".t4-ul-classifier").each(function(){jQuery(this).children('ul').addClass(jQuery(this).attr('data-ul-class'));});
// Resize iframe forms
jQuery('.ufws-ifr').iFrameResize({checkOrigin: false});
// Set audience menu via cookies
ufl_audience_cookie();
// Remove the loading class to enable transitions
jQuery('body').removeClass('loading');
// Show aux menu on smaller width
jQuery('.btn-show-aux').on('click',function(e){
e.preventDefault();
jQuery('.header').toggleClass('show-aux');
});
// Dropdown positioning
function showDropdown(el){
if(window.innerWidth > 992){
var $this = el,
$offset = $this.offset().left,
$dropdown = $this.find('.dropdown');
jQuery('.main-menu-wrap .hover').removeClass('hover');
$this.addClass('hover');
$this.removeClass('offscreen full');
if($dropdown.width() + $offset > window.innerWidth){
$this.addClass('offscreen');
}
if($this.hasClass('offscreen') && $dropdown.offset().left < 0 && window.innerWidth > 1140){
$dropdown.css({'transform':'translateX('+Math.abs($dropdown.offset().left)+'px)'});
}
$dropdown.find('.col-md-4').velocity('finish').velocity('transition.slideDownIn',{
duration: 400,
easing: 'easeOut',
stagger: 100
});
}
}
jQuery('.main-menu-wrap > ul > li').hoverIntent({
over: function(){
showDropdown(jQuery(this))
},
out: function(){
jQuery(this).removeClass('hover');
}
}).on('click',function(){
$this = jQuery(this);
if(Modernizr.touch){
if($this.hasClass('hover')){
$this.removeClass('hover');
} else {
showDropdown($this.closest('li'));
}
}
});
// Main menu focus for accessibility
jQuery('.main-menu-link').on('focus',function(e){
showDropdown(jQuery(this).closest('li'));
});
// Mobile dropdown content
jQuery('.main-menu-wrap > ul > li > a').on('click',function(e){
if(window.innerWidth < 992){
e.preventDefault();
$this = jQuery(this);
window.clearTimeout($mobileDropdownTimeout);
$menuWrap.off('click.closeMobile');
if($body.hasClass('open-mobile-dropdown')){
$body.removeClass('open-mobile-dropdown');
$mobileDropdown.empty();
jQuery('.aux-menu-wrap a').off('click.mobileNoClick')
} else {
$body.addClass('open-mobile-dropdown');
$mobileDropdown.html('' + ($this.next('.dropdown').length ? $this.next('.dropdown').html() : ""));
// Mobile dropdown height if VH isn't supported
if(!Modernizr.cssvhunit){
$mobileDropdown.height(jQuery(window).height() - 60);
}
$mobileDropdownTimeout = window.setTimeout(function(){
$menuWrap.one('click.closeMobile',function(){
$body.removeClass('open-mobile-dropdown');
$mobileDropdown.empty();
});
},0);
// Prevent clicks on other links when mobile dropdown is open
jQuery('.aux-menu-wrap a').one('click.mobileNoClick', function(e){
e.preventDefault();
});
}
}
});
// Header search form
$searchForm.on('click',function(e){
if(!$searchForm.hasClass('open-search')){
e.preventDefault();
$searchForm.addClass('open-search').find('input').focus();
if(window.innerWidth <= 992){
jQuery('.alert-small').hide();
}
// Close the search form on blur
window.setTimeout(function(){
jQuery(document).one('click.closeSearch',function(e){
if(!jQuery(e.target).closest('.search-wrap').length){
$searchForm.removeClass('open-search').find('input').val('');
jQuery('.alert-small').show();
}
});
},0);
}
})
// Footer mobile accordian
jQuery('.footer-menu h2').on('click',function(){
if(window.innerWidth <= 767){
jQuery(this).closest('.footer-menu').toggleClass('open');
}
});
//// Homepage featured story
// Setting homepage hero story on load
jQuery('.featured-story-img-wrap').each(function(){
jQuery(this).find('.featured-story-img:first').addClass('active');
});
// Switching to a new featured story
jQuery(document).on('click','.featured-story',function(){
$this = jQuery(this);
// Changed featured carousel
jQuery('.featured-story-img-wrap').each(function(){
$homeWrap = jQuery(this).closest('.homepage-wrapper');
// Get this carousel's clicked element
$el = $homeWrap.find('.featured-story[data-number="'+ $this.attr('data-number') +'"]');
// Move Carousel
jQuery(this).find('.featured-story-img').removeClass('active').eq($el.attr('data-number') - 1).addClass('active');
// Establish container to append to
$container = $homeWrap.find('.featured-story-content-wrap');
// Get this carousel's active element
$active = $homeWrap.find('.featured-story.active');
$active.removeClass('active');
// Move active to clicked element, and move clicked element to active
$el.before($active);
$el.addClass('active');
$el.prependTo($container);
});
});
// Homepage feature bio wrap
function bioSize(){
$activeWidth = 370;
if(window.innerWidth > 1220){
$activeWidth = 570;
}
jQuery('.feature-bio-wrap').each(function(){
$this = jQuery(this);
jQuery('.bio:first',$this).addClass('active').width($activeWidth);
jQuery('.bio:nth-child(2)',$this).css({
left: $activeWidth
});
jQuery('.bio:nth-child(3)',$this).css({
left: $activeWidth + jQuery('.bio:not(.active)',$this).width()
});
});
}
if(window.innerWidth > 992){
jQuery('.bio:first').addClass('active');
// Resize bios
bioSize();
}
jQuery(document).on('click','.bio',function(){
$activeWidth = jQuery('.bio.active').width();
$this = jQuery(this);
$bioWrap = $this.closest('.feature-bio-wrap');
if(jQuery('.feature-bios .bio.velocity-animating',$bioWrap).length || window.innerWidth < 767){
return;
}
if(!$this.hasClass('active')){
$this.velocity({
left: 0,
height: 638,
width: $activeWidth
},{
duration: 400,
queue: false
});
$curActive = jQuery('.bio.active',$bioWrap).clone();
$curActive.appendTo($bioWrap.find('.bio-wrap')).css({
left: $activeWidth + jQuery('.bio:not(.active)',$bioWrap).width() * 2,
height: '251px',
width: '251px'
})
.removeClass('active')
.velocity({
left: 900
},{
duration: 400,
queue: false,
complete: function(){
// Remove old active
jQuery('.bio.active',$bioWrap).remove();
$this.addClass('active');
jQuery('.feature-bio-copy-wrap',$bioWrap).html($this.find('.copy-wrap').html());
jQuery('.feature-bio-copy-wrap',$bioWrap).find('h2,h3,p').velocity('finish').velocity('transition.slideUpIn',{
duration: 400,
easing: 'easeOut',
stagger: 100
});
}
});
$this.nextAll('.bio').velocity({
left: '-=251px'
},{
duration: 400,
delay: 0,
queue: false,
complete: function(){
$newActive = $this.clone();
$this.remove();
$newActive.prependTo($bioWrap.find('.bio-wrap')).addClass('active');
}
});
}
});
// Position emergecy modal on smaller screens
if(jQuery('.emergency-modal').outerHeight() + parseInt(jQuery('.emergency-modal').css('margin-top')) < jQuery(window).height() - jQuery('.header').height()){
jQuery('.emergency-modal-wrap').addClass('fixed');
}
// Close emergency modal
jQuery('.emergency-modal-close').on('click',function(e){
e.preventDefault();
jQuery('.emergency-modal-wrap').velocity(
{
opacity: 0,
duration: 200
},{
complete: function(){
jQuery('.emergency-modal-wrap').remove();
}
});
});
// Bio hover effects
jQuery(document).on('mouseenter','.bio',function(){
if(Modernizr.touch == false && window.innerWidth > 767){
jQuery(this).find('h2,h3,.arw-right').velocity('finish').velocity('transition.slideUpIn',{
duration: 400,
easing: 'easeOut',
stagger: 100
});
}
});
// Big list mobile toggle
jQuery('.btn-mobile-toggle').on('click',function(e){
e.preventDefault();
$bigList = jQuery(this).parent();
$bigList.toggleClass('open-list');
});
// Stat block animation
jQuery('.stat-block-wrap').on('mouseenter',function(){
if(Modernizr.touch == false && window.innerWidth > 992){
$this = jQuery(this);
$infoCopy = jQuery('.info-copy',this);
$statHeight = $this.find('.stat').outerHeight();
$infoHeight = $this.find('.info').outerHeight();
$statHeight = (($infoHeight / 2 / $statHeight) * 100) + 50;
jQuery('.stat',this).css({'transform':'translateY(-50%)'}).velocity('finish').velocity({
marginTop: '-' + parseInt($infoHeight / 2 + 20)
},{
duration: 200,
easing: 'easeOut'
});
jQuery('.info',this).velocity('finish').velocity({
opacity: 1,
marginTop: parseInt($statHeight / 2 + 20)
},{
duration: 200,
easing: 'easeOut',
queue: false
});
}
}).on('mouseleave',function(){
if(Modernizr.touch == false && window.innerWidth > 992){
jQuery('.stat',this).velocity('stop').velocity('reverse');
jQuery('.info',this).velocity('stop').velocity({
opacity: 0,
marginTop: 0
},{
duration: 200,
easing: 'easeOut',
queue: false
});
}
});
// Equal height horizontal scroll
if(window.innerWidth < 992){
horScrollSize();
}
function horScrollSize(){
// Reset height of all horizontal elements
jQuery('.hor-scroll-el').css({'height':'','width':''});
jQuery('.hor-scroll-wrap').each(function(){
$horHeight = 0;
jQuery('.hor-scroll-el',this).each(function(){
if(jQuery(this).outerHeight() > $horHeight){
$horHeight = jQuery(this).outerHeight();
}
}).height($horHeight);
});
}
// Stat wrap offscreen listener
jQuery('.stat-wrap').on('mouseenter',function(){
$this = jQuery(this);
$classes = $this[0].classList;
if($classes.contains('in-right') && $this.offset().left + parseInt($this.width() * 2) > window.innerWidth){
$this.removeClass('in-right').addClass('in-left');
}
if($classes.contains('in-left') && $this.offset().left - parseInt($this.width() * 2) < 0){
$this.removeClass('in-left').addClass('in-right');
}
});
// Audience nav wrap arrow hover
jQuery('.audience-nav-wrap').hover(function(){
jQuery(this).find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-up');
},function(){
jQuery(this).find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-down');
});
// Debounced window resize listener
jQuery(window).smartresize(function(){
$windowWidth = window.innerWidth;
if($windowWidth > 767){
// Resize bios on window resize
bioSize();
}
if($windowWidth >= 992){
// Resize hor-scroll-wrap elements
jQuery('.hor-scroll-el').css({'height':''});
} else {
// Equal height hor-scroll elements
horScrollSize();
}
// Position emergecy modal on smaller screens
if(jQuery('.emergency-modal').outerHeight() + 200 < jQuery(window).height() - jQuery('.header').height()){
jQuery('.emergency-modal-wrap').addClass('fixed');
} else {
jQuery('.emergency-modal-wrap').removeClass('fixed');
}
});
// Styled select boxes
jQuery('select.styled').each(function(i){
$this = jQuery(this);
// Make new HTML select box
var $styledSelect = jQuery('');
$this.before($styledSelect);
// Get all options from this select box
jQuery('option',this).each(function(){
$styledSelect.find('ul').append(''+jQuery(this).text()+'')
});
// Hide this select box
$this.hide().attr('data-select','select'+i);
});
jQuery(document).on('click','.styled-select a',function(e){
e.preventDefault();
$this = jQuery(this);
$select = $this.closest('.styled-select');
// Change the text of selected
$select.find('.selected').text($this.text()).addClass('changed');
// Hide the dropdown
jQuery('.styled-select').removeClass('hover').find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-down');
jQuery('select[data-select="'+$select.attr('data-select')+'"]').val(jQuery(this).attr('data-value'));
// Unbind document close select
jQuery(document).off('click.closeSelect');
}).on('click','.styled-select .selected,.styled-select .arw-right',function(){
$select = jQuery(this).closest('.styled-select');
jQuery('.styled-select').not($select).removeClass('hover');
$select.toggleClass('hover');
// Change the arrow icon
if($select.hasClass('hover')){
$select.find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-up');
} else {
$select.find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-down');
}
// Change the arrow icon
jQuery('.styled-select').not($select).find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-down');
// Close the select on blur
window.setTimeout(function(){
jQuery(document).one('click.closeSelect',function(e){
if(!jQuery(e.target).closest('.styled-select').length){
$select.removeClass('hover');
$select.find('svg use').attr('xlink:href','/media/templates/uf2015/img/spritemap.svg#arw-down');
}
});
},0);
}).on('keydown','.styled-select',function(e){
if(e.keyCode == 32){
e.preventDefault();
jQuery(this).addClass('hover').find('li:first a').focus();
}
// Down arrow
if(e.keyCode == 40){
e.preventDefault();
jQuery(this).find('a:focus').closest('li').next('li').find('a').focus();
}
// Up arrow
if(e.keyCode == 38){
e.preventDefault();
jQuery(this).find('a:focus').closest('li').prev('li').find('a').focus();
}
}).on('blur','.styled-select',function(e){
if(!jQuery(e.relatedTarget).closest('.styled-select').hasClass('hover')){
jQuery('.styled-select').removeClass('hover');
}
});
// Custom checkboxes
jQuery('.uf-check input[type="checkbox"]').each(function(){
jQuery(this).after('
')
});
// Custom radio buttons
jQuery('.uf-check input[type="radio"]').each(function(){
jQuery(this).after('')
});
});