blob: 083acc0fb39c6b539cf9f99b94719bf3c2499cb8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
const debug = 0 ? console.log.bind(console, '[lang]') : function() {};
const toggleCodeblockVisibility = function(lang, visible) {
debug('toggleCodeblockVisibility', lang, visible);
document.querySelectorAll(`.highlight code.language-${lang}`).forEach((el) => {
let highlight = el.closest('.highlight');
highlight.style.display = visible ? 'block' : 'none';
});
};
export function newLangController() {
return {
tabs: [],
changeLanguage: function(index) {
debug('changeLanguage', index);
for (let i = 0; i < this.tabs.length; i++) {
let isActive = i === index;
this.tabs[i].active = isActive;
toggleCodeblockVisibility(this.tabs[i].key, isActive);
}
},
initLangs: function(tabs) {
debug('initLangs', tabs);
tabs[0].active = true;
this.tabs = tabs;
return this.$nextTick(() => {
this.changeLanguage(0);
});
}
};
}
|