MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Cryptshare Documentation
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
(9 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
function markAnonymousUser() { | function markAnonymousUser() { | ||
if ($("#pt-login").length > 0) { | if ($("#pt-login").length > 0) { | ||
Zeile 74: | Zeile 6: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
PageTitle.showTitle() | |||
markAnonymousUser() | markAnonymousUser() | ||
SideBar.updateSelectedMenuItem() | SideBar.updateSelectedMenuItem() | ||
}); | }); | ||
Zeile 85: | Zeile 17: | ||
normalizedName = normalizedName.replaceAll("%2B", "+") | normalizedName = normalizedName.replaceAll("%2B", "+") | ||
return normalizedName | return normalizedName | ||
}, | |||
escapeQuotes : function(value) { | |||
return value.replaceAll('"', '\"') | |||
}, | }, | ||
getPageName : function(url) { | getPageName : function(url) { | ||
var pos = | // Only consider the part after the last slash | ||
var pageName = url.substring(url.indexOf("/") + 1) | |||
var pos = pageName.indexOf(":") | |||
var endPositions = ["?", "&", "#"] | var endPositions = ["?", "&", "#"] | ||
var lastPos | var lastPos | ||
for (var i = 0;i < endPositions.length;i++) { | for (var i = 0;i < endPositions.length;i++) { | ||
if (lastPos === -1 || lastPos === undefined) | if (lastPos === -1 || lastPos === undefined) | ||
lastPos = | lastPos = pageName.indexOf(endPositions[i]) | ||
} | } | ||
if (lastPos === -1) | if (lastPos === -1) | ||
return decodeURI( | return decodeURI(pageName.substring(pos + 1)) | ||
else | else | ||
return decodeURI( | return decodeURI(pageName.substring(pos + 1, lastPos)) | ||
}, | }, | ||
makeSelection : function(selector) { | makeSelection : function(selector) { | ||
Zeile 105: | Zeile 43: | ||
selectMenuItem : function(name) { | selectMenuItem : function(name) { | ||
console.log("SideBar Navigation - Selecting ", name) | console.log("SideBar Navigation - Selecting ", name) | ||
var item = $( | var item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name) + "')") | ||
if (item.length === 0) // MediaWiki makes an uppercase URL in some cases | if (item.length === 0) // MediaWiki makes an uppercase URL in some cases | ||
item = $( | item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name.toLowerCase()) + "')") | ||
// console.log("Item: ", item); | |||
// console.log("Search term: ", SideBar.escapeQuotes(name)); | |||
if (item.length === 0) { // Handling titles containing a minus character | if (item.length === 0) { // Handling titles containing a minus character | ||
var splitItems = name.split(" ") | var splitItems = name.split(" ") | ||
Zeile 116: | Zeile 58: | ||
selector += ':contains("' | selector += ':contains("' | ||
} | } | ||
SideBar.makeSelection( | // console.log("Selecting: ", selector); | ||
$(selector).each(function(index, item) { | |||
var title = item.title.substring(item.title.indexOf(":") + 1) | |||
if (title === name) | |||
SideBar.makeSelection(item) | |||
}) | |||
} else if (item) { | } else if (item) { | ||
$(item).each(function(index, element) { | $(item).each(function(index, element) { | ||
if (element.innerText === name) | // console.log(element.innerText + "===" + name + " ?"); | ||
if (element.innerText === name || element.innerText === name.toLowerCase()) | |||
SideBar.makeSelection(element) | SideBar.makeSelection(element) | ||
}) | }) |
Aktuelle Version vom 10. Juli 2023, 06:29 Uhr
function markAnonymousUser() { if ($("#pt-login").length > 0) { $(document.body).addClass("anonymous"); } } $(document).ready(function () { PageTitle.showTitle() markAnonymousUser() SideBar.updateSelectedMenuItem() }); var SideBar = { normalizeName : function(name) { var normalizedName = name.replaceAll("_", " ") normalizedName = normalizedName.replaceAll("%26", "&") normalizedName = normalizedName.replaceAll("%2B", "+") return normalizedName }, escapeQuotes : function(value) { return value.replaceAll('"', '\"') }, getPageName : function(url) { // Only consider the part after the last slash var pageName = url.substring(url.indexOf("/") + 1) var pos = pageName.indexOf(":") var endPositions = ["?", "&", "#"] var lastPos for (var i = 0;i < endPositions.length;i++) { if (lastPos === -1 || lastPos === undefined) lastPos = pageName.indexOf(endPositions[i]) } if (lastPos === -1) return decodeURI(pageName.substring(pos + 1)) else return decodeURI(pageName.substring(pos + 1, lastPos)) }, makeSelection : function(selector) { $(selector).toggleClass("selected") $('#sidebar-navigation').animate({ scrollTop: ($(selector).offset().top-300)}, 'fast'); }, selectMenuItem : function(name) { console.log("SideBar Navigation - Selecting ", name) var item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name) + "')") if (item.length === 0) // MediaWiki makes an uppercase URL in some cases item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name.toLowerCase()) + "')") // console.log("Item: ", item); // console.log("Search term: ", SideBar.escapeQuotes(name)); if (item.length === 0) { // Handling titles containing a minus character var splitItems = name.split(" ") var selector = '#sidebar-navigation a:contains("' for (var i = 0;i < splitItems.length;i++) { selector += splitItems[i] + '")' if (splitItems[i+1]) selector += ':contains("' } // console.log("Selecting: ", selector); $(selector).each(function(index, item) { var title = item.title.substring(item.title.indexOf(":") + 1) if (title === name) SideBar.makeSelection(item) }) } else if (item) { $(item).each(function(index, element) { // console.log(element.innerText + "===" + name + " ?"); if (element.innerText === name || element.innerText === name.toLowerCase()) SideBar.makeSelection(element) }) } }, updateSelectedMenuItem : function() { SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href))) } } var PageTitle = { showTitle : function() { var element = document.getElementById('firstHeading') var title = element.innerText.substring(element.innerText.indexOf(':') + 1) element.innerText = title element.setAttribute("style", "display:inherit") } }