Skip to content

Commit 7a8b1f2

Browse files
dsdeepak17Dun-sin
authored andcommitted
fix: removes unnecessary EventListener to fix get-code button bug
the get code button was not working ie not copying the first time it was clicked because an event listener was being added in the first click and it made the copy to clipboard code unreachable the first time. Removing it fixed the bug.
1 parent 2ddea3f commit 7a8b1f2

File tree

1 file changed

+53
-60
lines changed

1 file changed

+53
-60
lines changed

src/general.ts

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,71 +15,64 @@ export function copyCodeToClipboard(
1515
attribute: string,
1616
outputElement: HTMLElement
1717
): void {
18-
const copyCodeButton = <HTMLElement>(
19-
document.querySelector(`[data-download=${attribute}-code]`)
20-
);
21-
copyCodeButton.addEventListener('click', (): void => {
22-
actOnGenerator();
23-
});
18+
actOnGenerator(attribute, outputElement);
19+
}
2420

25-
function actOnGenerator() {
26-
let codeToCopy = '';
27-
let element;
28-
switch (attribute) {
29-
case 'pic-text':
30-
codeToCopy = `
31-
div {
32-
background-position: ${outputElement.style.backgroundPosition};
33-
background-size: ${outputElement.style.backgroundSize};
34-
background-repeat: ${outputElement.style.backgroundRepeat};
35-
background-clip: ${outputElement.style.backgroundClip};
36-
-webkit-background-clip: ${outputElement.style.webkitBackgroundClip};
37-
-webkit-text-fill-color: ${outputElement.style.webkitTextFillColor};
21+
function actOnGenerator(attribute: string, outputElement: HTMLElement) {
22+
let codeToCopy = '';
23+
let element;
24+
switch (attribute) {
25+
case 'pic-text':
26+
codeToCopy = `
27+
div {
28+
background-position: ${outputElement.style.backgroundPosition};
29+
background-size: ${outputElement.style.backgroundSize};
30+
background-repeat: ${outputElement.style.backgroundRepeat};
31+
background-clip: ${outputElement.style.backgroundClip};
32+
-webkit-background-clip: ${outputElement.style.webkitBackgroundClip};
33+
-webkit-text-fill-color: ${outputElement.style.webkitTextFillColor};
34+
}
35+
`;
36+
break;
37+
case 'gradient-text':
38+
codeToCopy = `
39+
p{
40+
font-size: ${(outputElement.children[0] as HTMLElement).style.fontSize};
41+
background: ${
42+
(outputElement.children[0] as HTMLElement).style.backgroundImage
43+
};
44+
background-clip: 'text';
45+
-webkit-background-clip: 'text';
46+
-webkit-text-fill-color: 'transparent';
3847
}
39-
`;
40-
break;
41-
case 'gradient-text':
42-
codeToCopy = `
43-
p{
44-
font-size: ${
45-
(outputElement.children[0] as HTMLElement).style.fontSize
46-
};
47-
background: ${
48-
(outputElement.children[0] as HTMLElement).style.backgroundImage
49-
};
50-
background-clip: 'text';
51-
-webkit-background-clip: 'text';
52-
-webkit-text-fill-color: 'transparent';
48+
`;
49+
50+
break;
51+
case 'gradient-border':
52+
element = outputElement.style;
53+
codeToCopy = `
54+
div {
55+
border: ${element.border},
56+
border-width: ${element.borderWidth},
57+
border-image-slice: ${element.borderImageSlice},
58+
border-image-source: ${element.borderImageSource},
5359
}
54-
`;
55-
56-
break;
57-
case 'gradient-border':
58-
element = outputElement.style;
59-
codeToCopy = `
60-
div {
61-
border: ${element.border},
62-
border-width: ${element.borderWidth},
63-
border-image-slice: ${element.borderImageSlice},
64-
border-image-source: ${element.borderImageSource},
65-
}
66-
`;
67-
break;
68-
case 'gradient-background':
69-
element = outputElement.style;
70-
codeToCopy = `
71-
div {
72-
height: 100px;
73-
width: 100px;
74-
background: ${element.backgroundImage};
75-
}
76-
`;
77-
}
78-
79-
copy(codeToCopy);
60+
`;
61+
break;
62+
case 'gradient-background':
63+
element = outputElement.style;
64+
codeToCopy = `
65+
div {
66+
height: 100px;
67+
width: 100px;
68+
background: ${element.backgroundImage};
69+
}
70+
`;
71+
break;
8072
}
81-
}
8273

74+
copy(codeToCopy);
75+
}
8376
/**
8477
* @function countForText
8578
* @summary Counts the number of text in the input element

0 commit comments

Comments
 (0)