From d809600af5b898d22eac84adfbd705025ff1288a Mon Sep 17 00:00:00 2001 From: Ruben Pingol Date: Tue, 17 Oct 2023 17:52:20 +0800 Subject: [PATCH] Widget: Set default speed based on selected effect relates to xibosignageltd/xibo-private#522 --- ui/src/core/forms.js | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/ui/src/core/forms.js b/ui/src/core/forms.js index 2e1d5d70c6..168428a6a2 100644 --- a/ui/src/core/forms.js +++ b/ui/src/core/forms.js @@ -21,6 +21,7 @@ /* eslint-disable new-cap */ // Common functions/tools const Common = require('../editor-core/common.js'); +const PlayerHelper = require('../helpers/player-helper.js'); // Check condition const checkCondition = function(type, value, targetValue, isTopLevel = true) { @@ -1922,6 +1923,54 @@ window.forms = { skipSave: true, }]); } + + if ($(el).next().find('input[name="speed"]').length === 1) { + let currentSelected = null; + const speedInput = $(el).next().find('input[name="speed"]'); + const setEffectSpeed = function(prevEffect, newEffect, currSpeed) { + const marqueeDefaultSpeed = 1; + const noneMarqueeDefaultSpeed = 1000; + const currIsMarquee = PlayerHelper.isMarquee(prevEffect); + const isMarquee = PlayerHelper.isMarquee(newEffect); + + if (currIsMarquee && !isMarquee) { + return noneMarqueeDefaultSpeed; + } else if (!currIsMarquee && isMarquee) { + return marqueeDefaultSpeed; + } else { + if (String(currSpeed).length === 0) { + if (isMarquee) { + return marqueeDefaultSpeed; + } else { + return noneMarqueeDefaultSpeed; + } + } else { + return currSpeed; + } + } + }; + + $el.on('select2:open', function(e) { + currentSelected = e.currentTarget.value; + }); + + speedInput.val(setEffectSpeed( + currentSelected, + currentSelected, + speedInput.val(), + )); + + $el.on('select2:select', function(e) { + const data = e.params.data; + const effect = data.id; + + speedInput.val(setEffectSpeed( + currentSelected, + effect, + speedInput.val(), + )); + }); + } }); // Font selector