mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-13 16:18:30 +00:00
b1b29f4704
Change-Id: I08e80220c76a65cadaba20ce78b9eb2b36139095
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
( function ( mw, $ ) {
|
|
|
|
/**
|
|
* Creates the link element and appends it to the footer element.
|
|
*
|
|
* The following elements are considered to be the footer element (highest
|
|
* priority to lowest):
|
|
*
|
|
* # `#footer-places`
|
|
* # `#f-list`
|
|
* # The parent element of `#footer li`, which is either an `ol` or `ul`.
|
|
*
|
|
* @return {jQuery} The link element
|
|
*/
|
|
function createFooterLink() {
|
|
var $link = $( '<li>' ).append(
|
|
$( '<a>' )
|
|
.attr( 'href', '#' )
|
|
.text( mw.message( 'popups-settings-enable' ).text() )
|
|
),
|
|
$footer;
|
|
|
|
// As yet, we don't know whether the link should be visible.
|
|
$link.hide();
|
|
|
|
// From https://en.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.js,
|
|
// which was written by Yair rand <https://en.wikipedia.org/wiki/User:Yair_rand>.
|
|
$footer = $( '#footer-places, #f-list' );
|
|
|
|
if ( $footer.length === 0 ) {
|
|
$footer = $( '#footer li' ).parent();
|
|
}
|
|
|
|
$footer.append( $link );
|
|
|
|
return $link;
|
|
}
|
|
|
|
/**
|
|
* Creates an instance of the footer link change listener.
|
|
*
|
|
* The change listener covers the following behaviour:
|
|
*
|
|
* * The "Enable previews" link (the "link") is appended to the footer menu
|
|
* (see `createFooterLink` above).
|
|
* * When Page Previews are disabled, then the link is shown; otherwise, the
|
|
* link is hidden.
|
|
* * When the user clicks the link, then the `showSettings` bound action
|
|
* creator is called.
|
|
*
|
|
* @param {Object} boundActions
|
|
* @return {ext.popups.ChangeListener}
|
|
*/
|
|
mw.popups.changeListeners.footerLink = function ( boundActions ) {
|
|
var $footerLink;
|
|
|
|
return function ( prevState, state ) {
|
|
if ( $footerLink === undefined ) {
|
|
$footerLink = createFooterLink();
|
|
$footerLink.click( boundActions.showSettings );
|
|
}
|
|
|
|
if ( state.preview.enabled ) {
|
|
$footerLink.hide();
|
|
} else {
|
|
$footerLink.show();
|
|
}
|
|
};
|
|
};
|
|
|
|
}( mediaWiki, jQuery ) );
|