mediawiki-extensions-Popups/resources/ext.popups/linkTitleChangeListener.js
Sam Smith 089ee014ad Add link title change listener
Supporting changes:
* Remove the preview.previousActiveLink property from the state tree as
  it's unnecessary.

Change-Id: I657decf9425a7a9e2b27a798ed60b162569661d8
2016-11-18 09:51:01 +00:00

37 lines
916 B
JavaScript

( function ( mw, $ ) {
/**
* 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}
*/
mw.popups.changeListeners.linkTitle = function () {
var title;
return function ( prevState, state ) {
var $link;
// Has the user dwelled on a link? If we've already removed its title
// attribute, then NOOP.
if ( state.preview.activeLink && !title ) {
$link = $( state.preview.activeLink );
title = $link.attr( 'title' );
$link.attr( 'title', '' );
// Has the user abandoned the link?
} else if ( prevState && prevState.preview.activeLink ) {
$( prevState.preview.activeLink ).attr( 'title', title );
title = undefined;
}
};
};
}( mediaWiki, jQuery ) );