(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); (function($) { $(document).ready(function() { var colSets = $( '.colSet' ); colSets.each( function( index, element ) { var colSet = $(this); var columns = colSet.children( '.sColumn' ); var colNum = columns.length; var freeCols = 12; columns.each(function( index, element ) { // column does not have specified width if( ! $(this).is( '[class*=col-lg-]' ) ) { return; } var columnClasses = $(this).attr( 'class' ).split(' '); var numCols = 0; // Get # of initial grid columns assigned for the column for( var key in columnClasses ) { var currClass = columnClasses[key]; if( currClass.indexOf( 'col-lg-' ) >= 0 ) { numCols = currClass.substr(currClass.length - 2); if( numCols.substr(0, 1) == '-' ) { numCols = numCols.substr( numCols.length - 1 ); } } } // Adjust the remaining freeCols accordingly freeCols -= numCols; // Check if user provided widths with total that exceeds 100%. // If so, just divide all columns evenly. // If number is not exactly divisible => add remainder to the last column. if( freeCols < 0 ) { freeCols = 12; colNum = columns.length; columns.each(function( index, element ) { $(this).attr( 'class', function (i, c) { return c.replace( /col-lg-(\d+)/, 'col-lg-' + freeCols/colNum ); }); freeCols -= freeCols/colNum; colNum--; }); colNum = 0; return; } // Account for all columns having the class col-lg-.. colNum--; }); // Apply free width to the rest of the columns if( colNum != 0 ) { var numCols = Math.floor(freeCols / colNum); columns.each(function(index, element) { if( ! $(this).is( '[class*=col-lg-]' ) ) { $(this).addClass( 'col-lg-' + numCols ); freeCols -= numCols; } }); } // If all columns have set width, but freeWidth is remaining, add it to the last column if( freeCols != 0 ) { var $lastCol = columns.last(); var lastColClasses = $lastCol.attr( 'class' ).split(' '); for( var key in lastColClasses ) { var currClass = lastColClasses[key]; if( currClass.indexOf( 'col-lg-' ) >= 0 ) { numCols = Number( currClass.substr(currClass.length - 1) ); numCols += freeCols; $lastCol.removeClass(currClass); } } $lastCol.addClass( 'col-lg-' + numCols ); } }); }); })(jQuery);