( function ( $, mw ) { var currentLinkLogData, /** * @class mw.popups.settings * @singleton */ settings = {}; /** * The settings' dialog's section element. * Defined in settings.open * @property $element */ settings.$element = null; /** * Renders the relevant form and labels in the settings dialog * * @method render */ settings.render = function () { 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', name: mw.message( 'popups-settings-option-off' ).text() } ]; // Check if NavigationPopups is enabled /*global pg: false*/ if ( typeof pg === 'undefined' || pg.fn.disablePopups === undefined ) { // remove the advanced option choices.splice( 1, 1 ); } // 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 } ); // 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(); } ); $( 'body' ).append( settings.$element ); }; /** * Save the setting to the device and close the dialog * * @method save */ settings.save = function () { var v = $( 'input[name=mwe-popups-setting]:checked', '#mwe-popups-settings' ).val(); if ( v === 'simple' ) { mw.popups.saveEnabledState( true ); settings.reloadPage(); settings.close(); } else { mw.popups.saveEnabledState( false ); $( '#mwe-popups-settings-form' ).hide(); $( '#mwe-popups-settings-help' ).show(); mw.track( 'ext.popups.schemaPopups', $.extend( {}, currentLinkLogData, { action: 'disabled' } ) ); } }; /** * Show the settings element and position it correctly * * @method open * @param {Object} logData data to log */ settings.open = function ( logData ) { var h = $( window ).height(), w = $( window ).width(); currentLinkLogData = logData; $( 'body' ).append( $( '