MediaWiki:Common.js/preload.js

/* Template Preloads by User:Grunny Source - w:c:starwars:MediaWiki:Common.js  Import into Common.js */ function fillPreloads { if( !$( '#lf-preload' ).length ) { return; }	var	preloadOptionsHtml = '', $preloadOptionsList; $( '#lf-preload' ).attr( 'style', 'display: block' ); $.get( wgScript, { title: 'Template:Stdpreloads', action: 'raw', ctype: 'text/plain' }, function( data ) {		var lines = data.split( '\n' );		for( var i = 0; i < lines.length; i++ ) {			var value = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : "";			preloadOptionsHtml += '' + lines[i] + ' ';		}		$preloadOptionsList = $( ' ' ).attr( 'id', 'stdSummaries' ).html( preloadOptionsHtml ).change( function { var value = $( this ).val; if ( value !== '' ) { value = 'Template:' + value + '/preload'; value = value.replace( ' ', '_' ); $.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {					insertAtCursor( document.getElementById( 'wpTextbox1' ), data );				} ); }		} );		$( '#lf-preload-cbox' ).html( $preloadOptionsList );	} ); $( '#lf-preload-pagename' ).html( '' ); $( '#lf-preload-button' ).html( '' ); } $( fillPreloads ); function doCustomPreload { var value = $( '#lf-preload-pagename > input' ).val; value = value.replace( ' ', '_' ); $.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {		insertAtCursor( document.getElementById( 'wpTextbox1' ), data );	} ); } function insertAtCursor(myField, myValue) { //IE support if (document.selection) {		myField.focus; sel = document.selection.createRange; sel.text = myValue; }	//MOZILLA/NETSCAPE support else if(myField.selectionStart || myField.selectionStart == '0') {		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; } }