MediaWiki:Gadget-vector-headanchor.js

/** * Vector HeadAnchors * @author Krinkle, 2013 * @revision 2013-04-19 */

( function ( mw, $ ) {

var space = $( '#content' ).css( 'paddingLeft' );

mw.util.addCSS(		'.mw-headline-anchor {' +			'padding-left: ' + space + ';' +			'margin-left: -' + space + ';' +			''	);

// h1-h6 without the h2 in TOC $( '.mw-body :header' ).not( '.toc *' ).addClass( 'mw-header' );

$( '.mw-headline' ).each( function ( i, el ) {		var $h = $( el ).parent;

if ( $h.find( '.mw-headline-anchor').length ) { return; }

$h .append(			$( '' )			.prop({ href: '#' + el.id, className: 'mw-headline-anchor' })			.css({ top: $h.css( 'paddingTop' ), bottom: $h.css( 'paddingBottom' ) })		);	} );

}( mediaWiki, jQuery ) );