From a032be85f11968662828b3bec0cce7380011647d Mon Sep 17 00:00:00 2001 From: briandunnigan Date: Wed, 3 Feb 2016 11:07:05 -0500 Subject: [PATCH] Fixes to people page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salman’s fixes for the people page --- functions.php | 4 +- js/custom.js | 330 ++++++++++++++++++++++++++++-------------------- page_people.php | 3 +- 3 files changed, 199 insertions(+), 138 deletions(-) diff --git a/functions.php b/functions.php index 47c3efd..0c62b16 100644 --- a/functions.php +++ b/functions.php @@ -136,7 +136,9 @@ function neag_get_experts_callback(){ 'post_type' => array( 'person' ), 'fields' => 'ids', 'meta_key' => 'expertise', - 'meta_compare' => 'EXISTS', + 'meta_compare' => '!=', + 'meta_value' => ' ', + 'posts_per_page' => -1, ); $query = new WP_Query( $args ); diff --git a/js/custom.js b/js/custom.js index ee622d8..ead23ba 100644 --- a/js/custom.js +++ b/js/custom.js @@ -1,157 +1,215 @@ jQuery(document).ready(function($) { - var screenWidthFlag = false; // True if screen width is greater than 767 - if( screen.width > 767 ){ - screenWidthFlag = true; + if( $( "#directory-dropdown" ).length > 0 ){ + var hash = window.location.hash; - $(".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(); + var currentdropdownValue = $("#directory-dropdownMenu")[0].value; - $.each(response, function(i,v){ - var directoryRow = $('
', { - id: v.divid, - class: 'directory-person' - }).appendTo( directoryList ); - - var topLevelRow = $('
', { - class: 'row' - }).appendTo( directoryRow ); - - var faceWrap = $('
', { - class: 'col-sm-5 directory-face-wrap' - }).appendTo( topLevelRow ); - - var directoryPhoto = $('
', { - class: 'directory-photo' - }).appendTo( faceWrap ); // add photo to html - - $('', { - href: v.permalink, - html: v.photo - }).appendTo( directoryPhoto ); - - var colNameTitle = $('
', { - class: 'directory-name-title-wrap' - }).appendTo( faceWrap ); - var directoryName = $('
', { - class: 'directory-name' - }).appendTo( colNameTitle ); - $('', { - href: v.permalink, - text: v.name - }).appendTo( directoryName ); + if( hash.length > 1 ){ + hash = hash.replace( /-/g, ' ' ).substr(1); + + var category = $("#directory-dropdownMenu").children( "option:contains('" + hash + "')" ); - $('
', { - class: 'directory-title', - text: v.title - }).appendTo( colNameTitle ); - - if( expertsFlag ){ - var expertiseDiv = $('
', { - class: 'directory-expertise', - text: v.expertise - }).appendTo( colNameTitle ); - $('', { - class: 'expertise', - text: "Expertise: " - }).prependTo( expertiseDiv ); + 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; - var colPhoneEmail = $('
', { - class: 'col-sm-3 directory-contact-wrap' - }).appendTo( topLevelRow ); - $('
', { - class: 'directory-phone', - text: v.phone - }).appendTo( colPhoneEmail ); - var emailDiv = $('
', { - class: 'directory-email' - }).appendTo( colPhoneEmail ); - - var emailLink = $('', { - href: "mailto:"+v.email, - text: v.email - }).appendTo( emailDiv ); - - var colOffice = $('
', { - class: 'col-sm-4 directory-office-wrap' - }).appendTo( topLevelRow ); - $('
', { - class: 'directory-officeLabel', - text: "Office" - }).appendTo( colOffice ); - - $('
', { - 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', - }; + $(".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 directoryList = $("#directory-list"); - $.post(neag_object.ajaxurl, data, function(response) { - response = JSON.parse(response); - //console.log(response); - if( Object.keys(response).length != 0 ){ - modifyDirectoryList( response, directoryList, true ); - } - }); - } - - $("#directory-dropdownMenu").change(function(event){ - event.preventDefault(); - - var data = { - 'action': 'neag_get_people', - 'categoryID': this.value - }; + function modifyDirectoryList( response, directoryList, expertsFlag ){ + directoryList.empty(); + + $.each(response, function(i,v){ + var directoryRow = $('
', { + id: v.divid, + class: 'directory-person' + }).appendTo( directoryList ); + + var topLevelRow = $('
', { + class: 'row' + }).appendTo( directoryRow ); + + var faceWrap = $('
', { + class: 'col-sm-5 directory-face-wrap' + }).appendTo( topLevelRow ); + + var directoryPhoto = $('
', { + class: 'directory-photo' + }).appendTo( faceWrap ); // add photo to html + + $('', { + href: v.permalink, + html: v.photo + }).appendTo( directoryPhoto ); + + var colNameTitle = $('
', { + class: 'directory-name-title-wrap' + }).appendTo( faceWrap ); + var directoryName = $('
', { + class: 'directory-name' + }).appendTo( colNameTitle ); + $('', { + href: v.permalink, + text: v.name + }).appendTo( directoryName ); + + $('
', { + class: 'directory-title', + text: v.title + }).appendTo( colNameTitle ); + + if( expertsFlag ){ + var expertiseDiv = $('
', { + class: 'directory-expertise', + text: v.expertise + }).appendTo( colNameTitle ); + $('', { + class: 'expertise', + text: "Expertise: " + }).prependTo( expertiseDiv ); + } + + var colPhoneEmail = $('
', { + class: 'col-sm-3 directory-contact-wrap' + }).appendTo( topLevelRow ); + $('
', { + class: 'directory-phone', + text: v.phone + }).appendTo( colPhoneEmail ); + var emailDiv = $('
', { + class: 'directory-email' + }).appendTo( colPhoneEmail ); + + var emailLink = $('', { + href: "mailto:"+v.email, + text: v.email + }).appendTo( emailDiv ); + + var colOffice = $('
', { + class: 'col-sm-4 directory-office-wrap' + }).appendTo( topLevelRow ); + $('
', { + class: 'directory-officeLabel', + text: "Office" + }).appendTo( colOffice ); + + $('
', { + 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 ); + } + } + }); + } - if( this.value == "faculty-expert" ){ - displayExperts(); - return; + 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 directoryList = $("#directory-list"); - $.post(neag_object.ajaxurl, data, function(response) { - response = JSON.parse(response); + var flag = false; + $("#directory-dropdownMenu").on('click', function(event){ + event.preventDefault(); - if( Object.keys(response).length != 0 ){ - modifyDirectoryList( response, directoryList ); + 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( "

Archives ›

" ); + $( "#page-news .panel-grid:nth-child(5) .panel-grid-cell:nth-child(1) .widget_siteorigin-panels-postloop" ).append( "

News Archives ›

" ); $("h4.panel-title a").addClass("accordion-closed"); diff --git a/page_people.php b/page_people.php index 04f4234..df8318a 100644 --- a/page_people.php +++ b/page_people.php @@ -16,7 +16,8 @@ get_header(); ?> array( 'person' ), - 'fields' => 'ids' + 'fields' => 'ids', + 'posts_per_page' => -1, ); $query = new WP_Query( $args ); $people = $query->posts;