mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-27 17:00:37 +00:00
049729626c
Bug: T330517 Change-Id: Ib283e37f379e8cccc7f49ab0ce9aadd6535ea668
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
/**
|
|
* @module previewBehaviour
|
|
*/
|
|
const canSaveToUserPreferences = require( './canSaveToUserPreferences.js' );
|
|
|
|
/**
|
|
* A collection of event handlers specific to how the user interacts with all
|
|
* previews. The event handlers are are agnostic to how/when they are bound
|
|
* //but not to what they are bound//, i.e. the showSettings event handler is
|
|
* written to be bound to either an `<a>` or `<button>` element.
|
|
*
|
|
* @typedef {Object} ext.popups.PreviewBehavior
|
|
* @property {string} settingsUrl
|
|
* @property {Function} showSettings
|
|
* @property {Function} previewDwell
|
|
* @property {Function} previewAbandon
|
|
* @property {Function} previewShow
|
|
* @property {Function} click handler for the entire preview
|
|
*/
|
|
|
|
/**
|
|
* Creates an instance of `ext.popups.PreviewBehavior`.
|
|
*
|
|
* If the user is logged out, then clicking the cog should show the settings
|
|
* modal.
|
|
*
|
|
* If the user is logged in, then clicking the cog should send them to the
|
|
* the "Appearance" tab otherwise.
|
|
*
|
|
* @param {mw.User} user
|
|
* @param {Object} actions The action creators bound to the Redux store
|
|
* @return {ext.popups.PreviewBehavior}
|
|
*/
|
|
export default function createPreviewBehavior( user, actions ) {
|
|
let settingsUrl, showSettings = () => {};
|
|
|
|
if ( !canSaveToUserPreferences( user ) ) {
|
|
showSettings = ( event ) => {
|
|
event.preventDefault();
|
|
|
|
actions.showSettings();
|
|
};
|
|
} else {
|
|
const rawTitle = 'Special:Preferences#mw-prefsection-rendering';
|
|
|
|
settingsUrl = mw.Title.newFromText( rawTitle )
|
|
.getUrl();
|
|
}
|
|
|
|
return {
|
|
settingsUrl,
|
|
showSettings,
|
|
previewDwell: actions.previewDwell,
|
|
previewAbandon: actions.abandon,
|
|
previewShow: actions.previewShow,
|
|
click: actions.linkClick
|
|
};
|
|
}
|