User:The Earwig/copy-section-link.js

// Fixed version of User:Enterprisey/copy-section-link.js

//

$.when(

$.ready,

mw.loader.using( [ "mediawiki.util", "oojs-ui-core", "oojs-ui-widgets" ] )

).then( function () {

$( ".mw-heading" ).each( function () {

var popup = null;

var heading = $(this.children).filter("h1, h2, h3, h4, h5, h6").first();

var target = $(this.children).filter(".mw-editsection").first();

if (target.length === 0) {

target = heading;

}

target.after($( "", { "class": "copy-section-link-pilcrow" } )

.text( "¶" )

.click( function () {

if( popup === null ) {

var hash = heading.attr( "id" );

var oldid = mw.util.getParamValue( "oldid" );

var popupContent;

function makeContent( pageName, id ) {

var wikitext = (pageName + "#" + hash).replace( /_/g, " " );

if( !window.copySectionLinkNoSquareBrackets ) {

wikitext = '' + wikitext + '';

}

return $( '

', { "class": "copy-section-link-content" } ).append(

$( "", { "id": "copy-section-wikilink" + id } ).text( wikitext ),

$( "