From 68e656185783d76b055bcac2779f39c7b2bdbd4d Mon Sep 17 00:00:00 2001 From: MusikAnimal Date: Fri, 18 Mar 2022 14:08:32 -0400 Subject: [PATCH] RealtimePreview: add config setting for debounce time Change-Id: Iaf49f076c5a290ab9049267b0aede1e6b13a9136 --- extension.json | 4 ++++ includes/Hooks.php | 3 ++- modules/realtimepreview/RealtimePreview.js | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extension.json b/extension.json index 2f9b4adc..dc4a0b83 100644 --- a/extension.json +++ b/extension.json @@ -413,6 +413,10 @@ "WikiEditorRealtimePreview": { "description": "Whether to enable the Realtime Preview feature.", "value": false + }, + "WikiEditorRealtimePreviewDebounce": { + "description": "Debounce time in milliseconds for the Realtime Preview feature.", + "value": 2500 } }, "manifest_version": 2 diff --git a/includes/Hooks.php b/includes/Hooks.php index af9bde44..a0b8b886 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -356,7 +356,8 @@ class Hooks implements return [ // expose magic words for use by the wikieditor toolbar 'magicWords' => self::getMagicWords(), - 'signature' => self::getSignatureMessage( $context ) + 'signature' => self::getSignatureMessage( $context ), + 'realtimeDebounce' => $config->get( 'WikiEditorRealtimePreviewDebounce' ), ]; } diff --git a/modules/realtimepreview/RealtimePreview.js b/modules/realtimepreview/RealtimePreview.js index a98f7b03..0ddc2375 100644 --- a/modules/realtimepreview/RealtimePreview.js +++ b/modules/realtimepreview/RealtimePreview.js @@ -5,6 +5,7 @@ var TwoPaneLayout = require( './TwoPaneLayout.js' ); * @class */ function RealtimePreview() { + this.configData = mw.loader.moduleRegistry[ 'ext.wikiEditor' ].script.files[ 'data.json' ]; this.enabled = false; this.twoPaneLayout = new TwoPaneLayout(); this.pagePreview = require( 'mediawiki.page.preview' ); @@ -54,7 +55,6 @@ RealtimePreview.prototype.getToolbarButton = function ( context ) { * Toggle the two-pane preview display. * * @private - * @param {Object} context The WikiEditor context object. */ RealtimePreview.prototype.toggle = function () { var $uiText = this.context.$ui.find( '.wikiEditor-ui-text' ); @@ -107,7 +107,10 @@ RealtimePreview.prototype.addPreviewListener = function ( $editor ) { // Also get preview on keyup, change, paste etc. $editor .off( this.eventNames ) - .on( this.eventNames, mw.util.debounce( 2000, this.doRealtimePreview.bind( this ) ) ); + .on( this.eventNames, mw.util.debounce( + this.doRealtimePreview.bind( this ), + this.configData.realtimeDebounce + ) ); }; /**