Skip to content

Commit 73c7fd5

Browse files
committed
Reworked the copy button.
The copy button is now only once in every MultiCodeBlock so that some visual problems are fixed. + Removed some CSS
1 parent 4d0d068 commit 73c7fd5

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

includes/MultiCodeBlockBuilder.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ function createTab(string &$code, int $index, string $extra = 'outer') {
4949
*
5050
* @param array $lang All of the languages of the different codeblocks.
5151
* @param string $code The codeblocks as a whole.
52-
* @param string $extra Another class to be added to the element.
5352
* @param bool $addCopy If a copy button should be added to the element.
53+
* @param string $extra Another class to be added to the element.
5454
*
5555
* @return string The whole MultiCodeBlock.
5656
*/
57-
function createFrame(array $lang, string &$code, string $extra = 'outer', bool $addCopy = false) {
57+
function createFrame(array &$lang, string &$code, bool $addCopy = true, string $extra = 'outer') {
5858
$size = sizeof($lang);
5959
$copyIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>';
6060

@@ -125,7 +125,7 @@ function createCodeBlock(array &$codeTags, DOMNodeList &$descriptions, $lang, Pa
125125
$return .= createTab(combineCodeDescription(($isObject ? $highlight->value : $highlight), $languageBlock->getDescription($i), $parser), $i, 'inner');
126126
}
127127

128-
$return = createFrame($versions, $return, 'inner', true);
128+
$return = createFrame($versions, $return, false, 'inner');
129129

130130
return array($return, replaceLang($lang));
131131
}
@@ -145,7 +145,12 @@ function &combineCodeDescription(string $code, Description &$desc, Parser &$pars
145145

146146
$keysSize = sizeof($desc->keys);
147147

148-
$return = '<table class="code-table">';
148+
$return = '<table class="code-table">
149+
<tr class="table-header">
150+
<th>Code</th>
151+
<th>Description</th>
152+
</tr>
153+
';
149154

150155
$isFirst = ($arr[0] === '' ? true : false);
151156

resources/ext.multicodeblock/css/codeblock.css

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.multicodeblock {
2-
margin-top: calc(2em + 15px);
2+
margin-top: calc(2em + 20px);
33
}
44

55
.code-table tbody tr pre {
@@ -29,10 +29,6 @@
2929
cursor: pointer;
3030
}
3131

32-
.tab-button:active {
33-
background-color: #ddd;
34-
}
35-
3632
.tab-button:not(:last-of-type) {
3733
border-bottom: 1px solid #ccc;
3834
}
@@ -65,7 +61,7 @@
6561
width: 100%;
6662
display: flex;
6763
height: fit-content;
68-
transform: translateY(-100%);
64+
transform: translateY(calc(-2em - 7.5px));
6965
}
7066

7167
.inner.tab-button {
@@ -141,11 +137,12 @@
141137

142138
.copy {
143139
position: absolute;
144-
right: 0;
140+
right: 1px;
145141
padding: .7em;
146142
display: unset;
147143
cursor: pointer;
148144
z-index: 99;
145+
line-height: 0;
149146
}
150147

151148
.copy.anim {
@@ -161,13 +158,14 @@
161158
background-color: #555;
162159
color: #fff;
163160
text-align: center;
164-
padding: 5px 0;
161+
padding: 5px;
165162
border-radius: 6px;
166163
z-index: 1;
167164
transition: opacity .6s;
168165
top: 100%;
169166
left: -10%;
170-
margin-left: -60px;
167+
margin-left: -70px;
168+
line-height: initial;
171169
}
172170

173171
.copy svg {
@@ -186,6 +184,16 @@
186184
border-color: transparent transparent #555 transparent;
187185
}
188186

187+
.table-header {
188+
transform: translateY(-5px);
189+
}
190+
191+
.table-header th {
192+
border-bottom: #ccc 1px solid;
193+
margin: 0;
194+
padding-bottom: 3px;
195+
}
196+
189197
@keyframes bounceIn {
190198
from, 20%, 40%, 60%, 80%, to {
191199
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);

resources/ext.multicodeblock/css/highlight.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ hue-6-2: #c18401
1818
1919
*/
2020

21-
.hljs {
22-
display: block;
23-
overflow-x: auto;
24-
padding: 0.5em;
25-
color: #383a42;
26-
background: #fafafa;
27-
}
28-
2921
.hljs-comment,
3022
.hljs-quote {
3123
color: #a0a1a7;

resources/ext.multicodeblock/js/multicodeblock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ for(let i = 0; i < copyElems.length; i++) {
102102
let fail = false;
103103

104104
if (navigator.clipboard) {
105-
const code = elem.parentElement.getElementsByClassName('tc-active')[0].getElementsByClassName('first');
105+
const code = elem.parentElement.getElementsByClassName('outer tc-active')[0].getElementsByClassName('inner tc-active')[0].getElementsByClassName('first');
106106
let text = '';
107107
for(let i = 0; i < code.length; i++) {
108108
text += code[i].innerText;

0 commit comments

Comments
 (0)