From 79a038f16642206ea9b34285209aeebf793ec9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 28 Oct 2020 09:41:11 +0100 Subject: [PATCH] Handle Apply button little bit more sanely Change-Id: I55d48de703662f139549d764bf7c1f235111d5ab --- resources/js/ext.uls.displaysettings.js | 2 +- resources/js/ext.uls.inputsettings.js | 2 +- resources/js/ext.uls.languagesettings.js | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/resources/js/ext.uls.displaysettings.js b/resources/js/ext.uls.displaysettings.js index d675f9e2..04dffc23 100644 --- a/resources/js/ext.uls.displaysettings.js +++ b/resources/js/ext.uls.displaysettings.js @@ -537,7 +537,7 @@ */ markDirty: function () { this.dirty = true; - this.$parent.$window.find( 'button.uls-settings-apply' ).prop( 'disabled', false ); + this.$parent.enableApplyButton(); }, /** diff --git a/resources/js/ext.uls.inputsettings.js b/resources/js/ext.uls.inputsettings.js index 099e2a1a..7c08c8f2 100644 --- a/resources/js/ext.uls.inputsettings.js +++ b/resources/js/ext.uls.inputsettings.js @@ -111,7 +111,7 @@ */ markDirty: function () { this.dirty = true; - this.$parent.$window.find( 'button.uls-settings-apply' ).prop( 'disabled', false ); + this.$parent.enableApplyButton(); }, prepareInputmethods: function ( language ) { diff --git a/resources/js/ext.uls.languagesettings.js b/resources/js/ext.uls.languagesettings.js index 467f361b..f5748e1b 100644 --- a/resources/js/ext.uls.languagesettings.js +++ b/resources/js/ext.uls.languagesettings.js @@ -60,6 +60,7 @@ this.top = this.options.top; this.modules = {}; this.$settingsPanel = this.$window.find( '#languagesettings-settings-panel' ); + this.$applyButton = this.$window.find( '.uls-settings-apply' ); this.init(); this.listen(); } @@ -78,7 +79,7 @@ this.$window.find( '#languagesettings-close, button.uls-settings-cancel' ) .on( 'click', mw.hook( 'mw.uls.settings.cancel' ).fire.bind( this ) ); - this.$window.find( 'button.uls-settings-apply' ) + this.$applyButton .on( 'click', mw.hook( 'mw.uls.settings.apply' ).fire.bind( this ) ); // Hide the window when clicked outside $( document.documentElement ).on( 'click', this.hide.bind( this ) ); @@ -240,16 +241,14 @@ * false to unset the busy mode. */ setBusy: function ( busy ) { - var $applyButton = this.$window.find( 'button.uls-settings-apply' ); - if ( busy ) { this.$window.addClass( 'waiting' ); - $applyButton + this.$applyButton .text( $.i18n( 'ext-uls-language-settings-applying' ) ) .prop( 'disabled', true ); } else { this.$window.removeClass( 'waiting' ); - $applyButton.text( $.i18n( 'ext-uls-language-settings-apply' ) ); + this.$applyButton.text( $.i18n( 'ext-uls-language-settings-apply' ) ); } }, @@ -282,8 +281,12 @@ } }, + enableApplyButton: function () { + this.$applyButton.prop( 'disabled', false ); + }, + disableApplyButton: function () { - this.$window.find( 'button.uls-settings-apply' ).prop( 'disabled', true ); + this.$applyButton.prop( 'disabled', true ); } };