2015-09-01 16:47:18 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki EducationPopupTool class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2015-09-01 16:47:18 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UserInterface education popup tool. Used as a mixin to show a pulsating blue dot
|
|
|
|
* which, when you click, reveals a popup with useful information.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWEducationPopupTool = function VeUiMwEducationPopupTool( config ) {
|
2015-11-04 18:30:53 +00:00
|
|
|
var popupCloseButton, $popupContent, $shield,
|
2018-01-10 16:58:38 +00:00
|
|
|
tool = this;
|
2015-09-01 16:47:18 +00:00
|
|
|
|
|
|
|
config = config || {};
|
|
|
|
|
2019-10-22 18:02:21 +00:00
|
|
|
// Do not display on platforms other than desktop
|
|
|
|
if ( !( ve.init.mw.DesktopArticleTarget && ve.init.target instanceof ve.init.mw.DesktopArticleTarget ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not display if the user already acknowledged the popups
|
2020-05-02 01:49:00 +00:00
|
|
|
if ( !mw.libs.ve.shouldShowEducationPopups() ) {
|
2015-09-01 16:47:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-19 20:13:34 +00:00
|
|
|
if ( !( this.toolGroup instanceof OO.ui.BarToolGroup ) ) {
|
|
|
|
// The popup gets hideously deformed in other cases. Getting it to work would probably be
|
|
|
|
// difficult. Let's just not show it. (T170919)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-01 16:47:18 +00:00
|
|
|
popupCloseButton = new OO.ui.ButtonWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-educationpopup-dismiss' ),
|
|
|
|
flags: [ 'progressive', 'primary' ],
|
2015-10-15 21:11:47 +00:00
|
|
|
classes: [ 've-ui-educationPopup-dismiss' ]
|
2015-09-01 16:47:18 +00:00
|
|
|
} );
|
|
|
|
popupCloseButton.connect( this, { click: 'onPopupCloseButtonClick' } );
|
2015-10-15 21:11:47 +00:00
|
|
|
$popupContent = $( '<div>' ).append(
|
|
|
|
$( '<div>' ).addClass( 've-ui-educationPopup-header' ),
|
|
|
|
$( '<h3>' ).text( config.title ),
|
|
|
|
$( '<p>' ).text( config.text ),
|
2015-09-01 16:47:18 +00:00
|
|
|
popupCloseButton.$element
|
|
|
|
);
|
|
|
|
|
|
|
|
this.popup = new OO.ui.PopupWidget( {
|
2017-06-14 21:16:37 +00:00
|
|
|
$floatableContainer: this.$element,
|
2015-09-01 16:47:18 +00:00
|
|
|
$content: $popupContent,
|
|
|
|
padded: true,
|
|
|
|
width: 300
|
|
|
|
} );
|
|
|
|
|
2015-11-04 18:30:53 +00:00
|
|
|
this.shownEducationPopup = false;
|
2019-08-28 12:32:59 +00:00
|
|
|
this.$pulsatingDot = $( '<div>' ).addClass( 'mw-pulsating-dot' );
|
2016-03-02 21:48:05 +00:00
|
|
|
$shield = $( '<div>' ).addClass( 've-ui-educationPopup-shield' );
|
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-educationPopup' )
|
2019-06-27 14:35:50 +00:00
|
|
|
.append( $shield, this.popup.$element, this.$pulsatingDot );
|
2016-03-02 21:48:05 +00:00
|
|
|
this.$element.children().not( this.popup.$element ).on( 'click', function () {
|
2015-11-04 18:30:53 +00:00
|
|
|
if ( !tool.shownEducationPopup ) {
|
|
|
|
if ( ve.init.target.openEducationPopupTool ) {
|
|
|
|
ve.init.target.openEducationPopupTool.popup.toggle( false );
|
|
|
|
ve.init.target.openEducationPopupTool.setActive( false );
|
2019-01-18 21:03:38 +00:00
|
|
|
ve.init.target.openEducationPopupTool.$pulsatingDot.removeClass( 'oo-ui-element-hidden' );
|
2015-11-04 18:30:53 +00:00
|
|
|
}
|
|
|
|
ve.init.target.openEducationPopupTool = tool;
|
2019-01-18 21:03:38 +00:00
|
|
|
tool.$pulsatingDot.addClass( 'oo-ui-element-hidden' );
|
2015-11-04 18:30:53 +00:00
|
|
|
tool.popup.toggle( true );
|
2020-02-18 23:24:13 +00:00
|
|
|
popupCloseButton.focus();
|
2015-11-04 18:30:53 +00:00
|
|
|
$shield.remove();
|
2018-10-24 17:18:21 +00:00
|
|
|
|
|
|
|
ve.track( 'activity.' + tool.constructor.static.name + 'EducationPopup', { action: 'show' } );
|
2015-11-04 18:30:53 +00:00
|
|
|
}
|
|
|
|
} );
|
2015-09-01 16:47:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.initClass( ve.ui.MWEducationPopupTool );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the popup close button
|
|
|
|
*/
|
|
|
|
ve.ui.MWEducationPopupTool.prototype.onPopupCloseButtonClick = function () {
|
2015-11-04 18:30:53 +00:00
|
|
|
this.shownEducationPopup = true;
|
|
|
|
this.popup.toggle( false );
|
|
|
|
this.setActive( false );
|
|
|
|
ve.init.target.openEducationPopupTool = undefined;
|
2020-05-02 01:49:00 +00:00
|
|
|
mw.libs.ve.stopShowingEducationPopups();
|
2016-03-29 14:54:22 +00:00
|
|
|
|
|
|
|
this.onSelect();
|
2015-09-01 16:47:18 +00:00
|
|
|
};
|