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 + ';' +			''	);

$( '.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 ) );