Skip to content

Commit 8f1c83d

Browse files
committed
extension: Implement switch input element creation
1 parent 8369bd3 commit 8f1c83d

File tree

1 file changed

+33
-86
lines changed

1 file changed

+33
-86
lines changed

web/packages/extension/src/options.ts

Lines changed: 33 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type SettingForm = {
1313
placeholder?: string | number;
1414

1515
label: string;
16-
description: string;
16+
description?: string;
1717
options?: SelectOption[];
1818
};
1919

@@ -49,14 +49,10 @@ const settingData: SettingGroup = {
4949
},
5050
{
5151
id: "allowScriptAccess",
52-
type: "select",
52+
type: "switch",
5353
label: "Allow Script Access",
5454
description:
5555
"Allow movie to interact with page through JavaScript.",
56-
options: [
57-
{ value: "true", text: "Enabled" },
58-
{ value: "false", text: "Disabled" },
59-
],
6056
},
6157
{
6258
id: "backgroundColor",
@@ -88,24 +84,16 @@ const settingData: SettingGroup = {
8884
},
8985
{
9086
id: "unmuteOverlay",
91-
type: "select",
87+
type: "switch",
9288
label: "Unmute Overlay",
93-
description: "Show unmute overlay when player is muted.",
94-
options: [
95-
{ value: "visible", text: "Visible" },
96-
{ value: "hidden", text: "Hidden" },
97-
],
89+
description: "Show unmute overlay when player is muted.", // TODO: Update with better description to match switch
9890
},
9991
{
10092
id: "preloader",
10193
type: "select",
10294
label: "Preloader",
10395
description:
10496
"Whether or not to show a splash screen before the SWF has loaded.",
105-
options: [
106-
{ value: "true", text: "Enabled" },
107-
{ value: "false", text: "Disabled" },
108-
],
10997
},
11098
{
11199
id: "parameters",
@@ -284,14 +272,10 @@ const settingData: SettingGroup = {
284272
},
285273
{
286274
id: "polyfills",
287-
type: "select",
275+
type: "switch",
288276
label: "Polyfills",
289277
description:
290278
"Enable polyfills on the page for legacy Flash content.",
291-
options: [
292-
{ value: "true", text: "Enabled" },
293-
{ value: "false", text: "Disabled" },
294-
],
295279
},
296280
{
297281
id: "fontSources",
@@ -333,33 +317,21 @@ const settingData: SettingGroup = {
333317
},
334318
{
335319
id: "upgradeToHttps",
336-
type: "select",
320+
type: "switch",
337321
label: "Upgrade to HTTPS",
338322
description: "Auto-upgrade embedded HTTP URLs to HTTPS.",
339-
options: [
340-
{ value: "true", text: "Enabled" },
341-
{ value: "false", text: "Disabled" },
342-
],
343323
},
344324
{
345325
id: "compatibilityRules",
346-
type: "select",
326+
type: "switch",
347327
label: "Compatibility Rules",
348328
description: "Enable Ruffle's built-in compatibility rules.",
349-
options: [
350-
{ value: "true", text: "Enabled" },
351-
{ value: "false", text: "Disabled" },
352-
],
353329
},
354330
{
355331
id: "favorFlash",
356-
type: "select",
332+
type: "switch",
357333
label: "Favor Flash Player",
358334
description: "Prefer real Adobe Flash Player if available.",
359-
options: [
360-
{ value: "true", text: "Enabled" },
361-
{ value: "false", text: "Disabled" },
362-
],
363335
},
364336
// I am not sure if this can be done via UI
365337
/* {
@@ -415,72 +387,47 @@ const settingData: SettingGroup = {
415387
},
416388
{
417389
id: "showSwfDownload",
418-
type: "select",
390+
type: "switch",
419391
label: "Show SWF Download",
420392
description: "Add SWF download option to context menu.",
421-
options: [
422-
{ value: "true", text: "Enabled" },
423-
{ value: "false", text: "Disabled" },
424-
],
425393
},
426394
{
427395
id: "menu",
428-
type: "select",
396+
type: "switch",
429397
label: "Built-in Menu Items",
430-
description: "Equivalent to Stage.showMenu.",
431-
options: [
432-
{ value: "true", text: "Visible" },
433-
{ value: "false", text: "Hidden" },
434-
],
398+
description: "Equivalent to Stage.showMenu.", // TODO: Update with better description to match switch
435399
},
436400
{
437401
id: "splashScreen",
438-
type: "select",
402+
type: "switch",
439403
label: "Splash Screen",
440-
description: "Show splash screen before SWF loads.",
441-
options: [
442-
{ value: "true", text: "Show" },
443-
{ value: "false", text: "Hide" },
444-
],
404+
description: "Show splash screen before SWF loads.", // TODO: Update with better description to match switch
445405
},
446406
],
447407
settingsFullscreenScaling: [
448408
{
449409
id: "allowFullscreen",
450-
type: "select",
410+
type: "switch",
451411
label: "Allow Fullscreen",
452412
description: "Allow Stage's displayState to be changed.",
453-
options: [
454-
{ value: "true", text: "Enabled" },
455-
{ value: "false", text: "Disabled" },
456-
],
457413
},
458414
{
459415
id: "forceAlign",
460-
type: "select",
416+
type: "switch",
461417
label: "Force Alignment",
462418
description: "Prevent movies from changing stage alignment.",
463-
options: [
464-
{ value: "true", text: "Enabled" },
465-
{ value: "false", text: "Disabled" },
466-
],
467419
},
468420
{
469421
id: "forceScale",
470-
type: "select",
422+
type: "switch",
471423
label: "Force Scale",
472424
description: "Prevent movies from changing stage scale mode.",
473-
options: [
474-
{ value: "true", text: "Enabled" },
475-
{ value: "false", text: "Disabled" },
476-
],
477425
},
478426
{
479427
id: "fullScreenAspectRatio",
480428
type: "text",
481429
label: "Fullscreen Aspect Ratio",
482430
description: "Controls orientation on mobile in fullscreen mode.",
483-
options: [],
484431
},
485432
],
486433
settingMiscellaneous: [
@@ -490,27 +437,10 @@ const settingData: SettingGroup = {
490437
label: "Base URL",
491438
description:
492439
"Base directory/URL for resolving relative paths in SWF.",
493-
options: [],
494440
},
495441
],
496442
};
497443

498-
/* const template: string = `
499-
<div class="settings-option">
500-
<input type="checkbox" class="settings-option-toggle" data-option-id="{id}">
501-
502-
<div class="settings-option-control" id="control-{id}">
503-
<div class="form-element">
504-
<div class="form-group">
505-
<label class="form-label" for="site-{id}">{label}</label>
506-
<small>{description}</small>
507-
</div>
508-
<select class="form-type-text" id="site-{id}"></select>
509-
</div>
510-
</div>
511-
</div>
512-
`; */
513-
514444
function addElement(settingForm: SettingForm): HTMLElement {
515445
const settingsOption = document.createElement("div");
516446
settingsOption.classList.add("settings-option");
@@ -603,6 +533,23 @@ function addElement(settingForm: SettingForm): HTMLElement {
603533
}
604534
break;
605535
case "switch":
536+
{
537+
const formTypeSwitch = document.createElement("div");
538+
formTypeSwitch.classList.add("form-type-switch");
539+
540+
const formTypeSwitchCheckbox = document.createElement("input");
541+
formTypeSwitchCheckbox.id = `setting-${settingForm.id}`;
542+
formTypeSwitchCheckbox.type = "checkbox";
543+
544+
formTypeSwitch.appendChild(formTypeSwitchCheckbox);
545+
546+
const formTypeSwitchSlider = document.createElement("div");
547+
formTypeSwitchSlider.classList.add("slider");
548+
549+
formTypeSwitch.appendChild(formTypeSwitchSlider);
550+
551+
formElement.appendChild(formTypeSwitch);
552+
}
606553
break;
607554
}
608555

0 commit comments

Comments
 (0)