MediaWiki:Common.js
Catatan: Imbah disimpan, Pian pinanya parlu malincau talih paramban wéb gasan manjanaki paubahan.
- Firefox/Safari: Tahan Shift wayah manikin Reload, atawa tikin Ctrl-F5 atawa Ctrl-R (⌘-R di Mac)
- Google Chrome: Tikin Ctrl-Shift-R (⌘-Shift-R di Mac)
- Edge: Tikin Ctrl wayah dikalik Refresh, atawa tikin Ctrl-F5.
- Opera: Tulak ka Menu → Settings (Opera → Preferences di Mac) lalu ka Privacy & security → Clear browsing data → Cached images and files.
/* JavaScript yang ada di sini akan diterapkan untuk semua kulit. */
/**
__TOC__
== Deklarasi variabel ==
Variabel-variabel yang dipakai secara global */
var LoadInterProject = true;
var LoadLinkFA = true;
var LoadNavFrame = true;
var load_edittools = true;
var LoadExtraPortlet = true;
var LoadEditTop = true;
var load_extratabs = false;
var LoadPageCounter = false;
/**
== Variabel saklar par pamuruk ==
Ubah [[Istimewa:Mypage/switches.js]] gasan ma'atur muha nang handak Pian
aktipakan atawa pajahakan */
if ( mw.config.get('wgUserName') ) {
mw.loader.load('//bjn.wikipedia.org/w/index.php?title=Pamuruk:' + mw.config.get('wgUserName') + '/switches.js&action=raw&ctype=text/javascript');
}
/**
== Library functions ==
Librari fungsi nang diguna'akan ulih fungsi-fungsi lain.
** Gasan samantara di-remark marga manyebabakan fungsi-fungsi lainnya kada bafungsi di Firefox3 - (borgx 26 Juni 2008)
*/
// Fix tampaian gasan IE
/*
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
{
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);
attachEvent("onresize", fixIEScroll);
}
// addLoadEvent, manambahakan event
function addLoadEvent(func)
{
if (window.addEventListener)
window.addEventListener("load", func, false);
else if (window.attachEvent)
window.attachEvent("onload", func);
}
*/
/**
== MainPageTransform ==
Mahilangakan judul [[Tungkaran Tatambaian]] wan mangganti ngaran tab. */
var mpTitle = "Tungkaran Tatambaian";
var isMainPage = (document.title.substr(0, mpTitle.length) == mpTitle);
var isDiff = (document.location.search && (
document.location.search.indexOf("diff=") != -1 ||
document.location.search.indexOf("oldid=") != -1 ||
document.location.search.indexOf("action=history") != -1
));
if ( isMainPage && !isDiff && (wgCanonicalNamespace != 'Special') )
{
mw.util.addCSS(' #siteSub, #contentSub, h1.firstHeading { display: none!important; } #content, #content div.thumb, #p-cactions li a, #p-cactions li a:hover, #p-cactions li.selected a { background: #fff!important; }');
var mpSmallEnabled;
var mpMinWidth = 700;
function mainPageTransform()
{
var mpContentEl = document.getElementById("bodyContent");
var mpBrowseEl = document.getElementById("EnWpMpBrowse");
var mpContainEl = document.getElementById("EnWpMpBrowseContainer");
var mpMarginEl = document.getElementById("EnWpMpMargin");
var mpEl = document.getElementById("EnWpMainPage");
if (!mpContentEl || !mpBrowseEl || !mpContainEl || !mpMarginEl || !mpEl)
return;
if (!mpSmallEnabled && mpContentEl.offsetWidth < mpMinWidth)
{
mpContainEl.insertBefore(mpBrowseEl, mpContainEl.firstChild);
mpBrowseEl.className = "EnWpMpBrowseBottom";
mpMarginEl.style.marginRight = 0;
mpSmallEnabled = true;
}
else if (mpSmallEnabled && mpContentEl.offsetWidth > mpMinWidth)
{
mpEl.insertBefore(mpBrowseEl, mpEl.firstChild);
mpBrowseEl.className = "EnWpMpBrowseRight";
mpMarginEl.style.marginRight = "13.8em";
mpSmallEnabled = false;
}
}
$( mainPageTransform );
if (window.addEventListener)
window.addEventListener("resize", mainPageTransform, false);
else if (window.attachEvent)
window.attachEvent("onresize", mainPageTransform);
}
/**
== LinkFA ==
Manambahakan bintang di InterWiki
*/
if (LoadLinkFA == true) {
function LinkFA()
{
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) && InterwikiLinks[i].className.indexOf( "badge-featuredarticle" ) === -1 ) {
InterwikiLinks[i].className += " FA";
InterwikiLinks[i].title = "Ini adalah artikal pilihan pada bahasa lain.";
}
}
}
}
$( LinkFA );
}
/**
== Tautan luar pilihan ==
Manandai tautan luar pilihan. Guna'akan citajan {{tl|extlink-fa}} di depan atawa uncitan tautan luar. Ini akan mambariakan suatu objek "span" kusung nang akan dipinandui ulih JavaScript nang akan maubah style bulletnya.
*/
function linkExtLinkFA() {
oSpans = document.getElementById( "bodyContent" ).getElementsByTagName( "span" );
for ( var i = 0; i < oSpans.length; i++ ) {
if ( oSpans[i].className == 'extlink-fa' ) {
var oParent = oSpans[i].parentNode;
if ( oParent.tagName == 'LI' ) {
oParent.className += ' FA';
oParent.title = 'Tautan pilihan';
}
}
}
}
$( linkExtLinkFA );
/**
== InterProject ==
InterProject, link di menu samping untuk proyek lain.
<nowiki> */
if (LoadInterProject == true) {
mw.util.addCSS('#interProyek {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}');
function iProject() {
if (document.getElementById("interProyek")) {
var iProject = document.getElementById("interProyek").innerHTML;
var interProject = document.createElement("div");
interProject.style.marginTop = "0.7em";
interProject.innerHTML = '<h5>Proyek lain<\/h5><div class="pBody">'+iProject+'<\/div>';
document.getElementById("p-tb").appendChild(interProject);
}
}
$(iProject);
}
/* </nowiki> */
/**
== CollapsibleTable ==*/
var autoCollapse = 2;
var collapseCaption = "sungkupakan";
var expandCaption = "tampaiakan";
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
function collapseTable( tableIndex )
{
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = "collapseButton"; //Styles are declared in Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
$( createCollapseButtons );
/* End of CollapsibleTable */
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var isCollapsed = hasClass( NavFrame, "collapsed" );
/*
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if ( NavChild.style.display == 'none' ) {
isCollapsed = true;
}
}
}
if (isCollapsed) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(var j=0; j < NavFrame.childNodes.length; j++) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
$( createNavigationBarToggleButton );
/**
== Portlet tambahan ==
=== Jumlah babakan ===
*/
function addEditcountPortlet() {
if ( document.getElementById("t-contributions") ) {
var sServer = 'idwiki';
switch ( wgServer ) {
case 'http://id.wikibooks.org':
sServer = 'idwikibooks';
break;
case 'http://id.wiktionary.org':
sServer = 'idwiktionary';
break;
case 'http://id.wikiquote.org':
sServer = 'idwikiquote';
break;
case 'http://id.wikisource.org':
sServer = 'idwikisource';
break;
}
var sText = 'Statistik pamuruk';
var sLink = 'http://toolserver.org/~soxred93/count/index.php?&lang=id&wiki=wikipedia&uselang=id' +
'&name=' + wgTitle;
mw.util.addPortletLink( 'p-tb', sLink, sText, 't-editcount',
'Jumlah babakan pamuruk', null, document.getElementById( 't-contributions' ).nextSibling );
}
}
$( addEditcountPortlet );
/**
=== Sunting bagian 0 ===
*/
function addEdittopPortletLink() {
if(wgCanonicalNamespace == 'Special') return;
if(document.getElementById("wikiPreview")) return;
if(document.getElementById("histlegend")) return;
if(document.getElementById("difference")) return;
if(document.getElementById("watchdetails")) return;
if ( document.getElementById( "ca-edit" ) ) {
var sElm = document.getElementById( "ca-addsection" ) ? 'ca-addsection' : 'ca-edit';
var sText = '↑';
var sLink = wgScriptPath + "/index.php?title=" + wgPageName +
"&action=edit§ion=0";
mw.util.addPortletLink( 'p-cactions', sLink, sText, 'ca-edittop',
'Suntingan bagian atas halaman ini', null, document.getElementById( sElm ).nextSibling );
}
}
$( addEdittopPortletLink );
/**
=== Notice di [[Wikipidia:Bak pasir]] dan [[Pamandiran Wikipidia:Bak pasir]] ===
*/
function sandboxNotice() {
notice = document.createElement('div');
document.getElementById('bodyContent').insertBefore(notice, document.getElementById('jump-to-nav').nextSibling);
noticeLoader = sajax_init_object();
noticeLoader.open('GET', '//id.wikipedia.org/w/index.php?title=Templat:Bakpasir&action=render', true);
noticeLoader.onreadystatechange = function()
{
if (noticeLoader.readyState == 4 && noticeLoader.status == 200) {
notice.innerHTML = noticeLoader.responseText;
}
};
noticeLoader.send('');
}
if (wgAction.match(/view|edit|submit/)) {
$(function() {
if (document.getElementsByTagName('body')[0].className.match(/page-(Pamandiran_)?Wikipidia_Bak_pasir/)) {
return sandboxNotice();
}
});
}
/** Magic editintros ****************************************************
*
* Description: Adds editintros on disambiguation pages and BLP pages.
* Maintainers: [[User:RockMFR]]
*/
function addEditIntro(name)
{
var el = document.getElementById('ca-edit');
if (!el)
return;
el = el.getElementsByTagName('a')[0];
if (el)
el.href += '&editintro=' + name;
}
if (wgNamespaceNumber == 0) {
$(function(){
if (document.getElementById('disambigbox'))
addEditIntro('Template:Disambig_editintro');
});
$(function(){
var cats = document.getElementById('mw-normal-catlinks');
if (!cats)
return;
cats = cats.getElementsByTagName('a');
for (var i = 0; i < cats.length; i++) {
if (cats[i].title == 'Category:Living people' || cats[i].title == 'Category:Possibly living people') {
addEditIntro('Template:BLP_editintro');
break;
}
}
});
}
/** WikiMiniAtlas *******************************************************
*
* Description: WikiMiniAtlas is a popup click and drag world map.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Maintainers: [[User:Dschwen]]
*/
mw.loader.load("//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript")