Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This script is needed for (anonymously) logging search terms by our Squids!
  2. // The search URL will contain the search term,
  3. // please modify retroactively at [[wikt:de:MediaWiki:If-search.js]];
  4. // rather IMPORT this script; example: [[wikt:de:MediaWiki:If-search.js/import]].
  5. // --
  6. // Updated on de.wiktionary by Krinkle 2011-02-08
  7.  
  8. function getID( ID ) {
  9.  return document.getElementById(ID);
  10. }
  11. function firstInputInID( ID ) {
  12.  return getID( ID ).getElementsByTagName( 'input' )[0];
  13. }
  14.  
  15. function fixSearchForm( id, input ) {
  16.  var fNode = getID( id );
  17.  if ( fNode ) {
  18.   fNode.setAttribute( 'onsubmit', "SubSearch('" + id + "', '" + input + "', '/')" );
  19.   fNode.parentNode.innerHTML = getID( id ).parentNode.innerHTML; // f***ing IE
  20.  }
  21. }
  22.  
  23. function SubSearch( id, input, delimeter ) {
  24.  var inputNode = getID(input);
  25.  var formNode = getID(id);
  26.  if ( inputNode.value === '' ) {
  27.   delimeter = '';
  28.  }
  29.  formNode.action = wgArticlePath.replace( '$1', oSEAp + delimeter + inputNode.value );
  30.  
  31.  // Try to remove <input name="title"> from the <form>
  32.  if ( firstInputInID(id).name === 'title' ) {
  33.   if ( firstInputInID(id).parentNode == formNode ) {
  34.    formNode.removeChild( firstInputInID(id) );
  35.   } else {
  36.    formNode.firstChild.removeChild( firstInputInID(id) );
  37.   }
  38.  }
  39. }
  40.  
  41. function LogSearch() {
  42.  fixSearchForm( 'searchform', 'searchInput' );
  43.  fixSearchForm( 'search', 'searchText' );
  44.  fixSearchForm( 'powersearch', 'powerSearchText' );
  45.  fixSearchForm( 'bodySearch', 'bodySearchIput' );
  46.  var searchform = getID( 'searchform' );
  47.  if ( searchform && searchform.action.indexOf(wgScript) !== -1) {
  48.   window.oSEAp = firstInputInID( 'searchform' ).value;
  49.  } else {
  50.   window.oSEAp = searchform.action.replace( /^.*\/([^\/]+)$/, '$1' );
  51.  }
  52. }
  53.  
  54. // Execute it when the page is ready
  55. jQuery( document ).ready( LogSearch );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement