Skip to content

Commit d18fa4d

Browse files
committed
refactor: Extract createToolButton function
1 parent d39e59a commit d18fa4d

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

src/livecodes/core.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,14 +4803,23 @@ const handleResultLoading = () => {
48034803
eventsManager.addEventListener(window, 'message', showResultModeDrawer);
48044804
};
48054805

4806+
const createToolButton = (id: string, title: string, innerHTML: string) => {
4807+
const btn = document.createElement('div');
4808+
btn.id = id;
4809+
btn.classList.add('tool-buttons');
4810+
btn.title = title;
4811+
btn.style.pointerEvents = 'all'; // override setting to 'none' on toolspane bar
4812+
btn.innerHTML = innerHTML;
4813+
UI.getToolspaneTitles()?.appendChild(btn);
4814+
return btn;
4815+
};
4816+
48064817
const handleResultPopup = () => {
4807-
const popupBtn = document.createElement('div');
4808-
popupBtn.id = 'result-popup-btn';
4809-
popupBtn.classList.add('tool-buttons');
4810-
popupBtn.title = window.deps.translateString('core.result.hint', 'Show result in new window');
4811-
popupBtn.style.pointerEvents = 'all'; // override setting to 'none' on toolspane bar
4812-
const iconCSS = '<i class="icon-window-new"></i>';
4813-
popupBtn.innerHTML = `<button id="show-result">${iconCSS}</button>`;
4818+
const popupBtn = createToolButton(
4819+
'result-popup-btn',
4820+
window.deps.translateString('core.result.hint', 'Show result in new window'),
4821+
`<button id="show-result"><i class="icon-window-new"></i></button>`,
4822+
);
48144823
let url: string | undefined;
48154824
const openWindow = async () => {
48164825
if (resultPopup && !resultPopup.closed) {
@@ -4843,17 +4852,14 @@ const handleResultPopup = () => {
48434852
};
48444853

48454854
const handleResultZoom = () => {
4846-
const zoomBtn = document.createElement('div');
4847-
zoomBtn.id = 'zoom-button';
4848-
zoomBtn.classList.add('tool-buttons');
4849-
zoomBtn.title = window.deps.translateString('core.zoom.hint', 'Zoom') + ' (Ctrl/Cmd + Alt + Z)';
4850-
zoomBtn.style.pointerEvents = 'all'; // override setting to 'none' on toolspane bar
4851-
zoomBtn.innerHTML = `
4852-
<button class="text">
4853-
<span id="zoom-value">${String(Number(getConfig().zoom))}</span>
4854-
&times;
4855-
</button>`;
4856-
4855+
const zoomBtn = createToolButton(
4856+
'zoom-button',
4857+
window.deps.translateString('core.zoom.hint', 'Zoom') + ' (Ctrl/Cmd + Alt + Z)',
4858+
`<button class="text">
4859+
<span id="zoom-value">${String(Number(getConfig().zoom))}</span>
4860+
&times;
4861+
</button>`,
4862+
);
48574863
const toggleZoom = () => {
48584864
const config = getConfig();
48594865
const currentZoom = config.zoom;
@@ -4871,13 +4877,11 @@ const handleResultZoom = () => {
48714877
};
48724878

48734879
const handleBroadcastStatus = () => {
4874-
const broadcastStatusBtn = document.createElement('div');
4875-
broadcastStatusBtn.id = 'broadcast-status-btn';
4876-
broadcastStatusBtn.classList.add('tool-buttons');
4877-
broadcastStatusBtn.title = window.deps.translateString('core.broadcast.heading', 'Broadcast');
4878-
broadcastStatusBtn.style.pointerEvents = 'all'; // override setting to 'none' on toolspane bar
4879-
const iconCSS = '<i class="icon-broadcast"></i>';
4880-
broadcastStatusBtn.innerHTML = `<button id="broadcast-status">${iconCSS}<span class="mark"></span></button>`;
4880+
const broadcastStatusBtn = createToolButton(
4881+
'broadcast-status-btn',
4882+
window.deps.translateString('core.broadcast.heading', 'Broadcast'),
4883+
`<button id="broadcast-status"><i class="icon-broadcast"></i><span class="mark"></span></button>`,
4884+
);
48814885

48824886
const showBroadcast = () => {
48834887
showScreen('broadcast');

0 commit comments

Comments
 (0)