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.
222 lines (179 sloc)
6.15 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 hash = window.location.hash; | |
var currentdropdownValue = $("#directory-dropdownMenu")[0].value; | |
if( hash.length > 1 ){ | |
hash = hash.replace( /-/g, ' ' ).substr(1); | |
var category = $("#directory-dropdownMenu").children( "option:contains('" + hash + "')" ); | |
if( category.length != 0 ){ | |
var categoryID = category[0].value; | |
currentdropdownValue = categoryID; | |
if( categoryID != 0 ){ // categoryID == 0 is All Faculty & Staff, which loads by default | |
var data = { | |
'action': 'neag_get_people', | |
'categoryID': categoryID | |
}; | |
if( categoryID == "faculty-expert" ){ | |
displayExperts(); | |
} else { | |
var directoryList = $("#directory-list"); | |
$.post(neag_object.ajaxurl, data, function(response) { | |
response = JSON.parse(response); | |
if( Object.keys(response).length != 0 ){ | |
modifyDirectoryList( response, directoryList ); | |
} | |
}); | |
} | |
} | |
} | |
} | |
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 ); | |
} | |
}); | |
} | |
function modifyDirectoryList( response, directoryList, expertsFlag ){ | |
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( expertsFlag ){ | |
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 ); | |
} | |
} | |
}); | |
} | |
function displayExperts(){ | |
// Retrieve experts via AJAX | |
// Display experts in #directory-list | |
var data = { | |
'action': 'neag_get_experts', | |
}; | |
var directoryList = $("#directory-list"); | |
$.post(neag_object.ajaxurl, data, function(response) { | |
response = JSON.parse(response); | |
if( Object.keys(response).length != 0 ){ | |
modifyDirectoryList( response, directoryList, true ); | |
} | |
}); | |
} | |
var flag = false; | |
$("#directory-dropdownMenu").on('click', function(event){ | |
event.preventDefault(); | |
if( flag == true ){ | |
var data = { | |
'action': 'neag_get_people', | |
'categoryID': this.value | |
}; | |
if( currentdropdownValue != this.value ){ // Don't run if the newly-selected option is already selected. currentdropdownValue defined line 4 | |
currentdropdownValue = this.value; | |
if( this.value != 0 ){ | |
var categoryName = $(this)[0].selectedOptions[0].innerHTML.replace( /\s/g, '-' ); | |
window.location.hash = "#" + categoryName; | |
} else { | |
window.location.hash = ""; | |
} | |
if( this.value == "faculty-expert" ){ | |
displayExperts(); | |
} else { | |
var directoryList = $("#directory-list"); | |
$.post(neag_object.ajaxurl, data, function(response) { | |
response = JSON.parse(response); | |
if( Object.keys(response).length != 0 ){ | |
modifyDirectoryList( response, directoryList ); | |
} | |
}); | |
} | |
} | |
flag = false; | |
} else { | |
flag = true; | |
} | |
}).on('blur', function(){ | |
flag = false; | |
}); | |
} | |
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"); | |
}); | |
}); |