Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to people sorting
  • Loading branch information
briandunnigan authored and briandunnigan committed Mar 9, 2016
1 parent c70b795 commit fd32da3
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 169 deletions.
360 changes: 194 additions & 166 deletions js/custom.js
@@ -1,40 +1,5 @@
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;
Expand All @@ -51,157 +16,220 @@ jQuery(document).ready(function($) {
});
}

function modifyDirectoryList( response, directoryList, expertsFlag ){
directoryList.empty();
var directory = (function() {
var mod = {};
var directoryList = $("#directory-list");
var loadingText = $("#directory-list-loading-text");

$.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 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 ( data, categoryName ){
ajaxReqSettings.data = data;

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 );
ajaxReqSettings.success = function(response){
response = JSON.parse(response);

if( Object.keys(response).length != 0 ){
if( categoryName.indexOf( "Faculty Expert" ) != -1 ){ // User selected specific type of faculty expert
modifyDirectoryList( response, directoryList, true, categoryName );
} else {
modifyDirectoryList( response, directoryList );
}
}
};

$('<div />', {
class: 'directory-title',
text: v.title
}).appendTo( colNameTitle );
$.ajax( ajaxReqSettings );
};

mod.setFacultyExperts = function ( data ) {
ajaxReqSettings.data = data;

ajaxReqSettings.success = function(response){
response = JSON.parse(response);
if( Object.keys(response).length != 0 ){
modifyDirectoryList( response, directoryList, true );
}
};

if( expertsFlag ){
var expertiseDiv = $('<div />', {
class: 'directory-expertise',
text: v.expertise
$.ajax( ajaxReqSettings );
};

function modifyDirectoryList ( response, directoryList, expertsFlag, specificExpertise ){
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 );
$('<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 );
if( expertsFlag && specificExpertise ){
var expertiseDiv = $('<div />', {
class: 'directory-expertise',
text: specificExpertise
}).appendTo( colNameTitle );
$('<span />', {
class: 'expertise',
text: "Expertise: "
}).prependTo( expertiseDiv );
} else 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 );
}
}
});
}

return mod;
}());

var hash = window.location.hash;

if( hash.length > 1 ){
hash = hash.replace( /_/g, ' ' ).substr(1);

var colOffice = $('<div />', {
class: 'col-sm-4 directory-office-wrap'
}).appendTo( topLevelRow );
$('<div />', {
class: 'directory-officeLabel',
text: "Office"
}).appendTo( colOffice );
var category = $("#directory-dropdownMenu").children( "option:contains('" + hash + "')" );

if( category.length != 0 ){
var categoryID = category[0].value;

$('<div />', {
class: 'directory-office',
text: v.office_location
}).appendTo( colOffice );
$("#directory-dropdownMenu")[0].selectedIndex = category[0].index;

if( screenWidthFlag ){
var faceWrapHeight = faceWrap.height();
var nameTitleHeight = colNameTitle.height();
if( faceWrapHeight > nameTitleHeight ){
colNameTitle.css( 'padding-top', (faceWrapHeight - nameTitleHeight)/2 );
}
if( categoryID != 0 ){ // categoryID == 0 is All Faculty & Staff, which loads by default
if( categoryID == "faculty-expert" ){
var data = {
'action': 'neag_get_experts',
};

directory.setFacultyExperts( data );
} else {
var data = {
'action': 'neag_get_people',
'categoryID': categoryID
};

directory.setFaculty( data, hash );
}
}
});
}
}

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);
$("#directory-dropdownMenu").on('change', function(event){
event.preventDefault();

if( this.value == "faculty-expert" ){
var data = {
'action': 'neag_get_experts',
};

if( Object.keys(response).length != 0 ){
modifyDirectoryList( response, directoryList, true );
directory.setFacultyExperts( data );
} else {
var categoryName = this.options[this.options.selectedIndex].text;
if( this.value != 0 ){
window.location.hash = "#" + categoryName.replace( /\s/g, '_' );
} else {
window.location.hash = "";
}
});
}

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;
directory.setFaculty( data, categoryName );
}
}).on('blur', function(){
flag = false;
});
});
}

var d = new Date(),
Expand Down
2 changes: 1 addition & 1 deletion js/min/custom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd32da3

Please sign in to comment.