From f8fde381973b6a45613d799e37c07ef9c894a518 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Mon, 19 Oct 2020 13:09:31 -0700 Subject: [PATCH] Use require to clarify ext.uls.preferences ext.uls.preferences only depended on ext.uls.common because of its use of the uls global. This is unnecessary, and made clearer by using require and module.exports to access it. Change-Id: Ied2a1b560d19a18529fd766ced778c912199fa2f --- resources/js/ext.uls.ime.js | 5 +++-- resources/js/ext.uls.preferences.js | 3 +-- resources/js/ext.uls.webfonts.js | 6 +++--- tests/qunit/ext.uls.tests.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/js/ext.uls.ime.js b/resources/js/ext.uls.ime.js index ec260d9a..f9b7fde0 100644 --- a/resources/js/ext.uls.ime.js +++ b/resources/js/ext.uls.ime.js @@ -21,13 +21,14 @@ 'use strict'; var mwImeRulesPath, inputSelector, inputPreferences, ulsIMEPreferences, customHelpLink, + getULSPreferences = require( 'ext.uls.preferences' ), languageSettingsModules = [ 'ext.uls.displaysettings' ]; mwImeRulesPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/UniversalLanguageSelector/lib/jquery.ime/'; inputSelector = 'input:not([type]), input[type=text], input[type=search], textarea, [contenteditable]'; - inputPreferences = mw.uls.preferences(); + inputPreferences = getULSPreferences(); mw.ime = mw.ime || {}; @@ -74,7 +75,7 @@ // we don't want to save isDirty field. this.registry.isDirty = undefined; // get updated copy of preferences - inputPreferences = mw.uls.preferences(); + inputPreferences = getULSPreferences(); inputPreferences.set( 'ime', this.registry ); inputPreferences.save( callback ); // reset the dirty bit diff --git a/resources/js/ext.uls.preferences.js b/resources/js/ext.uls.preferences.js index 0afc40b2..136e5657 100644 --- a/resources/js/ext.uls.preferences.js +++ b/resources/js/ext.uls.preferences.js @@ -145,8 +145,7 @@ } }; - mw.uls = mw.uls || {}; - mw.uls.preferences = function () { + module.exports = function () { var data = $( document.body ).data( 'preferences' ); if ( !data ) { diff --git a/resources/js/ext.uls.webfonts.js b/resources/js/ext.uls.webfonts.js index e9189a46..9d7d7372 100644 --- a/resources/js/ext.uls.webfonts.js +++ b/resources/js/ext.uls.webfonts.js @@ -20,10 +20,10 @@ ( function () { 'use strict'; - var ulsPreferences; + var getULSPreferences = require( 'ext.uls.preferences' ), + ulsPreferences = getULSPreferences(); mw.webfonts = mw.webfonts || {}; - ulsPreferences = mw.uls.preferences(); mw.webfonts.preferences = { registry: { fonts: {}, @@ -52,7 +52,7 @@ save: function ( callback ) { // get updated copy of preferences - ulsPreferences = mw.uls.preferences(); + ulsPreferences = getULSPreferences(); ulsPreferences.set( 'webfonts', this.registry ); ulsPreferences.save( callback ); }, diff --git a/tests/qunit/ext.uls.tests.js b/tests/qunit/ext.uls.tests.js index 4d7e428c..65fdd9eb 100644 --- a/tests/qunit/ext.uls.tests.js +++ b/tests/qunit/ext.uls.tests.js @@ -40,7 +40,7 @@ // Here it's used as a meaningless word, to test // the preferences without changing anything useful. prefName = 'gofanim'; - prefs = mw.uls.preferences(); + prefs = require( 'ext.uls.preferences' )(); prefsToSave = {}; prefsToSave[ prefName ] = {