The toggle actually sticks (#7586)
This commit is contained in:
@@ -236,9 +236,11 @@ function platformToggle() {
|
|||||||
|
|
||||||
const createFrameworkButtons = sample => {
|
const createFrameworkButtons = sample => {
|
||||||
const pytorchButton = document.createElement("button");
|
const pytorchButton = document.createElement("button");
|
||||||
|
pytorchButton.classList.add('pytorch-button')
|
||||||
pytorchButton.innerText = "PyTorch";
|
pytorchButton.innerText = "PyTorch";
|
||||||
|
|
||||||
const tensorflowButton = document.createElement("button");
|
const tensorflowButton = document.createElement("button");
|
||||||
|
tensorflowButton.classList.add('tensorflow-button')
|
||||||
tensorflowButton.innerText = "TensorFlow";
|
tensorflowButton.innerText = "TensorFlow";
|
||||||
|
|
||||||
const selectorDiv = document.createElement("div");
|
const selectorDiv = document.createElement("div");
|
||||||
@@ -253,22 +255,36 @@ function platformToggle() {
|
|||||||
tensorflowButton.classList.remove("selected");
|
tensorflowButton.classList.remove("selected");
|
||||||
|
|
||||||
pytorchButton.addEventListener("click", () => {
|
pytorchButton.addEventListener("click", () => {
|
||||||
sample.element.innerHTML = sample.pytorchSample;
|
for(const codeBlock of updatedCodeBlocks){
|
||||||
pytorchButton.classList.add("selected");
|
codeBlock.element.innerHTML = codeBlock.pytorchSample;
|
||||||
tensorflowButton.classList.remove("selected");
|
}
|
||||||
|
Array.from(document.getElementsByClassName('pytorch-button')).forEach(button => {
|
||||||
|
button.classList.add("selected");
|
||||||
|
})
|
||||||
|
Array.from(document.getElementsByClassName('tensorflow-button')).forEach(button => {
|
||||||
|
button.classList.remove("selected");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
tensorflowButton.addEventListener("click", () => {
|
tensorflowButton.addEventListener("click", () => {
|
||||||
sample.element.innerHTML = sample.tensorflowSample;
|
for(const codeBlock of updatedCodeBlocks){
|
||||||
tensorflowButton.classList.add("selected");
|
codeBlock.element.innerHTML = codeBlock.tensorflowSample;
|
||||||
pytorchButton.classList.remove("selected");
|
}
|
||||||
|
Array.from(document.getElementsByClassName('tensorflow-button')).forEach(button => {
|
||||||
|
button.classList.add("selected");
|
||||||
|
})
|
||||||
|
Array.from(document.getElementsByClassName('pytorch-button')).forEach(button => {
|
||||||
|
button.classList.remove("selected");
|
||||||
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
codeBlocks
|
const updatedCodeBlocks = codeBlocks
|
||||||
.map(element => {return {element: element.firstChild, innerText: element.innerText}})
|
.map(element => {return {element: element.firstChild, innerText: element.innerText}})
|
||||||
.filter(codeBlock => codeBlock.innerText.includes(pytorchIdentifier) && codeBlock.innerText.includes(tensorflowIdentifier))
|
.filter(codeBlock => codeBlock.innerText.includes(pytorchIdentifier) && codeBlock.innerText.includes(tensorflowIdentifier))
|
||||||
.map(getFrameworkSpans)
|
.map(getFrameworkSpans)
|
||||||
.forEach(createFrameworkButtons);
|
|
||||||
|
updatedCodeBlocks
|
||||||
|
.forEach(createFrameworkButtons)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user