Wikia

OnePiece Wiki Italia

Differenze: MediaWiki:Common.js/preloadTemplates.js

Visualizza sorgente

Ritorna alla pagina

m (Leviathan 89 ha spostato la pagina MediaWiki:Common.js/templatePreload.js a MediaWiki:Common.js/preloadTemplates.js senza lasciare redirect)
(+ missing function)
Riga 40: Riga 40:
 
}
 
}
 
$( customPreloadTemplates );
 
$( customPreloadTemplates );
  +
  +
/**
  +
* Inserts text at the cursor's current position
  +
* Originally from Wookieepedia
  +
*/
  +
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;
  +
}
  +
}

Versione delle 08:10, giu 27, 2013

// ================================
//     Custom preload templates
// ================================
/* @author Grunny 
   @version 0.0.1 
   From http://harrypotter.wikia.com/wiki/MediaWiki:Wikia.js
*/
 
function customPreloadTemplates() {
 
	if( wgAction !== 'edit' || !$( 'div.module_content' ).length ) {
		return;
	}
 
	var	preloadOptionsHtml = '',
		$preloadOptionsList;
 
	$( 'div.module_content:first' ).append( '<div id="lf-preload" style="display: block; padding: 10px;">Standard preloads:<br /></div>' );
 
	$.get( wgScript, { title: 'MediaWiki:PreloadTemplates', action: 'raw', ctype: 'text/plain' }, function( data ) {
		var lines = data.split( '\n' );
		for( var i in lines ) {
			var value = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : "";
			preloadOptionsHtml += '<option value="' + value + '">' + lines[i] + '</option>';
		}
		$preloadOptionsList = $( '<select />' ).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 );
				} );
			}
		} );
 
		$( 'div#lf-preload' ).append( $preloadOptionsList );
	} );
 
}
$( customPreloadTemplates );
 
/**
 * Inserts text at the cursor's current position
 * Originally from Wookieepedia
 */
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;
	}
}

Nella rete di Wikia

Una wiki a caso