This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
neag/js/custom.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
219 lines (177 sloc)
6.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
if( $( "#directory-dropdown" ).length > 0 ){ | |
var screenWidthFlag = false; // True if screen width is greater than 767 | |
if( screen.width > 767 ){ | |
screenWidthFlag = true; | |
$(".directory-face-wrap").each(function(i,el){ | |
var divHeight = $(el).height(); | |
var nameTitle = $(el).find( ".directory-name-title-wrap" ); | |
var nameTitleHeight = nameTitle.height(); | |
if( divHeight > nameTitleHeight ){ | |
nameTitle.css( "padding-top", (divHeight - nameTitleHeight)/2 ); | |
} | |
}); | |
} | |
var directory = (function() { | |
var mod = {}; | |
var directoryList = $("#directory-list"); | |
var loadingText = $("#directory-list-loading-text"); | |
var ajaxReqSettings = { | |
type: "POST", | |
url: neag_object.ajaxurl, | |
timeout: 10000, // 10,000ms = 10s | |
beforeSend: function(){ | |
loadingText.show(); | |
}, | |
complete: function( jqXHR, textStatus ){ | |
if( textStatus === 'success' ){ | |
loadingText.hide(); | |
} else if( textStatus === 'timeout' ) { | |
loadingText.text("Request has timed out, please refresh this page"); | |
} else { | |
loadingText.text("Error: " + textStatus); | |
} | |
}, | |
}; | |
mod.setFaculty = function ( categoryID, categoryName ){ | |
ajaxReqSettings.data = { | |
'action': 'neag_get_people', | |
'categoryID': categoryID | |
}; | |
ajaxReqSettings.success = function(response){ | |
response = JSON.parse(response); | |
if( Object.keys(response).length != 0 ){ | |
if( categoryName.indexOf( "Faculty Expert" ) == -1 ){ | |
modifyDirectoryList( response, directoryList ); | |
} else { | |
modifyDirectoryList( response, directoryList, true ); // User selected specific type of faculty expert | |
} | |
} | |
}; | |
$.ajax( ajaxReqSettings ); | |
}; | |
function modifyDirectoryList ( response, directoryList, displayExpertiseFlag ){ | |
directoryList.empty(); | |
$.each(response, function(i,v){ | |
var directoryRow = $('<div/>', { | |
id: v.divid, | |
class: 'directory-person' | |
}).appendTo( directoryList ); | |
var topLevelRow = $('<div/>', { | |
class: 'row' | |
}).appendTo( directoryRow ); | |
var faceWrap = $('<div />', { | |
class: 'col-sm-5 directory-face-wrap' | |
}).appendTo( topLevelRow ); | |
var directoryPhoto = $('<div/>', { | |
class: 'directory-photo' | |
}).appendTo( faceWrap ); // add photo to html | |
$('<a />', { | |
href: v.permalink, | |
html: v.photo | |
}).appendTo( directoryPhoto ); | |
var colNameTitle = $('<div />', { | |
class: 'directory-name-title-wrap' | |
}).appendTo( faceWrap ); | |
var directoryName = $('<div />', { | |
class: 'directory-name' | |
}).appendTo( colNameTitle ); | |
$('<a />', { | |
href: v.permalink, | |
text: v.name | |
}).appendTo( directoryName ); | |
$('<div />', { | |
class: 'directory-title', | |
text: v.title | |
}).appendTo( colNameTitle ); | |
if( displayExpertiseFlag && v.expertise ){ | |
var expertiseDiv = $('<div />', { | |
class: 'directory-expertise', | |
text: v.expertise | |
}).appendTo( colNameTitle ); | |
$('<span />', { | |
class: 'expertise', | |
text: "Expertise: " | |
}).prependTo( expertiseDiv ); | |
} | |
var colPhoneEmail = $('<div />', { | |
class: 'col-sm-3 directory-contact-wrap' | |
}).appendTo( topLevelRow ); | |
$('<div />', { | |
class: 'directory-phone', | |
text: v.phone | |
}).appendTo( colPhoneEmail ); | |
var emailDiv = $('<div />', { | |
class: 'directory-email' | |
}).appendTo( colPhoneEmail ); | |
var emailLink = $('<a />', { | |
href: "mailto:"+v.email, | |
text: v.email | |
}).appendTo( emailDiv ); | |
var colOffice = $('<div />', { | |
class: 'col-sm-4 directory-office-wrap' | |
}).appendTo( topLevelRow ); | |
$('<div />', { | |
class: 'directory-officeLabel', | |
text: "Office" | |
}).appendTo( colOffice ); | |
$('<div />', { | |
class: 'directory-office', | |
text: v.office_location | |
}).appendTo( colOffice ); | |
if( screenWidthFlag ){ | |
var faceWrapHeight = faceWrap.height(); | |
var nameTitleHeight = colNameTitle.height(); | |
if( faceWrapHeight > nameTitleHeight ){ | |
colNameTitle.css( 'padding-top', (faceWrapHeight - nameTitleHeight)/2 ); | |
} | |
} | |
}); | |
} | |
return mod; | |
}()); | |
var hash = window.location.hash; | |
if( hash.length > 1 ){ | |
hash = hash.substr(1); | |
var categories = $("#directory-dropdownMenu").children().toArray(); | |
var categoryID = 0; | |
$.each(categories, function(i, v){ | |
if( v.innerHTML.replace( /[^\w]/gi, '' ) === hash ){ | |
categoryID = v.value; | |
$("#directory-dropdownMenu")[0].selectedIndex = i; | |
directory.setFaculty( categoryID, hash ); | |
return false; | |
} | |
}); | |
} | |
$(".fsd-dropdown li").on('click', "a", function(event){ | |
event.preventDefault(); | |
var thisHref= $(this).attr('href').split("#"); | |
if( thisHref.length > 1 ){ | |
window.location.hash = thisHref[1]; | |
} else { | |
window.location.hash = ""; | |
} | |
window.location.reload(true); | |
}); | |
$("#directory-dropdownMenu").on('change', function(event){ | |
event.preventDefault(); | |
var categoryName = this.options[this.options.selectedIndex].text; | |
if( this.value != 0 ){ | |
window.location.hash = "#" + categoryName.replace( /[^\w]/gi, '' ); | |
} else { | |
window.location.hash = ""; | |
} | |
directory.setFaculty( this.value, categoryName ); | |
}); | |
} | |
var d = new Date(), | |
n = d.getMonth()+1, | |
y = d.getFullYear(); | |
$( ".widget_archives" ).append( "<p><a href='/"+y+"/"+n+"'>Archives ›</a></p>" ); | |
$( "#page-news .panel-grid:nth-child(5) .panel-grid-cell:nth-child(1) .widget_siteorigin-panels-postloop" ).append( "<p><a href='/news-archive'>News Archives ›</a></p>" ); | |
$("h4.panel-title a").addClass("accordion-closed"); | |
$("h4.panel-title a").click(function() { | |
$(this).addClass("accordion-open"); | |
}); | |
}); |