MediaWiki:Common.js
From OpenMedia
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
/* Any JavaScript here will be loaded for all users on every page load. */
// <source lang="javascript">
// This JavaScript will be loaded for all users on every page load.
// Except for additions at the end, imported from en.wikipedia.org and modified (parts removed).
// for authors see http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=history
// NEW: targetHighlighting (Hagedorn) and collapsibleTables (wikipedia) moved to jKey.js!
/* Import more specific scripts if necessary */
if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") { //scripts specific to editing pages
importScript("MediaWiki:Common.js/edit.js");
}
/* Scripts specific to Internet Explorer */
if (navigator.appName == "Microsoft Internet Explorer") {
/** Internet Explorer bug fix **************************************************
* Description: Fixes IE horizontal scrollbar bug
* Maintainers: [[User:Tom-]]?
*/
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll() {
if (!oldWidth || docEl.clientWidth > oldWidth)
doFixIEScroll();
else
setTimeout(doFixIEScroll, 1);
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
document.attachEvent("onresize", fixIEScroll);
// In print IE (7?) does not like line-height
appendCSS( '@media print { sup, sub, p, .documentDescription { line-height: normal; }}');
//Import scripts specific to Internet Explorer 6
// THIS IS A PNG transparency FIX, here commented out:
// if (navigator.appVersion.substr(22, 1) == "6") {
// importScript("MediaWiki:Common.js/IE60Fixes.js");
// }
} // END "Microsoft Internet Explorer"
/**
* ImageAnnotator
* Globally enabled per
* http://commons.wikimedia.org/?title=Commons:Village_pump&oldid=26818359#New_interface_feature
* Maintainer: [[User:Lupo]]
*/
// Not on Special pages, and only if viewing the page
if (wgNamespaceNumber != -1 && $.inArray(mw.config.get('wgAction'), ['view', 'purge']) != -1 ) {
if (typeof ImageAnnotator_disable == 'undefined' || !ImageAnnotator_disable) {
// Don't even import it if it's disabled.
importScript('MediaWiki:Gadget-ImageAnnotator.js');
}
}
/** Table sorting fixes
* Description: Disables code in table sorting routine to set classes on even/odd rows
*/
ts_alternate_row_colors = false;
/**
* sort event-tables according to column 3.
*/
function presort() {
var table = document.getElementById("event-table");
if (table != null && table != 'undefined') {
var sortLink = table.rows[0].cells[2].lastChild;
ts_resortTable(sortLink);
}
}
// collapsible parts: div and tr → Template:Hidden
// may be fused later with toggleCollapse
// main difference: initCollapsebox() uses a switcher defined by the Wikitemplate
// and is not using a javascript resource title
function initCollapsebox() {
/* is nested in: div.collapsebox
└ div.switcher
└ div.collapsecontent */
jQuery("div.collapsebox div.switcher").live('click',
function() {
jQuery(this).nextAll("div.collapsecontent:first").slideToggle(250);
/* $(this).toggle() does not work in live as toggle is a bind()
therefore toggle must be bound to a different DOM element */
jQuery(this).find(".show, .hide").toggle();
});
/* is in a table: tr.collapsebox
└ div.switcher
tr.collapsecontent */
jQuery("tr.collapsebox div.switcher").live('click',
function() {
jQuery(this).closest("tr.collapsebox").nextAll("tr.collapsecontent:first").toggle();
jQuery(this).find(".show, .hide").toggle();
});
}// END initCollapsebox()
///////////////////////////////////
// confirm deletion using SMW forms
// does not work in IE 6
//////////////////////////////////
function initConfirmDeleteSubform() {
$j.extend(true, $j.jI18n, {
en: {
message : "'Delete this sub form irreversibly?'"
},
de: {
message : "'Dieses Teilformular unwiderruflich löschen?'"
}
});
// default buttons: <input type="button" ... class="remove"/>
$j("input.remove").attr("onClick", function() {// case sensitive not: onclick
//typeof this.onclick → function
var currentClickHandlerString = this.getAttributeNode('onclick').value;
// add a confirm
return "var removethis = confirm("+$j.resource('message')+"); if(removethis) {return " + currentClickHandlerString + "};";
});
/* added delete buttons by the SMW-form: <input type="button" />
add onclick handling */
$j("input.addAnother").click(function () {
// just new generated div#div_gen_1
$j("div")
.filter(function() { return this.id.match(/div_gen_\d+/); })
.find(":button")
.attr("onClick",function() {// case sensitive not: onclick
// add a confirm
return "var removethis = confirm("+$j.resource('message')+"); if(removethis) {$j('#' + String($j(this).parent().attr('id'))).remove();} else {return false;};";
});
});
}// end initConfirmDeleteSubform()
/*
///////////////////////////////////
// indicate hidden inputs created
// from template:Hidden
//////////////////////////////////
structure of template:Hidden:
div.collapsebox
├ div.switcher (float)
├ div.collapsetitle
└ div.collapsecontent
tr.collapsebox
└ th/td
├ div.switcher (float)
└ div.collapsetitle
tr.collapsecontent
*/
function initMarkHiddenInputs(){
var jDivHiddenFormTexts = $j(
// select only input type text + textarea with values
"div.collapsecontent.indicateHiddenInputs * :text[value!=]"
+", div.collapsecontent.indicateHiddenInputs * textarea[value!=]"
);
var jTrHiddenFormTexts = $j(
// select only input type text + textarea with values
"tr.collapsecontent.indicateHiddenInputs *:not(.collapsecontent) :text[value!=]"
+", tr.collapsecontent.indicateHiddenInputs *:not(.collapsecontent) textarea[value!=]"
);
// <div>
jDivHiddenFormTexts
.parents(".collapsebox")
.css({'border-left':'2px solid #ce5c00'});
//indicate the fields itself
jDivHiddenFormTexts
.css({'background-color':'#fcdeb1'}); //pale orange
// <tr>
//indicate the fields itself
jTrHiddenFormTexts
.css({'background-color':'#fcdeb1'}); //pale orange
//indicate current level
jTrHiddenFormTexts
.closest(".collapsebox")
.css({'border-left':'2px solid #ce5c00'});
// to ?upermost level
jTrHiddenFormTexts
.parents(".collapsecontent")
.prev(".collapsebox")
.css({'border-left':'2px solid #ce5c00'});
}// END initMarkHiddenInputs()
addOnloadHook(presort);
$j(document).ready(function() {
// try to add the toolbar on uploading
if(wgPageName == "Special:Upload" && wgUserName){
$j("textarea#wpUploadDescription").before('<div id="toolbar"></div>');
}
initCollapsebox();//collapsable parts
// page specific
if(wgAction=="formedit" || wgPageName=="Spezial:FormEdit"){
initConfirmDeleteSubform();
initMarkHiddenInputs();
}
});
importScript('MediaWiki:Multilingual description.js');
// </source>