User:Dixtosa/editAndGo.js
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
// documentation: [[Wiktionary:Grease_pit/2016/April#Editable title]]
$(function() {
if (mw.config.values.wgAction != "view") return;
$("#firstHeading").prop("contenteditable", "true");
$('#firstHeading').keypress(function(e) {
var key = e.which;
let newTitle = $('#firstHeading').contents().get(0).textContent;
if (key == 13) {
window.location = "/w/index.php?search=" + newTitle + "&title=Special:Search&go=Go";
return false;
}
});
});
mw.loader.using(['jquery.ui'], function() {
var ctrl = $("#firstHeading");
ctrl.autocomplete({
source: function(request, response) {
var prefix = ctrl.contents().get(0).textContent;
new mw.Api().get({
action: 'opensearch',
search: prefix
}).done(function(data) {
response(data[1]);
});
},
focus: function() {
return false;
},
select: function(e, ui) {
window.location.href = "/wiki/" + ui.item.value;
return false;
},
open: function() {
$(".ui-autocomplete")
.css({})
.position({
my: "right top",
at: "right bottom",
of: ctrl,
offset: "0",
collision: 'none fit'
})
.find('li').css({});
}
});
});