"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "6070b55443d14ae480a0f359f3aff45308e7341d"
Unverified Commit 818c294f authored by Lysandre Debut's avatar Lysandre Debut Committed by GitHub
Browse files

The toggle actually sticks (#7586)

parent 03835af7
......@@ -236,9 +236,11 @@ function platformToggle() {
const createFrameworkButtons = sample => {
const pytorchButton = document.createElement("button");
pytorchButton.classList.add('pytorch-button')
pytorchButton.innerText = "PyTorch";
const tensorflowButton = document.createElement("button");
tensorflowButton.classList.add('tensorflow-button')
tensorflowButton.innerText = "TensorFlow";
const selectorDiv = document.createElement("div");
......@@ -253,22 +255,36 @@ function platformToggle() {
tensorflowButton.classList.remove("selected");
pytorchButton.addEventListener("click", () => {
sample.element.innerHTML = sample.pytorchSample;
pytorchButton.classList.add("selected");
tensorflowButton.classList.remove("selected");
for(const codeBlock of updatedCodeBlocks){
codeBlock.element.innerHTML = codeBlock.pytorchSample;
}
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", () => {
sample.element.innerHTML = sample.tensorflowSample;
tensorflowButton.classList.add("selected");
pytorchButton.classList.remove("selected");
for(const codeBlock of updatedCodeBlocks){
codeBlock.element.innerHTML = codeBlock.tensorflowSample;
}
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}})
.filter(codeBlock => codeBlock.innerText.includes(pytorchIdentifier) && codeBlock.innerText.includes(tensorflowIdentifier))
.map(getFrameworkSpans)
.forEach(createFrameworkButtons);
updatedCodeBlocks
.forEach(createFrameworkButtons)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment