User:PerfektesChaos/js/citoidWikitext/core/d.js: Difference between revisions

Content deleted Content added
-2.3
-2.4
Line 1:
/// User:PerfektesChaos/js/citoidWikitext/core.js
// Execute core functionality for citoid on wikitext source editing
/// 2016-03-2529 PerfektesChaos@de.wikipedia
// ResourceLoader: compatible;
// dependencies: --
Line 17:
( function ( mw, $ ) {
"use strict";
var VERSION = -2.34,
MW_LIB = "citoidWikitext",
Sub = "core",
Line 47:
CITWT.vsn = CITWT.vsn + "c:" + VERSION;
CITWT.type = MW_LIB;
CITWT.support = "[[w:en:user:PerfektesChaos/js/" + CITWT.type + "]]";
if ( typeof CITWT[ Sub ] !== "object" || ! CITWT[ Sub ] ) {
CITWT[ Sub ] = { };
Line 256:
 
//-----------------------------------------------------------------------
 
 
 
/*
BOOK.countries978 = [
[ "bg", 954 ],
[ "cs", 80 ],
[ "da", 87 ],
[ "de", 3 ],
[ "el", 960, 9963 ],
[ "en", 0, 1 ],
[ "es", 84, 950, 956, 958, 959, 968, 970, 980, 987,
9942, 9945, 9962, 9968, 9972, 9974, 9977, 9978,
99905, 99922, 99923, 99924, 99925, 99926,
99934, 99939, 99953, 99954 ],
[ "et", 9949, 9985 ],
[ "fi", 951, 952 ],
[ "fr", 2 ],
[ "he", 965 ],
[ "hu", 963 ],
[ "it", 88 ],
[ "ja", 4 ],
[ "ko", 89, 9946 ],
[ "nl", 90 ],
[ "nn", 82 ],
[ "no", 82 ],
[ "pl", 83 ],
[ "pt", 85, 972, 989 ],
[ "ru", 5 ],
[ "sk", 80 ],
[ "sl", 961 ],
[ "sv", 91 ],
[ "th", 974 ],
[ "tr", 975, 9944 ],
[ "uk", 966 ],
[ "zh", 7 ]
]; // BOOK.countries978 2015-05-01
*/
 
 
 
BOOK.finder = function ( assign ) {
// Retrieve set of library catalog URLs for a particular language
// Precondition:
// assign -- language code (not "qqq"), or false
// Postcondition:
// Returns Array, might be empty
// "qqq" will always precede the list
// Uses:
// this
// > BOOK.catalogs
// BOOK.furnish()
// 2016-03-25 PerfektesChaos@de.wikipedia
/*
// 2015-05-01 PerfektesChaos@de.wikipedia
var r = [ ],
g, i;
if ( typeof BOOK.catalogs !== "object" ) {
BOOK.furnish();
}
for ( i = 0; i < BOOK.catalogs.qqq.length; i++ ) {
r.push( BOOK.catalogs.qqq[ i ] );
} // for i
if ( assign &&
typeof BOOK.catalogs[ assign ] === "object" ) {
g = BOOK.catalogs[ assign ];
for ( i = 0; i < g.length; i++ ) {
r.push( g[ i ] );
} // for i
}
return r;
*/
return CITWT.isbnLib.finder( assign );
}; // BOOK.finder()
 
 
Line 361 ⟶ 287:
GUIP.fire();
}; // BOOK.first()
 
 
 
BOOK.focus = function ( analyse, advanced ) {
// Guess language code from ISBN string
// Precondition:
// analyse -- ISBN string (length 10 or 13)
// advanced -- ISBN-13 from 979
// Postcondition:
// Returns language code, or false
// Uses:
// this
// > BOOK.countries978
// 2016-03-25 PerfektesChaos@de.wikipedia
/*
// 2015-05-01 PerfektesChaos@de.wikipedia
var r = false,
g, i, k, n;
if ( advanced ) {
switch ( analyse.substr( 3, 2 ) ) {
case "10": r = "fr"; break;
case "11": r = "ko"; break;
case "12": r = "it"; break;
} // switch substr( 3, 2 )
} else {
switch ( analyse.substr( 0, 1 ) ) {
case "0":
case "1": r = "en"; break;
case "2": r = "fr"; break;
case "3": r = "de"; break;
case "4": r = "ja"; break;
case "5": r = "ru"; break;
case "6":
n = analyse.substr( 0, 3 );
break;
case "7": r = "zh"; break;
case "8":
n = analyse.substr( 0, 2 );
break;
case "9":
switch ( analyse.substr( 0, 2 ) ) {
case "90":
case "94": r = "nl"; break;
case "91": r = "sv"; break;
case "92": r = "mul"; break;
default:
if ( analyse.substr( 1, 1 ) === "9" ) {
if ( analyse.substr( 2, 1 ) === "9" ) {
n = 5;
} else {
n = 4;
}
} else {
n = 3;
}
n = analyse.substr( 0, n );
} // switch substr( 0, 2 )
break;
} // switch substr( 0, 1 )
if ( n ) {
n = parseInt( n, 10 );
for ( i = 0; i < this.countries978.length; i++ ) {
g = this.countries978[ i ];
for ( k = 1; k < g.length; k++ ) {
if ( g[ k ] === n ) {
r = g[ 0 ];
break; // for k
}
} // for k
if ( r ) {
break; // for i
}
} // for i
}
}
return r;
*/
return CITWT.isbnLib.focus( analyse );
}; // BOOK.focus()
 
 
 
/*
BOOK.furnish = function () {
// Build set of library catalogs, including user defined
// Uses:
// this
// > .isbn (user defined)
// < BOOK.catalogs
// 2015-05-01 PerfektesChaos@de.wikipedia
var g, i, s, slang, user;
BOOK.catalogs = {
de: [ "http://swb.bsz-bw.de/"
+ "DB=2.1/CMD?ACT=SRCHA&IKT=1007&TRM=#",
// "http://gso.gbv.de/DB=2.1/"
// + "CMD?ACT=SRCHA&IKT=1007&TRM=#",
"https://portal.dnb.de/"
+ "opac.htm?method=simpleSearch&query=#" ],
en: [ "http://catalog.loc.gov/"
+ "cgi-bin/Pwebrecon.cgi?DB=local&CNT=10&CMD=#" ],
// British Library requires Login
// "http://explore.bl.uk/"
// + "primo_library/libweb/action/search.do"
// + "?fn=search&vl(freeText0)=#"
fr: [ "http://catalogue.bnf.fr/servlet/AccueilConnecte?"
+ "recherche=equation&Equation=ibn+=+#" ],
nl: [ "http://opc4.kb.nl/"
+ "LNG=NE/CMD?ACT=SRCH&IKT=1007&TRM=#" ],
pl: [ "http://koha.biblos.pk.edu.pl/cgi-bin/koha/"
+ "opac-search.pl?idx=nb&q=#" ],
qqq: [ "http://www.worldcat.org/search?q=isbn:#" ]
};
switch ( typeof CITWT.isbn ) {
case "string":
user = { qqq: [ CITWT.isbn ] };
break;
case "object":
if ( CITWT.isbn ) {
if ( CITWT.isbn.length === "number" ) {
user = { qqq: CITWT.isbn };
} else {
user = CITWT.isbn;
}
}
break;
} // switch typeof CITWT.isbn
if ( user ) {
for ( slang in user ) {
g = user[ slang ];
if ( typeof g === "object" && g
&& typeof g.length === "number" ) {
if ( typeof BOOK.catalogs[ slang ] !== "object" ) {
BOOK.catalogs[ slang ] = [ ];
}
for ( i = 0; i < g.length; i++ ) {
s = g[ i ];
if ( typeof s === "string" &&
s.indexOf( "#" ) > 10 ) {
BOOK.catalogs[ slang ].push( s );
}
} // for i
}
} // for slang in user
} // user defined
}; // BOOK.furnish()
*/
 
 
Line 853 ⟶ 633:
// Returns object, or not
// Uses:
// BOOK.isbnLib.focus()
// BOOK.isbnLib.finder()
// 20152016-0503-0129 PerfektesChaos@de.wikipedia
var got, i, isbnLib, r;
switch ( achieved ) {
case 0:
Line 869 ⟶ 649:
got = /^([-0-9]+x?)(?:[^-0-9x].*)?$/i.exec( r.isbn );
if ( got ) {
isbnLib = CITWT.isbnLib;
r.isbn = got[ 1 ].replace( /-/g, "" );
switch ( r.isbn.length ) {
Line 874 ⟶ 655:
r.isbn = r.isbn.toUpperCase();
if ( /^[0-9]+X?$/.test( r.isbn ) ) {
r.lang = BOOKisbnLib.focus( r.isbn );
r.url = true;
}
Line 882 ⟶ 663:
if ( got ) {
if ( got[ 1 ] === "8" ) {
r.lang = BOOKisbnLib.focus( r.isbn.substr( 3 ) );
} else {
r.lang = BOOKisbnLib.focus( r.isbn, true );
}
r.url = true;
Line 891 ⟶ 672:
} // switch n
if ( r.url ) {
r.url = BOOKisbnLib.finder( r.lang );
r.say = r.isbn;
r.url.push( "/wiki/Special:Booksources/#" );