Join the PidgiNet Discord! https://discord.gg/Eg9QahqpXf
MediaWiki:Common.js
on PidgiWiki, the video game media repository
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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */ /* Automatically add Aboutfile in file-description by running a script. Source: http://www.mariowiki.com/wiki/MediaWiki:Common.js */ if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { function loadAutoAboutfileTemplate() { uploadDescription = document.getElementById('wpUploadDescription'); var doubleBracket = '{' + '{'; uploadDescription.value = doubleBracket + 'info\n|description=\n|game=\n|event=\n|season=\n|movie=\n|set=\n|series=\n|subseries=\n|characters=\n|system=\n|language=\n|artist=\n|style=\n|purpose=\n|source=\n|sourcelink=\n}}'; } addOnloadHook(loadAutoAboutfileTemplate); } /** * Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See * [[Wikipedia:NavFrame]]. * Maintainers: [[User:R. Koot]] */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; window.collapseTable = function ( tableIndex ) { var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; } var Rows = Table.rows; var i; if ( Button.firstChild.data === collapseCaption ) { for ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; } Button.firstChild.data = expandCaption; } else { for ( 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' ); var i; function handleButtonLink( index, e ) { window.collapseTable( index ); e.preventDefault(); } for ( i = 0; i < Tables.length; i++ ) { if ( $( Tables[i] ).hasClass( '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', '#' ); $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) ); Header.insertBefore( Button, Header.firstChild ); tableIndex++; } } for ( i = 0; i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) { window.collapseTable( i ); } else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; } } } } } $( createCollapseButtons ); /*Q*/ $(".header").click(function () { $header = $(this); //getting the next element $content = $header.next(); //open up the content needed - toggle the slide- if visible, slide up, if not slidedown. $content.slideToggle(500, function () { //execute this after slideToggle is done //change text of header based on visibility of content div $header.text(function () { //change text based on condition }); }); }); /** * SVG images: adds links to rendered PNG images in different resolutions * * @author Krinkle, 2012-2013 * @deprecated in 1.18 */ function SVGThumbs() { function svgAltSize(w, title) { var path, a; // Example: // - https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png // - https://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Example.png/116px-Example.png // - https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Gerrit_patchset_25838_test.svg/200px-Gerrit_patchset_25838_test.svg.png // - https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Gerrit_patchset_25838_test.svg/langde-200px-Gerrit_patchset_25838_test.svg.png path = thumbu.replace(/\/(lang[a-z-]+-)?\d+(px-[^\/]+$)/, '/$1' + w + '$2'); a = document.createElement('A'); a.setAttribute('href', path); a.appendChild(document.createTextNode(title)); return a; } var file = document.getElementById('file'); // might fail if MediaWiki can't render the SVG if (file && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgTitle' ).match(/\.svg$/i)) { var thumbu = jQuery(file).find('img:first').attr('src'); if (!thumbu) { return; } var p = document.createElement('p'); p.className = 'SVGThumbs'; var i18n = { 'be-tarask': 'Гэтая выява ў фармаце PNG у іншых памерах: ', 'be-x-old': 'Гэтая выява ў фармаце PNG у іншых памерах: ', bn: 'এই চিত্রটি অন্যান্য প্রস্থের মধ্যে PNG হিসেবে রূপান্তরিত: ', en: 'This image rendered as PNG in other widths: ', eo: 'Ĉi tiu bildo en la aranĝo PNG kun aliaj larĝoj: ', de: 'Dieses Bild im PNG-Format in folgenden Breiten: ', cs: 'Tento obrázek jako PNG v jiné velikosti: ', cy: 'Caiff y ddelwedd hon ei chynhyrchu mewn PNG yn y lled canlynol: ', fa: 'رندر پی\u200cان\u200cجی این تصویر در اندازه\u200cهای دیگر: ', fr: 'Cette image restituée en PNG dans d’autres tailles : ', hr: 'Prikaži sliku u PNG formatu u ostalim veličinama: ', hy: 'Այս պատկերը մատուցված որպես ՓիԷնՋի այլ լայնքերով՝ ', id: 'Gambar ini dijadikan PNG dengan lebar berbeda: ', ja: 'この画像の PNG 版は他のサイズでも利用可能です:', min: 'Gambar ko dijadian PNG jo leba babedo: ', ml: 'ഈ ചിത്രം PNG ആയി ലഭ്യമാകുന്ന മറ്റ് വലിപ്പങ്ങൾ: ', mk: 'Сликава како PNG во други големини: ', nl: 'Deze afbeelding als PNG in andere groottes: ', pt: 'Esta imagem renderizada como PNG em outros tamanhos: ', 'pt-br': 'Esta imagem renderizada como PNG em outros tamanhos: ', sl: 'Prikaži to sliko v PNG-zapisu v drugih velikostih: ', sv: 'Denna bild i PNG-format i olika storlekar: ', vi: 'Hình này được kết xuất ở dạng PNG có chiều ngang khác: ', 'zh-hans': '该图像转换为PNG格式的其他尺寸:', 'zh-hant': '該圖像轉換為PNG格式的其他尺寸:' }; var ptext = i18n[mw.config.get( 'wgUserLanguage' )] || i18n.en; p.appendChild(document.createTextNode(ptext)); var l = [200, 500, 800, 1000, 1500, 2000]; for (var i = 0; i < l.length; i++) { p.appendChild(svgAltSize(l[i], l[i] + 'px')); if (i < l.length - 1) { p.appendChild(document.createTextNode(', ')); } } p.appendChild(document.createTextNode('.')); var info = $(file.parentNode).find('div.fullMedia').get(0); if (info) { info.appendChild(p); } } } $(SVGThumbs);