Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug fix for special characters on faculty page
  • Loading branch information
briandunnigan authored and briandunnigan committed Mar 24, 2016
1 parent f281599 commit 4d8463b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 74 deletions.
26 changes: 0 additions & 26 deletions functions.php
Expand Up @@ -128,32 +128,6 @@ function neag_get_people_callback(){
wp_die();
}

add_action( 'wp_ajax_neag_get_experts', 'neag_get_experts_callback' );
add_action( 'wp_ajax_nopriv_neag_get_experts', 'neag_get_experts_callback' );
function neag_get_experts_callback(){
$args = array(
'post_type' => array( 'person' ),
'fields' => 'ids',
'posts_per_page' => -1,
'meta_key' => 'expertise',
'meta_compare' => '!=',
'meta_value' => ' ',
);

$query = new WP_Query( $args );
$queryPosts = $query->posts;

$people = array();

if( $query->have_posts() ){
$people = processPosts( $queryPosts, true );
}

echo wp_json_encode( $people );

wp_die();
}

if(function_exists("register_field_group"))
{
register_field_group(array (
Expand Down
75 changes: 29 additions & 46 deletions js/custom.js
Expand Up @@ -49,32 +49,17 @@ jQuery(document).ready(function($) {
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 );
} else {
modifyDirectoryList( response, directoryList );
if( categoryName.indexOf( "Faculty Expert" ) == -1 ){
modifyDirectoryList( response, directoryList );
} else {
modifyDirectoryList( response, directoryList, true ); // User selected specific type of faculty expert
}
}
};

$.ajax( ajaxReqSettings );
};

mod.setFacultyExperts = function () {
ajaxReqSettings.data = {
'action': 'neag_get_experts',
};

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

$.ajax( ajaxReqSettings );
};


function modifyDirectoryList ( response, directoryList, displayExpertiseFlag ){
directoryList.empty();

Expand Down Expand Up @@ -117,10 +102,10 @@ jQuery(document).ready(function($) {
text: v.title
}).appendTo( colNameTitle );

if( displayExpertiseFlag ){
if( displayExpertiseFlag && v.expertise ){
var expertiseDiv = $('<div />', {
class: 'directory-expertise',
text: ((v.expertise) ? v.expertise: '')
text: v.expertise
}).appendTo( colNameTitle );
$('<span />', {
class: 'expertise',
Expand Down Expand Up @@ -169,45 +154,43 @@ jQuery(document).ready(function($) {

return mod;
}());

var hash = window.location.hash;

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

var category = $("#directory-dropdownMenu").children( "option:contains('" + hash + "')" );

if( category.length != 0 ){
$("#directory-dropdownMenu")[0].selectedIndex = category[0].index;

var categoryID = category[0].value;

if( categoryID != 0 ){ // categoryID == 0 is All Faculty & Staff, which loads by default
if( categoryID === "faculty-expert" ){
directory.setFacultyExperts();
} else {
directory.setFaculty( categoryID, hash );
}
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").on('click', "li", function(event){
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( /\s/g, '_' );
if( this.value != 0 ){
window.location.hash = "#" + categoryName.replace( /[^\w]/gi, '' );
} else {
window.location.hash = "";
}

if( this.value === "faculty-expert" ){
directory.setFacultyExperts();
} else {
directory.setFaculty( this.value, categoryName );
}
directory.setFaculty( this.value, categoryName );
});
}

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.

1 change: 0 additions & 1 deletion page_people.php
Expand Up @@ -30,7 +30,6 @@ get_header(); ?>
<div class="col-sm-5">
<select id="directory-dropdownMenu" class="form-control">
<option class="directory-dropdownItem" value="0">All Faculty & Staff</option>
<option class="directory-dropdownItem" value="faculty-expert">Faculty Expert</option>
<?php
$categories = get_terms( 'group' );
foreach( $categories as $c ){
Expand Down

0 comments on commit 4d8463b

Please sign in to comment.