MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Cryptshare Documentation
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
var SideBar = { | var SideBar = { | ||
| Zeile 87: | Zeile 9: | ||
getPageName : function(url) { | getPageName : function(url) { | ||
var pos = url.lastIndexOf(":") | var pos = url.lastIndexOf(":") | ||
var | var endPositions = ["?", "&", "#"] | ||
var lastPos | |||
for (var i = 0;i < endPositions.length;i++) { | |||
if (lastPos === -1 || lastPos === undefined) | |||
lastPos = url.indexOf(endPositions[i]) | |||
} | |||
if (lastPos === -1) | if (lastPos === -1) | ||
return decodeURI(url.substring(pos + 1)) | return decodeURI(url.substring(pos + 1)) | ||
Version vom 15. Oktober 2021, 05:36 Uhr
var SideBar = {
normalizeName : function(name) {
var normalizedName = name.replaceAll("_", " ")
normalizedName = normalizedName.replaceAll("%26", "&")
normalizedName = normalizedName.replaceAll("%2B", "+")
return normalizedName
},
getPageName : function(url) {
var pos = url.lastIndexOf(":")
var endPositions = ["?", "&", "#"]
var lastPos
for (var i = 0;i < endPositions.length;i++) {
if (lastPos === -1 || lastPos === undefined)
lastPos = url.indexOf(endPositions[i])
}
if (lastPos === -1)
return decodeURI(url.substring(pos + 1))
else
return decodeURI(url.substring(pos + 1, lastPos))
},
selectMenuItem : function(name) {
console.log("SideBar Navigation - Selecting ", name)
var item = $('#sidebar-navigation a:contains("' + name + '")')
if (item.length === 0) // MediaWiki makes an uppercase URL in some cases
item = $('#sidebar-navigation a:contains("' + name.toLowerCase() + '")')
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("Selector: ", selector);
$(selector).toggleClass("selected")
$('#sidebar-navigation').animate({ scrollTop: ($(selector).offset().top-300)}, 'fast');
} else if (item) {
$(item).toggleClass("selected")
$('#sidebar-navigation').animate({ scrollTop: ($(item).offset().top-300)}, 'fast');
}
},
updateSelectedMenuItem : function() {
SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href)))
}
}