MediaWiki:Gadget-wikimenu.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
/*
== Menük és tabsetek inicializálása ==
*/

/**
 * Generate menu
 * 
 * @param {jQuery} $dest Destination
 * @return {string} HTML id of destination
 */
function generateMenuLayout( $dest ) {
	function getMenuItems( $dest, level ) {
		if ( level > 2 ) return 0; // max. 2 szint
		var $curr = $( '<ul>' );
		$( 'div', $dest ).each( function () {
			var $cdiv = $( this );
			if ( $cdiv.hasClass( 'menuItem' ) ) {
				$( '<li>' ).html( $cdiv.html() ).appendTo( $curr );
			} else {
				var $ret = getMenuItems( $( '#wikiMenu-' + $cdiv.attr( 'title' ).replace( /<>/g, '' ) ), level + 1 );
				if ( $ret !== 0 ) {
					$( '<li>' ).html( $cdiv.html() ).append( $ret ).appendTo( $curr );
				}
			}
		} );
		return $curr;
	}
	var $curr = getMenuItems( $dest, 0 );
	$dest.after( $curr );
	var destid = 'menu-' + $dest.attr( 'id' ).slice( 10 );
	$curr.attr( 'id', destid ).addClass( 'sf-menu' );
	$dest.remove();
 
	if (
		mw.config.get( 'wikimenu.useCustomMenu', false ) === true &&
		mw.config.get( 'wgUserName' ) !== null &&
		$curr.parents( '#header-menu' ).length > 0
	) {
		$.get(
			mw.util.getUrl( 'User:' + mw.config.get( 'wgUserName' ) + '/Saját menü', { action: 'raw' } ),
			{ async: false }
		).done( function ( data ) {
			if ( data.length === 0 ) return;
			var items = data.split( '\n' );
			var $cmenu = $( '<ul>' );
			for ( var zs = 0; zs < items.length; zs++ ) {
				if (items[zs] === '' || items[zs].charAt( 0 ) !== '#' ) continue;
				var foo = items[zs].slice( 1 );
				var title, text;
				if ( foo.indexOf( '|' ) > -1 ) {
					var splitem = foo.split( '|' );
					title = splitem[ 0 ];
					text = splitem[ 1 ];
				} else {
					title = foo;
					text = foo;
				}
				$cmenu.append(
					$( '<li>' ).append(
						$( '<a>' ).attr( 'href', mw.util.getUrl( title ) ).text( text )
					)
				);
			}
			if ( ( $cmenu ).children().length > 0 ) {
				$curr.append(
					$( '<li>' ).append(
						$( '<a>' ).attr( 'href', '#' ).text( 'Saját' ),
						$cmenu
					)
				);
			}
		} );
	}
	return destid;
}

mw.hook( 'wikipage.content' ).add( function buildHeader( $content ) {
	/* Cikkben nem */
	if ( mw.config.get( 'wgNamespaceNumber' ) === 0) return;
	
	/* Gombok */
	$( '.bigButton', $content ).each( function () {
		var $link = $( 'a:first', this );
		if ( $link.length ) {
			var curLink = $link.attr( 'href' );
			$link.parent().html( $link.html() );
			$( this )
				.css( 'cursor', 'pointer' )
				.wrap( $( '<a>').attr( 'href', curLink ).addClass( 'buttonWrapperAnchor' ) );
		}
	} );
	
	/* Eligazítólapok */
	$( '.eligazitoLap > .eligazitoElem', $content ).each( function () {
		var $link = $( '.eligazitoTovabb > a', this );
		if ( $link.length ) {
			var curLink = $link.attr( 'href' );
			$link.parent().html( $link.html() );
			$( this )
				.css( 'cursor', 'pointer' )
				.wrap( $( '<a>' ).attr( 'href', curLink ).addClass( 'eligazitoWrapLink' ) );
		}
	} );
	
	/* Fülek felépítése */
	$( '.tabset-tabs', $content ).each( function () {
		var $tabul = $( '<ul>' );
		var curid = $( this ).attr( 'id' ).slice( 10 ).replace(/<>/g, '');
		$( '#' + curid + '-content > div' ).each( function () {
			var $cdiv = $( this );
			$cdiv.removeClass( 'tab-nojs' );
			if ( $cdiv.attr( 'title' ) ) {
				$( '<li>' ).append( $( '<a>' ).text( $cdiv.attr( 'title' ) ) ).appendTo( $tabul );
			} else {
				$cdiv.remove();
			}
		} );
		if ( $tabul.children().length ) {
			$tabul
				.insertAfter( this )
				.attr( 'id', curid )
				.addClass( 'tabset-tabs' )
				.jqttabs( '#' + curid + '-content > div' )
				.trigger( 'tabsetReady' );
		} else {
			$( '#' + curid + '-content' ).remove();
		}
		$( this ).remove();
	} );
	
	/* Menük felépítése */
	if ( mw.config.get( 'wikimenu.disabled', false ) === false ) {
		var $menuRoots = $( '.wikiMenu-rootContainer', $content );
		if ( $menuRoots.length ) {
			$menuRoots.each( function () {
				var destid = generateMenuLayout( $( this ) );
				$( '#' + destid ).supersubs( {
					minWidth:	12,	// minimum width of sub-menus in em units
					maxWidth:	27,	// maximum width of sub-menus in em units
					extraWidth:	2	// extra width can ensure lines don't sometimes turn over
									// due to slight rounding differences and font-family
				} ).superfish();
			} );
			$( '.wikiMenu-container', $content ).remove();
		}
	}
} );

/* Kapcsolódó lapok */
mw.hook( 'wikipage.content' ).add( function createRelatedPagesPopup( $content ) {
	if ( mw.config.get( 'wgNamespaceNumber' ) === 0) return;
	if(!$.swap) return;
	$( '.buborekGomb' ).each( function () {
		var $this = $( this );
		var contentDivSelector = '#' + $this.attr( 'id' ).replace( /^button-/, '' ).replace(/<>/g, '') + '-content';
		var $contentDiv = $( contentDivSelector );
		$contentDiv.appendTo( 'body' );
		
		var contentDivWidth = 0;
		$.swap( $contentDiv[0], { display: 'block' }, function () {
			contentDivWidth = $( this ).outerWidth();
		} );
		
		function reposBuborek() {
			var contentDivLeft = $this.offset().left;
			if ( contentDivLeft + contentDivWidth > $(window).width() ) {
				contentDivLeft += $this.outerWidth() - contentDivWidth;
			}
			$contentDiv.css( {
				position: 'absolute',
				top: $this.offset().top + $this.outerHeight(),
				left: contentDivLeft
			} );
		}
		reposBuborek();
		
		$contentDiv.find( '.buborekTitlebar' ).prepend(
			$( '<div>' )
				.addClass( 'buborekCloseButton' )
				.text( 'x' )
				.click( function () {
					$this.removeClass( 'button-active' );
					$contentDiv.stop().fadeTo( 200, 0 ).removeClass( 'buborekVisible' ).hide();
				} )
		);
		$this.click( function () {
			if ( $contentDiv.hasClass( 'buborekVisible' ) ) {
				$contentDiv.stop().fadeTo( 200, 0 ).removeClass( 'buborekVisible' ).hide();
			} else {
				reposBuborek();
				$this.addClass( 'button-active' );
				$contentDiv.stop().show().fadeTo( 200, 1 ).addClass( 'buborekVisible' );
			}
		} );
	} );
} );