Järjestelmäviesti:Common.js
Star Wars Fanon Wikistä
Siirry navigaatioonSiirry hakuunHuomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.
- Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
- Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
- Internet Explorer: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
- Opera: Valikko → Asetukset (Opera → Asetukset Macilla) ja sitten Tietosuoja ja turvallisuus → Tyhjennä selaustiedot → Välimuistissa olevat kuvat ja tiedostot.
/* <pre><nowiki> */
/* global $, ActiveXObject, mw */
/* If you need help with these JS functions (i.e. you want some features, like standard summaries, for your own wiki), please ask [[User:Jack Phoenix|Jack Phoenix]]. */
// onload stuff
var firstRun = true;
function loadFunc() {
if ( firstRun ) {
firstRun = false;
} else {
return;
}
window.pageName = mw.config.get( 'wgPageName' );
window.storagePresent = ( typeof localStorage != 'undefined' );
// DEPRECATED
if ( document.getElementById( 'infoboxinternal' ) !== null && document.getElementById( 'infoboxend' ) !== null ) {
document.getElementById( 'infoboxend' ).innerHTML = '<a id="infoboxtoggle" href="javascript:infoboxToggle()">[Piilota]</a>';
}
// Upload form - need to run before adding hide buttons
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
setupUploadForm();
}
addHideButtons();
if ( document.getElementById( 'mp3-navlink' ) !== null ) {
document.getElementById( 'mp3-navlink' ).onclick = onArticleNavClick;
document.getElementById( 'mp3-navlink' ).getElementsByTagName( 'a' )[0].href = 'javascript:void(0)';
}
if ( window.storagePresent ) {
initVisibility();
}
fillEditSummaries();
fillPreloads();
substUsername();
substUsernameTOC();
rewriteTitle();
showEras( 'title-eraicons' );
showEras( 'title-shortcut' );
rewriteHover();
checkblock();
hideContentSub();
if ( typeof onPageLoad != 'undefined' ) {
onPageLoad();
}
}
function infoboxToggle() {
var page = window.pageName.replace( /\W/g, '_' );
var nowShown;
if ( document.getElementById( 'infoboxtoggle' ).innerHTML == '[Piilota]' ) {
document.getElementById( 'infoboxinternal' ).style.display = 'none';
document.getElementById( 'infoboxtoggle' ).innerHTML = '[Näytä]';
nowShown = false;
} else {
document.getElementById( 'infoboxinternal' ).style.display = 'block';
document.getElementById( 'infoboxtoggle' ).innerHTML = '[Piilota]';
nowShown = true;
}
if ( window.storagePresent ) {
localStorage.setItem( 'infoboxshow-' + page, nowShown );
}
}
/**
* jQuery version of Sikon's fillEditSummaries
* @author Grunny
*/
function fillEditSummaries() {
if ( !$( '#wpSummaryLabel' ).length ) {
return;
}
$.get( mw.config.get( 'wgScript' ), { title: 'Malline:Yhteenvedot', action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
var $summaryOptionsList,
$summaryLabel = $( '#wpSummaryLabel' ),
lines = data.split( '\n' ),
$wrapper = $( '<div>').addClass( 'edit-widemode-hide' ).text( 'Yleiset yhteenvedot: ' );
$summaryOptionsList = $( '<select />' ).attr( 'id', 'stdEditSummaries' ).change( function() {
var editSummary = $( this ).val();
if ( editSummary !== '' ) {
$( '#wpSummaryWidget input[name="wpSummary"]' ).val( editSummary );
}
} );
for ( var i = 0; i < lines.length; i++ ) {
var editSummaryText = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : '';
$summaryOptionsList.append( $( '<option>' ).val( editSummaryText ).text( lines[i] ) );
}
$summaryLabel.prepend( $wrapper.append( $summaryOptionsList ) );
} );
}
/**
* jQuery version of Sikon's fillPreloads
* @author Grunny
*/
function fillPreloads() {
if ( !$( '#lf-preload' ).length ) {
return;
}
$( '#lf-preload' ).attr( 'style', 'display: block' );
$.get( mw.config.get( 'wgScript' ), { title: 'Malline:Stdpreloads', action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
var $preloadOptionsList,
lines = data.split( '\n' );
$preloadOptionsList = $( '<select />' ).attr( 'id', 'stdSummaries' ).change( function() {
var templateName = $( this ).val();
if ( templateName !== '' ) {
templateName = 'Malline:' + templateName + '/preload';
templateName = templateName.replace( ' ', '_' );
$.get( mw.config.get( 'wgScript' ), { title: templateName, action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
} );
for ( var i = 0; i < lines.length; i++ ) {
var templateText = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : '';
$preloadOptionsList.append( $( '<option>' ).val( templateText ).text( lines[i] ) );
}
$( '#lf-preload-cbox' ).html( $preloadOptionsList );
} );
$( '#lf-preload-pagename' ).html( '<input type="text" class="textbox" />' );
$( '#lf-preload-button' ).html( '<input type="button" class="button" value="Insert" onclick="doCustomPreload()" />' );
}
function doCustomPreload() {
var value = $( '#lf-preload-pagename > input' ).val();
value = value.replace( ' ', '_' );
$.get( mw.config.get( 'wgScript' ), { title: value, action: 'raw', ctype: 'text/plain' } ).done( function( data ) {
insertAtCursor( document.getElementById( 'wpTextbox1' ), data );
} );
}
/* Stores the (unmodified) page title. */
function storePageName() {
if ( mw.config.get( 'skin' ) == 'monobook' || mw.config.get( 'skin' ) == 'vector' ) {
window.pageName = $( 'h1#firstHeading span' ).text();
} else if ( mw.config.get( 'skin' ) == 'bluecloud' || mw.config.get( 'skin' ) == 'eminence' || mw.config.get( 'skin' ) == 'monaco' ) {
window.pageName = $( 'h1.firstHeading' ).text();
} else if ( mw.config.get( 'skin' ) == 'games' || mw.config.get( 'skin' ) == 'nimbus' || mw.config.get( 'skin' ) == 'sports' ) {
window.pageName = $( 'h1.pagetitle' ).text();
} else if ( mw.config.get( 'skin' ) == 'hope' ) {
window.pageName = $( 'h2#one' ).text();
} else if ( mw.config.get( 'skin' ) == 'modern' ) {
window.pageName = $( 'h1#firstHeading span' ).text();
} else if ( mw.config.get( 'skin' ) == 'truglass' ) {
window.pageName = $( 'h1#title' ).text();
}
}
/* Adds a trim method to string variables. */
String.prototype.trim = function() {
return this.replace( /^\s+|\s+$/g, '' );
};
/* Searches an array for an element and returns its index, or -1 if it's not in the array. */
function arrayFind( array, value ) {
for ( var i = 0; i < array.length; i++ ) {
if ( array[i] == value ) {
return i;
}
}
return -1;
}
/* Removes the first occurrence of an element in an array, if it is there. */
function arrayRemove( array, value ) {
var i = arrayFind( array, value );
if ( i != -1 ) {
array.splice( i, 1 );
}
}
/*
the ContentLoader class to encapsulate "creative differences" with XHR
Usage:
- construct a ContentLoader object: var loader = new ContentLoader();
- set necessary state parameters (via fields); e.g. loader.myvar = 'mytext';
- set the callback: loader.callback = myfunc;
- send the request:
loader.send(url, postdata = null, contentType = 'application/x-www-form-urlencoded');
(if postdata isn't null or omitted, POST is used, otherwise GET)
- the callback function is called when the content is loaded
- the ContentLoader object is this
- the raw response data is this.text
- the XML DOM object, if any, is this.document
*/
function ContentLoader() {
this.cache = true;
}
ContentLoader.prototype.enableCache = function( caching ) {
this.cache = ( caching === null ) ? true : this.cache;
};
ContentLoader.prototype.createRequest = function() {
if ( typeof XMLHttpRequest != 'undefined' ) {
return new XMLHttpRequest();
} else if ( typeof ActiveXObject != 'undefined' ) {
return new ActiveXObject( 'Msxml2.XMLHTTP' );
}
return null;
};
ContentLoader.prototype.send = function( url, postdata, contentType ) {
var method = ( postdata === null ) ? 'GET' : 'POST';
this.request = this.createRequest();
this.request.open( method, url );
if ( !this.cache ) {
this.request.setRequestHeader( 'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT' );
}
var request = this.request;
var loader = this;
if ( postdata === null ) {
if ( contentType === null ) {
contentType = 'application/x-www-form-urlencoded';
}
request.setRequestHeader( 'Content-type', contentType );
}
var f = function() {
if ( request.readyState == 4 ) {
loader.text = request.responseText;
loader.document = request.responseXML;
request = null;
loader.request = null;
loader.callback();
}
};
this.request.onreadystatechange = f;
this.request.send( postdata );
};
/* end ContentLoader */
/*
Source: http://www.dustindiaz.com/getelementsbyclass/
getElementsByClass, which complements getElementById and getElementsByTagName, returns an array of all subelements of ''node'' that are tagged with a specific CSS class (''searchClass'') and are of the tag name ''tag''. If tag is null, it searches for any suitable elements regardless of the tag name.
Example: getElementsByClass('infobox', document.getElementById('content'), 'div') selects the same elements as the CSS declaration #content div.infobox
*/
function ClassTester( className ) {
this.regex = new RegExp( "(^|\\s)" + className + "(\\s|$)" );
}
ClassTester.prototype.isMatch = function( element ) {
return this.regex.test( element.className );
};
function getElementsByClass( searchClass, node, tag ) {
var classElements = [];
if ( node === null || node === undefined ) {
node = document;
}
if ( tag === null ) {
tag = '*';
}
var els = node.getElementsByTagName( tag );
var elsLen = els.length;
var tester = new ClassTester( searchClass );
var i, j;
for ( i = 0, j = 0; i < elsLen; i++ ) {
if ( tester.isMatch( els[i] ) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
/* end getElementsByClass */
/*
Dynamically load a combobox's content by pagename (e. g. Template:Stdsummaries)
The page should be of the same format as http://starwars.wikia.com/wiki/Template:Stdsummaries
*/
function requestComboFill( id, page ) {
var loader = new ContentLoader();
loader.comboID = id;
loader.callback = onComboDataArrival;
loader.send( mw.config.get( 'wgScriptPath' ) + '/index.php?title=' + page + '&action=raw&ctype=text/plain' );
}
function onComboDataArrival() {
fillCombo( this.text, this.comboID );
}
function fillCombo( text, comboid ) {
var combo = document.getElementById( comboid );
var lines = text.split( "\n" );
for ( var i = 0; i < lines.length; i++ ) {
var value = lines[i].indexOf( '-- ' ) === 0 ? lines[i].substring( 3 ) : '';
var option = document.createElement( 'option' );
option.setAttribute( 'value', value );
option.appendChild( document.createTextNode( lines[i] ) );
combo.appendChild( option );
}
}
/* end combo fill code */
/*
Loads the current source of the page "pagename" (as stored in the database)
and inserts it at the cursor position
*/
function doPreload( pagename ) {
var loader = new ContentLoader();
loader.callback = onPreloadArrival;
loader.send( mw.config.get( 'wgScriptPath' ) + '/index.php?title=' + pagename + '&action=raw&ctype=text/plain' );
}
function insertAtCursor( myField, myValue ) {
// IE support
if ( document.selection ) {
myField.focus();
var sel = document.selection.createRange();
sel.text = myValue;
} else if ( myField.selectionStart || myField.selectionStart == '0' ) { // MOZILLA/NETSCAPE support
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring( 0, startPos ) +
myValue +
myField.value.substring( endPos, myField.value.length );
} else {
myField.value += myValue;
}
}
function onPreloadArrival() {
insertAtCursor( document.getElementById( 'wpTextbox1' ), this.text );
}
/* end preload code */
/* Returns h1.firstHeading (the page title element). */
function getFirstHeading() {
var elements = getElementsByClass( 'firstHeading', document.getElementById( 'content' ), 'h1' );
return ( elements !== null && elements.length > 0 ) ? elements[0] : null;
}
/* Returns the element's nearest parent that has the specified CSS class. */
function getParentByClass( className, element ) {
var tester = new ClassTester( className );
var node = element.parentNode;
while ( node !== null && node != document ) {
if ( tester.isMatch( node ) ) {
return node;
}
node = node.parentNode;
}
return null;
}
/*
Replaces {{USERNAME}} with the name of the user browsing the page.
Requires copying Template:USERNAME.
*/
function substUsername() {
var userpage = document.getElementById( 'pt-userpage' );
if ( !userpage ) {
return;
}
var username = userpage.firstChild.innerHTML;
var spans = getElementsByClass( 'insertusername', document.getElementById( 'content' ), 'span' );
for ( var i = 0; i < spans.length; i++ ) {
spans[i].innerHTML = username;
}
}
/*
Performs dynamic hover class rewriting to work around the IE6 :hover bug
(needs CSS changes as well)
*/
function rewriteHover() {
var gbl = document.getElementById( 'hover-global' );
if( gbl === null ) {
return;
}
var nodes = getElementsByClass( 'hoverable', gbl );
for ( var i = 0; i < nodes.length; i++ ) {
nodes[i].onmouseover = function() {
this.className += ' over';
};
nodes[i].onmouseout = function() {
this.className = this.className.replace( new RegExp( " over\\b" ), '' );
};
}
}
/* Force preview for anons */
/* by Marc Mongenet, 2006, fr.wikipedia */
function forcePreview() {
if ( mw.config.get( 'wgUserName' ) !== null || mw.config.get( 'wgAction' ) != 'edit' ) {
return;
}
var saveButton = document.getElementById( 'wpSave' );
if ( !saveButton ) {
return;
}
saveButton.disabled = true;
saveButton.value = 'Tallenna sivu (esikatsele muokkauksiasi ensiksi)';
saveButton.style.fontWeight = 'normal';
document.getElementById( 'wpPreview' ).style.fontWeight = 'bold';
}
$( forcePreview );
/* End of forcePreview */
// ============================================================
// BEGIN JavaScript title rewrite
function rewriteTitle() {
if ( typeof window.SKIP_TITLE_REWRITE != 'undefined' && window.SKIP_TITLE_REWRITE ) {
return;
}
var titleDiv = document.getElementById( 'title-meta' );
if ( titleDiv === null ) {
return;
}
var cloneNode = titleDiv.cloneNode( true );
var firstHeading = getFirstHeading();
var node = firstHeading.childNodes[0];
// new, then old!
firstHeading.replaceChild( cloneNode, node );
cloneNode.style.display = 'inline';
var titleAlign = document.getElementById( 'title-align' );
firstHeading.style.textAlign = titleAlign.childNodes[0].nodeValue;
}
function showEras( className ) {
if ( typeof window.SKIP_ERAS != 'undefined' && window.SKIP_ERAS ) {
return;
}
var titleDiv = document.getElementById( className );
if ( titleDiv === null || titleDiv === undefined ) {
return;
}
var cloneNode = titleDiv.cloneNode( true );
var firstHeading = getFirstHeading();
firstHeading.insertBefore( cloneNode, firstHeading.childNodes[0] );
cloneNode.style.display = 'block';
}
// END JavaScript title rewrite
function initVisibility() {
var page = window.pageName.replace( /\W/g, '_' );
var show = localStorage.getItem( 'infoboxshow-' + page );
if ( show == 'false' ) {
infoboxToggle();
}
var hidables = getElementsByClass( 'hidable' );
for ( var i = 0; i < hidables.length; i++ ) {
show = localStorage.getItem('hidableshow-' + i + '_' + page);
var content, button;
if ( show == 'false' ) {
content = getElementsByClass( 'hidable-content', hidables[i] );
button = getElementsByClass( 'hidable-button', hidables[i] );
if (
content !== null && content.length > 0 &&
button !== null && button.length > 0 &&
content[0].style.display != 'none'
)
{
button[0].onclick( 'bypass' );
}
} else if ( show == 'true' ) {
content = getElementsByClass( 'hidable-content', hidables[i] );
button = getElementsByClass( 'hidable-button', hidables[i] );
if (
content !== null && content.length > 0 &&
button !== null && button.length > 0 &&
content[0].style.display == 'none'
)
{
button[0].onclick( 'bypass' );
}
}
}
}
function onArticleNavClick() {
var div = document.getElementById( 'mp3-nav' );
if ( div.style.display == 'block' ) {
div.style.display = 'none';
} else {
div.style.display = 'block';
}
}
function addHideButtons() {
var hidables = getElementsByClass( 'hidable' );
for ( var i = 0; i < hidables.length; i++ ) {
var box = hidables[i];
var button = getElementsByClass( 'hidable-button', box, 'span' );
if ( button !== null && button.length > 0 ) {
button = button[0];
button.onclick = toggleHidable;
button.appendChild( document.createTextNode( '[Piilota]' ) );
if ( new ClassTester( 'start-hidden' ).isMatch( box ) ) {
button.onclick( 'bypass' );
}
}
}
}
function toggleHidable( bypassStorage ) {
var parent = getParentByClass( 'hidable', this );
var content = getElementsByClass( 'hidable-content', parent );
var nowShown;
if ( content !== null && content.length > 0 ) {
content = content[0];
if ( content.style.display == 'none' ) {
content.style.display = content.oldDisplayStyle;
this.firstChild.nodeValue = '[Piilota]';
nowShown = true;
} else {
content.oldDisplayStyle = content.style.display;
content.style.display = 'none';
this.firstChild.nodeValue = '[Näytä]';
nowShown = false;
}
if ( window.storagePresent && ( typeof bypassStorage == 'undefined' || bypassStorage != 'bypass' ) ) {
var page = window.pageName.replace( /\W/g, '_' );
var items = getElementsByClass( 'hidable' );
var item = -1;
for ( var i = 0; i < items.length; i++ ) {
if ( items[i] == parent ) {
item = i;
break;
}
}
if ( item == -1 ) {
return;
}
localStorage.setItem('hidableshow-' + item + '_' + page, nowShown);
}
}
}
function substUsernameTOC() {
var toc = $( '#toc' );
var userpage = $( '#pt-userpage' );
if ( !userpage || !toc ) {
return;
}
var username = $( '#pt-userpage' ).children( ':first-child' ).text();
$( 'span.toctext:not(:has(*)), span.toctext i', toc ).each( function() {
$( this ).text( $( this ).text().replace( '<insert name here>', username ) );
} );
}
$( loadFunc );
function checkblock() {
if ( mw.util.getParamValue( 'submitblock' ) == 'true' && document.getElementById( 'blockip' ) ) {
document.getElementById( 'blockip' ).wpBlock.click();
}
}
/**
* Start upload form customisations
* @author Green tentacle
*/
function setupUploadForm() {
// Check if cookie has been set for form style. Overrides URL parameter if set.
var formstyle = localStorage.getItem( 'uploadform' );
$( '#uploadBasicLinkJS' ).show();
$( '#uploadTemplateNoJS' ).hide();
var wpLicense = $( '#wpLicense' );
if ( wpLicense.length && window.location.search.indexOf( 'wpForReUpload=1' ) == -1 ) {
if (
formstyle == 'guided' ||
( formstyle === '' && window.location.search.indexOf( 'basic=true' ) == -1 )
)
{
// Add link to basic form
$( '#uploadtext' ).prepend( '<div style="float: right;" id="uploadBasicLinkJS"><a href="' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/index.php?title=Toiminnot:Tallenna&basic=true" onclick="javascript:localStorage.setItem(\'uploadform\', \'basic\')">Vaihda tavalliseen tallennukseen</a></div>' );
// Stretch table to full width
$( '#mw-htmlform-description' ).css( 'width', '100%' );
// Bind upload button to verify function
$( '#mw-upload-form' ).bind( 'submit', verifySummary );
// Hide existing rows
var rows = $( '#mw-htmlform-description' ).find( 'tr' );
$( 'tr.mw-htmlform-field-HTMLTextAreaField' ).hide();
$( 'tr.mw-htmlform-field-HTMLTextAreaField' ).next().detach();
$( '#mw-htmlform-description' ).addClass( 'hidable start-hidden' );
// Add new required rows
rows.eq( 1 ).after( '<tr><td class="mw-label" style="width: 125px;">Lähde:</td><td class="mw-input"><textarea id="sourceBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
$( '#mw-htmlform-description' ).append( '<tbody class="hidable-content"></tbody>' );
var tbody1 = $( '#mw-htmlform-description' ).children( 'tbody' ).eq( 0 );
tbody1.append( '<tr><td class="mw-label" style="width: 125px;">Kuvaus:</td><td class="mw-input"><textarea id="descriptionBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody1.append( '<tr><td colspan="2" style="text-align: center;">Valinnaiset kentät <span class="hidable-button"></span></td></tr>' );
// Add new optional rows
var tbody2 = $( '#mw-htmlform-description' ).children( 'tbody' ).eq( 1 );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Huomio:</td><td class="mw-input"><textarea id="attentionBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Alkuperäinen tekijä / artisti:</td><td class="mw-input"><textarea id="artistBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Muut versiot:</td><td class="mw-input"><textarea id="versionsBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
tbody2.append( '<tr><td class="mw-label" style="width: 125px;">Luokat:</td><td class="mw-input"><textarea id="catBox" cols="60" rows="2" style="overflow: auto;"></textarea></td></tr>' );
} else {
// Old style form just needs Information template in the summary box
$( '#wpUploadDescription' ).val( '{{Tiedot\r\n|huomio=\r\n|kuvaus=\r\n|lähde=\r\n|tekijä=\r\n|lisenssi=\r\n|muut versiot=\r\n}}' );
// Add link to guided form
$( '#uploadtext' ).prepend( '<div style="float: right;" id="uploadBasicLinkJS"><a href="' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/index.php?title=Toiminnot:Tallenna" onclick="javascript:localStorage.setItem(\'uploadform\', \'guided\')">Vaihda ohjattuun tallennukseen</a></div>' );
$( '#mw-upload-form' ).bind( 'submit', verifyName );
}
}
}
function verifySummary() {
var wpLicense = document.getElementById( 'wpLicense' );
var wpDestFile = document.getElementById( 'wpDestFile' );
// Check for licensing
if ( wpLicense.value === '' ) {
alert( 'Lisenssi on merkittävä.' );
return false;
}
// Check for source
if ( document.getElementById( 'sourceBox' ).value === '' ) {
alert( 'Lähde on merkittävä.' );
return false;
}
// Check for duplicated or capitalized file extensions
if ( wpDestFile.value.match( /(JPG|PNG|GIF|SVG|jpg\.jpg|png\.png|gif\.gif|svg\.svg)$/ ) ) {
alert( 'Älä käytä isokirjaimisia tai kaksinkertaisia tiedostopäätteitä tiedoston nimessä.' );
return false;
}
var strBuilder = '{{Tiedot\r\n';
strBuilder += '|huomio=' + document.getElementById( 'attentionBox' ).value + '\r\n';
strBuilder += '|kuvaus=' + document.getElementById( 'descriptionBox' ).value + '\r\n';
strBuilder += '|lähde=' + document.getElementById( 'sourceBox' ).value + '\r\n';
strBuilder += '|tekijä=' + document.getElementById( 'artistBox' ).value + '\r\n';
strBuilder += '|lisenssi=' + wpLicense.options[wpLicense.selectedIndex].title + '\r\n';
strBuilder += '|muut versiot=' + document.getElementById( 'versionsBox' ).value + '\r\n';
strBuilder += '|luokat=' + document.getElementById( 'catBox' ).value + '\r\n';
strBuilder += '}}';
document.getElementById( 'wpUploadDescription' ).value = strBuilder;
wpLicense.selectedIndex = 0;
return true;
}
function verifyName() {
var wpDestFile = document.getElementById( 'wpDestFile' );
var wpLicense = document.getElementById( 'wpLicense' );
// Check for duplicated or capitalized file extensions
if ( wpDestFile.value.match( /(JPG|PNG|GIF|SVG|jpg.jpg|png.png|gif.gif|svg.svg)$/ ) ) {
alert( 'Älä käytä isokirjaimisia tai kaksinkertaisia tiedostopäätteitä tiedoston nimessä.' );
return false;
}
// Check for annoying characters
if ( wpDestFile.value.match( /(\(|\)|!|\?|,|\+|\'|\’)/ ) ) {
alert( 'Älä käytä erikoismerkkejä tiedoston nimessä.' );
return false;
}
if ( wpLicense.value !== '' ) {
$( '#wpUploadDescription' ).val(
$( '#wpUploadDescription' ).val().replace( '|lisenssi=', '|lisenssi=' + wpLicense.options[wpLicense.selectedIndex].title )
);
wpLicense.selectedIndex = 0;
}
return true;
}
/**
* End upload form customisations
*/
/** Archive edit tab disabling *************************************
* Disables the edit tab on old forum topic pages to stop noobs bumping old topics.
* Page can still be edited by going via the edit tab on the history etc, or by
* typing the edit address manually.
* By [[:en:User:Spang|Spang]]
* Monaco support by [[:en:User:Uberfuzzy|Uberfuzzy]]
* Removal of new section tab on talk pages added by [[:en:User:Grunny|Grunny]]
* Vector support by [[User:--miki--|--miki--]]
*/
function disableOldForumEdit() {
if ( typeof window.enableOldForumEdit != 'undefined' && window.enableOldForumEdit ) {
return;
}
if (
!document.getElementById( 'archive-page' ) ||
!document.getElementById( 'ca-edit' ) ||
mw.config.get( 'wgNamespaceNumber' ) === 10
)
{
return;
}
var editLink;
if ( mw.config.get( 'skin' ) == 'monaco' ) {
editLink = document.getElementById( 'ca-edit' );
} else if ( mw.config.get( 'skin' ) == 'monobook' || mw.config.get( 'skin' ) == 'vector' ) {
editLink = document.getElementById( 'ca-edit' ).firstChild;
}
editLink.removeAttribute( 'href', 0 );
editLink.removeAttribute( 'title', 0 );
editLink.style.color = 'gray';
editLink.innerHTML = 'Arkisto';
mw.util.addCSS( '#control_addsection, #ca-addsection { display: none !important; }' );
}
$( disableOldForumEdit );
/**
* Konami Code JavaScript from http://snipplr.com/view/15785/jquery-konami-code-listener/
* Some fixes & MediaWikification by Jack Phoenix <jack@countervandalism.net>
* @date February 5, 2010
*/
function konamiCode() {
var kkeys = [],
// up, up, down, down, left, right, left, right, B, A
konami = '38,38,40,40,37,39,37,39,66,65';
$( document ).on( 'keydown', function( e ) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
var logoURL = 'http://www.shoutwiki.com/w/Logo.png';
// Hide the current logo...
mw.util.addCSS( '#p-logo a { display: none !important; }' );
// ...and append the new one!
mw.util.addCSS( '#p-logo {' +
'background-image: url("' + logoURL + '") !important;' +
'background-repeat: no-repeat !important;' +
'background-position: 35% 50% !important;' +
'display: block !important;' +
'}' );
}
} );
}
$( konamiCode );
// Katso [[Foorumi:SH:Malline:Suositeltu]]
/* Magic edit intro. Copied from Wikipedia's MediaWiki:Common.js, modified for use in both Monaco and Monobook skins by Sikon */
function addEditIntro( name ) {
// Top link
var el = document.getElementById( 'ca-edit' );
if ( typeof el.href == 'undefined' ) {
el = el.getElementsByTagName( 'a' )[0];
}
if ( el ) {
el.href += '&editintro=' + name;
}
// Section links
var spans = document.getElementsByTagName( 'span' );
for ( var i = 0; i < spans.length; i++ ) {
el = null;
if ( spans[i].className == 'editsection' ) {
el = spans[i].getElementsByTagName( 'a' )[0];
if ( el ) {
el.href += '&editintro=' + name;
}
} else if ( spans[i].className == 'editsection-upper' ) {
el = spans[i].getElementsByTagName( 'a' )[0];
if ( el ) {
el.href += '&editintro=' + name;
}
}
}
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
$( function() {
var cats = document.getElementById( 'catlinks' );
if ( !cats ) {
return;
}
cats = cats.getElementsByTagName( 'a' );
for ( var i = 0; i < cats.length; i++ ) {
if ( cats[i].title === 'Luokka:Suositellut sivut' ) {
addEditIntro( 'Malline:Suositeltu sivu' );
break;
} else if ( cats[i].title === 'Luokka:Suositellut tarinat' ) {
addEditIntro( 'Malline:Suositeltu tarina' );
break;
}
}
} );
}
/**
* Hides the link to parent pages from subpages if {{HideContentSub}} is included
*/
function hideContentSub() {
if ( $( '#hideContentSub' ).length > 0 ) {
if ( $( '#contentSub span.subpages' ).text().substring( 0, 1 ) === '<' ) {
$( '#contentSub span.subpages' ).hide();
}
}
}
// </nowiki></pre>