Content deleted Content added
-0.0 |
-1.5 |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1:
/// User:PerfektesChaos/js/refNames/core/d.js
///
// <ref name="..."> major work
// ResourceLoader: compatible;
Line 19:
( function ( mw, $ ) {
"use strict";
var Version = -
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: {
+ "-destructive.svg" ],
drop: [ "9b", "OOjs_UI_icon_trash"
+ "-invert.svg" ],
exch: [ "e9", "OOjs_UI_icon_reload"
+ "-invert.svg" ],
edit: [ "8a", "OOjs_UI_icon_edit-ltr"
Line 84 ⟶ 94:
wait: [ "de", "Ajax-loader.gif" ]
},
section: "section",
$box: false,
$editor: false,
Line 167 ⟶ 178:
// Portlet request
// Uses:
// > PARSER.$textarea
// > THIS.$widget
// > THIS.selector
// >< SOURCE.section
// VIEW.fire()
// SOURCE.first()
// 2022-
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 (
SOURCE.first( true );
}
Line 189 ⟶ 208:
// [ 0 ] -- string, with 2 hex storage path
// [ 1 ] -- string, with signifcant ID
// appearance --
// 2022-07-01 PerfektesChaos@de.wikipedia
var $r = $( "<img>" );
Line 343 ⟶ 362:
// > THIS.selItem
// > THIS.selWarn
// > SOURCE.section
// failure()
// $fault()
//
// 2022-08-08 PerfektesChaos@de.wikipedia
var $r = $( "<span>" ),
$swap;
Line 356 ⟶ 377:
$r.append( $fault( apply ) )
.append( $swap );
}
if ( SOURCE.section ) {
$r.click( SOURCE.forward );
}
return $r;
Line 366 ⟶ 390:
// Precondition:
// all -- string, with entire story
// at --
// allow -- true, if bidi permitted
// Postcondition:
Line 448 ⟶ 472:
PARSER.fault = function ( all, at, alert, about ) {
// Communicate error details (browser console)
// Precondition:
//
// at -- number, position in wikitext
// alert -- string, with message
// about -- string, with detail, or not
// Uses:
// > Signature
//
// 2022-08-25 PerfektesChaos@de.wikipedia
var i, n, s;
if ( typeof window.console === "object" &&
typeof window.console.warn === "function" ) {
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 474 ⟶ 519:
// Precondition:
// all -- string, with entire story
// at --
// after --
// about -- string, with attribute name
// Postcondition:
Line 481 ⟶ 526:
// .set -- string, value
// .lock -- boolean, on error
// .more --
// Uses:
// PARSER.first()
Line 487 ⟶ 532:
// PARSER.focus()
// flat()
// 2022-
var r = { "set": "",
"lock": false,
Line 499 ⟶ 544:
if ( k < 0 || k > after ) {
r.lock = true;
PARSER.fault(
at,
"Unbalanced delimiter",
about + "=" + s );
} else if ( k === i + 1 ) {
r.lock = true;
PARSER.fault(
at,
"Missing identifier",
about + "=" + s + s );
Line 512 ⟶ 559:
}
} else if ( k === 0x2F || k === 0x3E ) { // / >
PARSER.fault( all, at, "Identifier missing", about + "=" );
r.lock = true;
} else {
Line 521 ⟶ 568:
if ( k === i ) {
r.lock = true;
PARSER.fault(
at,
"Missing identifier",
about + "=" );
Line 529 ⟶ 577:
case 0x20:
r.set = all.substring( i, k );
r.more = k
k = after + 1;
break;
} // switch flat()
} // for k
}
Line 540 ⟶ 588:
PARSER.features = function ( all, at, after, alone ) {
// Retrieve <ref> or </references> tag attributes
// Precondition:
// all -- string, with entire story
// at --
// after --
// alone -- boolean, for </ref>
// Postcondition:
// Returns object with name="", or not
Line 553 ⟶ 602:
// .content -- string, content until </ref>, or not
// .lone -- boolean, unary (/)
// .next --
// Uses:
// < PARSER.lock
Line 560 ⟶ 609:
// PARSER.feature()
// PARSER.first()
// 2022-
var i = at,
j, lock, r, s, v;
Line 579 ⟶ 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 593 ⟶ 643:
break;
default:
PARSER.fault( all, at, "Unknown keyword", s );
lock = true;
} // switch
Line 600 ⟶ 650:
if ( lock ) {
PARSER.lock = true;
} else if ( r ) {
i = PARSER.first( all, i, after );
if ( all.charCodeAt( i ) === 0x2F ) { // /
r.lone = true;
i = PARSER.first( all, ++i, after );
}
if (
if ( r
r = false;
}
} else {
PARSER.lock = true;
PARSER.fault( all, i, "Trailing garbage" );
}
}
}
Line 625 ⟶ 677:
// Precondition:
// all -- string, with entire story
// at --
// after --
// about -- object
// .group -- string, ID, or not
// .name -- string, ID
// .extends -- string, text, or not
// .lone -- boolean, unary (/)
// .content -- string, until </ref>, or not
Line 638 ⟶ 691:
// Returns about object with modified entries
// .wikitext -- string, modified all
// .next --
// Uses:
// PARSER.fix()
// 2022-07-01 PerfektesChaos@de.wikipedia
var
i, set, sign;
for ( i = 0; i < 3; i++ ) {
set = ( i === 1 ? adjust.shift : about[ sign ] );
if ( set ) {
s = s + " " + sign + "=\"" + PARSER.fix( set ) + "\"";
}
} // for i
if ( about.lone ) {
s = s + " /";
Line 691 ⟶ 749:
s = v.name;
if ( typeof c[ s ] === "object" ) {
e = c[ s ];
e.linked = true;
if ( ! v.lone ) {
e.lone = false;
if ( e.content && v.content ) {
e.multi++;
}
}
c[ s ] = e;
} else {
c[ s ] = { name: s,
content: v.content,
lone: v.lone,
multi: v.multi };
o.push( s );
}
Line 723 ⟶ 783:
PARSER.finish = function ( all, at, alone ) {
// Find </ref> or </references> tag
// Precondition:
// all -- string, with entire story
// at --
// alone -- boolean, for </ref>
// Postcondition:
// Returns Array [ begin, end ] of < >
Line 733 ⟶ 794:
// Uses:
// PARSER.first()
// 2022-07-
var i = at,
j, kR, kE, kF, n, r, s;
do {
i = all.indexOf( "<", i );
Line 755 ⟶ 816:
if ( ( kR === 0x52 || kR === 0x72 ) &&
( kE === 0x45 || kE === 0x65 ) &&
( kF === 0x46 || kF === 0x66 ) )
if ( 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 839 ⟶ 912:
// .extends -- string, text, or false
// .content -- string, until </ref>, or false
// .linked -- boolean, repeated
// .lone -- boolean, unary (/)
// Uses:
// PARSER.front()
// 2022-
var i = 0,
s = all,
Line 861 ⟶ 935:
if ( e.name === v.name &&
e.group === v.group ) {
v = false;
break; // for k
}
Line 872 ⟶ 947:
if ( e.name === v.name &&
e.group === v.group ) {
v = false;
break; // for k
}
Line 880 ⟶ 956:
}
if ( v ) {
v.linked = true;
p.push( v );
}
}
} else if ( r ) {
v.linked = false;
for ( k = 0; k < r.length; k++ ) {
e = r[ k ];
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 ) {
r[ k ].lone = false;
}
v = false;
break; // for k
}
Line 914 ⟶ 997:
for ( i = 0; i < r.length; i++ ) {
e = r[ i ];
if ( e
} else if ( e.name === v.name &&
e.group === v.group ) {
r[ i ].linked = true;
if ( e.content &&
e.content === v.content ) {
r[ i ].multi++;
}
v = false;
}
Line 935 ⟶ 1,025:
// Precondition:
// all -- string, with entire story
// at --
// after --
// Postcondition:
// Returns position in all, even after
Line 944 ⟶ 1,034:
var r = at,
i;
for ( i = at; i <= after; i++ ) {
if ( flat( all, i ) !== 0x20 ) {
r = i;
Line 1,011 ⟶ 1,101:
// Precondition:
// all -- string, with entire story
// at --
// adjust -- object, with name-group to be replaced, or not
// .group -- string, ID, or not
Line 1,022 ⟶ 1,112:
// .content -- string, content until </ref>, or not
// .lone -- boolean, unary (/)
// .
// .next -- number, position of closing '>' in all
// .wikitext -- string, modified all
// Uses:
// >< PARSER.pending
// < PARSER.lock
// PARSER.first()
Line 1,030 ⟶ 1,122:
// PARSER.features()
// PARSER.fiat()
//
// 2022-07-28 PerfektesChaos@de.wikipedia
var i = at,
j, kR, kE, kF, n, r, v;
Line 1,042 ⟶ 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,
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
kE = all.charCodeAt( j +
if ( kE === 0x45
}
}
Line 1,081 ⟶ 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,269 ⟶ 1,415:
// > SOURCE.locked
// > PARSER.lock
// > SOURCE.grouped
// > VIEW.offered
Line 1,275 ⟶ 1,420:
// > THIS.selProblem
// > SOURCE.pics.edit
// > SOURCE.pics.drag
// >< SOURCE.groups
// < SOURCE.lock
// fruit()
Line 1,282 ⟶ 1,429:
// (SOURCE.further)
// (SOURCE.flip)
//
// 2022-07-25 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,293 ⟶ 1,442:
SOURCE.lock = false;
}
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,350 ⟶ 1,516:
.css( { "cursor": "pointer" } );
$li.append( $item );
if ( ! e.linked ) {
$img = $file( SOURCE.pics.drag, 16 );
$item = $( "<span>" );
$item.append( $img )
.attr( { "lang": "en",
"role": "button",
"title": "discard" } )
.click( [ $li, e, s, $item, css ],
SOURCE.flopping )
.css( css )
.css( { "cursor": "pointer" } );
$li.append( $item );
}
}
$ul.append( $li );
Line 1,367 ⟶ 1,546:
// > SOURCE.before
// > THIS.selItem
// > THIS.selector
// > SOURCE.section
// > THIS.show
// < SOURCE.grouped
// < SOURCE.groups
Line 1,379 ⟶ 1,559:
// SOURCE.fill()
// (SOURCE.favour)
// 2022-
var collection = PARSER.fire( always ),
i, $before, $editform, $head, $header;
Line 1,393 ⟶ 1,573:
$head = $( "<span>" );
$head.addClass( THIS.selItem )
.attr( { "
"lang": "en",
"role": "link",
"title": "help" } )
.click( SOURCE.favour )
.css( { "cursor": "pointer",
"font-size": "130%" } )
.html( THIS.show );
Line 1,413 ⟶ 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,464 ⟶ 1,679:
}
}; // SOURCE.flip()
SOURCE.flop = function ( about ) {
// Offer removal
// Precondition:
// about -- Event object, with Array[ 6 ]
// 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 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()
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 css, discard, e, s, $drag, $img, $drop, $li;
if ( ! SOURCE.lock ) {
SOURCE.lock = true;
$li = about.data[ 0 ];
e = about.data[ 1 ];
s = about.data[ 2 ];
$drag = about.data[ 3 ];
css = about.data[ 4 ];
$drag.focus()
.hide();
$img = $file( SOURCE.pics.drop, 16 );
$drop = $( "<span>" );
discard = [ $li, e, s, $drag, css, $drop ];
$drop.addClass( THIS.selector + "discard" )
.append( $img )
.attr( { "lang": "en",
"role": "button",
"title": "discard" } )
.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.flopping()
Line 1,510 ⟶ 1,814:
// SOURCE.fresh()
// SOURCE.focus()
//
var s = fruit( PARSER.focus( SOURCE.$input.val() ) ),
group, i, lapsus;
Line 1,524 ⟶ 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();
}
}
}
Line 1,545 ⟶ 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,573 ⟶ 1,891:
// Equip references list item -- $.each()
// Precondition:
// at --
// apply -- object, with <li> DOM
// Postcondition:
Line 1,612 ⟶ 1,930:
// Equip references list -- $.each()
// Precondition:
// at --
// apply -- object, with <ol> DOM
// Postcondition:
|