MediaWiki:Gadget-enhanced-search.js

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.
// Skrypt dla strony specjalnej [[Special:Search]]

/**
 * Change Special:Search to use a drop-down menu
 * Description: Dodaje do strony Special:Search menu rozwijane
 *              pozwalające na wybór wyszukiwarki
 * Created by: [[:en:User:Gracenotes]]
 */

function specialSearchEnhanced() {
	var searchEngines, createOption, searchForm, searchBox, selectBox, optSelected, lStat;
	searchEngines = [];
	
	createOption = function ( site, action, mainQ, addQ, addV ) {
		var opt = document.createElement( 'option' );
		opt.appendChild( document.createTextNode( site ) );
		searchEngines.push( [ action, mainQ, addQ, addV ] );
		return opt;
	};

	if ( document.forms.powersearch ) {
		searchForm = document.forms.powersearch;
	} else if ( document.forms.search ) {
		searchForm = document.forms.search;
	}

	if ( searchForm.lsearchbox ) {
		searchBox = searchForm.lsearchbox;
	} else {
		searchBox = searchForm.search;
	}
	
	selectBox = document.createElement( 'select' );
	selectBox.id = 'searchEngine';
	
	searchForm.onsubmit = function () {
		optSelected = searchEngines[ document.getElementById( 'searchEngine' ).selectedIndex ];
		searchForm.action = optSelected[ 0 ];
		searchBox.name = optSelected[ 1 ];
		searchForm.title.value = optSelected[ 3 ];
		searchForm.title.name = optSelected[ 2 ];
	};
	
	selectBox.appendChild( createOption( 'MediaWiki', mw.util.wikiScript(), 'search', 'title', 'Special:Search' ) );
	selectBox.appendChild( createOption( 'Google', '//www.google.pl/search', 'q', 'sitesearch', 'pl.wiktionary.org' ) );
	selectBox.appendChild( createOption( 'Yahoo', '//search.yahoo.com/search', 'p', 'vs', 'pl.wiktionary.org' ) );
	selectBox.appendChild( createOption( 'Bing', '//www.bing.com/search', 'q', 'q1', 'site:http://pl.wiktionary.org' ) );
	searchBox.style.marginLeft = '0px';
	
	if ( document.getElementById( 'loadStatus' ) ) {
		lStat = document.getElementById( 'loadStatus' );
	} else {
		lStat = searchForm.title;
	}
	
	lStat.parentNode.appendChild( selectBox );
}

/**
 * Small search keyboard
 * Author: Maciej Jaros [[:pl:User:Nux]]
 * Licence: CC-BY or [http://opensource.org/licenses/gpl-license.php GNU General Public License v2]
 */

function addSearchKeyboard( searchForm ) {
	var searchBoxId, $input, $panel, letters;
	searchBoxId = 'lsearchbox';
	
	if ( !searchForm.lsearchbox ) {
		if ( searchForm.search.id === '' ) {
			searchBoxId = searchForm.name + 'box';
			searchForm.search.id = searchBoxId;
		} else {
			searchBoxId = searchForm.search.id;
		}
	}

	$input = $( '#' + searchBoxId );
	$panel = $( '<div>' )
		.addClass( 'search_keyboard' )
		.css( {
			width: '50%',
			fontSize: 'small',
			fontWeight: 'bold'
		} );
	$panel.append( 'Wstaw znak specjalny: ' );

	letters = [
		'ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż', 'á', 'é', 'í', 'ó', 'ú',
		'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'ô',
		'û', 'ŷ', 'å', 'ů', 'ã', 'ẽ', 'ĩ', 'ñ', 'õ', 'ũ', 'æ', 'ð', 'œ', 'ø',
		'þ', 'ə', 'ŋ', 'ß',
		document.createElement( 'br' ),
		'č', 'ě', 'ň', 'ř', 'š', 'ž', 'ŕ', 'ĉ', 'ĝ', 'ĥ', 'ĵ', 'ŝ', 'ŵ', 'ă',
		'ĕ', 'ŭ',
		document.createElement( 'br' ),
		'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',
		'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь',
		'ы', 'ъ', 'э', 'ю', 'я',
		document.createElement( 'br' ),
		'ґ', 'є', 'і', 'ї'
	];
	
	$.each( letters, function ( i, item ) {
		var $link;
		
		if ( typeof( item ) === 'object' ) {
			$panel.append( item );
			return true;
		}
		
		$link = $( '<a>' ).attr( 'href', '#' );
		$link.append( item );
		
		$link.on( 'click', function ( event ) {
			$input.textSelection( 'encapsulateSelection', {
				pre: $( this ).text()
			} );
			event.preventDefault();
		} );
		
		$panel.append( $link );
	} );

	$input.parent().parent().append( $panel );
}

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ) {
	$.when(
		mw.loader.using( [ 'jquery.textSelection', 'mediawiki.util' ] ),
		$.ready
	).done( function () {
		specialSearchEnhanced();
		
		if ( document.forms.search ) {
			addSearchKeyboard( document.forms.search );
		}

		if ( document.forms.powersearch ) {
			addSearchKeyboard( document.forms.powersearch );
		}
	} );
}