/// PerfektesChaos/js/isbnLib/d.js
/// 2018-08-24 [email protected]
/// Fingerprint: #0#0#
/// ISBN utility package
/* global window:false */
/* jshint forin:false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var LIB = "isbnLib",
Version = -2.8,
PRIVATE = { wstmBB: "SU" };
if ( typeof mw.libs !== "object" || ! mw.libs ) {
mw.libs = { };
}
mw.libs.vsn = Version;
mw.libs.type = LIB;
LIB = mw.libs;
/// @license GPL (+GFDL, LGPL, CC-BY-SA)
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
if ( typeof LIB.doc !== "string" ) {
LIB.doc = "]";
}
// Requires: JavaScript 1.5 RegExp non-capturing parenthese
PRIVATE.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/vwebv/search?"
+ "searchCode=ISBL&searchType=1&searchArg=#" ],
// "http://catalog.loc.gov/vwebv/search?"
// + "searchCode=STNO&searchType=1&searchArg=#"
// British Library requires Login
// "http://explore.bl.uk/"
// + "primo_library/libweb/action/search.do"
// + "?fn=search&vl(freeText0)=#"
// DEPRECATED:
// "http://catalog.loc.gov/"
// + "cgi-bin/Pwebrecon.cgi?DB=local&CNT=10&CMD=#"
fr: [ "http://catalogue.bnf.fr/search.do?"
+ "mots0=NRC;-1;0;#&pageRech=rav" ],
nl: ,
pl: [ "http://koha.biblos.pk.edu.pl/cgi-bin/koha/"
+ "opac-search.pl?idx=nb&q=#" ],
pt: [ "http://aleph20.letras.up.pt/F/?"
+ "func=find-b&find_code=ISBN&request=#",
"http://porbase.bnportugal.pt/ipac20/ipac.jsp?"
+ "menu=search&index=ISBN&term=#" ],
sv: ,
qqq:
}; // 2017-05-18
PRIVATE.countries978 = [
,
,
,
,
,
,
[ "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 ],
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
]; // .countries978 2015-05-01
function feed( about ) {
/**
Callback from external library
@version 2018-08-24 [email protected]
@param about Array with details; about = "U" or "S"
*/
var rls, s;
if ( typeof about === "object" &&
typeof about === "string" ) {
LIB.loaded = true;
LIB.wstm ] = true;
for ( s in LIB.wstm ) {
LIB.loaded = LIB.loaded && LIB.wstm;
} // for s in LIB.wstm
if ( LIB.loaded ) {
rls = { };
rls = "ready";
mw.loader.state( rls );
mw.hook( "isbnLib.ready" ).fire( LIB );
}
}
} // feed()
function fill() {
/**
Ensure minimal catalogs
@version 2016-03-20 [email protected]
*/
if ( typeof LIB.catalogs !== "object"
|| ! LIB.catalogs ||
typeof LIB.catalogs.qqq !== "object"
|| ! LIB.catalogs.qqq ||
typeof LIB.catalogs.qqq.length !== "number" ||
typeof LIB.catalogs.qqq !== "string" ) {
LIB.catalogs = PRIVATE.catalogs;
}
} // fill()
function fine() {
/**
Retrieve pointer to external library
@version 2016-03-22 [email protected]
@return object with external library, or undefined
*/
var r;
if ( typeof LIB.loaded === "boolean"
&& LIB.loaded &&
typeof mw.libs.WikiSyntaxTextMod === "object" &&
typeof mw.libs.WikiSyntaxTextMod.util === "object" &&
typeof mw.libs.WikiSyntaxTextMod.util.isbn === "object" ) {
r = mw.libs.WikiSyntaxTextMod.util.isbn;
}
return r;
} // fine()
function first() {
/**
Internal initialization, last attempt to attach libraries
@version 2018-08-24 [email protected]
*/
var i, rls, s, self, signature, state, sub;
if ( typeof LIB.wstm !== "object" ) {
rls = { };
self = "ext.gadget." + LIB.type;
rls = "loading";
mw.loader.state( rls );
LIB.wstm = { };
sub = ( Version > 0 ? "r" : "d" );
for ( i = 0; i < PRIVATE.wstmBB.length; i++ ) {
s = PRIVATE.wstmBB.substr( i, 1 );
LIB.wstm = false;
signature = "user:PerfektesChaos/WikiSyntaxTextMod/"
+ s;
state = mw.loader.getState( signature );
if ( ! state ) {
rls = { };
rls = "loading";
mw.loader.state( rls );
mw.loader.load( "https://en.wikipedia.org/w/index.php?"
+ "title=User:PerfektesChaos/js/"
+ "WikiSyntaxTextMod/" + sub + s + ".js"
+ "&bcache=1&maxage=604812"
+ "&action=raw&ctype=text/javascript" );
}
if ( state === "ready" ) {
feed( );
} else {
mw.hook( "WikiSyntaxTextMod/" + s + ".ready" )
.add( feed );
}
} // for i
rls = { };
rls = "ready";
mw.loader.state( rls );
}
} // first()
LIB.factory = function ( attribute ) {
/**
Make regexp string for ISBN detection
@version 2013-11-04 [email protected]
@param attribute true: URLs are excluded from detection
@return string for RegExp; null if no libraries
*/
var wstmUisbn = fine(),
r;
if ( wstmUisbn ) {
r = wstmUisbn.factory( attribute );
} else {
r = null;
}
return r;
}; // .factory()
LIB.finder = function ( assign ) {
/**
Retrieve set of library catalog URLs for particular languages
@version 2016-04-14 [email protected]
@param assign string with language code (not "qqq"), or false
@return Array of URL strings, "qqq" will always precede the list
*/
var r = ,
b, g, i, k, s, u;
fill();
for ( i = 0; i < LIB.catalogs.qqq.length; i++ ) {
r.push( LIB.catalogs.qqq );
} // for i
if ( typeof assign === "string"
&& assign !== "qqq" ) {
b = assign.split( " " );
for ( k = 0; k < b.length; k++ ) {
s = b;
if ( typeof LIB.catalogs === "object" ) {
g = LIB.catalogs;
for ( i = 0; i < g.length; i++ ) {
u = g;
if ( $.inArray( u, r ) < 0 ) {
r.push( u );
}
} // for i
}
} // for k
}
return r;
}; // .finder()
LIB.flip = function ( adjust ) {
/**
Retrieve corresponding ISBN-10 for ISBN-13, or ISBN-13 for ISBN-10
@version 2013-11-04 [email protected]
@param adjust string with ISBN (ID only, freestyle, no keyword)
@return string, if valid; false if invalid sequence; null else
*/
var wstmUisbn = fine(),
r;
if ( wstmUisbn ) {
r = wstmUisbn.flip( adjust, function () { } );
} else {
r = null;
}
return r;
}; // .flip()
LIB.focus = function ( about ) {
/**
Guess language(s) from ISBN: space separated ISO 639 codes
@version 2016-03-22 [email protected]
@param about string with ISBN
@return string, if valid; false if not detected
*/
var r = false,
s = about.replace( /-/g, "" ),
k = s.length,
g, i, n;
if ( k === 13 ) {
k = s.substr( 0, 3 );
if ( k === "979" ) {
switch ( s.substr( 3, 2 ) ) {
case "10": r = "fr"; break;
case "11": r = "ko"; break;
case "12": r = "it"; break;
} // switch substr( 3, 2 )
} else if ( k === "978" ) {
k = 10;
s = s.substr( 3 );
}
}
if ( k === 10 ) {
switch ( s.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 = s.substr( 0, 3 );
break;
case "7": r = "zh"; break;
case "8":
n = s.substr( 0, 2 );
break;
case "9":
switch ( s.substr( 0, 2 ) ) {
case "90":
case "94": r = "nl"; break;
case "91": r = "sv"; break;
case "92": r = "mul"; break;
default:
if ( s.substr( 1, 1 ) === "9" ) {
if ( s.substr( 2, 1 ) === "9" ) {
n = 5;
} else {
n = 4;
}
} else {
n = 3;
}
n = s.substr( 0, n );
} // switch substr( 0, 2 )
break;
} // switch substr( 0, 1 )
if ( n ) {
n = parseInt( n, 10 );
for ( i = 0; i < PRIVATE.countries978.length; i++ ) {
g = PRIVATE.countries978;
for ( k = 1; k < g.length; k++ ) {
if ( g === n ) {
r = g;
break; // for k
}
} // for k
if ( r ) {
break; // for i
}
} // for i
}
}
return r;
}; // .focus()
LIB.format = function ( adjust, additional ) {
/**
Retrieve formatted ISBN
@version 2016-04-11 [email protected]
@param adjust string with ISBN (ID only, freestyle, no keyword)
@param additional true: return Array rather than string
@return string/Array if valid; false if invalid sequence; null else
*/
var wstmUisbn = fine(),
r;
if ( wstmUisbn ) {
r = wstmUisbn.format( adjust, false, function () { } );
if ( r ) {
if ( ! additional ) {
r = r;
}
} else {
r = false;
}
} else {
r = null;
}
return r;
}; // .format()
LIB.furnish = function ( add ) {
/**
Add resolvers to default catalogs
@version 2016-03-22 [email protected]
@param add object with language dependant resolvers
*/
var cat, g, i, j, s, slang, user;
switch ( typeof add ) {
case "string":
user = { qqq: };
break;
case "object":
if ( add ) {
if ( add.length === "number" ) {
user = { qqq: add };
} else {
user = add;
}
}
break;
} // switch typeof add
if ( user ) {
fill();
if ( typeof LIB.reLang !== "object" ) {
LIB.reLang = new RegExp( "^+$" );
LIB.reURL1 = new RegExp( "^\\S+$" );
LIB.reURL2 = new RegExp( "^https?://+\\.+/.*#" );
}
for ( slang in user ) {
if ( typeof slang === "string" &&
LIB.reLang.test( slang ) ) {
g = user;
if ( typeof g === "object" && g
&& typeof g.length === "number" ) {
if ( typeof LIB.catalogs !== "object" ) {
LIB.catalogs = ;
}
cat = LIB.catalogs;
for ( i = 0; i < g.length; i++ ) {
s = g;
if ( typeof s === "string" &&
LIB.reURL1.test( s ) &&
LIB.reURL2.test( s ) ) {
for ( j = 0; j < cat.length; j++ ) {
if ( cat === s ) {
s = false;
break; // for j
}
} // for j
if ( s ) {
cat.push( s );
}
}
} // for i
}
}
} // for slang in user
} // user defined
}; // .furnish()
// autoInit onLoad
first();
}( window.mediaWiki, window.jQuery ) );
// Emacs
// Local Variables:
// coding: iso-8859-1-dos
// fill-column: 80
// End:
/// EOF </nowiki> isbnLib/d.js