MediaWiki:Gadget-externalsearch-bar.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/** * Add a small dropdown menu to the search box to add the [[Wikimedia technical search]]. * * Created by [[d:User:Bene*]] */ // <nowiki> ( function ( mw, $ ) { var i18nData = { 'en': { 'title': 'Wikimedia tech', 'description': 'Use the custom Wikimedia technical search', 'placeholder': 'Wikimedia tech' } }; if( $( 'body' ).is( '.rtl' ) ) { i18nData.en.dir = 'rtl'; i18nData.en.left = 'right'; i18nData.en.right = 'left'; } else { i18nData.en.dir = 'ltr'; i18nData.en.left = 'left'; i18nData.en.right = 'right'; } var i18nLang = mw.config.get( 'wgUserLanguage' ), lang = i18nLang.split( '-' )[0]; if( !( i18nLang in i18nData ) ) { i18nLang = 'en'; } if( i18nLang === 'be-tarask' ) { // Hack for be_x_oldwiki lang = 'be-x-old'; } /** * Returns the localized version of a message. */ function i18n( key ) { if( i18nData[ i18nLang ][ key ] ) { return i18nData[ i18nLang ][ key ]; } else { return i18nData.en[ key ]; } } var $improvedsearch = $( '<form>' ) .attr( { id: 'improvedsearch', action: 'https://www.google.com/cse' } ) .append( $( '<div>' ) .attr( 'id', 'simpleSearch' ) // This is a hack. .append( $( '<input>' ) .attr( { type: 'hidden', name: 'cx', value: '010768530259486146519:twowe4zclqy' } ) ) .append( $( '<input>' ) .attr( { id: 'searchInput', // This is a hack. 'class': 'improvedsearch-page', type: 'text', accesskey: 'g', title: i18n( 'title' ) + ' [alt-shift-g]', name: 'q', autocomplete: 'off', placeholder: i18n( 'placeholder' ) } ) ) .append( $( '<button>' ) .attr( { id: 'searchButton', // This is a hack. 'class': 'improvedsearch-search', title: i18n( 'description' ) } ) ) ); function toggle() { $( '#improvedsearch' ).toggle( 'normal' ); $( '.improvedsearch-page' ).focus(); } function init() { var skin = mw.config.get( 'skin' ); if( skin === 'vector' ) { $( '#p-search' ).append( $improvedsearch ); $( '#improvedsearch' ).hide( 0 ); $( '.improvedsearch-search' ) .html( $( '<img>' ) .attr( { width: '12', height: '13', alt: i18n( 'title' ), src: mw.config.get( 'stylepath' ) + '/vector/images/search-' + i18n( 'dir' ) + '.png?303-4' } ) ); var toggleCss = { width: '20px', height: '1.3em' }; toggleCss['margin-' + i18n( 'left' )] = '14.5em'; toggleCss['margin-' + i18n( 'right' )] = '-0.8em'; $( '#searchform' ).prepend( $( '<div>' ) .attr( { id: 'improvedsearch-toggle', 'class': 'vectorMenu', title: i18n( 'title' ) } ) .css( toggleCss ) .click( toggle ) ); } else if( $( '#searchBody' ).length ) { $( '#searchBody' ).append( $( '<br />' ) .after( $improvedsearch ) ); $( '.improvedsearch-search' ) .replaceWith( $( '<input>' ) .attr( { type: 'submit', 'class': 'searchButton improvedsearch-search', value: i18n( 'title' ), title: i18n( 'description' ) } ) ); } } $( document ).ready( init ); } ( mediaWiki, jQuery ) ); // </nowiki>