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

Content deleted Content added
-0.03
-1.5
 
(7 intermediate revisions by the same user not shown)
Line 1:
/// User:PerfektesChaos/js/refNames/core/d.js
/// 20222023-0705-2701 PerfektesChaos@de.wikipedia
// <ref name="..."> major work
// ResourceLoader: compatible;
Line 19:
( function ( mw, $ ) {
"use strict";
var Version = -01.035,
Signature = "refNames",
THIS = { lapsus: false,
Line 54:
0x2003, // emsp
0x2009, // thinsp
0x200A, // HAIRsp
0x200B, // ZEROsp
0x200C, // zwnj
0x200D, // zwj
Line 67 ⟶ 69:
0x2032, // prime
0x2033, // Prime
0x2039, // ‹
0x203A, // ›
0x5D )
],
Line 72 ⟶ 76:
},
PARSER = { reQuot: false,
reWS: false,
pending: false,
$textarea: false },
SOURCE = { before: [ ".wikibase-entity-usage",
Line 88 ⟶ 94:
wait: [ "de", "Ajax-loader.gif" ]
},
section: "section",
$box: false,
$editor: false,
Line 171 ⟶ 178:
// Portlet request
// Uses:
// > THIS.$widget
// > PARSER.$textarea
// > THIS.$widget
// > THIS.selector
// >< SOURCE.section
// VIEW.fire()
// SOURCE.first()
// 2022-0708-0108 PerfektesChaos@de.wikipedia
var learn = ( PARSER.$textarea ? true : false );
if ( THIS.$widget ) {
THIS.$widget.empty();
}
if ( learn ) {
SOURCE.section = THIS.selector + SOURCE.section;
} else {
SOURCE.section = false;
}
VIEW.fire();
if ( PARSER.$textarealearn ) {
SOURCE.first( true );
}
Line 193 ⟶ 208:
// [ 0 ] -- string, with 2 hex storage path
// [ 1 ] -- string, with signifcant ID
// appearance -- intnumber, with pixel size
// 2022-07-01 PerfektesChaos@de.wikipedia
var $r = $( "<img>" );
Line 347 ⟶ 362:
// > THIS.selItem
// > THIS.selWarn
// > SOURCE.section
// failure()
// $fault()
// 2022-07-01 PerfektesChaos@de (SOURCE.wikipediaforward)
// 2022-08-08 PerfektesChaos@de.wikipedia
var $r = $( "<span>" ),
$swap;
Line 360 ⟶ 377:
$r.append( $fault( apply ) )
.append( $swap );
}
if ( SOURCE.section ) {
$r.click( SOURCE.forward );
}
return $r;
Line 370 ⟶ 390:
// Precondition:
// all -- string, with entire story
// at -- intnumber, position in all
// allow -- true, if bidi permitted
// Postcondition:
Line 452 ⟶ 472:
 
 
PARSER.fault = function ( all, at, alert, about ) {
// Communicate error details (browser console)
// Precondition:
// at all -- intstring, positionwith inentire wikitextstory
// at -- number, position in wikitext
// alert -- string, with message
// about -- string, with detail, or not
// Uses:
// > Signature
// 2022-07-01 PerfektesChaos@de >< PARSER.wikipediareWS
// 2022-08-25 PerfektesChaos@de.wikipedia
var s;
var i, n, s;
if ( typeof window.console === "object" &&
typeof window.console.warn === "function" ) {
si = Signature + " #" + at + " " + alert-1;
n = 0;
do {
i = all.indexOf( "\n", i + 1 );
n++;
} while ( i >= 0 && i < at );
s = Signature + " #" + at + " @" + n + " " + alert;
if ( about ) {
s = s + " -- " + about;
}
if ( ! PARSER.reWS ) {
PARSER.reWS = new RegExp( "\\s+" );
}
i = at;
while ( all.charCodeAt( i ) !== 0x3C && i >= 0 ) {
i--;
} // while
n = all.indexOf( ">", i + 1 );
if ( n < 0 ) {
n = i + 100;
}
s = s + "\n"
+ all.substring( i, n + 1).replace( PARSER.reWS, " " );
window.console.warn( s );
}
Line 478 ⟶ 519:
// Precondition:
// all -- string, with entire story
// at -- intnumber, first possible position in all
// after -- intnumber, position of '>' in all
// about -- string, with attribute name
// Postcondition:
Line 485 ⟶ 526:
// .set -- string, value
// .lock -- boolean, on error
// .more -- intnumber, position after value
// Uses:
// PARSER.first()
Line 491 ⟶ 532:
// PARSER.focus()
// flat()
// 2022-0708-0124 PerfektesChaos@de.wikipedia
var r = { "set": "",
"lock": false,
Line 503 ⟶ 544:
if ( k < 0 || k > after ) {
r.lock = true;
PARSER.fault( atall,
at,
"Unbalanced delimiter",
about + "=" + s );
} else if ( k === i + 1 ) {
r.lock = true;
PARSER.fault( atall,
at,
"Missing identifier",
about + "=" + s + s );
Line 516 ⟶ 559:
}
} else if ( k === 0x2F || k === 0x3E ) { // / >
PARSER.fault( all, at, "Identifier missing", about + "=" );
r.lock = true;
} else {
Line 525 ⟶ 568:
if ( k === i ) {
r.lock = true;
PARSER.fault( atall,
at,
"Missing identifier",
about + "=" );
Line 544 ⟶ 588:
 
 
PARSER.features = function ( all, at, after, alone ) {
// Retrieve <ref> or </references> tag attributes
// Precondition:
// all -- string, with entire story
// at -- intnumber, first possible position in all
// after -- intnumber, position of '>' in all
// alone -- boolean, for </ref>
// Postcondition:
// Returns object with name="", or not
Line 557 ⟶ 602:
// .content -- string, content until </ref>, or not
// .lone -- boolean, unary (/)
// .next -- intnumber, position of '>' in all
// Uses:
// < PARSER.lock
Line 564 ⟶ 609:
// PARSER.feature()
// PARSER.first()
// 2022-0708-2724 PerfektesChaos@de.wikipedia
var i = at,
j, lock, r, s, v;
Line 588 ⟶ 633:
}
if ( typeof r[ s ] === "string" ) {
PARSER.fault( all, at, "Duplicated keyword", s );
lock = true;
} else {
Line 598 ⟶ 643:
break;
default:
PARSER.fault( all, at, "Unknown keyword", s );
lock = true;
} // switch
Line 605 ⟶ 650:
if ( lock ) {
PARSER.lock = true;
} else if ( r ) {
i = PARSER.first( all, i, after );
if ( all.charCodeAt( i ) === 0x2F ) { // /
Line 611 ⟶ 656:
i = PARSER.first( all, ++i, after );
}
if ( ialone ===|| afterr.lone ) {
ifi = PARSER.first( rall, i, && ! r.nameafter ) {;
if ( ri === after ) false;{
if ( r && ! r.name && alone ) {
r = false;
}
} else {
PARSER.lock = true;
PARSER.fault( all, i, "Trailing garbage" );
}
} else {
PARSER.lock = true;
PARSER.fault( i, "Trailing garbage" );
}
}
Line 629 ⟶ 677:
// Precondition:
// all -- string, with entire story
// at -- intnumber, position after '<' in all
// after -- intnumber, position of '>' in all
// about -- object
// .group -- string, ID, or not
Line 643 ⟶ 691:
// Returns about object with modified entries
// .wikitext -- string, modified all
// .next -- intnumber, modified after position
// Uses:
// PARSER.fix()
Line 735 ⟶ 783:
 
 
PARSER.finish = function ( all, at, alone ) {
// Find </ref> or </references> tag
// Precondition:
// all -- string, with entire story
// at -- intnumber, first possible position in all
// alone -- boolean, for </ref>
// Postcondition:
// Returns Array [ begin, end ] of < >
Line 745 ⟶ 794:
// Uses:
// PARSER.first()
// 2022-07-0128 PerfektesChaos@de.wikipedia
var i = at,
j, kR, kE, kF, n, r, s;
do {
i = all.indexOf( "<", i );
Line 767 ⟶ 816:
if ( ( kR === 0x52 || kR === 0x72 ) &&
( kE === 0x45 || kE === 0x65 ) &&
( kF === 0x46 || kF === 0x66 ) ) &&{
if ( n === j + 4 alone) ||{
if ( n === PARSER.first( all, j + 4, n ) ) ) {||
r n === [ iPARSER.first( -all, 1 j + 4, n ];) ) {
r = [ i - 1, n ];
}
} else if ( n >= j + 10 ) {
kE = all.charCodeAt( j + 4 );
if ( kE === 0x45 || kE === 0x65 ) {
s = all.substring( j + 1, j + 11 )
.toLowerCase();
if ( s === "references" ) {
r = [ i - 1, n ];
}
}
}
}
}
Line 855 ⟶ 916:
// Uses:
// PARSER.front()
// 2022-0708-2701 PerfektesChaos@de.wikipedia
var i = 0,
s = all,
Line 905 ⟶ 966:
if ( e.name === v.name &&
e.group === v.group ) {
if ( v.content &&
e.content === v.content ) {
r[ k ].multi++;
}
r[ k ].content = e.content || v.content;
if ( r[ k ].content ) {
Line 960 ⟶ 1,025:
// Precondition:
// all -- string, with entire story
// at -- intnumber, first position in all
// after -- intnumber, beyond position in all
// Postcondition:
// Returns position in all, even after
Line 1,036 ⟶ 1,101:
// Precondition:
// all -- string, with entire story
// at -- intnumber, first possible position in all
// adjust -- object, with name-group to be replaced, or not
// .group -- string, ID, or not
Line 1,047 ⟶ 1,112:
// .content -- string, content until </ref>, or not
// .lone -- boolean, unary (/)
// .next multi -- intnumber, position of closing '>' in all0
// .next -- number, position of closing '>' in all
// .wikitext -- string, modified all
// Uses:
// >< PARSER.pending
// < PARSER.lock
// PARSER.first()
Line 1,055 ⟶ 1,122:
// PARSER.features()
// PARSER.fiat()
// 2022-07-01 PerfektesChaos@de PARSER.wikipediafrontal()
// 2022-07-28 PerfektesChaos@de.wikipedia
var i = at,
j, kR, kE, kF, n, r, v;
Line 1,067 ⟶ 1,135:
if ( n < 0 ) {
break; // while ! r
} else if ( n >= i + 10 ) {
j = PARSER.first( all, i, n );
if ( n >= j + 10 ) {
kR = all.charCodeAt( j );
kE = all.charCodeAt( j + 1 );
kF = all.charCodeAt( j + 2 );
if ( ( kR === 0x52 || kR === 0x72 ) &&
( kE === 0x45 || kE === 0x65 ) &&
( kF === 0x46 || kF === 0x66 ) ) &&{
if ( flat( all, j + 3 ) === 0x20 ) {
r = PARSER.features( all, j + 4, n, true );
if ( r ) {
if ( ! r.lone ) {
v = PARSER.finish( all, n + 1, true );
if ( v ) {
r.content = all.substring( n + 1, v[ 0 ] )
.trim( v[ 0 ] );
r.next = v[ 1 ] + 1 .trim();
} else { r.next = v[ 1 ] + 1;
PARSER.lock} =else true;{
PARSER.fault( i, "Missing </ref>"PARSER.lock = )true;
PARSER.fault( all,
i,
"Missing </ref>" );
}
}
if ( PARSER.pending ) {
if ( r.next < PARSER.pending.max ) {
r.group = PARSER.pending.shared;
} else {
PARSER.pending = false;
}
}
if ( r.name &&
adjust &&
adjust.seek === r.name &&
( ( ! adjust.group && ! r.group ) ||
adjust.group === r.group ) &&
! PARSER.lock ) {
r = PARSER.fiat( all, i, n, r, adjust );
}
}
} else if ( r.name &&{
kE = all.charCodeAt( j + adjust3 &&);
if ( kE === 0x45 adjust.seek || kE === r.name 0x65 ) &&{
PARSER.frontal( (all, !j, adjust.group && ! r.groupn ) ||;
adjust.group === r.group ) &&
! PARSER.lock ) {
r = PARSER.fiat( all, i, n, r, adjust );
}
}
Line 1,106 ⟶ 1,190:
return r;
}; // PARSER.front()
 
 
 
PARSER.frontal = function ( all, at, after ) {
// Check opening <references group=""> tag
// Precondition:
// all -- string, with entire story
// at -- number, position of "ref" in all
// after -- number, position of ">" in all
// Uses:
// >< PARSER.pending
// < PARSER.lock
// flat()
// PARSER.features()
// PARSER.finish()
// 2022-08-09 PerfektesChaos@de.wikipedia
var s = all.substring( at, at + 10 ).toLowerCase(),
k, q;
if ( s === "references" ) {
k = flat( all, at + 10 );
if ( k === 0x20 ) {
q = PARSER.features( all, at + 10, after, false );
if ( q && q.group && ! q.lone ) {
PARSER.pending = { shared: q.group };
q = PARSER.finish( all, at + 10, false );
if ( q ) {
PARSER.pending.max = q[ 0 ];
} else {
PARSER.pending.max = all.length;
PARSER.lock = true;
}
}
} else if ( PARSER.pending ) {
PARSER.pending = false;
}
}
}; // PARSER.frontal()
 
 
Line 1,425 ⟶ 1,546:
// > SOURCE.before
// > THIS.selItem
// > THIS.show
// > THIS.selector
// > SOURCE.section
// > THIS.show
// < SOURCE.grouped
// < SOURCE.groups
Line 1,437 ⟶ 1,559:
// SOURCE.fill()
// (SOURCE.favour)
// 2022-0708-0108 PerfektesChaos@de.wikipedia
var collection = PARSER.fire( always ),
i, $before, $editform, $head, $header;
Line 1,451 ⟶ 1,573:
$head = $( "<span>" );
$head.addClass( THIS.selItem )
.attr( { "langid": "en" SOURCE.section,
"lang": "en",
"role": "link",
"title": "help" } )
.click( SOURCE.favour )
.css( { "cursor": "pointer",
"font-size": "130%" } )
.html( THIS.show );
Line 1,482 ⟶ 1,605:
// < SOURCE.lock
// PARSER.fire()
// 2022-07-0129 PerfektesChaos@de.wikipedia
var $li = about.data[ 0 ],
pre = about.data[ 1 ],
Line 1,488 ⟶ 1,611:
$drag = about.data[ 3 ],
$drop = about.data[ 5 ];
if ( $drop.remove( ); {
$drop.remove();
}
if ( PARSER.fire( false,
{ group: group,
Line 1,498 ⟶ 1,623:
pre.name = false;
$li.remove();
} else if ( $drag ) {
$drag.show();
}
Line 1,582 ⟶ 1,707:
// Uses:
// >< SOURCE.lock
// 2022-07-0129 PerfektesChaos@de.wikipedia
var $drag, $drop;
if ( SOURCE.lock ) {
$drag = about.data[ 3 ];
$drop = about.data[ 5 ];
if ( $drop ) {
$drop.remove();
}
if ( $drag ) {
$drag.show();
}
SOURCE.lock = false;
}
}; // SOURCE.flopped()
Line 1,689 ⟶ 1,814:
// SOURCE.fresh()
// SOURCE.focus()
// 20222023-0705-01 PerfektesChaos@de.wikipedia
var s = fruit( PARSER.focus( SOURCE.$input.val() ) ),
group, i, lapsus;
Line 1,703 ⟶ 1,828:
SOURCE.fresh();
group = SOURCE.grouped[ SOURCE.pre.group ];
if ( group ) {
for ( i = 0; i < group.length; i++ ) {
if ( s === group[ i ].name ) {
lapsus = true;
break; // for i
}
} // for i
if ( ! lapsus ) {
SOURCE.exec = { group: SOURCE.pre.group,
seek: SOURCE.start,
shift: s };
SOURCE.$deny.hide();
SOURCE.$doit.show();
}
} // for i
if ( ! lapsus ) {
SOURCE.exec = { group: SOURCE.pre.group,
seek: SOURCE.start,
shift: s };
SOURCE.$deny.hide();
SOURCE.$doit.show();
}
}
Line 1,724 ⟶ 1,851:
}
}; // SOURCE.formal()
 
 
 
SOURCE.forward = function () {
// Jump to section
// Uses:
// > SOURCE.section
// 2022-08-08 PerfektesChaos@de.wikipedia
var url = window.___location;
url.hash = "#" + SOURCE.section;
window.___location = url;
}; // SOURCE.forward()
 
 
Line 1,752 ⟶ 1,891:
// Equip references list item -- $.each()
// Precondition:
// at -- intnumber, with sequence index
// apply -- object, with <li> DOM
// Postcondition:
Line 1,791 ⟶ 1,930:
// Equip references list -- $.each()
// Precondition:
// at -- intnumber, with sequence index
// apply -- object, with <ol> DOM
// Postcondition: