From 472432517a148d6c2d3ab68e05aaea2971e0bfa1 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 24 Jul 2013 16:35:50 +0530 Subject: [PATCH] Lazy initilization of language settings from ULS For personal toolbar position, initialize langauge settings only after user clicks on the settings links Bug: 48211 Change-Id: Ib3e2372e982de890db614a81c06fbbe170ce0d01 --- resources/js/ext.uls.interface.js | 71 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index e1eba256..51b1f47e 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -22,6 +22,7 @@ /** * Construct the display settings link + * @return {jQuery} */ function displaySettings() { var $displaySettingsTitle, displaySettingsText, $displaySettings; @@ -40,6 +41,7 @@ /** * Construct the input settings link + * @returns {jQuery} */ function inputSettings() { var $inputSettingsTitle, inputSettingsText, $inputSettings; @@ -61,28 +63,32 @@ * @param {Object} uls The ULS object */ function addDisplaySettings( uls ) { - var $displaySettings = displaySettings(), - ulsPosition = mw.config.get( 'wgULSPosition' ), - anonMode = ( mw.user.isAnon() && - !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ), - displaySettingsOptions = { - defaultModule: 'display' - }; - - // If the ULS trigger is shown in the top personal menu, - // closing the display settings must show the main ULS - // languages list, unless we are in anon mode and thus - // cannot show the language list - if ( ulsPosition === 'personal' && !anonMode ) { - displaySettingsOptions.onClose = function () { - uls.show(); - }; - } - $.extend( displaySettingsOptions, uls.position() ); + var $displaySettings = displaySettings(); uls.$menu.find( '#settings-block' ).append( $displaySettings ); - $displaySettings.languagesettings( displaySettingsOptions ); $displaySettings.on( 'click', function () { + var languagesettings = $displaySettings.data( 'languagesettings' ), + displaySettingsOptions = { + defaultModule: 'display' + }, + ulsPosition = mw.config.get( 'wgULSPosition' ), + anonMode = ( mw.user.isAnon() && + !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ); + + if ( !languagesettings ) { + // If the ULS trigger is shown in the top personal menu, + // closing the display settings must show the main ULS + // languages list, unless we are in anon mode and thus + // cannot show the language list + if ( ulsPosition === 'personal' && !anonMode ) { + displaySettingsOptions.onClose = function () { + uls.show(); + }; + } + $.extend( displaySettingsOptions, uls.position() ); + $displaySettings.languagesettings( displaySettingsOptions ) + .click(); + } uls.hide(); } ); } @@ -92,22 +98,23 @@ * @param {Object} uls The ULS object */ function addInputSettings( uls ) { - var $inputSettings, position; + var $inputSettings = inputSettings(); - $inputSettings = inputSettings(); uls.$menu.find( '#settings-block' ).append( $inputSettings ); - position = uls.position(); - - $inputSettings.languagesettings( { - defaultModule: 'input', - onClose: function () { - uls.show(); - }, - top: position.top, - left: position.left - } ); - $inputSettings.on( 'click', function () { + var position = uls.position(), + languagesettings = $inputSettings.data( 'languagesettings' ); + + if ( !languagesettings ) { + $inputSettings.languagesettings( { + defaultModule: 'input', + onClose: function () { + uls.show(); + }, + top: position.top, + left: position.left + } ).click(); + } uls.hide(); } ); }