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

Content deleted Content added
-0.01
-1.5
 
(9 intermediate revisions by the same user not shown)
Line 1:
/// User:PerfektesChaos/js/refNames/core/d.js
/// 20222023-0705-01 PerfektesChaos@de.wikipedia
// <ref name="..."> major work
// ResourceLoader: compatible;
Line 19:
( function ( mw, $ ) {
"use strict";
var Version = -01.015,
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 78 ⟶ 84:
".limitreport" ],
locked: true,
pics: { dropdrag: [ "de", "OOjs_UI_icon_trash"
+ "-destructive.svg" ],
drop: [ "9b", "OOjs_UI_icon_trash"
+ "-invert.svg" ],
exch: [ "e9", "OOjs_UI_icon_reload"
+ "-invert.svg" ],
Line 86 ⟶ 94:
wait: [ "de", "Ajax-loader.gif" ]
},
section: "section",
$box: false,
$editor: false,
Line 169 ⟶ 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 191 ⟶ 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 345 ⟶ 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 358 ⟶ 377:
$r.append( $fault( apply ) )
.append( $swap );
}
if ( SOURCE.section ) {
$r.click( SOURCE.forward );
}
return $r;
Line 368 ⟶ 390:
// Precondition:
// all -- string, with entire story
// at -- intnumber, position in all
// allow -- true, if bidi permitted
// Postcondition:
Line 450 ⟶ 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 476 ⟶ 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 483 ⟶ 526:
// .set -- string, value
// .lock -- boolean, on error
// .more -- intnumber, position after value
// Uses:
// PARSER.first()
Line 489 ⟶ 532:
// PARSER.focus()
// flat()
// 2022-0708-0124 PerfektesChaos@de.wikipedia
var r = { "set": "",
"lock": false,
Line 501 ⟶ 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 514 ⟶ 559:
}
} else if ( k === 0x2F || k === 0x3E ) { // / >
PARSER.fault( all, at, "Identifier missing", about + "=" );
r.lock = true;
} else {
Line 523 ⟶ 568:
if ( k === i ) {
r.lock = true;
PARSER.fault( atall,
at,
"Missing identifier",
about + "=" );
Line 534 ⟶ 580:
k = after + 1;
break;
} // switch flat()
} // for k
}
Line 542 ⟶ 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 555 ⟶ 602:
// .content -- string, content until </ref>, or not
// .lone -- boolean, unary (/)
// .next -- intnumber, position of '>' in all
// Uses:
// < PARSER.lock
Line 562 ⟶ 609:
// PARSER.feature()
// PARSER.first()
// 2022-0708-0124 PerfektesChaos@de.wikipedia
var i = at,
j, lock, r, s, v;
Line 581 ⟶ 628:
"content": false,
"lone": false,
"multi": 0,
"next": after,
"wikitext": false };
}
if ( typeof r[ s ] === "string" ) {
PARSER.fault( all, at, "Duplicated keyword", s );
lock = true;
} else {
Line 595 ⟶ 643:
break;
default:
PARSER.fault( all, at, "Unknown keyword", s );
lock = true;
} // switch
Line 602 ⟶ 650:
if ( lock ) {
PARSER.lock = true;
} else if ( r ) {
i = PARSER.first( all, i, after );
if ( all.charCodeAt( i ) === 0x2F ) { // /
Line 608 ⟶ 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 626 ⟶ 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 640 ⟶ 691:
// Returns about object with modified entries
// .wikitext -- string, modified all
// .next -- intnumber, modified after position
// Uses:
// PARSER.fix()
Line 712 ⟶ 763:
lone: v.lone,
linked: v.linked || v.lone,
multi: 0v.multi };
o.push( s );
}
Line 732 ⟶ 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 742 ⟶ 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 764 ⟶ 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 852 ⟶ 916:
// Uses:
// PARSER.front()
// 2022-0708-01 PerfektesChaos@de.wikipedia
var i = 0,
s = all,
Line 902 ⟶ 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 929 ⟶ 997:
for ( i = 0; i < r.length; i++ ) {
e = r[ i ];
if ( e.name === v.name ) &&{
e.groupv === v.group ) {false;
} else if ( e.name === v.name &&
e.group === v.group ) {
r[ i ].linked = true;
vif ( e.content = false;&&
e.content === v.content ) {
r[ i ].multi++;
}
v = false;
}
} // for i
Line 951 ⟶ 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,027 ⟶ 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,038 ⟶ 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,046 ⟶ 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,058 ⟶ 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,097 ⟶ 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,285 ⟶ 1,415:
// > SOURCE.locked
// > PARSER.lock
// > SOURCE.groups
// > SOURCE.grouped
// > VIEW.offered
Line 1,291 ⟶ 1,420:
// > THIS.selProblem
// > SOURCE.pics.edit
// > SOURCE.pics.dropdrag
// >< SOURCE.groups
// < SOURCE.lock
// fruit()
Line 1,299 ⟶ 1,429:
// (SOURCE.further)
// (SOURCE.flip)
// (SOURCE.flopflopping)
// 2022-07-0125 PerfektesChaos@de.wikipedia
var css = { "display": "inline-block",
"margin-left": "1em",
"margin-right": "1em" },
n = SOURCE.groups.length,
e, group, i, k, o, s, $head, $img, $item, $li, $ul;
if ( ! adjust ) {
Line 1,311 ⟶ 1,442:
SOURCE.lock = false;
}
forif ( in => 0; i < SOURCE.groups.length; i++1 ) {
SOURCE.groups.sort();
if ( ! SOURCE.groups[ n - 1 ] ) {
SOURCE.groups.pop();
SOURCE.groups.unshift( false );
}
}
for ( i = 0; i < n; i++ ) {
s = SOURCE.groups[ i ];
group = SOURCE.grouped[ s ];
for ( k = 0; k < group.length; k++ ) {
e = group[ k ];
if ( e.lone ) {
PARSER.lock = true;
}
} // for k
} // for i
for ( i = 0; i < n; i++ ) {
s = SOURCE.groups[ i ];
group = SOURCE.grouped[ s ];
Line 1,369 ⟶ 1,517:
$li.append( $item );
if ( ! e.linked ) {
$img = $file( SOURCE.pics.dropdrag, 16 );
$item = $( "<span>" );
$item.append( $img )
Line 1,375 ⟶ 1,523:
"role": "button",
"title": "discard" } )
.click( [ $li, e, s, $item, css ], SOURCE.flop )
SOURCE.flopping )
.css( css )
.css( { "cursor": "pointer" } );
Line 1,397 ⟶ 1,546:
// > SOURCE.before
// > THIS.selItem
// > THIS.show
// > THIS.selector
// > SOURCE.section
// > THIS.show
// < SOURCE.grouped
// < SOURCE.groups
Line 1,409 ⟶ 1,559:
// SOURCE.fill()
// (SOURCE.favour)
// 2022-0708-0108 PerfektesChaos@de.wikipedia
var collection = PARSER.fire( always ),
i, $before, $editform, $head, $header;
Line 1,423 ⟶ 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,443 ⟶ 1,594:
}
}; // SOURCE.first()
 
 
 
SOURCE.flash = function ( about ) {
// Removing requested
// Precondition:
// about -- Event object, with Array .data[ 6 ]
// Uses:
// > VIEW.offered
// < SOURCE.lock
// PARSER.fire()
// 2022-07-29 PerfektesChaos@de.wikipedia
var $li = about.data[ 0 ],
pre = about.data[ 1 ],
group = about.data[ 2 ],
$drag = about.data[ 3 ],
$drop = about.data[ 5 ];
if ( $drop ) {
$drop.remove();
}
if ( PARSER.fire( false,
{ group: group,
seek: pre.name,
shift: false } ) ) {
if ( typeof VIEW.offered[ pre.name ] === "object" ) {
delete VIEW.offered[ pre.name ];
}
pre.name = false;
$li.remove();
} else if ( $drag ) {
$drag.show();
}
SOURCE.lock = false;
}; // SOURCE.flash()
 
 
Line 1,498 ⟶ 1,683:
 
SOURCE.flop = function ( about ) {
// RemovingOffer requestedremoval
// Precondition:
// about -- Event object, with Array .data[ 46 ]
// Uses:
// > SOURCE.lock
// (SOURCE.flash)
// 2022-07-01 PerfektesChaos@de.wikipedia
var $drop;
if ( SOURCE.lock ) {
$drop = about[ 5 ];
$drop.click( about, SOURCE.flash )
.css( { "background-color": "#FF0000",
"cursor": "pointer" } );
}
}; // SOURCE.flop()
 
 
 
SOURCE.flopped = function ( about ) {
// Abort removal
// Precondition:
// about -- Event object, with Array .data[ 6 ]
// Uses:
// >< SOURCE.lock
// 2022-07-29 PARSERPerfektesChaos@de.fire()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()
 
 
 
SOURCE.flopping = function ( about ) {
// Preparing removal
// Precondition:
// about -- Event object, with Array .data[ 5 ]
// Uses:
// > SOURCE.pics.drop
// > THIS.selector
// >< SOURCE.lock
// (SOURCE.flop)
// (SOURCE.flopped)
// 2022-07-01 PerfektesChaos@de.wikipedia
var precss, discard, e, s, $drag, $img, $itemdrop, $li;
if ( ! SOURCE.lock ) {
SOURCE.lock = true;
$li = about.data[ 0 ];
pree = about.data[ 1 ];
$items = about.data[ 32 ];
$itemdrag = about.remove()data[ 3 ];
ifcss ( PARSER = about.fire(data[ 4 false,];
$drag.focus()
{ group: about.data[ 2 ],
seek: pre.name,hide();
$img = $file( SOURCE.pics.drop, shift: false }16 ) ) {;
$drop if= $( typeof VIEW.offered[ pre.name ] === "object<span>" ) {;
discard = [ $li, e, s, delete$drag, VIEW.offered[css, pre.name$drop ];
$drop.addClass( THIS.selector + }"discard" )
pre .nameappend( =$img false;)
$li .removeattr(); { "lang": "en",
} "role": "button",
"title": "discard" } )
SOURCE.lock = false;
.css( css )
.css( { "background-color": "#FFB0B0",
"border-color": "transparent",
"border-radius": "2px",
"border-style": "solid",
"border-width": "2px",
"cursor": "none",
"transition": "background-color 2s" } )
.focusout( discard, SOURCE.flopped )
.mouseout( discard, SOURCE.flopped );
$li.append( $drop );
$drop.focus();
window.setTimeout( SOURCE.flop, 1500, discard );
}
}; // SOURCE.flopflopping()
 
 
Line 1,571 ⟶ 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,585 ⟶ 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,606 ⟶ 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,634 ⟶ 1,891:
// Equip references list item -- $.each()
// Precondition:
// at -- intnumber, with sequence index
// apply -- object, with <li> DOM
// Postcondition:
Line 1,673 ⟶ 1,930:
// Equip references list -- $.each()
// Precondition:
// at -- intnumber, with sequence index
// apply -- object, with <ol> DOM
// Postcondition: