/*! * ULS interface integration logic * * Copyright (C) 2012-2013 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris, * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other * contributors. See CREDITS for a list. * * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't * have to do anything special to choose one license or the other and you don't * have to notify anyone which license you are using. You are free to use * UniversalLanguageSelector in commercial projects as long as the copyright * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details. * * @file * @ingroup Extensions * @licence GNU General Public Licence 2.0 or later * @licence MIT License */ ( function () { 'use strict'; var languageSettingsModules = [ 'ext.uls.displaysettings' ], launchULS = require( './ext.uls.launch.js' ), ActionsMenu = require( './ext.uls.actions.menu.js' ), ActionsMenuItem = require( './ext.uls.actions.menu.item.js' ); require( './ext.uls.actions.menu.items.registry.js' ); /** * For Vector, check if the language button id exists. * For other skins, check wgULSDisplaySettingsInInterlanguage for the current skin. * * @return {boolean} */ function isUsingStandaloneLanguageButton() { // Checking for the ULS language button id returns true for Vector, false for other skins. return $( '#p-lang-btn' ).length > 0 || mw.config.get( 'wgULSDisplaySettingsInInterlanguage' ); } /** * @param {jQuery} $element * @param {Function} onCloseHandler * @param {Object} uls */ function openLanguageSettings( $element, onCloseHandler, uls ) { mw.loader.using( languageSettingsModules ).then( function () { $element.languagesettings( { defaultModule: 'display', onClose: onCloseHandler, onPosition: uls.position.bind( uls ), onVisible: uls.hide.bind( uls ) } ).trigger( 'click' ); } ); } /** * Provide entry points to create article in other languages. T290436 * * @param {Object} uls The ULS object */ function addEmptyState( uls ) { var $emptyStateContainer = $( '
' ).addClass( 'uls-empty-state' ); function openActionsMenuEventHandler( event ) { event.stopPropagation(); function onMenuClose() { uls.show(); } openLanguageSettings( $( event.target ), onMenuClose, uls ); } var languageSettingsMenuItem = { name: 'languageSettings', icon: 'settings', text: $.i18n( 'ext-uls-actions-menu-language-settings-item-label' ), handler: openActionsMenuEventHandler }; var actionItemsRegistry = mw.uls.ActionsMenuItemsRegistry; actionItemsRegistry.register( languageSettingsMenuItem ); var $header = $( '

' ) .addClass( 'uls-empty-state__header' ) .text( $.i18n( 'ext-uls-empty-state-header' ) ); var $desc = $( '

' ) .addClass( 'uls-empty-state__desc' ) .text( $.i18n( 'ext-uls-empty-state-desc' ) ); $emptyStateContainer.append( $header, $desc ); uls.$resultsView.append( $emptyStateContainer ); var actionItems = actionItemsRegistry.getItems(); if ( actionItems.length > 1 ) { // languageSettingsMenuItem will be always there. // If other actions available, change text $header.text( $.i18n( 'ext-uls-empty-state-header-actions-available' ) ); $desc.text( $.i18n( 'ext-uls-empty-state-desc-actions-available' ) ); } // Action menu items need OOUI widgets. Load them and register trigger event handler. mw.loader.using( [ 'oojs-ui-widgets', 'oojs-ui.styles.icons-interactions' ] ).done( function () { var $actionsList = $( '