2014-06-17 11:08:05 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
|
2016-05-16 20:32:11 +00:00
|
|
|
var currentLinkLogData,
|
|
|
|
/**
|
|
|
|
* @class mw.popups.settings
|
|
|
|
* @singleton
|
|
|
|
*/
|
|
|
|
settings = {};
|
2014-06-17 11:08:05 +00:00
|
|
|
|
|
|
|
/**
|
2014-08-29 04:22:55 +00:00
|
|
|
* The settings' dialog's section element.
|
|
|
|
* Defined in settings.open
|
2014-06-17 11:08:05 +00:00
|
|
|
* @property $element
|
|
|
|
*/
|
2014-08-29 04:22:55 +00:00
|
|
|
settings.$element = null;
|
2014-06-17 11:08:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the relevant form and labels in the settings dialog
|
|
|
|
*
|
|
|
|
* @method render
|
|
|
|
*/
|
|
|
|
settings.render = function () {
|
2016-04-28 20:40:36 +00:00
|
|
|
var path = mw.config.get( 'wgExtensionAssetsPath' ) + '/Popups/resources/',
|
|
|
|
choices = [
|
|
|
|
{
|
|
|
|
id: 'simple',
|
|
|
|
name: mw.message( 'popups-settings-option-simple' ).text(),
|
|
|
|
description: mw.message( 'popups-settings-option-simple-description' ).text(),
|
|
|
|
image: path + 'images/hovercard.svg',
|
|
|
|
isChecked: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'advanced',
|
|
|
|
name: mw.message( 'popups-settings-option-advanced' ).text(),
|
|
|
|
description: mw.message( 'popups-settings-option-advanced-description' ).text(),
|
|
|
|
image: path + 'images/navpop.svg'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'off',
|
2016-07-06 19:18:16 +00:00
|
|
|
name: mw.message( 'popups-settings-option-off' ).text()
|
2016-04-28 20:40:36 +00:00
|
|
|
}
|
|
|
|
];
|
2015-10-07 18:41:28 +00:00
|
|
|
|
|
|
|
// Check if NavigationPopups is enabled
|
|
|
|
/*global pg: false*/
|
2016-04-28 20:40:36 +00:00
|
|
|
if ( typeof pg === 'undefined' || pg.fn.disablePopups === undefined ) {
|
|
|
|
// remove the advanced option
|
|
|
|
choices.splice( 1, 1 );
|
2014-06-17 11:08:05 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 20:40:36 +00:00
|
|
|
// render the template
|
|
|
|
settings.$element = mw.template.get( 'ext.popups.desktop', 'settings.mustache' ).render( {
|
|
|
|
heading: mw.message( 'popups-settings-title' ).text(),
|
|
|
|
closeLabel: mw.message( 'popups-settings-cancel' ).text(),
|
|
|
|
saveLabel: mw.message( 'popups-settings-save' ).text(),
|
|
|
|
helpText: mw.message( 'popups-settings-help' ).text(),
|
|
|
|
okLabel: mw.message( 'popups-settings-help-ok' ).text(),
|
|
|
|
descriptionText: mw.message( 'popups-settings-description' ).text(),
|
|
|
|
choices: choices
|
|
|
|
} );
|
2014-06-17 11:08:05 +00:00
|
|
|
|
2016-04-28 20:40:36 +00:00
|
|
|
// setup event bindings
|
|
|
|
settings.$element.find( '.save' ).click( settings.save );
|
|
|
|
settings.$element.find( '.close' ).click( settings.close );
|
|
|
|
settings.$element.find( '.okay' ).click( function () {
|
|
|
|
settings.close();
|
|
|
|
settings.reloadPage();
|
|
|
|
} );
|
2014-06-17 11:08:05 +00:00
|
|
|
|
2016-04-28 20:40:36 +00:00
|
|
|
$( 'body' ).append( settings.$element );
|
2014-06-17 11:08:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-13 20:15:36 +00:00
|
|
|
* Save the setting to the device and close the dialog
|
2014-06-17 11:08:05 +00:00
|
|
|
*
|
|
|
|
* @method save
|
|
|
|
*/
|
|
|
|
settings.save = function () {
|
2015-08-26 10:15:16 +00:00
|
|
|
var v = $( 'input[name=mwe-popups-setting]:checked', '#mwe-popups-settings' ).val();
|
2014-08-29 04:22:55 +00:00
|
|
|
if ( v === 'simple' ) {
|
2016-05-16 20:32:11 +00:00
|
|
|
mw.popups.saveEnabledState( true );
|
2016-04-27 18:42:59 +00:00
|
|
|
settings.reloadPage();
|
2014-08-29 04:22:55 +00:00
|
|
|
settings.close();
|
2014-06-17 11:08:05 +00:00
|
|
|
} else {
|
2016-05-16 20:32:11 +00:00
|
|
|
mw.popups.saveEnabledState( false );
|
2014-08-29 04:22:55 +00:00
|
|
|
$( '#mwe-popups-settings-form' ).hide();
|
|
|
|
$( '#mwe-popups-settings-help' ).show();
|
2016-05-16 20:32:11 +00:00
|
|
|
mw.track( 'ext.popups.schemaPopups', $.extend( {}, currentLinkLogData, {
|
|
|
|
action: 'disabled'
|
|
|
|
} ) );
|
2014-06-17 11:08:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the settings element and position it correctly
|
|
|
|
*
|
|
|
|
* @method open
|
2016-05-16 20:32:11 +00:00
|
|
|
* @param {Object} logData data to log
|
2014-06-17 11:08:05 +00:00
|
|
|
*/
|
2016-05-16 20:32:11 +00:00
|
|
|
settings.open = function ( logData ) {
|
2014-06-17 11:08:05 +00:00
|
|
|
var
|
|
|
|
h = $( window ).height(),
|
|
|
|
w = $( window ).width();
|
|
|
|
|
2016-05-16 20:32:11 +00:00
|
|
|
currentLinkLogData = logData;
|
|
|
|
|
2014-06-17 11:08:05 +00:00
|
|
|
$( 'body' ).append( $( '<div>' ).addClass( 'mwe-popups-overlay' ) );
|
|
|
|
|
2014-08-29 04:22:55 +00:00
|
|
|
if ( !settings.$element ) {
|
|
|
|
settings.render();
|
|
|
|
}
|
|
|
|
|
2014-06-17 11:08:05 +00:00
|
|
|
settings.$element
|
|
|
|
.show()
|
|
|
|
.css( 'left', ( w - 600 ) / 2 )
|
|
|
|
.css( 'top', ( h - settings.$element.outerHeight( true ) ) / 2 );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-04-27 18:42:59 +00:00
|
|
|
* Close the setting dialog and remove the overlay.
|
2014-08-29 04:22:55 +00:00
|
|
|
* If the close button is clicked on the help dialog
|
|
|
|
* save the setting and reload the page.
|
2014-06-17 11:08:05 +00:00
|
|
|
*
|
|
|
|
* @method close
|
|
|
|
*/
|
|
|
|
settings.close = function () {
|
2014-08-29 04:22:55 +00:00
|
|
|
if ( $( '#mwe-popups-settings-help' ).is( ':visible' ) ) {
|
2016-04-27 18:42:59 +00:00
|
|
|
settings.reloadPage();
|
2014-08-29 04:22:55 +00:00
|
|
|
} else {
|
|
|
|
$( '.mwe-popups-overlay' ).remove();
|
|
|
|
settings.$element.hide();
|
|
|
|
}
|
2014-06-17 11:08:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a link to the footer to re-enable hovercards
|
|
|
|
*
|
|
|
|
* @method addFooterLink
|
|
|
|
*/
|
|
|
|
settings.addFooterLink = function () {
|
2015-08-26 10:15:16 +00:00
|
|
|
var $setting, $footer;
|
|
|
|
|
2014-06-17 11:08:05 +00:00
|
|
|
if ( mw.popups.enabled ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
$setting = $( '<li>' ).append(
|
|
|
|
$( '<a>' )
|
|
|
|
.attr( 'href', '#' )
|
|
|
|
.text( mw.message( 'popups-settings-enable' ).text() )
|
|
|
|
.click( function ( e ) {
|
|
|
|
settings.open();
|
|
|
|
e.preventDefault();
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
$footer = $( '#footer-places, #f-list' );
|
2014-06-17 11:08:05 +00:00
|
|
|
|
|
|
|
// From https://en.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.js
|
|
|
|
if ( $footer.length === 0 ) {
|
|
|
|
$footer = $( '#footer li' ).parent();
|
|
|
|
}
|
|
|
|
$footer.append( $setting );
|
|
|
|
};
|
|
|
|
|
2016-04-27 18:42:59 +00:00
|
|
|
/**
|
|
|
|
* Wrapper around window.location.reload. Exposed for testing purposes only.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
settings.reloadPage = function () {
|
|
|
|
location.reload();
|
|
|
|
};
|
|
|
|
|
2014-06-17 11:08:05 +00:00
|
|
|
$( function () {
|
2015-08-26 10:15:16 +00:00
|
|
|
if ( !mw.popups.enabled ) {
|
2014-06-17 11:08:05 +00:00
|
|
|
settings.addFooterLink();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
mw.popups.settings = settings;
|
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
} )( jQuery, mediaWiki );
|