Skip to content

Commit

Permalink
Widget: Set default speed based on selected effect
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenberttpingol committed Oct 17, 2023
1 parent 87f110b commit d809600
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ui/src/core/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d809600

Please sign in to comment.