MediaWiki:Gadget-cimerhatarozo.mutato.js

A Wikikönyvekből, a szabad elektronikus könyvtárbó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
/**
 * Do the actual search.
 * @param {string} str The search string
 */
function searchInner( str ) {
	var reString = mw.util.escapeRegExp( str.replace( /^\s*|\s*$/g, '' ) ).replace( /\s*,\s*/g, '|' );
	var re = new RegExp( reString, 'iu' );
	var regExps = [];
	var reStringSplit = reString.split( '|' );
	for ( var i = 0; i < reStringSplit.length; i++ ) {
		regExps.push( new RegExp( reStringSplit[ i ], 'iu' ) );
	}
	$( '.ch-mutato-cimer' ).each( function () {
		$( this ).data( 'mw-collapsible' ).collapse();
	} );
	$( '.ch-talalat' ).removeClass( 'ch-talalat' );
	$( '.ch-mutato-cimer' ).each( function () {
		var $this = $( this );
		var keywords = $this.find( '.ch-mutato-cimszavak' ).text();
		for ( var i = 0; i < regExps.length; i++ ) {
			if ( !regExps[ i ].test( keywords ) ) {
				return;
			}
		}
		$this.find( '.ch-mutato-cimszavak span' ).each( function () {
			var $this = $( this );
			if ( re.test( $this.text() ) ) {
				$this.addClass( 'ch-talalat' );
			}
		} );
		$this.data( 'mw-collapsible' ).expand();
	} );
}

/**
 * Process the form submit event: prevent navigation, get search string,
 * load the mw.RegExp module, and call the processing function.
 * @param {jQuery.Event} e The form submit event
 */
function searchCh( e ) {
	e.preventDefault();
	var str = this.elements.search.value;
	mw.loader.using( 'mediawiki.util', function () {
		searchInner( str );
	} );
}

/**
 * Close all tables.
 * @param {jQuery.Event} e The click event
 */
function closeAll( e ) {
	if (
		e.type === 'click' &&
		e.target.nodeName.toLowerCase() === 'a' &&
		$( e.target ).attr( 'href' )
	) {
		// Don't fire if a link was clicked (for premade togglers)
		return;
	} else if ( e.type === 'keypress' && e.which !== 13 && e.which !== 32 ) {
		// Only handle keypresses on the "Enter" or "Space" keys
		return;
	} else {
		e.preventDefault();
		e.stopPropagation();
	}
	$( '.ch-mutato-cimer' ).each( function () {
		$( this ).data( 'mw-collapsible' ).collapse();
	} );
}

/**
 * Initialize search and collapse button once content is loaded.
 * @param {jQuery} $content The page content
 */
function initCh( $content ) {
	$content.find( '.ch-mutato-kereso form' ).submit( searchCh );
	$( '<a class="mw-collapsible-text"></a>' )
		.text( 'összes becsukása' )
		.wrap( '<button type="button" class="mw-collapsible-toggle mw-collapsible-toggle-default"></button>' )
		.parent()
		.on( 'click.mw-collapsible keypress.mw-collapsible', closeAll )
		.prependTo( $content.find( '#ch-mutato-cimerek' ).find( 'tr:first th, tr:first td' ).first() );
}

mw.hook( 'wikipage.content' ).add( initCh );