Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5954678
ext.cite.highlighting.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ext.cite.highlighting.js
View Options
'use strict'
;
/**
* Dynamic highlighting while reading an article
*
* @author Thiemo Kreuz
*/
(
function
()
{
/**
* Checks if the ID uses a composite format that does not only consist of a sequential number.
*
* @param {string} id
* @return {boolean}
*/
function
isNamedReference
(
id
)
{
// Note: This assumes IDs start with the prefix; this is guaranteed by the parser function
return
/^cite_ref-\D/
.
test
(
id
);
}
/**
* @param {string} id
* @param {jQuery} $content
* @return {boolean}
*/
function
isReusedNamedReference
(
id
,
$content
)
{
if
(
!
isNamedReference
(
id
)
)
{
return
false
;
}
// Either the ID is already a reuse, or at least one reuse exists somewhere else on the page
return
!
id
.
endsWith
(
'-0'
)
||
$content
.
find
(
'.references a[href="#'
+
$
.
escapeSelector
(
id
.
slice
(
0
,
-
1
)
)
+
'1"]'
).
length
;
}
/**
* @param {jQuery} $backlinkWrapper
* @return {jQuery}
*/
function
makeUpArrowLink
(
$backlinkWrapper
)
{
// We assume the first node we find here is the "↑ " text node
let
textNode
=
$backlinkWrapper
[
0
].
firstChild
;
const
accessibilityLabel
=
mw
.
msg
(
'cite_references_link_accessibility_back_label'
);
const
$upArrowLink
=
$
(
'<a>'
)
.
addClass
(
'mw-cite-up-arrow-backlink'
)
.
attr
(
'aria-label'
,
accessibilityLabel
)
.
attr
(
'title'
,
accessibilityLabel
);
if
(
!
textNode
)
{
return
$upArrowLink
;
}
// Skip custom HTML wrappers, but abort when it's our own a11y label (see T384204)
while
(
textNode
.
firstChild
&&
textNode
.
className
!==
'cite-accessibility-label'
)
{
textNode
=
textNode
.
firstChild
;
}
if
(
textNode
.
nodeType
!==
Node
.
TEXT_NODE
||
textNode
.
data
.
trim
()
===
''
)
{
return
$upArrowLink
;
}
const
upArrow
=
textNode
.
data
.
trim
();
// The text node typically contains "↑ ", and we need to keep the space.
textNode
.
data
=
textNode
.
data
.
replace
(
upArrow
,
''
);
// Create a plain text and a clickable "↑". CSS :target selectors make sure only
// one is visible at a time.
$backlinkWrapper
.
prepend
(
$
(
'<span>'
)
.
addClass
(
'mw-cite-up-arrow'
)
.
text
(
upArrow
),
$upArrowLink
.
text
(
upArrow
)
);
return
$upArrowLink
;
}
/**
* @param {jQuery} $backlink
*/
function
updateUpArrowLink
(
$backlink
)
{
// It's convenient to stop at the class name, but it's not guaranteed to be there.
const
$backlinkWrapper
=
$backlink
.
closest
(
'.mw-cite-backlink, li'
);
let
$upArrowLink
=
$backlinkWrapper
.
find
(
'.mw-cite-up-arrow-backlink'
);
if
(
!
$upArrowLink
.
length
&&
$backlinkWrapper
.
length
)
{
$upArrowLink
=
makeUpArrowLink
(
$backlinkWrapper
);
}
$upArrowLink
.
attr
(
'href'
,
$backlink
.
attr
(
'href'
)
);
}
mw
.
hook
(
'wikipage.content'
).
add
(
(
$content
)
=>
{
// We are going to use the ID in the code below, so better be sure one is there.
$content
.
find
(
'.reference[id] > a'
).
on
(
'click'
,
function
()
{
const
id
=
$
(
this
).
parent
().
attr
(
'id'
);
$content
.
find
(
'.mw-cite-targeted-backlink'
).
removeClass
(
'mw-cite-targeted-backlink'
);
// Bail out if there is not at least a second backlink ("cite_references_link_many").
if
(
!
isReusedNamedReference
(
id
,
$content
)
)
{
return
;
}
// The :not() skips the duplicate link created below. Relevant when double clicking.
const
$backlink
=
$content
.
find
(
'.references a[href="#'
+
$
.
escapeSelector
(
id
)
+
'"]:not(.mw-cite-up-arrow-backlink)'
)
.
first
()
.
addClass
(
'mw-cite-targeted-backlink'
);
if
(
$backlink
.
length
)
{
updateUpArrowLink
(
$backlink
);
}
}
);
}
);
}()
);
File Metadata
Details
Attached
Mime Type
text/x-asm
Expires
Sat, Oct 3, 03:09 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
17/17/ab26d95f39ff6636267c94215b4e
Default Alt Text
ext.cite.highlighting.js (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment