MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Cryptshare Documentation
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
var SideBar = { | var SideBar = { | ||
| Zeile 90: | Zeile 11: | ||
}, | }, | ||
getPageName : function(url) { | getPageName : function(url) { | ||
var pos = url. | // Only consider the part after the last slash | ||
url = url.substring(url.indexOf("/") + 1) | |||
var pos = url.indexOf(":") | |||
var endPositions = ["?", "&", "#"] | var endPositions = ["?", "&", "#"] | ||
var lastPos | var lastPos | ||
| Zeile 112: | Zeile 36: | ||
item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name.toLowerCase()) + "')") | item = $("#sidebar-navigation a:contains('" + SideBar.escapeQuotes(name.toLowerCase()) + "')") | ||
console.log("Item: ", item); | // console.log("Item: ", item); | ||
console.log("Search term: ", SideBar.escapeQuotes(name)); | // 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 | ||
| Zeile 138: | Zeile 62: | ||
updateSelectedMenuItem : function() { | updateSelectedMenuItem : function() { | ||
SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href))) | SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href))) | ||
} | } | ||
} | } | ||
Version vom 15. Dezember 2021, 09:15 Uhr
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
url = url.substring(url.indexOf("/") + 1)
var pos = url.indexOf(":")
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))
},
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) {
if (element.innerText === name)
SideBar.makeSelection(element)
})
}
},
updateSelectedMenuItem : function() {
SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href)))
}
}