MediaWiki:Common.js: Porōwnanie wersyji
Linijŏ 1: | Linijŏ 1: | ||
+ | // <pre> | ||
// Skrypt dla strony specjalnej [[Special:Search]] | // Skrypt dla strony specjalnej [[Special:Search]] | ||
+ | /* | ||
+ | == 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] | ||
+ | */ | ||
+ | if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == "Search" ) { | ||
+ | jQuery( document ).ready( function() { | ||
+ | if ( document.forms['search'] ) { | ||
+ | addSearchKeyboard( document.forms['search'] ); | ||
+ | } | ||
− | + | if ( document.forms['powersearch'] ) { | |
− | + | addSearchKeyboard( document.forms['powersearch'] ); | |
− | + | } | |
− | + | } ); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | |||
− | |||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function addSearchKeyboard( searchForm ) { | function addSearchKeyboard( searchForm ) { | ||
− | var | + | var searchBoxId = 'lsearchbox'; |
− | |||
− | |||
if ( !searchForm.lsearchbox ) { | if ( !searchForm.lsearchbox ) { | ||
− | if ( searchForm.search.id | + | if ( searchForm.search.id == '' ) { |
searchBoxId = searchForm.name + 'box'; | searchBoxId = searchForm.name + 'box'; | ||
searchForm.search.id = searchBoxId; | searchForm.search.id = searchBoxId; | ||
Linijŏ 76: | Linijŏ 29: | ||
} | } | ||
− | $input = | + | var $input = jQuery( '#' + searchBoxId ); |
− | $panel = | + | var $panel = jQuery( '<div class="search_keyboard" style="width:50%; font-size:small; font-weight: bold" />' ); |
− | $panel.append( | + | $panel.append( "Polskie znaki: " ); |
− | letters = [ | + | var letters = ['ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż', '–', '„', '”']; |
− | + | for ( var i = 0; i < letters.length; i++ ) { | |
− | + | var $link = jQuery( '<a href="#"/>' ); | |
− | + | $link.append( letters[i] ); | |
− | + | $link.click( function( event ) { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | var | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | $link.append( | ||
− | |||
− | $link. | ||
$input.textSelection( 'encapsulateSelection', { | $input.textSelection( 'encapsulateSelection', { | ||
− | pre: | + | pre: jQuery( this ).text() |
} ); | } ); | ||
event.preventDefault(); | event.preventDefault(); | ||
} ); | } ); | ||
− | |||
$panel.append( $link ); | $panel.append( $link ); | ||
− | } | + | } |
$input.parent().parent().append( $panel ); | $input.parent().parent().append( $panel ); | ||
} | } | ||
− | if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == | + | /** Change Special:Search to use a drop-down menu |
− | + | * | |
− | + | * Description: Dodaje do strony Special:Search menu rozwijane | |
− | + | * pozwalające na wybór wyszukiwarki | |
− | if ( document.forms.search ) { | + | * Created by: [[en:User:Gracenotes]] |
− | + | */ | |
+ | |||
+ | if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == "Search" ) { | ||
+ | jQuery( document ).ready( function() { | ||
+ | var searchEngines = []; | ||
+ | |||
+ | var 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; | ||
+ | }; | ||
+ | |||
+ | var searchForm; | ||
+ | if ( document.forms['powersearch'] ) { | ||
+ | searchForm = document.forms['powersearch']; | ||
+ | } else if ( document.forms['search'] ) { | ||
+ | searchForm = document.forms['search']; | ||
} | } | ||
− | if ( document. | + | if ( searchForm.lsearchbox ) { |
− | + | var searchBox = searchForm.lsearchbox; | |
+ | } else { | ||
+ | var searchBox = searchForm.search; | ||
+ | } | ||
+ | var selectBox = document.createElement( 'select' ); | ||
+ | selectBox.id = 'searchEngine'; | ||
+ | searchForm.onsubmit = function() { | ||
+ | var 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.wikipedia.org' ) ); | ||
+ | selectBox.appendChild( createOption( 'Yahoo', 'http://search.yahoo.com/search', 'p', 'vs', 'pl.wikipedia.org' ) ); | ||
+ | selectBox.appendChild( createOption( 'Bing', 'http://www.bing.com/search', 'q', 'q1', 'site:http://pl.wikipedia.org' ) ); | ||
+ | selectBox.appendChild( createOption( 'Wikiwix', 'http://pl.wikiwix.com/', 'action', 'lang', 'pl' ) ); | ||
+ | |||
+ | searchBox.style.marginLeft = '0px'; | ||
+ | if ( document.getElementById( 'loadStatus' ) ) { | ||
+ | var lStat = document.getElementById( 'loadStatus' ); | ||
+ | } else { | ||
+ | var lStat = searchForm.title; | ||
} | } | ||
+ | lStat.parentNode.insertBefore( selectBox, lStat ); | ||
} ); | } ); | ||
} | } |
Wersyjŏ ze dnia 21:21, 31 mar 2019
// <pre> // Skrypt dla strony specjalnej [[Special:Search]] /* == 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] */ if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == "Search" ) { jQuery( document ).ready( function() { if ( document.forms['search'] ) { addSearchKeyboard( document.forms['search'] ); } if ( document.forms['powersearch'] ) { addSearchKeyboard( document.forms['powersearch'] ); } } ); } function addSearchKeyboard( searchForm ) { var searchBoxId = 'lsearchbox'; if ( !searchForm.lsearchbox ) { if ( searchForm.search.id == '' ) { searchBoxId = searchForm.name + 'box'; searchForm.search.id = searchBoxId; } else { searchBoxId = searchForm.search.id; } } var $input = jQuery( '#' + searchBoxId ); var $panel = jQuery( '<div class="search_keyboard" style="width:50%; font-size:small; font-weight: bold" />' ); $panel.append( "Polskie znaki: " ); var letters = ['ą', 'ć', 'ę', 'ł', 'ń', 'ó', 'ś', 'ź', 'ż', '–', '„', '”']; for ( var i = 0; i < letters.length; i++ ) { var $link = jQuery( '<a href="#"/>' ); $link.append( letters[i] ); $link.click( function( event ) { $input.textSelection( 'encapsulateSelection', { pre: jQuery( this ).text() } ); event.preventDefault(); } ); $panel.append( $link ); } $input.parent().parent().append( $panel ); } /** 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]] */ if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == "Search" ) { jQuery( document ).ready( function() { var searchEngines = []; var 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; }; var searchForm; if ( document.forms['powersearch'] ) { searchForm = document.forms['powersearch']; } else if ( document.forms['search'] ) { searchForm = document.forms['search']; } if ( searchForm.lsearchbox ) { var searchBox = searchForm.lsearchbox; } else { var searchBox = searchForm.search; } var selectBox = document.createElement( 'select' ); selectBox.id = 'searchEngine'; searchForm.onsubmit = function() { var 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.wikipedia.org' ) ); selectBox.appendChild( createOption( 'Yahoo', 'http://search.yahoo.com/search', 'p', 'vs', 'pl.wikipedia.org' ) ); selectBox.appendChild( createOption( 'Bing', 'http://www.bing.com/search', 'q', 'q1', 'site:http://pl.wikipedia.org' ) ); selectBox.appendChild( createOption( 'Wikiwix', 'http://pl.wikiwix.com/', 'action', 'lang', 'pl' ) ); searchBox.style.marginLeft = '0px'; if ( document.getElementById( 'loadStatus' ) ) { var lStat = document.getElementById( 'loadStatus' ); } else { var lStat = searchForm.title; } lStat.parentNode.insertBefore( selectBox, lStat ); } ); }