User:Erutuon/scripts/editableHeading.js

/*	Makes page name in top header editable, and usable as a search box. This makes it easier to copy the page title, and allows you to easily search for a modification of the page title. Based on User:Dixtosa/editAndGo.js, with modifications to hopefully allow it to be used when User:Erutuon/scripts/editTop.js is enabled. Buggy on certain pages.

mw.loader.using("mediawiki.util", function {

var pageName = mw.config.values.wgPageName; /*	Take pagename, then replace underscores with spaces, escape periods and slashes, make sure pagename is not before &, which would indicate it is in a href attribute. */ if ( pageName && pageName.match("&") ) pageName = "&amp;"; else pageName = pageName.replace(/_/g, " ").replace(/([\.\/])/g, "\\$1");

// Avoid finding page name inside of HTML attributes by requiring it to be // surrounded by ends of string or spacing characters. var pageNameRegex = new RegExp("(\\s|^)(" + mw.util.escapeRegExp(pageName) + ")(\\s|$)");

var makeEditable = function(number, text) { return text.replace(		pageNameRegex,		'$1 $2 $3'	); };

$(function {	$("#firstHeading").html(makeEditable);	$('#editable-title').keypress(function (event) { if(event.which === 13) { // enter key window.location = mw.util.getUrl("", {				search: $('#editable-title').text,			}); return false; }	}); });

});