MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Cryptshare Documentation
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 19: | Zeile 19: | ||
else | else | ||
return decodeURI(url.substring(pos + 1, lastPos)) | return decodeURI(url.substring(pos + 1, lastPos)) | ||
}, | |||
makeSelection : function(selector) { | |||
setTimeout(() => { | |||
$(selector).toggleClass("selected") | |||
$('#sidebar-navigation').animate({ scrollTop: ($(selector).offset().top-300)}, 'fast'); | |||
}, 500) | |||
}, | }, | ||
selectMenuItem : function(name) { | selectMenuItem : function(name) { | ||
Zeile 33: | Zeile 39: | ||
selector += ':contains("' | selector += ':contains("' | ||
} | } | ||
SideBar.makeSelection(selector) | |||
} else if (item) { | } else if (item) { | ||
SideBar.makeSelection(item) | |||
} | } | ||
}, | }, |
Version vom 15. Oktober 2021, 05:41 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)) }, makeSelection : function(selector) { setTimeout(() => { $(selector).toggleClass("selected") $('#sidebar-navigation').animate({ scrollTop: ($(selector).offset().top-300)}, 'fast'); }, 500) }, 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("' } SideBar.makeSelection(selector) } else if (item) { SideBar.makeSelection(item) } }, updateSelectedMenuItem : function() { SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href))) } }