MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
m
Fix wgPageName reference error, remove flattrButton
(+Headquarter8302 custom CSS)
m (Fix wgPageName reference error, remove flattrButton)
 
Line 97: Line 97:
setUrl:function() {
setUrl:function() {
var obj = $(this).children('object');
var obj = $(this).children('object');
if(!obj) return;
if(!obj.length) return;
obj.append($('<param name="allowscriptaccess" value="true"></param>'));
obj.append($('<param name="allowscriptaccess" value="true"></param>'));
obj.append($('<param name="allowfullscreen" value="true"></param>'));
obj.append($('<param name="allowfullscreen" value="true"></param>'));
var titleParts = wgPageName.split(/\//g);
var titleParts = mw.config.get('wgPageName').split(/\//g);
var lang = 'en';
var lang = 'en';
if(titleParts.length == 2 && !wgCanonicalSpecialPageName) {
if(titleParts.length == 2 && !mw.config.get('wgCanonicalSpecialPageName')) {
lang = titleParts[titleParts.length-1];
lang = titleParts[titleParts.length-1];
}
}
var playerUrl = obj.children('param[name="movie"]').attr('value') + '&fs=1&theme=dark&color=white' + ($(this).hasClass('hd-on') ? '&hd=1' : '') + '&cc_load_policy=1&hl=' + lang + '&cc_lang_pref=' + lang;
var playerUrl = obj.children('param[name="movie"]').attr('value') + '&version=2&fs=1&theme=dark&color=white' + ($(this).hasClass('hd-on') ? '&hd=1' : '') + '&cc_load_policy=1&modestbranding=1&hl=' + lang + '&cc_lang_pref=' + lang;
obj.children('param[name="movie"]').attr('value', playerUrl);
obj.children('param[name="movie"]').attr('value', playerUrl);
obj.children('embed').attr('src', playerUrl).attr('allowscriptaccess', 'always').attr('allowfullscreen', 'true');
obj.children('embed').attr('src', playerUrl).attr('allowscriptaccess', 'always').attr('allowfullscreen', 'true');
Line 258: Line 258:
   var lang = defaultLang;
   var lang = defaultLang;
   for(var i in langList) {
   for(var i in langList) {
     if(wgPageName.substr(wgPageName.length-1-langList[i].length).toLowerCase() == '/' + langList[i].toLowerCase()) {
     if(mw.config.get('wgPageName').substr(mw.config.get('wgPageName').length - 1 - langList[i].length).toLowerCase() == '/' + langList[i].toLowerCase()) {
       lang = langList[i];
       lang = langList[i];
       break;
       break;
Line 446: Line 446:
// Fancy diffs
// Fancy diffs
var fancyDiffs = {
var fancyDiffs = {
isBigDiff: false,
isBigDiffThreshold: 72,
toggle: function(element) {
toggle: function(element) {
var expanded = element.hasClass('diff-expanded');
var expanded = element.hasClass('diff-expanded');
Line 451: Line 453:
if(expanded) { // Just collapse then
if(expanded) { // Just collapse then
element.removeClass('diff-expanded');
element.removeClass('diff-expanded');
contents.slideUp('fast');
if(fancyDiffs.isBigDiff) {
contents.hide();
} else {
contents.slideUp('fast');
}
} else if(element.hasClass('diff-data-loaded')) { // Stuff is already loaded, expand
} else if(element.hasClass('diff-data-loaded')) { // Stuff is already loaded, expand
element.addClass('diff-expanded');
element.addClass('diff-expanded');
Line 458: Line 464:
element.addClass('diff-data-requested');
element.addClass('diff-data-requested');
var fileName = element.find('span').text().replace(/^\s+|\s+$/g);
var fileName = element.find('span').text().replace(/^\s+|\s+$/g);
$.get('/w/?title=Template:PatchDiff/' + encodeURIComponent(wgPageName.replace(/^Template:PatchDiff\//, '')) + '/' + encodeURIComponent(fileName) + '&action=raw', function(data) {
var patchName = element.closest('.diffname');
var diffName = mw.config.get('wgPageName');
if(patchName && patchName.length && patchName.attr('class')) {
diffName = patchName.attr('class').substr(9);
}
$.get('/w/?title=Template:PatchDiff/' + encodeURIComponent(diffName.replace(/^Template:PatchDiff\//, '')) + '/' + encodeURIComponent(fileName) + '&action=raw', function(data) {
contents.html(data);
contents.html(data);
contents.slideDown('fast');
if(fancyDiffs.isBigDiff) {
contents.show();
} else {
contents.slideDown('fast');
}
element.removeClass('diff-data-requested').addClass('diff-data-loaded').addClass('diff-expanded');
element.removeClass('diff-data-requested').addClass('diff-data-loaded').addClass('diff-expanded');
});
});
Line 478: Line 493:
return false;
return false;
});
});
fancyDiffs.isBigDiff = $('.diff-file').length > fancyDiffs.isBigDiffThreshold;
}
}
}
}
Line 567: Line 583:
init: function() {
init: function() {
for(var i in pageScripts.pagesJS) {
for(var i in pageScripts.pagesJS) {
if(wgPageName == pageScripts.pagesJS[i]) {
if(mw.config.get('wgPageName') == pageScripts.pagesJS[i]) {
$.getScript(wgScript + '?title=' + encodeURIComponent(wgPageName + pageScripts.suffixJS) + '&ctype=text/javascript&action=raw');
mw.loader.load(mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName') + pageScripts.suffixJS) + '&ctype=text/javascript&action=raw');
}
}
}
}
for(var i in pageScripts.pagesCSS) {
for(var i in pageScripts.pagesCSS) {
if(wgPageName == pageScripts.pagesCSS[i]) {
if(mw.config.get('wgPageName') == pageScripts.pagesCSS[i]) {
$('head').append($('<link rel="stylesheet" type="text/css" media="screen" />').attr('href', wgScript + '?title=' + encodeURIComponent(wgPageName + pageScripts.suffixCSS) + '&ctype=text/css&action=raw'));
mw.loader.load(mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName') + pageScripts.suffixCSS) + '&ctype=text/css&action=raw', 'text/css');
}
}
}
}
Line 767: Line 783:
};
};
$(selector3d.init);
$(selector3d.init);
var flattrButton = {
init: function() {
$('#mw-panel').append($('<div class="flattr-sidebar"><a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="https://theportalwiki.com/wiki/Portal_Wiki:Donate"></a></div>'));
$('head').append($('<script src="https://api.flattr.com/js/0.6/load.js?mode=auto" async="async"></script>'));
}
};


// Google Analytics/Flattr; do not track if user is on Tor.
// Google Analytics/Flattr; do not track if user is on Tor.
if(location.host.indexOf('.onion') == -1) {
if(location.host.indexOf('.onion') == -1) {
$(flattrButton.init);
var _gaq = _gaq || [];
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22928841-2']);
_gaq.push(['_setAccount', 'UA-22928841-2']);

Navigation menu