Szerkesztő:B.Zsolt/repteres.js

A Wikipédiából, a szabad enciklopédiából

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
// -*- mode:javascript; coding:utf-8 -*-
(function() {
'use strict';

var $currentFocused;

function insertCharacter( e ) {
	e.preventDefault();
	var char = $( this ).data( 'mw-charinsert-start' );
	if ( $currentFocused.length ) {
		$currentFocused.textSelection(
			'encapsulateSelection', {
				pre: char,
				peri: '',
				post: ''
			}
		);
	}
}

function createCustomBar() {
	var insert = [


		[ '<small>repülőtér infobox</small>', '{'+'{repülőtér infobox'+"\n"+
	                                          '| kifutó szög 1       = '+"\n"+
                                              '| kifutó hossz 1      = '+"\n"+
                                              '| kifutó burkolat 1   = '+"\n"+
                                              '| kifutó szög 2       = '+"\n"+
                                              '| kifutó hossz 2      = '+"\n"+
                                              '| kifutó burkolat 2   = '+"\n"+
		                                      '}}' ],
		[ '<small>Jegyzetek</small>', '== Jegyzetek =='+"\n"
									+'{'+'{jegyzetek}}'],
		[ '<small>nemzetközi katalógusok</small>', '{'+'{nemzetközi katalógusok}}' ],
		[ '<small>személy infobox</small>', '{'+'{személy infobox}}' ],
		[ '<small>vasút fejléc</small>', '{'+'|'+'{'+'{Vasút fejléc}}' ],
		[ '<small>pagenamebase</small>', '{'+'{subst:PAGENAMEBASE}}' ],
		[ '<small>portál:vasút</small>', '{'+'{portál|Vasút}}' ],
	    [ '<small>portál:Filmművészet</small>', '{'+'{portál|Filmművészet|-|}}' ],
		[ '<small>ref-ek</small>', '<ref> </ref>'],
		[ '<small>nowiki</small>', '<nowiki> </nowiki>' ],
		[ '<small>járatok fordítása</small>', fixLatin1Chars ],
		[ '<small>navbox fordítása</small>', navbox ],
		[ '<small>USA település</small>',
'{'+'{hasonló}} <!-- Ha létezik egyértelműsítő lap -->'+"\n"+
'{'+'{Amerikai település infobox'+"\n"+
' | név = {'+'{subst:PAGENAMEBASE}}'+"\n"+
' | kép = '+"\n"+
' | képméret = '+"\n"+
' | képaláírás = '+"\n"+
' | zászló = '+"\n"+
' | pecsét = '+"\n"+
' | becenév = '+"\n"+
' | mottó = '+"\n"+
' | állam = '+"\n"+
' | megye = '+"\n"+
' | kerületei = '+"\n"+
' | rang = '+"\n"+
' | alapítás éve = '+"\n"+
' | alapítás éve forrás = '+"\n"+
' | kormányzati típus = '+"\n"+
' | vezető neve = '+"\n"+
' | vezető címe = '+"\n"+
' | irányítószám = '+"\n"+
' | körzethívószám = '+"\n"+
' | testvértelepülései = '+"\n"+
' | népsűrűség = '+"\n"+
' | népsűrűség forrás = '+"\n"+
' | tengerszint feletti magasság = '+"\n"+
' | terület = '+"\n"+
' | vízi terület = '+"\n"+
' | időzóna = '+"\n"+
' | térkép = '+"\n"+
' | térképméret = '+"\n"+
' | térképaláírás = '+"\n"+
' | weboldal = '+"\n"+
'}'+'}'+"\n"+
"\n"+
'\'\'\'{'+'{subst:PAGENAMEBASE}}\'\'\' település az [[Amerikai Egyesült Államok]] [[Arkansas]] államában, {{usamegye}}. {{lakosság}} {{határos|településekkel}}'+"\n"+
"\n"+
'==Népesség=='+"\n"+
'A település népességének változása:'+"\n"+
'{'+'{népességdiagram}}'+"\n"+
"\n"+
'==További információk=='+"\n"+
'{'+'{wikidatahivatalosoldal}}'+"\n"+
"\n"+
'==Jegyzetek=='+"\n"+
'{'+'{jegyzetek}}'+"\n"+
"\n"+
'{{USA megyeszékhelyek}}'+"\n"+
'{{Nemzetközi katalógusok}}'+"\n"+
'{{Portál|Földrajz||USA|-|}}'+"\n"+
'{{'+'csonk-USA település}}'+"\n"+
"\n"+
'[['+'Kategória:Arkansas megyeszékhelyei]]'
],
	];
	var $list = $( '<ul>' ).addClass( 'hlist' );
	$.each( insert, function () {
		var text = this[ 0 ],
			func = this[ 1 ],
			$a = $( '<a>' )
				.attr( 'href', '#' )
				.html( text );
		if ( typeof func === 'function' ) {
			$a.click( func );
		} else {
			$a.data( 'mw-charinsert-start', func );
			$a.click( insertCharacter );
		}
		// jQuery doesn't insert any whitespace between <li>s by default
		$list.append( ' ' );
		$( '<li>' )
			.append( $a )
			.appendTo( $list );
	} );
	var $boxDiv = $( '<div>' )
		.attr( 'id', 'customBar' )
		.append(
			$( '<a>' )
				.attr( 'href', '//hu.wikipedia.org/wiki/Wikipédia:Különleges_karakterek' )
				.attr( 'title', 'Wikipédia:Különleges karakterek' )
				.text( 'Sablonok, karakterek:' ),
			$list
		);
	return $boxDiv;
}

function replaceRegexp( replaceWhat, replaceWith, modifiers ) {
	if ( !modifiers ) modifiers = '';
	var pattern = new RegExp( replaceWhat, modifiers );
	var $textbox = $( '#wpTextbox1' );
	$textbox.val( $textbox.val().replace( pattern, replaceWith ) );
}
 
function replaceString( replaceWhat, replaceWith ) {
	var $textbox = $( '#wpTextbox1' );
	$textbox.val( $textbox.val().replaceAll( replaceWhat, replaceWith ) );
}

function fixLatin1Chars( e ) {
	e.preventDefault();
	
	//vasútállomásokhoz
	
	replaceString('Linie','Járat');
	replaceRegexp('Fahrtverlauf|Strecke|Verlauf','Útvonal');
	//replaceString('Verlauf','Útvonal');
	replaceRegexp('Taktfrequenz|Takt|Frequenz','Gyakoriság');
	replaceRegexp('Fahrzeuge im Regelbetrieb|Fahrzeugmaterial','Vasúti jármű');
	replaceString('Betreiber','Üzemeltető');
	replaceString('Zugnummer','Vonatszám');
	replaceString('{Anker','{horgony');
	replaceString('Baureihe',''); //sorozat, de ide regexp kell majd
	replaceString('viermal wöchentlich','négyszer hetente');
	replaceRegexp('Ein |ein ','egy ');
    replaceRegexp('Zwei |zwei ','két ');
	replaceRegexp('Drei |drei ','három ');
	replaceRegexp('Vier |vier ','négy ');
	replaceRegexp('Fünf |fünf ','öt ');
	replaceString('Stundentakt','óránként');
	replaceString('Zweistundentakt','kétóránként');
	replaceRegexp('Zugpaare|Zugpaar','vonatpár');
	replaceRegexp('stundentakt|Stundentakt','óránként');
	replaceString('täglich','naponta');
	replaceString('einzelne Züge','egyes vonatok');
	replaceString('am Wochenende','hétvégente');
}

function navbox( e ) {
	e.preventDefault();
	
	//navboxokhoz
	
	replaceString('name','név');
	replaceString('title','cím');
	replaceString('list','lista');
	replaceString('group','csoport');
	replaceString('|state = {{{state|autocollapse}}}','');
	replaceString('{{collapsible option}}','{{navboxdoc}}');
	replaceString('{{Collapsible option}}','{{navboxdoc}}');
	replaceString('[[Category:','[[Kategória:');	
	replaceString('listclass = hlist','listaosztály = hlist');
	replaceString('Airport','repülőtér');
	replaceString('International','nemzetközi');
	replaceString('Domestic','Belföldi');
	replaceString('Air base','légibázis');
	replaceString('below','alul');
//	replaceRegexp('Fahrtverlauf|Strecke|Verlauf','Útvonal');
}

function fixHungarianQuotes( e ) {
	e.preventDefault();
	replaceRegexp('"([^"]*)"', '„$1”', "mg");
}

function translateDatesEnHu( e ) {
	e.preventDefault();
	var months = [
		[ 'January', 'január' ],
		[ 'February', 'február' ],
		[ 'March', 'március' ],
		[ 'April', 'április' ],
		[ 'May', 'május' ],
		[ 'June', 'június' ],
		[ 'July', 'július' ],
		[ 'August', 'augusztus' ],
		[ 'September', 'szeptember' ],
		[ 'October', 'október' ],
		[ 'November', 'november' ],
		[ 'December', 'december' ]
	];

	$.each( months, function () {
		var enMonth = this[ 0 ];
		var huMonth = this[ 1 ];
		// alert( 'Replacing ' + enMonth + ' with ' + huMonth );
		// Replace "[[November 15]], [[2005]]" with "[[2005]]. [[november 15.]]"
		// $1 = "15", $2 = "2005"
		replaceRegexp( '\\[\\[' + enMonth + ' (\\d+)\\]\\],?\\s*\\[\\[(\\d{4})\\]\\]', '[[$2]]. [[' + huMonth + ' $1.]]', 'gm' );
		replaceRegexp( '\\[\\[(\\d+) ' + enMonth + '\\]\\]', '[[' + huMonth + ' $1.]]', 'gm' );
	} );
}

function customReplaceForm( e ) {
	e.preventDefault();
	var $form = $( '<form>' )
		.html(
			'<label>Cseréld ezt a reguláris kifejezést: <input id="customReplaceThis" type="text" size="40"></label> ' +
			'<label>erre: <input id="customReplaceWith" type="text" size="40"></label> ' +
			'<label><input id="customReplaceCS" type="checkbox"> méretérzékeny</label> ' +
			'<button type="submit">csere</button>'
		)
		.submit( performCustomReplace );
	insertCustomForm( $form );
	$( '#customReplaceThis' ).focus();
}

function performCustomReplace( e ) {
	var replaceThis = $( '#customReplaceThis', this ).val(),
		replaceWith = $( '#customReplaceWith', this ).val(),
		cs = $( '#customReplaceCS', this ).is( ':checked' ),
		flags = 'gm';
	if ( !cs ) {
		flags += 'i';
	}
	replaceRegexp( replaceThis, replaceWith, flags );
	e.preventDefault();
	return false;
}

function insertCustomForm( $formContent ) {
	var $customBar = $( '#customBar' );
	if ( !$customBar.length ) return;

	var $customForm = $( '<div>' )
		.attr( 'id', 'customForm' )
		.append(
			$( '<span>' )
				.attr( 'id', 'customFormClose' )
				.click( deleteCustomForm ),
			$formContent
		);

	var $oldForm = $( '#customForm' );
	if ( $oldForm.length ) {
		$oldForm.replaceWith( $customForm );
	} else {
		$customBar.before( $customForm );
	}
}

function deleteCustomForm() {
	$( '#customForm' ).remove();
}

function orszagEnHu( e ) {
	e.preventDefault();
	$.each( orszag, function () {
		replaceRegexp( this[ 0 ], this[ 1 ], 'gm' );
	} );
}

function orszagSablon( e ) {
	e.preventDefault();
	$.each( orszag, function () {
		var huorszag = this[ 1 ];
		var sablon = '{'+'{' + huorszag + '}}';
		replaceRegexp( huorszag, sablon, 'gm' );
	} );
}

$( function () {
	// Find the element that comes right after the special character box
	$currentFocused = $( '#wpTextbox1' );
	if ( $currentFocused.length ) {
		$( document ).on( 'focus', 'textarea, input:text, .CodeMirror', function () {
			if ( $( this ).is( '.CodeMirror' ) ) {
				// CodeMirror hooks into #wpTextbox1 for textSelection changes
				$currentFocused = $( '#wpTextbox1' );
			} else {
				$currentFocused = $( this );
			}
		} );
		$( '#specialchars' ).after( createCustomBar() );
	}
} );
}) ();