jQuery(document).ready(function() { //banner links jQuery('a.bannerDetailed').click(bClassGetDetailed); jQuery('.ajaxLoading').hide(); }); function bClassGetDetailed() { a_semester = jQuery(this).attr('data-semester'); a_subject = jQuery(this).attr('data-subject'); a_id = jQuery(this).attr('data-id'); a_type = jQuery(this).attr('data-type'); a_attribute = jQuery(this).attr('data-attribute'); elementID = jQuery(this).attr('id'); jQuerytarget = jQuery(this).parent().children('.bClassDetails'); if(jQuerytarget.hasClass("animating")) return; jQuerytarget.addClass("animating"); if('' == jQuerytarget.html()) { var data = { action: 'get_banner_detail', type: a_type, semester: a_semester, subject: a_subject, id: a_id, attribute: a_attribute, htmlID: elementID }; jQuery(this).parent().children('.ajaxLoading').show(); jQuery.post(ajaxurl, data, function(response) { jQuerytarget = jQuery('#'+response.id).parent().children('.bClassDetails'); jQuerytarget.parent().children('.ajaxLoading').hide(); jQuerytarget.html(response.data); jQuery('a.bannerDetailed').click(bClassGetDetailed); var totalHeight = jQuerytarget.css('display','inline-block').outerHeight(); jQuerytarget.height(0).animate({'height':totalHeight+'px'},500, function(){jQuery(this).css("height",""); jQuery(this).removeClass("animating");}); },'json'); } else { var totalHeight = jQuerytarget.height(); if(totalHeight > 1) { jQuerytarget.animate({'height':0},500, function(){jQuery(this).css("display","").removeClass("animating");}); } else { totalHeight = jQuerytarget.css('display','inline-block').height("auto").outerHeight(); jQuerytarget.height(0).animate({'height':totalHeight+'px'},500, function(){jQuery(this).css("height",""); jQuery(this).removeClass("animating");}); } } // make sure that spry height gets adjusted accordingly for the new theme jQuery('a.bannerDetailed').closest( 'div.contentOpened' ).css("height", "auto").height(); } (function($) { $(document).ready(function() { var titles = $(".collapsableContent .collapsableTitle, .collapsableTextContent .collapsableTextTitle"); var width = $(window).width(); var height = $(window).height(); // Loop through each spry titles.each(function(index, element) { $(this).find('span .fa-chevron-up').hide(); $(this).find('span .fa-chevron-down').show(); var heightTitle = $(this).outerHeight(); // Click listener // Expands & closes the content section accordingly $(this).click(function(e) { var $this = $(this); animate_spry($this); }); // Deal with anchor functionality targeting sprys IDs var jQueryparent = $(this).parent(); var theID = jQueryparent.attr("id"); if(theID) { var paramPattern = new RegExp("[?|&]"+theID+"=","i"); if(paramPattern.exec(window.location.search)) { var offset = jQueryparent.offset().top; $("html, body") .animate({ scrollTop: (offset-heightTitle)+"px" }); jQueryparent.toggleClass("contentOpened"); return; } } jQueryparent.height(heightTitle); }); // When using find on sprys, open them up. $('.collapsableContent').scroll(function(){ var $this = $(this); if (! $this.hasClass('contentOpened') ) { $this.children('.collapsableTitle, .collapsableTextTitle').click(); } }); // Open spry on keydown $('.collapsableContent').keydown(function(e){ if (event.which == 13 || event.keyCode == 13) { var $this = $(this); $this.children('.collapsableTitle, .collapsableTextTitle').click(); } }); // Recalculate height when resizing $( window ).resize(function() { if($(window).width() == width && $(window).height() == height){ return; } titles.each(function(index, element) { var $this = $(this); var heightTitle = $this.outerHeight(); var jQueryparent = $this.parent(); if( jQueryparent.hasClass("contentOpened") ){ // do not collapse the item that is open jQueryparent.css("height", "auto"); return; } jQueryparent.height(heightTitle); }); }); // Function to collapse / hide spry based on current state of the spry animate_spry = function(curr_el) { var jQueryparent = curr_el.parent(); if(jQueryparent.hasClass("contentOpened")) { curr_el.find('span .fa-chevron-up').hide(); curr_el.find('span .fa-chevron-down').show(); var heightTitle = $(curr_el).outerHeight(); jQueryparent.animate({"height":heightTitle}, 500); } else { curr_el.find('span .fa-chevron-up').show(); curr_el.find('span .fa-chevron-down').hide(); var oldHeight = jQueryparent.height(); var newHeight = jQueryparent.css("height", "auto").height(); jQueryparent .css("height", oldHeight) .animate({"height":newHeight},{duration: 500, complete: function(){ $(curr_el).height(""); }}); } jQueryparent.toggleClass("contentOpened"); } // pass a URL paramater to expand all sprys var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; var expand = getUrlParameter('expandAll'); if( true === expand ) { //open sprys $( ".collapsableContent" ).each(function( i ) { $(".collapsableContent").addClass('contentOpened'); $(".collapsableContent").css("height", "auto"); }); } }); })(jQuery);