MediaWiki:Hydradark.js

/* Any JavaScript here will be loaded for users using the Hydra Dark skin */

/* Collapsible infobox sections */ var collapsing = document.querySelectorAll(".section-collapse"); if (collapsing.length > 0) { for (var i = 0; i < collapsing.length; i++) { collapsing[i].addEventListener('click', collapseHandler, false); for (var c = collapsing[i].parentNode.parentNode.nextSibling; c; c = c.nextSibling) { if (c.classList) { if (c.classList.contains("section-collapse") || c.classList.contains("stop-section-collapse")) break; c.classList.add('section-collapsed'); }       }    } }

function collapseHandler { if (!this.parentNode) return;

var hasFlag = false; var flag; for (var c = this.parentNode.parentNode.nextSibling; c; c = c.nextSibling) { if (c.classList) { if (c.classList.contains("section-collapse") || c.classList.contains("stop-section-collapse")) break; if (!hasFlag) { hasFlag = true; flag = c.classList.contains('section-collapsed'); }           if (flag) c.classList.remove('section-collapsed'); else c.classList.add('section-collapsed'); }   }    this.classList.toggle('collapsed-icon'); }

$(collapseHandler);

/* Any JavaScript here will be loaded for users using the Hydra Dark skin */ /***************************************** /* Front Page column height equalization * /*****************************************/ // Author: Shawn Bruckner // Date:   2015-Feb-12 // License: CC-BY 3.0 // Version: beta

var fp = fp || { equalizeColumns : function { $( '.fpmain' ).each( function {      fp.resetSectionBoxHeights( $( this ).find( '#fptopsection, #fpflexsection, #fpbottomsection' ) );    } ); var excludeSel = ''; if ( $( '.fpmaybercol' ).css( 'float' ) == 'right' ) { excludeSel = '.fpmaybercol'; // at this width, it's necessary to hit those boxes in a separate pass after .fpmain }   if ( $( '#fpflexsection' ).css( 'float' ) == 'right' ) { fp.equalizeColumnsOfBlock( '.fpmain',                                '#fptopsection, #fpbottomsection',                                 '#fpbottomsection',                                 '#fpflexsection',                                 '#fpflexsection',                                 excludeSel                               ); }   if ( $( '.fpmaybercol' ).css( 'float' ) == 'right' ) { fp.equalizeColumnsOfBlock( '.fpmaybecols',                                '.fpmaybelcol',                                 '.fpmaybelcol',                                 '.fpmaybercol',                                 '.fpmaybercol',                                 ''                               ); } },

equalizeColumnsOfBlock : function( blockSel, leftSel, leftBottomSel, rightSel, rightBottomSel, excludeSel ) { $( blockSel ).each( function ( index ) {     var tryCount = 0;      do {        var leftBottom = $( this ).find( leftBottomSel ).offset.top + $( this ).find( leftBottomSel ).height;        var rightBottom = $( this ).find( rightBottomSel ).offset.top + $( this ).find( rightBottomSel ).height;

var difference = Math.round( Math.abs( rightBottom - leftBottom ) ); if ( leftBottom < rightBottom ) { fp.adjustSectionBoxHeights( difference, $( this ).find( leftSel ).not( excludeSel ) ); } else if ( rightBottom < leftBottom ) { fp.adjustSectionBoxHeights( difference, $( this ).find( rightSel ).not( excludeSel ) ); }       ++tryCount; } while ( Math.round( leftBottom ) != Math.round( rightBottom ) && tryCount < 4 ); } ); },

resetSectionBoxHeights : function ( sections ) { sections.each( function {      $( this ).find( '.fpbox' ).each( function  { $( this ).height( 'auto' ); } );   } );  },

adjustSectionBoxHeights : function ( heightToAdd, sections ) { var boxCount = 0; sections.each( function {     boxCount += $( this ).find( '.fpbox' ).length;    } );

var avgHeightToAdd = heightToAdd / boxCount; var decimalPortion = 0.0; var boxes, heightToAdd; sections.each( function {     boxes = $( this ).find( '.fpbox' );

boxes.each( function {       heightToAdd = Math.round( decimalPortion + avgHeightToAdd ); /* should iron out rounding error */        decimalPortion += avgHeightToAdd - heightToAdd;        $( this ).height( $( this ).height + heightToAdd );      } ); } ); } };

$( document ).ready( fp.equalizeColumns ); $( window ).resize( fp.equalizeColumns ); /********************************************* /* End Front Page column height equalization * /*********************************************/