BookStack/resources/js/components/details-highlighter.js

24 lines
542 B
JavaScript
Raw Normal View History

import {Component} from './component';
2020-01-15 20:18:02 +00:00
2022-11-15 11:24:31 +00:00
export class DetailsHighlighter extends Component {
setup() {
this.container = this.$el;
2020-01-15 20:18:02 +00:00
this.dealtWith = false;
2022-11-15 11:24:31 +00:00
this.container.addEventListener('toggle', this.onToggle.bind(this));
2020-01-15 20:18:02 +00:00
}
onToggle() {
if (this.dealtWith) return;
2022-11-15 11:24:31 +00:00
if (this.container.querySelector('pre')) {
window.importVersioned('code').then(Code => {
2022-11-15 11:24:31 +00:00
Code.highlightWithin(this.container);
});
}
2020-01-15 20:18:02 +00:00
this.dealtWith = true;
}
}