2015-09-01 16:47:18 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki EducationPopupTool class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 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,
|
2015-10-15 21:11:47 +00:00
|
|
|
usePrefs = !mw.user.isAnon(),
|
2015-09-01 16:47:18 +00:00
|
|
|
prefSaysShow = usePrefs && !mw.user.options.get( 'visualeditor-hideusered' ),
|
2018-01-10 16:58:38 +00:00
|
|
|
tool = this;
|
2015-09-01 16:47:18 +00:00
|
|
|
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
if (
|
2016-01-04 18:43:43 +00:00
|
|
|
!( ve.init.mw.DesktopArticleTarget && ve.init.target instanceof ve.init.mw.DesktopArticleTarget ) ||
|
2015-09-01 16:47:18 +00:00
|
|
|
(
|
|
|
|
!prefSaysShow &&
|
|
|
|
!(
|
|
|
|
!usePrefs &&
|
2018-01-10 16:58:38 +00:00
|
|
|
mw.storage.get( 've-hideusered' ) === null &&
|
2015-09-01 16:47:18 +00:00
|
|
|
$.cookie( 've-hideusered' ) === null
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
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;
|
2015-10-15 21:11:47 +00:00
|
|
|
this.$pulsatingDot = $( '<div>' ).addClass( 've-ui-pulsatingDot' );
|
2015-10-15 23:23:33 +00:00
|
|
|
this.$stillDot = $( '<div>' ).addClass( 've-ui-stillDot' );
|
2016-03-02 21:48:05 +00:00
|
|
|
$shield = $( '<div>' ).addClass( 've-ui-educationPopup-shield' );
|
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-educationPopup' )
|
|
|
|
.append( $shield, this.popup.$element, this.$stillDot, this.$pulsatingDot );
|
|
|
|
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 );
|
|
|
|
ve.init.target.openEducationPopupTool.$pulsatingDot.show();
|
|
|
|
ve.init.target.openEducationPopupTool.$stillDot.show();
|
|
|
|
}
|
|
|
|
ve.init.target.openEducationPopupTool = tool;
|
|
|
|
tool.$pulsatingDot.hide();
|
|
|
|
tool.$stillDot.hide();
|
|
|
|
tool.popup.toggle( true );
|
|
|
|
$shield.remove();
|
|
|
|
}
|
|
|
|
} );
|
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 () {
|
|
|
|
var usePrefs = !mw.user.isAnon(),
|
|
|
|
prefSaysShow = usePrefs && !mw.user.options.get( 'visualeditor-hideusered' );
|
|
|
|
|
2015-11-04 18:30:53 +00:00
|
|
|
this.shownEducationPopup = true;
|
|
|
|
this.popup.toggle( false );
|
|
|
|
this.setActive( false );
|
|
|
|
ve.init.target.openEducationPopupTool = undefined;
|
2015-09-01 16:47:18 +00:00
|
|
|
|
2015-11-04 18:30:53 +00:00
|
|
|
if ( prefSaysShow ) {
|
2018-05-04 13:30:10 +00:00
|
|
|
ve.init.target.getLocalApi().saveOption( 'visualeditor-hideusered', 1 );
|
2015-11-04 18:30:53 +00:00
|
|
|
mw.user.options.set( 'visualeditor-hideusered', 1 );
|
|
|
|
} else if ( !usePrefs ) {
|
2018-01-10 16:58:38 +00:00
|
|
|
if ( !mw.storage.set( 've-hideusered', 1 ) ) {
|
2015-11-04 18:30:53 +00:00
|
|
|
$.cookie( 've-hideusered', 1, { path: '/', expires: 30 } );
|
2015-09-01 16:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-29 14:54:22 +00:00
|
|
|
|
|
|
|
this.onSelect();
|
2015-09-01 16:47:18 +00:00
|
|
|
};
|