From cff0089326daa4fb210e0562da42777bf25925bd Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Thu, 7 Jul 2022 13:04:28 +0800 Subject: [PATCH] Realtime Preview: only add window-resize handler if toolbar button is used Move the resize handler from the RealtimePreview constructor to the getToolbarButton() method, to prevent it being used when the button is not used (e.g. if the gadget is misconfigured). Bug: T309330 Change-Id: I7abc335112648605404785528b37a81d946e900e --- modules/realtimepreview/RealtimePreview.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/realtimepreview/RealtimePreview.js b/modules/realtimepreview/RealtimePreview.js index a1f5f284..02a08176 100644 --- a/modules/realtimepreview/RealtimePreview.js +++ b/modules/realtimepreview/RealtimePreview.js @@ -68,8 +68,6 @@ function RealtimePreview() { this.lastWikitext = null; // Used to average response times and automatically disable realtime preview if it's very slow. this.responseTimes = []; - - $( window ).on( 'resize', this.enableFeatureWhenScreenIsWideEnough.bind( this ) ); } /** @@ -105,6 +103,9 @@ RealtimePreview.prototype.getToolbarButton = function ( context ) { this.button.toggle( false ); } + // Hide or show the preview and toolbar button when the window is resized. + $( window ).on( 'resize', this.enableFeatureWhenScreenIsWideEnough.bind( this ) ); + // Add the onboarding popup. var onboardingPopup = new OnboardingPopup(); this.button.connect( onboardingPopup, { change: onboardingPopup.onPreviewButtonClick } );