MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
// Change the top-left logo from navigating to the wiki home page to go to the signup page.
$("#p-logo a.mw-wiki-logo").attr("href", "https://app.displayr.com/SignUp").attr("title", "Try Displayr");
// Add a login link under the logo. Image set in Common.css.
$("<a>").addClass("login-under-logo").attr("href", "https://app.displayr.com/Login").attr("title", "Log in to Displayr").appendTo($("#p-logo"));
//
// Hide the "Content:" part of category pages headings.
// The way we organise our wiki is to have category pages as the main
// page on the topic with an overview; not just a listing of all pages
// in the category.
//
var firstHeading = $('h1#firstHeading');
if (firstHeading.length === 1) {
var text = firstHeading.text();
var cat_length = 'Category:'.length;
if (text.substr(0, cat_length) === 'Category:') {
firstHeading.text(text.substr(cat_length, text.length - cat_length));
}
}
//
// Use JavaScript to turn a soft redirect into a hard redirect,
// without using MediaWiki's #REDIRECT feature (which prevents inclusion
// of those pages which REDIRECT to the included page, because it is
// an overview).
//
// This is primarily used for the auto-generated pages of JavaScript
// snippets.
//
var softredirect = $('#softredirect a');
if (softredirect.length && window.location.search.indexOf('redirect=no') === -1) {
window.location = softredirect.attr('href');
}
//
// Apply tooltips to the category tree sidebar, because in CSS we trim the
// text using ellipsis.
//
$('a.CategoryTreeLabel').each(function () { $(this).attr('title', $(this).text()); });
// Redirect the search bar on every page to search on displayr.com helpcenter instead
function processForm(e) {
if (e.preventDefault) e.preventDefault();
// Get the search string and go to displayr help center with that query
var query = document.getElementById("searchInput").value;
window.location.href = "https://www.displayr.com/search/?ss360Query=" + query;
// False here also prevents default behavior
return false;
}
// Attach listener to interrupt the search bar form submit
document.getElementById('searchform').addEventListener("submit", processForm);
//
// Add toggles to code tags to allow you to show and hide the code tag.
// Collapse the code tag by default.
//
$('#Code').parent().nextAll('.mw-highlight.mw-content-ltr').before('<p class="code_collapser" style="cursor: pointer">▼ Hide Code</p>');
$('.code_collapser').click(function() {
// The next item is the div and its first child is the pre code block
$(this).next().children().first().slideToggle();
if ( $(this).text() == '▶ Show Code') {
$(this).text('▼ Hide Code');
} else {
$(this).text('▶ Show Code');
}
})
$('.code_collapser').click();