MediaWiki:SearchTools.js

Aus Open Source Ecology - Germany
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Gehe zu Menü → Einstellungen (Opera → Einstellungen auf dem Mac) und dann auf Datenschutz & Sicherheit → Browserdaten löschen → Gespeicherte Bilder und Dateien.
// <source lang="javascript">
// This JavaScript will be loaded only for some pages, see MediaWiki:Common.js
// License Creative Commons Share Alike: A. Plank
// This program is free software; you can redistribute it and/or modify it under the terms of the EUPL v.1.1 or (at your option) the GNU General Public License as published by the Free Software Foundation; either GPL v.3 or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License (http://www.gnu.org/licenses/) for more details. */

/* global $, document */ /* = settings for JSLint */
"use strict"; // set ECMAScript 5 Strict Mode

/**
 * Fix Nasa patent Search
 *
 * Nasa patent Search only allows a concatenated Search-URL, it has no GET, no POST interface
 * @returns void
 */
function onsubmit_fix_nasa_search() {
  var query = $(this).find('input[type=text]').val();
  query = $.trim( query );

  var url = encodeURIComponent( query );

  //remove wildcard
  url = url.split('*').join('_wc_');

  //double quote fix
  url = url.split('%22').join('_dq_');

  $( this ).attr("action").replace('%s', url);
}

/**
 * @description Generate a search form passing the input text to the defined URL
 * @augments $
 * @requires jQuery
 * @requires $.jI18n
 * @requires $.resource
 * @param {string} id HTML id
 * @param {string} urlBasis basis URL without variables; if forMethod GET including questionmark at the end http://…?
 * @param {string} title HTML title attribute
 * @param {string} urlVariables all necessary URL variables
 * @param {string} formMethod optional: get or post (default: get)
 * @param {string} defaultString optional: string of the default search text (default: text of the original <span id="DryadesDataBaseSearch">Default text</span>)
 * @param {string} onSubmitCaller optional: a function called at onsubmit event of this very form
 * @returns {String}
 */
function CreateSearchForm(id, urlBasis, urlVariables, title, formMethod, defaultString
//                          , onSubmitCaller
) {
  /* USAGE
    <span id="PatentsGoogleComSearchStatusGRANT"></span> or e.g. with a default string:
    <span id="PatentsGoogleComSearchStatusGRANT">Default string</span>
    urlVariables you get from opera's 'Create search…' by clicking right mouse at any HTML-search field
  */
  formMethod = formMethod ? formMethod : 'get'; // default form method is get
  id = 'span#'+id;
  // get optionally text value enclosed by <span></span>
  defaultString = $(id).text() ? $(id).text() : ( defaultString ? defaultString : $.resource('SearchTool_defaultSearchString') );
  // delete text value enclosed by <span></span>
  // <form></form> must be added here otherwise just <form/> will be created (jQuery/Browser <-> xhtml?)
  $(id).text('').html("<form class='search' method ='" + formMethod + "' target='_blank' action='" + urlBasis + "' onsubmit='" +
    // ( onSubmitCaller===undefined ? "" : onSubmitCaller )
     + "' " +
     + "></form>");

  id = id + ' form';// adjust jQuery to find forms
  if (urlVariables==='%s') {
      $(id).append(
        "<input  type='text' title='" + title + "' size=30 " +
        (defaultString.match(/(…$)/ig) ? " onfocus=\"this.value == &quot;"+ defaultString +"&quot; ? this.value = &quot;&quot; : null;\" onblur=\"this.value == '' ? this.value = '"+ defaultString +"' : null\" " : "")  +
        " value ='" + defaultString + "' "+
        ">" +
        "<input type='submit' value='" + $.resource('SearchTool_submitString') + "' title='" + $.resource('SearchTool_submitHint') + "'> "
      );
  } else {
    // split url + create input fields
    $.each(urlVariables.split('&'), function(key, value) {
      //alert(key + ': ' + value);
      var urlVariable = value.split('=')[0];
      var urlValue    = value.split('=')[1];
      $(id).append(
        "<input " +
        (urlValue === '%s' ? " type='text' " : " type='hidden' " ) +
        (urlValue === '%s' ? " title='" + title + "' " : "" ) +
        (urlValue === '%s' ? " size=30 " : "" ) +
        (urlValue === '%s' ? (defaultString.match(/(…$)/ig) ? " onfocus=\"this.value == &quot;"+ defaultString +"&quot; ? this.value = &quot;&quot; : null;\" onblur=\"this.value == '' ? this.value = '"+ defaultString +"' : null\" " : "") : "" ) +
        "  name ='" + urlVariable +"' " +
        " value ='" + (urlValue === '%s' ? defaultString : urlValue ) + "' "+
        ">" +
        (key === (urlVariables.split('&').length - 1) ? "<input type='submit'  value='" + $.resource('SearchTool_submitString') + "' title='" + $.resource('SearchTool_submitHint') + "'> " : "")
      );
      //alert($j(id).html());
    });// END each()
  }
}// END CreateSearchForm


$(document).ready(function() {
  // append local resources to global object, "true" = deep extension
  $.extend(true, $.jI18n, {
    de: {
      SearchTool_defaultSearchString : 'Suchbegriff hier eingeben…',
      SearchTool_submitString  : 'Los',
      SearchTool_submitHint    : 'Suche in neuer Seite…'
    },
    en: {
      SearchTool_defaultSearchString : 'Type in a search term…',
      SearchTool_submitString  : 'Go',
      SearchTool_submitHint    : 'Opens a new page…'
    },
    fr: {
      SearchTool_defaultSearchString : 'Entrez les recherche de mots ici…',
      SearchTool_submitString  : 'Et allez',
      SearchTool_submitHint    : 'Rechercher dans une nouvelle page…'
    }
  });
  CreateSearchForm(
    /* span.id       */ 'PatentsGoogleComSearchStatusGRANT',
    /* urlBasis      */ 'https://patents.google.com/?',
    /* urlVariables  */ 'q=%s&status=GRANT',
    /* title         */ 'Patentsuche bei Google (mit Status GRANT, stattgegeben)',
    /* formMethod    */ 'get'
  );
  CreateSearchForm(
    /* span.id       */ 'FreeInactivePatentSearch',
    /* urlBasis      */ 'http://freeip.mtu.edu/home/index.php',
    /* urlVariables  */ 'STerm=%s',
    /* title         */ 'Suche Free Inactive Patent Search',
    /* formMethod    */ 'post'
  );
  CreateSearchForm(
    /* span.id       */ 'TechnologyNasaGovPublicDomain',
    /* urlBasis      */ 'https://technology.nasa.gov/search/public_domain/%s',
    /* urlVariables  */ '%s',
    /* title         */ 'Suche Technologie in NASA Public Domain',
    /* formMethod    */ 'get',
     null,
    /* onSubmitCaller */ 'onsubmit_fix_nasa_search()'
  );


});// END doc-ready