ผู้ใช้:Geonuch/common.js/InterProject.js
< ผู้ใช้:Geonuch | common.js
หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง
- ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
- กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
- อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
- โอเปร่า: กด Ctrl-F5
//<source lang="javascript">
/**
* Workaround for [[phabricator:T2708]] via [[Template:InterProject]].
* Originally based on code from [[wikt:de:MediaWiki:Common.js]] by
* [[wikt:de:User:Melancholie]], cleaned up and modified for compatibility
* with the Vector skin.
*
* This script is being used by several Wikimedia Wikis, not only Wikimedia
* Commons.
*
* Maintainers: [[User:Krinkle]], [[User:Ilmari Karonen]]
*/
$( function () {
// avoid double execution
if ( document.getElementById( 'p-interproject' ) ) return;
var interPr = document.getElementById( 'interProject' );
var sisterPr = document.getElementById( 'sisterProjects' );
if (!interPr) return;
var toolBox = document.getElementById( 'p-tb' );
var legacyPanel;
if (!toolBox) {
// legacy skins
var panelIds = [ 'mw-panel', 'panel', 'column-one', 'mw_portlets' ];
for (var i = 0; !legacyPanel && i < panelIds.length; i++) {
legacyPanel = document.getElementById(panelIds[i]);
}
// can't find a place for the portlet, try to undo hiding
if (!legacyPanel) {
mw.util.addCSS( '#interProject, #sisterProjects { display: block; }' );
return;
}
}
mw.util.addCSS( '#interProject, #sisterProjects { display: none; }' );
var interProject = document.createElement( 'div' );
interProject.id = 'p-interproject';
interProject.setAttribute( 'role', 'navigation' );
interProject.setAttribute( 'aria-labelledby', 'p-interproject-label' );
var toolsList = document.getElementById( 'p-tb-list' );
var flatList = document.getElementById( 'p-logo-text' );
if (!toolsList) {
interProject.className = (mw.user.options.get( 'skin' ) == 'vector' ? 'portal' : 'portlet' );
interProject.innerHTML =
'<h3 id="p-interproject-label">' +
( sisterPr && sisterPr.firstChild ? sisterPr.firstChild.innerHTML : 'Sister Projects' ) +
'</h3><div class="' + (mw.user.options.get( 'skin' ) == 'vector' ? 'body' : 'pBody' ) +'">' +
interPr.innerHTML + '</div>';
} else if (!flatList) {
interProject.className = 'portal';
interProject.innerHTML =
'<h3 tabindex="0" id="p-interproject-label">' +
'<a role="button" aria-expanded="false" aria-haspopup="true" aria-pressed="false" aria-controls="p-interproject-list" href="#">' +
( sisterPr && sisterPr.firstChild ? sisterPr.firstChild.innerHTML : 'Sister Projects' ) +
'</a></h3><div class="body">' + interPr.innerHTML + '</div>';
} else {
interProject.className = 'panel';
interProject.innerHTML =
'<div tabindex="0" class="panelLabel" id="p-interproject-label">' +
'<a tabindex="-1" class="a-icon-spacer" role="button" aria-haspopup="true" aria-controls="p-interproject-list" href="#">' +
'<i class="a-icon-container a-icon-arrow a-icon-transition" id="a-icon-toggle"></i>' +
( sisterPr && sisterPr.firstChild ? sisterPr.firstChild.innerHTML : 'Sister Projects' ) +
'</a></div><div class="body">' + interPr.innerHTML + '</div>';
}
if (legacyPanel) {
legacyPanel.appendChild(interProject);
} else {
$(toolBox).after(interProject);
}
var state = $.cookie( 'vector-nav-' + interProject.id );
if (toolsList && !flatList) {
if ( state === 'true' ) {
$(interProject).addClass( 'expanded' ).find( '.body, .pBody' ).show();
} else {
$(interProject).addClass( 'collapsed' );
}
}
} );
//</source>