Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4093415
linkTitle.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
linkTitle.js
View Options
/**
* Creates an instance of the link title change listener.
*
* While the user dwells on a link, then it becomes the active link. The
* change listener will remove a link's `title` attribute while it's the
* active link.
*
* @return {ext.popups.ChangeListener}
*/
export
default
function
linkTitle
()
{
let
savedTitle
;
/**
* Destroys the title attribute of the element, storing its value in local
* state so that it can be restored later (see `restoreTitleAttr`).
*
* @param {HTMLElement|undefined} el
*/
function
destroyTitleAttr
(
el
)
{
// Has the user dwelled on a link? If we've already removed its title attribute, then NOOP.
if
(
el
&&
!
savedTitle
)
{
savedTitle
=
el
.
getAttribute
(
'title'
);
el
.
setAttribute
(
'title'
,
''
);
}
}
/**
* Restores the title attribute of the element.
*
* @param {HTMLElement|undefined} el
*/
function
restoreTitleAttr
(
el
)
{
// Avoid overwriting a non-empty title with an empty one, just to be sure
if
(
el
&&
savedTitle
)
{
el
.
setAttribute
(
'title'
,
savedTitle
);
savedTitle
=
undefined
;
}
}
return
(
oldState
,
newState
)
=>
{
const
oldLink
=
oldState
&&
oldState
.
preview
.
activeLink
;
// Usually only one side is set when the user enters or leaves a link. Both sides contain
// two different links when the user dwelled on a link immediately after abandoning another
// (remembering that the ABANDON_END action is delayed by ~100 ms).
if
(
oldLink
!==
newState
.
preview
.
activeLink
)
{
restoreTitleAttr
(
oldLink
);
// FIXME: This will not work on anything other than 'reference' or 'preview' types as
// mw.popups.register does not register the previewType as a key in
// newState.preview.enabled
// This is not a problem at time of writing (November 2022) but will become a problem if
// we introduce custom preview types that must remove the title attribute.
if
(
newState
.
preview
.
enabled
[
newState
.
preview
.
previewType
]
)
{
destroyTitleAttr
(
newState
.
preview
.
activeLink
);
}
}
};
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 18 2026, 12:48 (4 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
de/dc/b86bc6c9952b58a23374efea467c
Default Alt Text
linkTitle.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment