User:Hasley/diff-permalink-ooui.js

/** * diff-permalink-ooui.js * @author Enterprisey, all credit to him * Fork of User:Enterprisey/diff-permalink.js for OOUI support */

// $.when( $.ready, mw.loader.using( [ "mediawiki.util", "oojs-ui" ] ) ).then( function {    var suffix = mw.config.get( "wgDiffNewId" );    var page;    if( suffix ) {        if( document.getElementsByClassName( "diff-multi" ).length || mw.config.get("wgCanonicalSpecialPageName") === "ComparePages" ) {           suffix = mw.config.get( "wgDiffOldId" ) + "/" + suffix;        }        page = "Special:Diff/" + suffix;    } else {        var oldidMatch = mw.util.getParamValue( "oldid" );        if( oldidMatch ) {            page = "Special:Permalink/" + oldidMatch;        } else return; // nothing to do here    }

var permalinkEl = new OO.ui.FieldsetLayout;

permalinkEl.addItems( [ 		new OO.ui.ActionFieldLayout( new OO.ui.TextInputWidget( {					value: page,					inputId: "diff-permalink-link"			} ), new OO.ui.ButtonWidget( {					label: "Copy",					flags: [							"primary",							"progressive"					]			} ), {	    		label: "Permalink to this " + ( suffix ? "diff" : "oldid" ) + ": ", align: "top", id: 'diff-permalink' }		)	] );

permalinkEl.$element.click( function {		document.getElementById( "diff-permalink-link" ).select;		document.execCommand( "copy" );    } ); if ( suffix ) { $( "#bodyContent" ).prepend( permalinkEl.$element ); } else { $( "#contentSub" ).after( permalinkEl.$element ); }

var pageLength = ( page.length <= 50 ? page.length : 50 ) + '%'; $("#diff-permalink").css({		"maxWidth": pageLength	});

} ); //