Content deleted Content added
update from my commons.js |
update (fixes error for high level taxa) |
||
Line 287:
// we don't ahve the rank, so first get the rank (needed to get speciesboxes for genus)
var search = '
console.log(search);
jQuery.getJSON(
mw.util.wikiScript( 'api' ),
{ 'format': 'json', 'action': 'query', 'list': 'search', 'srnamespace' :10, 'srlimit' :
function( data ) {
if (data.query == undefined) return; // intermittant and seemingly random - not clear why
Line 299 ⟶ 301:
if (nResults === 0) {
console.log ('no results for rank of taxon ' + taxon );
addChildrenInteractive(taxon, level, mode , depth, taxonId); // pass without a rank
}
else { // so we have some results
$.each ( data.query.search , function( index , sr ) {
if (sr.title == "Template:Taxonomy/" + taxon ) {
var match = sr.snippet.match(/rank[\s]*=[\s]*([a-zA-Z ]*)/);
if (match && match[1] ) {
Line 328 ⟶ 331:
taxon = taxon.replace(")","\\)");
taxon = taxon.replace("?","\\?");
//taxon = taxon.replace("/","\\/");
taxon = taxon.replace(/\//g,"\\/");
taxon = taxon.replace(".","\\.");
Line 691 ⟶ 695:
// if (debug) alert ('no results for taxon (rank) = ' + taxon + ' (' + rank + ')');
// speciesboxes search now launched after the end of the if else results loop
output = ' [no child templates]'; // "zero hits: " + taxon;
if (hideChildless) {
Line 702:
else {
if (showParameters) $('#'+taxonId+' span.tree-info').append(output);
if (rank != "genus" && rank != "subgenus" && rank != "sectio" && rank != "series") {
$('#'+taxonId+'-collapse').html('<span style="color:grey;"> ⊡ </span>').off("click"); // change symbols and disable
}
}
Line 713 ⟶ 711:
$('#'+taxonId).append('<ul class="' + bullets + '"></ul>'); // add ul element to contain children
var listCount = 0;
Line 758 ⟶ 755:
variant = ' [parent='+parent+']';
}
if ( sameAs && $("#search-sameas").prop("checked")) { // accept if sameas (any or =taxon)
accept = true;
Line 861 ⟶ 858:
}); // end @each loop
if (listCount == 0 ) { // we are here when there are no strict results
// e.g. with Panthera, which has results with "parent=Pantherapsida"
console.log("no results with strict matching of " + taxon + ' (' + rank + ')');
}
if (showParameters) {
$('#'+taxonId+' > span.tree-info').append(" [" + count + " child templates]"); // number of results; excludes variants
Line 905 ⟶ 868:
} // end if results
} else {
//if (debug) alert ("Speciesbox block doesn't exist; will add one");
addSpeciesboxes(taxon, level, mode, depth, taxonId, rank, parent); // look for species boxes
}
}
}
else if (showSpeciesboxes) { // check speciesboxes even when there are child templates
if (rank == 'genus' || rank == 'subgenus' || rank == 'sectio' || rank == 'series' ) {
//if (debug) alert ('rank = ' + rank + '; taxon = ' + taxon + '; parent = ' + parent );
addSpeciesboxes(taxon, level, mode, depth, taxonId, rank, parent);
}
}
} // end processing function (data)
);
Line 917 ⟶ 893:
//------------------------------------function to check species boxes under generic taxa---------------------------------------------
function addSpeciesboxes(taxon, level, mode, depth, taxonId, rank,
//if (debug) alert ('Call to addSpeciesboxs for taxon (rank) = ' + taxon + ' (' + rank + '); parent = ' + parent );
Line 1,011 ⟶ 987:
$.each ( data.query.search , function( index , sr ) {
//
//var extinct = getExtinct(index , sr);
//if (hideExtinct && extinct) return true; // don't show extinct taxa (info not available for speciesboxes)
// display the selected child taxa
count += 1;
var child = sr.title.replace(" ", "_");
var parent = "";
var
if ( sr.snippet.search(/taxon *=/) > 0 ) {
var snippet = sr.snippet.replace ('<span class="searchmatch">', ''); // remove highlighting from search snippet
snippet = snippet.replace ('</span>', '');
//var snippetTaxon = snippet.replace(/[\s\S]+taxon *= *(\w+) (\w+)[\s\S]+/, "$1 $2");
//
if (snippetTaxon == snippet) {
if (debug) comment = " [taxon not available in search snippet]"; //
} else {
binomial = snippetTaxon; // should snippetTaxon be checke?
}
console.log("taxon=" + snippetTaxon + comment);
}
else if (sr.snippet.search(/genus *=/) > 0 && sr.snippet.search(/species *=/) > 0 ) { // if speciesbox with genus= and species=
if (species == sr.snippet) { // if species epithet not available in search snippet
species = "</i>sp.";
comment = " [species epithet not available in search snippet]"; // when species not available in snippet
}
console.log("taxon(genus+species)=" + genus + " " + species + " " + comment);
} else {
comment = " [snippet doesn't contain taxon or genus and species]";
binomial = "not available";
}
parent = sr.snippet.replace(/[\s\S]+parent *= *(\w+[\w \.]*\w+)[\s\S]+/, "$1");
//parent = sr.snippet.replace(/[\s\S]+parent *= *(\w+)[\s\S]+/, "$1");
if (parent == sr.snippet) { // if parent not captured
if (debug) comment += " [no parent or not in snippet]";
} else {
if (debug) comment += " [parent = " + parent + "]";
}
var name = sr.title;
if ( binomial == sr.title ) {
binomial = ""; // don't show if binomial if same as page title
name = "<i>" + name + "</i>" ; // italicise page title if binomial
} else {
binomial = " (<i>" + binomial + "</i>)" ; // display binomial after page title if different
if ( genus == sr.title ) name = "<i>" + name + "</i>" ; // italicise page title is monotypic genus
}
var titleString = ' title=""';
if (showParameters) {
Line 1,054 ⟶ 1,048:
}
var childId = sr.title.replace(" ", "_") + "_SPECIES"; // + '-li';
output = '<li id="' + childId + '" class="taxon_identifier" >';
//if (extinct) output += '†'; // cannot know extinct status for speciesbox
output += '<a href="/wiki/' + sr.title + '" ' + titleString + ' target="_blank"
output += '<span class="tree-info" style="color:grey;" >'; // span for add information
output += binomial;
if (debug) {
//output += extraText(index , sr);
output += comment;
}
output += '</span>'; // close info span
|