Skip to content

Commit d396281

Browse files
author
Christopher Baker
committed
remove jquery better
1 parent 2e598e4 commit d396281

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var getConfig = function(lineString, lineCount) {
8585
};
8686
};
8787

88-
function findPrevious(el, tag) {
88+
function findPreviousSibling(el, tag) {
8989
tag = tag.toUpperCase();
9090

9191
while (el = el.previousSibling) {
@@ -101,7 +101,7 @@ module.exports = function() {
101101
for (var i = 0; i < highlights.length; i++) {
102102
var highlight = highlights[i];
103103

104-
var preBlock = findPrevious(highlight.parentElement, 'pre');
104+
var preBlock = findPreviousSibling(highlight.parentElement, 'pre');
105105
var codeBlock = preBlock.childNodes.item(0);
106106

107107
var total = codeBlock.innerHTML.split('\n').length - 1;

prism-collapse.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function adjustHighlights(pre, collapseRange, visible) {
3232
var top = parseFloat(highlight.style.top.slice(0, -2));
3333
var offset = (collapseRange[1] - collapseRange[0]) * lineHeight;
3434

35-
highlight.style.top = top + (visible ? offset : -offset);
35+
highlight.style.top = top + (visible ? offset : -offset) + 'px';
3636
return;
3737
}
3838

@@ -49,7 +49,7 @@ function adjustHighlights(pre, collapseRange, visible) {
4949
var top = parseFloat(highlight.style.top.slice(0, -2));
5050
var offset = (collapseRange[1] - collapseRange[0]) * lineHeight;
5151

52-
highlight.style.top = top + (visible ? offset : -offset);
52+
highlight.style.top = top + (visible ? offset : -offset) + 'px';
5353
return;
5454
}
5555

@@ -60,7 +60,7 @@ function adjustHighlights(pre, collapseRange, visible) {
6060

6161
function getLineHeight(highlights) {
6262
var highlight = highlights[0];
63-
var height = parseFloat(highlight.css('height').slice(0, -2));
63+
var height = parseFloat(highlight.style.height.slice(0, -2));
6464

6565
var range = highlight.getAttribute('data-range').split('-').map(function(value) {
6666
return parseInt(value);
@@ -138,6 +138,16 @@ function collapseLines(pre, config, hasLineNumbers) {
138138
}
139139
}
140140

141+
function findPreviousParent(el, tag) {
142+
tag = tag.toUpperCase();
143+
144+
while (el = el.parentElement) {
145+
if (el.tagName && el.tagName.toUpperCase() === tag) {
146+
return el;
147+
}
148+
}
149+
}
150+
141151
Prism.hooks.add('complete', function completeHook(env) {
142152
var pre = env.element.parentNode;
143153
var config = pre && pre.getAttribute('data-collapse');
@@ -163,11 +173,13 @@ document.body.addEventListener('click', function(event) {
163173
}
164174

165175
var index = collapse.getAttribute('data-index');
166-
var code = collapse.parentElement;
167-
var pre = code.parentElement;
176+
var code = findPreviousParent(collapse, 'code');
177+
var pre = findPreviousParent(code, 'pre');
168178

169-
var line = code.querySelectorAll('.collapse[data-index=' + index + ']');
170-
line.classList.remove('collapsed');
179+
var lines = code.querySelectorAll('.collapse[data-index="' + index + '"]');
180+
for (var i = 0; i < lines.length; i++) {
181+
lines[i].classList.remove('collapsed');
182+
}
171183

172184
adjustHighlights(pre, collapse.getAttribute('data-range'), true);
173185
}, false);

0 commit comments

Comments
 (0)