diff --git a/js/custom.js b/js/custom.js index ead23ba..6b74a32 100644 --- a/js/custom.js +++ b/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; @@ -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 = $('
', { - 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 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 = $('
', { - class: 'directory-name-title-wrap' - }).appendTo( faceWrap ); - var directoryName = $('
', { - class: 'directory-name' - }).appendTo( colNameTitle ); - $('', { - 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 ); + } + } + }; - $('
', { - 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 = $('
', { - class: 'directory-expertise', - text: v.expertise + $.ajax( ajaxReqSettings ); + }; + + function modifyDirectoryList ( response, directoryList, expertsFlag, specificExpertise ){ + 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 ); - $('', { - 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 ); + if( expertsFlag && specificExpertise ){ + var expertiseDiv = $('
', { + class: 'directory-expertise', + text: specificExpertise + }).appendTo( colNameTitle ); + $('', { + class: 'expertise', + text: "Expertise: " + }).prependTo( expertiseDiv ); + } else 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 ); + } + } + }); + } + + return mod; + }()); + + var hash = window.location.hash; + + if( hash.length > 1 ){ + hash = hash.replace( /_/g, ' ' ).substr(1); - var colOffice = $('
', { - class: 'col-sm-4 directory-office-wrap' - }).appendTo( topLevelRow ); - $('
', { - class: 'directory-officeLabel', - text: "Office" - }).appendTo( colOffice ); + var category = $("#directory-dropdownMenu").children( "option:contains('" + hash + "')" ); + + if( category.length != 0 ){ + var categoryID = category[0].value; - $('
', { - 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(), diff --git a/js/min/custom.min.js b/js/min/custom.min.js index 942fae3..5675dce 100644 --- a/js/min/custom.min.js +++ b/js/min/custom.min.js @@ -1 +1 @@ -jQuery(document).ready(function(e){function a(a,t,r){t.empty(),e.each(a,function(a,o){var p=e("
",{id:o.divid,"class":"directory-person"}).appendTo(t),c=e("
",{"class":"row"}).appendTo(p),n=e("
",{"class":"col-sm-5 directory-face-wrap"}).appendTo(c),d=e("
",{"class":"directory-photo"}).appendTo(n);e("",{href:o.permalink,html:o.photo}).appendTo(d);var s=e("
",{"class":"directory-name-title-wrap"}).appendTo(n),l=e("
",{"class":"directory-name"}).appendTo(s);if(e("",{href:o.permalink,text:o.name}).appendTo(l),e("
",{"class":"directory-title",text:o.title}).appendTo(s),r){var h=e("
",{"class":"directory-expertise",text:o.expertise}).appendTo(s);e("",{"class":"expertise",text:"Expertise: "}).prependTo(h)}var v=e("
",{"class":"col-sm-3 directory-contact-wrap"}).appendTo(c);e("
",{"class":"directory-phone",text:o.phone}).appendTo(v);var f=e("
",{"class":"directory-email"}).appendTo(v),y=(e("",{href:"mailto:"+o.email,text:o.email}).appendTo(f),e("
",{"class":"col-sm-4 directory-office-wrap"}).appendTo(c));if(e("
",{"class":"directory-officeLabel",text:"Office"}).appendTo(y),e("
",{"class":"directory-office",text:o.office_location}).appendTo(y),i){var g=n.height(),u=s.height();g>u&&s.css("padding-top",(g-u)/2)}})}function t(){var t={action:"neag_get_experts"},i=e("#directory-list");e.post(neag_object.ajaxurl,t,function(e){e=JSON.parse(e),0!=Object.keys(e).length&&a(e,i,!0)})}var i=!1;screen.width>767&&(i=!0,e(".directory-face-wrap").each(function(a,t){var i=e(t).height(),r=e(t).find(".directory-name-title-wrap"),o=r.height();i>o&&r.css("padding-top",(i-o)/2)})),e("#directory-dropdownMenu").change(function(i){i.preventDefault();var r={action:"neag_get_people",categoryID:this.value};if("faculty-expert"==this.value)return t(),void 0;var o=e("#directory-list");e.post(neag_object.ajaxurl,r,function(e){e=JSON.parse(e),0!=Object.keys(e).length&&a(e,o)})});var r=new Date,o=r.getMonth()+1,p=r.getFullYear();e(".widget_archives").append("

Archives ›

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

News Archives ›

"),e("h4.panel-title a").addClass("accordion-closed"),e("h4.panel-title a").click(function(){e(this).addClass("accordion-open")})}); \ No newline at end of file +jQuery(document).ready(function(e){if(e("#directory-dropdown").length>0){var t=!1;screen.width>767&&(t=!0,e(".directory-face-wrap").each(function(t,a){var i=e(a).height(),r=e(a).find(".directory-name-title-wrap"),o=r.height();i>o&&r.css("padding-top",(i-o)/2)}));var a=function(){function a(a,i,r,o){i.empty(),e.each(a,function(a,n){var c=e("
",{id:n.divid,"class":"directory-person"}).appendTo(i),s=e("
",{"class":"row"}).appendTo(c),p=e("
",{"class":"col-sm-5 directory-face-wrap"}).appendTo(s),d=e("
",{"class":"directory-photo"}).appendTo(p);e("",{href:n.permalink,html:n.photo}).appendTo(d);var l=e("
",{"class":"directory-name-title-wrap"}).appendTo(p),h=e("
",{"class":"directory-name"}).appendTo(l);if(e("",{href:n.permalink,text:n.name}).appendTo(h),e("
",{"class":"directory-title",text:n.title}).appendTo(l),r&&o){var f=e("
",{"class":"directory-expertise",text:o}).appendTo(l);e("",{"class":"expertise",text:"Expertise: "}).prependTo(f)}else if(r){var f=e("
",{"class":"directory-expertise",text:n.expertise}).appendTo(l);e("",{"class":"expertise",text:"Expertise: "}).prependTo(f)}var u=e("
",{"class":"col-sm-3 directory-contact-wrap"}).appendTo(s);e("
",{"class":"directory-phone",text:n.phone}).appendTo(u);var v=e("
",{"class":"directory-email"}).appendTo(u),y=(e("",{href:"mailto:"+n.email,text:n.email}).appendTo(v),e("
",{"class":"col-sm-4 directory-office-wrap"}).appendTo(s));if(e("
",{"class":"directory-officeLabel",text:"Office"}).appendTo(y),e("
",{"class":"directory-office",text:n.office_location}).appendTo(y),t){var x=p.height(),g=l.height();x>g&&l.css("padding-top",(x-g)/2)}})}var i={},r=e("#directory-list"),o=e("#directory-list-loading-text"),n={type:"POST",url:neag_object.ajaxurl,timeout:1e4,beforeSend:function(){o.show()},complete:function(e,t){"success"===t?o.hide():"timeout"===t?o.text("Request has timed out, please refresh this page"):o.text("Error: "+t)}};return i.setFaculty=function(t,i){n.data=t,n.success=function(e){e=JSON.parse(e),0!=Object.keys(e).length&&(-1!=i.indexOf("Faculty Expert")?a(e,r,!0,i):a(e,r))},e.ajax(n)},i.setFacultyExperts=function(t){n.data=t,n.success=function(e){e=JSON.parse(e),0!=Object.keys(e).length&&a(e,r,!0)},e.ajax(n)},i}(),i=window.location.hash;if(i.length>1){i=i.replace(/_/g," ").substr(1);var r=e("#directory-dropdownMenu").children("option:contains('"+i+"')");if(0!=r.length){var o=r[0].value;if(e("#directory-dropdownMenu")[0].selectedIndex=r[0].index,0!=o)if("faculty-expert"==o){var n={action:"neag_get_experts"};a.setFacultyExperts(n)}else{var n={action:"neag_get_people",categoryID:o};a.setFaculty(n,i)}}}e("#directory-dropdownMenu").on("change",function(e){if(e.preventDefault(),"faculty-expert"==this.value){var t={action:"neag_get_experts"};a.setFacultyExperts(t)}else{var i=this.options[this.options.selectedIndex].text;window.location.hash=0!=this.value?"#"+i.replace(/\s/g,"_"):"";var t={action:"neag_get_people",categoryID:this.value};a.setFaculty(t,i)}})}var c=new Date,s=c.getMonth()+1,p=c.getFullYear();e(".widget_archives").append("

Archives ›

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

News Archives ›

"),e("h4.panel-title a").addClass("accordion-closed"),e("h4.panel-title a").click(function(){e(this).addClass("accordion-open")})}); \ No newline at end of file diff --git a/page_people.php b/page_people.php index df8318a..7e14705 100644 --- a/page_people.php +++ b/page_people.php @@ -55,9 +55,10 @@ get_header(); ?> } echo "
"; - echo "
"; - + echo ""; + echo ""; + echo "
"; foreach( $people as $p ){ foreach( $fields as $k=>$v ){