MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus Cryptshare Documentation
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
function executeStatisticsTools(current_page) { | |||
// Google Analytics | |||
(function (i, s, o, g, r, a, m) { | |||
i["GoogleAnalyticsObject"] = r; | |||
(i[r] = | |||
i[r] || | |||
function () { | |||
(i[r].q = i[r].q || []).push(arguments); | |||
}), | |||
(i[r].l = 1 * new Date()); | |||
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); | |||
a.async = 1; | |||
a.src = g; | |||
m.parentNode.insertBefore(a, m); | |||
})( | |||
window, | |||
document, | |||
"script", | |||
"https://www.google-analytics.com/analytics.js", | |||
"ga" | |||
); | |||
ga("create", "UA-24783289-5", "auto"); | |||
ga("set", "anonymizeIp", true); | |||
ga("require", "displayfeatures"); | |||
ga("require", "linkid", "linkid.js"); | |||
if (current_page) { | |||
ga("send", current_page); | |||
} else { | |||
ga("send", "pageview"); | |||
} | |||
// Bing | |||
(function (w, d, t, r, u) { | |||
var f, n, i; | |||
(w[u] = w[u] || []), | |||
(f = function () { | |||
var o = { | |||
ti: "28001641" | |||
}; | |||
(o.q = w[u]), (w[u] = new UET(o)), w[u].push("pageLoad"); | |||
}), | |||
(n = d.createElement(t)), | |||
(n.src = r), | |||
(n.async = 1), | |||
(n.onload = n.onreadystatechange = function () { | |||
var s = this.readyState; | |||
(s && s !== "loaded" && s !== "complete") || | |||
(f(), (n.onload = n.onreadystatechange = null)); | |||
}), | |||
(i = d.getElementsByTagName(t)[0]), | |||
i.parentNode.insertBefore(n, i); | |||
})(window, document, "script", "//bat.bing.com/bat.js", "uetq"); | |||
} | |||
if (Cookiebot) { | |||
window.addEventListener( | |||
"CookiebotOnAccept", | |||
function (e) { | |||
if (Cookiebot.consent.statistics) { | |||
executeStatisticsTools(); | |||
} | |||
}, | |||
false | |||
); | |||
} | |||
function markAnonymousUser() { | |||
if ($("#pt-login").length > 0) { | |||
$(document.body).addClass("anonymous"); | |||
} | |||
} | |||
$(document).ready(function () { | |||
PageTitle.showTitle() | |||
markAnonymousUser() | |||
SideBar.updateSelectedMenuItem() | |||
}); | |||
var SideBar = { | var SideBar = { | ||
| Zeile 12: | Zeile 91: | ||
getPageName : function(url) { | getPageName : function(url) { | ||
// Only consider the part after the last slash | // Only consider the part after the last slash | ||
var pageName = url.substring(url.indexOf("/") + 1) | |||
var pos = | 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 62: | Zeile 141: | ||
updateSelectedMenuItem : function() { | updateSelectedMenuItem : function() { | ||
SideBar.selectMenuItem(SideBar.normalizeName(SideBar.getPageName(window.location.href))) | 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") | |||
} | } | ||
} | } | ||
Version vom 15. Dezember 2021, 09:17 Uhr
function executeStatisticsTools(current_page) {
// Google Analytics
(function (i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function () {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(
window,
document,
"script",
"https://www.google-analytics.com/analytics.js",
"ga"
);
ga("create", "UA-24783289-5", "auto");
ga("set", "anonymizeIp", true);
ga("require", "displayfeatures");
ga("require", "linkid", "linkid.js");
if (current_page) {
ga("send", current_page);
} else {
ga("send", "pageview");
}
// Bing
(function (w, d, t, r, u) {
var f, n, i;
(w[u] = w[u] || []),
(f = function () {
var o = {
ti: "28001641"
};
(o.q = w[u]), (w[u] = new UET(o)), w[u].push("pageLoad");
}),
(n = d.createElement(t)),
(n.src = r),
(n.async = 1),
(n.onload = n.onreadystatechange = function () {
var s = this.readyState;
(s && s !== "loaded" && s !== "complete") ||
(f(), (n.onload = n.onreadystatechange = null));
}),
(i = d.getElementsByTagName(t)[0]),
i.parentNode.insertBefore(n, i);
})(window, document, "script", "//bat.bing.com/bat.js", "uetq");
}
if (Cookiebot) {
window.addEventListener(
"CookiebotOnAccept",
function (e) {
if (Cookiebot.consent.statistics) {
executeStatisticsTools();
}
},
false
);
}
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) {
if (element.innerText === name)
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")
}
}