From 3135efd6938ae31102c9cbe120505b28dca9eb49 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Tue, 30 Mar 2021 10:35:31 +0000
Subject: [PATCH] update helper
---
assets/js/code.js | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/assets/js/code.js b/assets/js/code.js
index 7116657..3088550 100644
--- a/assets/js/code.js
+++ b/assets/js/code.js
@@ -37,15 +37,16 @@
const panelBox = 'panel_box';
const fullHeight = 'initial';
const highlightWrap = 'highlight_wrap'
+const highlight = 'highlight';
function wrapOrphanedPreElements() {
const pres = elems('pre');
Array.from(pres).forEach(function(pre){
const parent = pre.parentNode;
- const isOrpaned = !containsClass(parent, 'highlight');
+ const isOrpaned = !containsClass(parent, highlight) ;
if(isOrpaned) {
const preWrapper = createEl();
- preWrapper.className = 'highlight';
+ preWrapper.className = highlight;
const outerWrapper = createEl();
outerWrapper.className = highlightWrap;
wrapEl(pre, preWrapper);
@@ -63,7 +64,7 @@
function codeBlocks() {
const markedCodeBlocks = elems('code');
const blocks = Array.from(markedCodeBlocks).filter(function(block){
- return hasClasses(block) && !Array.from(block.classList).includes('noClass');
+ return block.closest("pre") && !Array.from(block.classList).includes('noClass');
}).map(function(block){
return block
});
@@ -73,7 +74,7 @@
function codeBlockFits(block) {
// return false if codeblock overflows
const blockWidth = block.offsetWidth;
- const highlightBlockWidth = block.parentNode.parentNode.offsetWidth;
+ const highlightBlockWidth = block.closest(`.${highlight}`).offsetWidth;
return blockWidth <= highlightBlockWidth ? true : false;
}
@@ -105,6 +106,14 @@
function collapseCodeBlock(block) {
const lines = elems('.ln', block);
const codeLines = lines.length;
+ if(!lines) {
+ // hide lines toggle button for blocks that have no lines.
+ setTimeout(() => {
+ let panelLinesParentEl = block.closest(`.${highlightWrap}`);
+ let panelLinesEl = elem(`.${linesId}`, panelLinesParentEl);
+ pushClass(panelLinesEl, panelHide);
+ }, 2000)
+ }
if (codeLines > maxLines) {
const expandDot = createEl()
pushClass(expandDot, panelExpand);
@@ -194,6 +203,7 @@
// wrap code block in a div
const highlightWrapper = createEl();
highlightWrapper.className = highlightWrapId;
+
wrapEl(highlightElement, highlightWrapper);
const panel = actionPanel();
--
Gitblit v1.10.0