Skip to content

Commit 4a00f08

Browse files
committed
fix #1 behavior with a close button
1 parent bf3d01c commit 4a00f08

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

assets/js/main.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,35 @@ $(document).on('ready turbolinks:load', function () {
145145
});
146146

147147
// Highlight
148-
$('pre.highlight code').on('dblclick', function() {
149-
let code = $(this);
148+
$('pre.highlight code')
149+
.on('click', function() {
150+
let code = $(this);
150151

151-
if (code.closest('tr').hasClass("hightlight")) {
152-
code.
153-
removeClass()
154-
.html(code.data('raw'))
155-
.closest('tr')
156-
.removeClass("hightlight")
157-
} else {
158-
code.data('raw', code.html());
152+
if (!code.closest('tr').hasClass("hightlight")) {
153+
code.data('raw', code.html());
159154

160-
try {
161-
let json = JSON.parse(code.html());
162-
code.html(JSON.stringify(json, null, 2));
163-
} catch (e) {}
155+
try {
156+
let json = JSON.parse(code.html());
157+
code.html(JSON.stringify(json, null, 2));
158+
} catch (e) {}
164159

165-
hljs.highlightBlock(code[0]);
160+
hljs.highlightBlock(code[0]);
166161

167-
code.closest('tr').addClass("hightlight");
168-
}
169-
});
162+
code.closest('tr').addClass("hightlight");
163+
code.closest('td').find('button.close').toggleClass('d-none');
164+
}
165+
})
166+
.closest('td')
167+
.find('button.close')
168+
.on('click', function() {
169+
$(this).toggleClass('d-none');
170+
171+
let code = $(this).parent().find('code');
172+
$(this).parent().find('code')
173+
.removeClass()
174+
.html(code.data('raw'))
175+
.closest('tr')
176+
.removeClass("hightlight")
177+
})
178+
;
170179
});

public/blocks/topic/data.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
</tr>
135135
<tr <#if !(data.getValue())??>class="deleted"</#if>>
136136
<td colspan="${(canDeleteRecords == true)?then("6", "5")}">
137+
<button type="button" class="close d-none" aria-label="Close">
138+
<span aria-hidden="true">&times;</span>
139+
</button>
137140
<#if data.getHeaders()?size != 0>
138141
<table class="table table-sm collapse headers-${i}">
139142
<#list data.getHeaders() as key, value>

0 commit comments

Comments
 (0)