MediaWiki:SearchTools.js

Aus Bayernflora
Wechseln zu: Navigation, Suche

Hinweis: Leeren Sie 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: Extras → Internetspuren löschen … → Individuelle Auswahl → Den kompletten Cache löschen
// <syntaxhighlight lang="javascript">
/* 
  This JavaScript should be loaded only for some pages, see USAGE
  Copyright 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 */ 
/*jslint devel: true, eqeq: true, sloppy: true, stupid: true, todo: true, white: true, indent: 2 */
 
/*
  @description create a search form and open a new browser window that will query according to URL specifications set here
  @param {string} id HTML id
  @param {string} urlBasis the basic URL
  @param {string} urlVariables all the variables, must contain a '%s' that becomes substituted by the actual search string
  @param {string} formMethod either 'post' or 'get'
  @param {string} defaultstring any default string that is pre-filled in the form
  @requires jQuery
  @requires $.jI18n as resource dictionary
*/
function createSearchForm(id, urlBasis, urlVariables, title, formMethod, defaultstring) {
  "use strict"; // set ECMAScript 5 Strict Mode
  /*
  USAGE SETUP
    Setup in MediaWiki:Common.js may be
      importScript('MediaWiki:SearchTools.js')
    or specific to pages
      switch (mw.config.get( 'wgPageName' )) {
        case "A page name":
        case "Another page name":
          importScript('MediaWiki:SearchTools.js')
        break;
      }
  USAGE ON PAGES
    Search boxes are identified via HTML id defiend in this JavaScript file, e.g:
 
    <span id="DryadesDataBaseSearch"></span> or e.g. with a default string: 
    <span id="DryadesDataBaseSearch">{{PAGENAME}}</span>
 
    Note: the correct urlVariables you get from opera's context menu '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('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 + "'></form>");
  id = id + ' form';// adjust jQuery to find forms
  // 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=50 " : "" ) +
  (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('submitString') + "' title='" + $.resource('submitHint') + "'> " : "")
    );
    //alert($(id).html());
  });// END each()
}// END createSearchForm


$(document).ready(function() {
  // append local resources to global object, "true" = deep extension
  $.extend(true, $.jI18n, {
  en: { 
    defaultSearchString : 'Input a taxon name…', 
    submitString  : 'Go', 
    submitHint    : 'Opens a new page…'
    },
  de: {
    defaultSearchString : 'Taxon eingeben…', 
    submitString  : 'Los', 
    submitHint    : 'Suche in neuer Seite…'
    }
  });
  createSearchForm(
    /* span.id       */ 'PilzFotoPageSearch', 
    /* urlBasis      */ 'http://www.pilzfotopage.de/planetsearchplus.php',
    /* urlVariables  */ 'search_exp=%s&exp_capital=no&exp_full=no&submit2=Suche+starten',
    /* title         */ 'Pilzfoto Projekt (Bilder/Steckbrief)-Suche',
    /* formMethod    */ 'post'
    );
  createSearchForm(
    /* span.id       */ 'DryadesDataBaseSearch', 
    /* urlBasis      */ 'http://dbiodbs.univ.trieste.it/carso/ico02',
   // 'http://dbiodbs.univ.trieste.it/carso/icon02',
    /* urlVariables  */ 'spe=%s',
   // 'fa=%&spe=%s&co=&chi=0',
    /* title         */ 'Dryades Projekt (Bilder) Suche',
    /* formMethod    */ 'get'
    );
  createSearchForm(
    /* span.id       */ 'FloraWebDataBaseSearch',
    /* urlBasis      */ 'http://www.floraweb.de/pflanzenarten/taxoquery.xsql?',
    /* urlVariables  */ 'taxname=%s&max-rows=10&skip-rows=0&submit.x=0&submit.y=0',
    /* title         */ 'Flora-Web Suche',
    /* formMethod    */ 'get' 
  );
  createSearchForm(// Fix? I do not know or I+do+not+know ? Search works with cookies
    /* span.id       */ 'FloraSearchDataBaseSearch', 
    /* urlBasis      */ 'http://www.botanicalkeys.co.uk/flora/content/findthoseplants.asp',
    /* urlVariables  */ 'NAME=%s&FAMILY=I do not know&HABITAT=I do not know&PLANTFORM=&ESORW=I do not know&SPOREPRODUCING=I do not know&MONTHS=I do not know&FLOWERCOLOUR=I do not know&FLOWERTYPE=&ARRANGEMENT=&HAIR=&LEAFFORM=&MARGINS=&LEAFLENGTH=&STIPULES=I do not know&PETIOLES=I do not know',
    /* title         */ 'Flora Search Datenbank-Suche',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'LedaTraitbaseSearch', 
    /* urlBasis      */ 'http://www.leda-traitbase.org/LEDAfactsheet/list.jsp?',
    /* urlVariables  */ 'specieslist=60001&searchFor=%s',
    /* title         */ 'Pflanzensteckbriefe LEDA-Traitbase-Suche',
    /* formMethod    */ 'get'
  );
  createSearchForm(// won't work long: ?time stamp
    /* span.id       */ 'EncyclopediaOfLifeSearch', 
    /* urlBasis      */ 'https://www.eol.org/search?',
    /* urlVariables  */ 'q=%s&search=Go',
    /* title         */ 'Durchsuche Encyclopedia of Life',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'BioLibTaxonomicTreeSearch', 
    /* urlBasis      */ 'http://www.biolib.cz/en/formsearch/?',
    /* urlVariables  */ 'action=execute&searcharea=1&string=%s',
    /* title         */ 'Durchsuche BioLib (Biological Library)',
    /* formMethod    */ 'get'
  );
  createSearchForm(// TODO fix: works in opera but not here
    /* span.id       */ 'BiodiversityLibrarySearch', 
    /* urlBasis      */ 'http://www.biodiversitylibrary.org/Search.aspx?',
    /* urlVariables  */ 
'searchTerm=%s&searchCat=N',
    /* title         */ 'Durchsuche Biodiversity library (Namen)',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'NaturfotographBjornRorslettSearch', 
    /* urlBasis      */ 'http://www.google.com/search?',
    /* urlVariables  */ 'domains=naturfotograf.com&q=%s&sa=Google+Search&sitesearch=www.naturfotograf.com',
    /* title         */ 'Naturfotograph Bjørn Rørslett (via Google)',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'HerbariumBerlinenseSearch',
    /* urlBasis      */ 'http://ww2.bgbm.fu-berlin.de/herbarium/access.cfm?Col=4&IsoCode=all&Fam=all&SubColl=all&Genus=all&FullNameCache=',
    /* urlVariables  */ 'SubCollectionList=all&CountryList=all&FamilyList=all&GenusList=all&q=%s',
    /* title         */ 'Durchsuche Herbarium Berlinense (Botanischer Garten und Museum Berlin)',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'HerbariumErlangenseSearch',
    /* urlBasis      */ 'http://www.herbarium-erlangense.nat.uni-erlangen.de/datenbank/suche.shtml',
    /* urlVariables  */ 'taxon=%s&sammler=&ort=&join=and&submit1=suchen',
    /* title         */ 'Durchsuche Herbarium Erlangense',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'BayernfloraTaxonSearch',
    /* urlBasis      */ 'http://daten.bayernflora.de/de/info_pflanzen.php?taxnr=#nav_rechts',
    /* urlVariables  */ 'de=&g=&suchtext=%s',
    /* title         */ 'Durchsuche Bayernflora (Verbreitungskarten/Bilder)',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'BayernfloraCommonNameSearch',
    /* urlBasis      */ 'http://daten.bayernflora.de/de/info_pflanzen.php?taxnr=#nav_rechts',
    /* urlVariables  */ 'de=1&g=&suchtext=%s',
    /* title         */ 'Durchsuche Bayernflora (Verbreitungskarten/Bilder)',
    /* formMethod    */ 'post',
    /* defaultstring */ 'Umgangssprachlichen Namen eingeben…'
  );
  createSearchForm(
    /* span.id       */ 'BioLibSearch',
    /* urlBasis      */ 'http://www.google.com/search?',
    /* urlVariables  */ 'as_sitesearch=http://caliban.mpiz-koeln.mpg.de&q=%s',
    /* title         */ 'Durchsuche BioLib (Tafeln/Bilder aus alten Büchern via Google)',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'NKISInfoSearch',
    /* urlBasis      */ 'http://www.nkis.info/nkis/extaustaxonshow.cgi?',
    /* urlVariables  */ 'uid=guest&taxnr=%s&lang=g',
    /* title         */ 'Durchsuche Taxonbeschreibungen des NKIS (GROß/klein + vollständiger Name!)',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'TelabotanikaSearch',
    /* urlBasis      */ 'http://www.tela-botanica.org/page:bdnff?',
    /* urlVariables  */ 'eflore_nom=%s&eflore_referentiel=25&eflore_type_nom=nom_scientifique&module=recherche&action=recherche_nom&langue=en',
    /* title         */ 'Durchsuche Telabotanika (Französische Pflanzen Datenbank)',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'FungiKonradSchieferdeckerSearch',
    /* urlBasis      */ 'http://www.botanischestaatssammlung.de/DatabaseClients/BSMschiefcoll/DiversityCollection_BSMschiefcoll_FindList.cfm',
    /* urlVariables  */ 'TaxonNameMainUnit=&TaxonPartMainUnit=%s&TaxonMainPartSearchType=acceptednames&CountryName=Germany&Locality=&CollectorsName=&Exsiccata=&Collection=265&TaxonNameSubstratum=&TaxonPartSubstratum=&StartRow=1&MaxItems=10',
    /* title         */ 'Suche Bilder/Zeichnungen Pilzen im deutschsprachigen Raum von Konrad Schieferdecker',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'FungiFritzWohlfarthSearch',
    /* urlBasis      */ 'http://www.botanischestaatssammlung.de/DatabaseClients/BSMwohlfcoll/DiversityCollection_BSMwohlfcoll_FindList.cfm',
    /* urlVariables  */ 'TaxonNameMainUnit=&TaxonPartMainUnit=%s&TaxonMainPartSearchType=acceptednames&CountryName=Germany&Locality=&CollectorsName=&Exsiccata=&Collection=266&TaxonNameSubstratum=&TaxonPartSubstratum=&StartRow=1&MaxItems=10',
    /* title         */ 'Suche Bilder/Zeichnungen Pilzen im deutschsprachigen Raum von Fritz Wohlfarth',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'NaturInNRWSearch',
    /* urlBasis      */ 'http://www.natur-in-nrw.de/cgi-bin/sitesearch.php.cgi',
    /* urlVariables  */ 'template=suche.tpl&searchprocess=&language=&query=%s&maxresults=50',
    /* title         */ 'Durchsuche Natur in NRW Steckbriefe/Bilder von Tieren',
    /* formMethod    */ 'post'
  );
  createSearchForm(
    /* span.id       */ 'CommonsMultimediaSearch',
    /* urlBasis      */ 'http://commons.wikimedia.org/w/index.php?',
    /* urlVariables  */ 'title=Special%3ASearch&redirs=1&search=%s&fulltext=Search&ns6=1',
    /* title         */ 'Durchsuche Wikimedia Commons nach Multimedia-Dateien',
    /* formMethod    */ 'get',
    /* defaultstring */ 'Suchwort hier eingeben…'
  );
  createSearchForm(
    /* span.id       */ 'PhotopediaSearch',
    /* urlBasis      */ 'http://www.fotopedia.com/search/albums/all?',
    /* urlVariables  */ 'domain=fotopedia&sort=relevance&q=%s',
    /* title         */ 'Durchsuche Photopedia (dann Reiter „Photo“ drücken)',
    /* formMethod    */ 'get',
    /* defaultstring */ 'Suchwort hier eingeben…'
  );
  createSearchForm(
    /* span.id       */ 'OpenmediaSearch',
    /* urlBasis      */ 'http://www.species-id.net/o/index.php?',
    /* urlVariables  */ 'title=Special%3ASearch&redirs=1&search=%s&fulltext=Search&ns6=1',
    /* title         */ 'Durchsuche Openmedia Archiv',
    /* formMethod    */ 'get',
    /* defaultstring */ 'Suchwort hier eingeben…'
  );
  createSearchForm(
    /* span.id       */ 'ThePlantlistSearch',
    /* urlBasis      */ 'http://www.theplantlist.org/tpl1.1/search',
    /* urlVariables  */ 'q=%s',
    /* title         */ 'Taxon eingeben und Pflanzenliste abfragen',
    /* formMethod    */ 'get'
  );
  createSearchForm(
    /* span.id       */ 'BayernfloraBibliographieSearch',
    /* urlBasis      */ 'http://daten.bayernflora.de/de/biblio.php#nav_rechts',
    /* urlVariables  */ 'de=1&g=&suchtext=%s',
    /* title         */ 'Durchsuche Bayernflora (Bibliographie)',
    /* formMethod    */ 'post'
   );
  createSearchForm(
    /* span.id       */ 'InternetArchiveSearch',
    /* urlBasis      */ 'http://www.archive.org/searchresults.php',
    /* urlVariables  */ 'search=%s&mediatype=all&limit=100&start=0&searchAll=yes&submit=this+was+submitted&gobutton.x=0&gobutton.y=0',
    /* title         */ 'Suchbegriff in Büchern, Medien suchen',
    /* formMethod    */ 'post'
  );
});// END doc-ready
// </syntaxhighlight>