MediaWiki:Gadget-citation-templates-extracts.js

Z Wikisłownika – wolnego słownika wielojęzycznego

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
if ( mw.config.get( 'wgTitle' ).indexOf( 'Szablony źródeł' ) === 0 ) {
	mw.loader.using( 'mediawiki.api' ).done( function () {
		var API_DELAY = 100,
			api = new mw.Api();
		
		function makeRequest( template ) {
			return api.parse( mw.format( '{' + '{$1}}', template ), {
				title: 'hasło',
				prop: 'text',
				disablelimitreport: true
			} );
		}
		
		mw.hook( 'wikipage.content' ).add( function ( $content ) {
			$content.find( '#mw-pages' ).find( 'li > a[title^="Szablon:"]' ).each( function () {
				var popup,
					$el = $( this );
				
				$el.data( 'title', $el.attr( 'title' ) ).removeAttr( 'title' );
				
				$el.on( 'mouseenter.popup-ref', function ( evt ) {
					if ( popup ) {
						popup.toggle( true );
						return;
					}
					
					$el.data( 'timer-id', setTimeout( function () {
						var template = $el.data( 'title' ).replace( /^Szablon:/, '' ),
							request = makeRequest( template );
						
						$el.data( 'request', request ).removeData( 'timer-id' );
						
						$.when(
							request,
							mw.loader.using( 'oojs-ui-core' )
						).done( function ( wikitext ) {
							$el.removeData( 'request' );
							
							popup = new OO.ui.PopupWidget( {
								$content: $( wikitext ),
								$floatableContainer: $el,
								padded: true
							} );
							
							$( document.body ).append( popup.$element );
							popup.toggle( true );
							
							if ( $el.is( ':hover' ) ) {
								$el.trigger( 'mouseenter' );
							}
						} );
					}, API_DELAY ) );
				} );
				
				$el.on( 'mouseleave.popup-ref', function ( evt ) {
					var timerID = $el.data( 'timer-id' ),
						request = $el.data( 'request' );
					
					if ( timerID !== undefined ) {
						clearTimeout( timerID );
					}
					
					if ( request !== undefined ) {
						request.abort();
					}
					
					$el.removeData( [ 'timer-id', 'request' ] );
					
					if ( popup ) {
						popup.toggle( false );
					}
				} );
			} );
		} );
	} );	
}