MediaWiki:SearchTools.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „// <source lang="javascript"> // This JavaScript will be loaded only for some pages, see MediaWiki:Common.js // License Creative Commons Share Alike: A. Plank…“) |
(kein Unterschied)
|
Version vom 19. März 2018, 13:43 Uhr
// <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
/**
* @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>)
* @returns {String}
*/
function CreateSearchForm(id, urlBasis, urlVariables, title, formMethod, defaultString) {
/* 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 + "'></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=30 " : "" ) +
(urlValue === '%s' ? (defaultString.match(/(…$)/ig) ? " onfocus=\"this.value == ""+ defaultString +"" ? this.value = "" : 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',
// 'fa=%&spe=%s&co=&chi=0',
/* title */ 'Suche Free Inactive Patent Search',
/* formMethod */ 'post'
);
});// END doc-ready