Dec 14, 2024
0
Level 1
add button
hello, I created a file with the name toolbarLatext.js which is in the resources/js folder then I registered it in Vite
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/sass/ui.scss',
'resources/js/app.js',
'resources/js/toolbarLatext.js',
],
refresh: true,
}),
],
});
inside app.blade.php I call it like this
@vite(['resources/sass/ui.scss', 'resources/js/app.js','resources/js/toolbarLatext.js'])
toolbarLatext.js is connected to the create.blade.php file through this
<div id="toolbar" class="mt-3 toolbar-container">
<!-- toolbar here -->
</div>
toolbarLatext.js
document.addEventListener('DOMContentLoaded', function () {
const toolbarButtons = [
{ latex: "+", label: "+" },
{ latex: "-", label: "−" },
{ latex: "\\times", label: "×" },
{ latex: "\\div", label: "÷" },
{ latex: "=", label: "=" },
{ latex: "\\neq", label: "≠" },
{ latex: "\\geq", label: "≥" },
{ latex: "\\leq", label: "≤" },
{ latex: "\\sqrt{}", label: "√" },
{ latex: "\\frac{}{}", label: "a/b" },
{ latex: "x^2", label: "x²" },
{ latex: "x^n", label: "xⁿ" },
{ latex: "\\in", label: "∈" },
{ latex: "\\notin", label: "∉" },
{ latex: "\\subset", label: "⊂" },
{ latex: "\\subseteq", label: "⊆" },
{ latex: "\\cup", label: "∪" },
{ latex: "\\cap", label: "∩" },
{ latex: "\\int", label: "∫" },
{ latex: "\\partial", label: "∂" },
{ latex: "\\nabla", label: "∇" },
{ latex: "\\sin", label: "sin" },
{ latex: "\\cos", label: "cos" },
{ latex: "\\tan", label: "tan" },
{ latex: "\\ln", label: "ln" },
{ latex: "e^x", label: "e^x" },
{ latex: "\\alpha", label: "α" },
{ latex: "\\beta", label: "β" },
{ latex: "\\pi", label: "π" },
{ latex: "\\theta", label: "θ" }
];
const toolbarContainer = document.getElementById("toolbar");
// Menambahkan tombol secara dinamis ke toolbar
toolbarButtons.forEach(button => {
const btn = document.createElement("button");
btn.type = "button";
btn.classList.add("btn", "btn-secondary");
btn.textContent = button.label;
btn.setAttribute("data-latex", button.latex);
btn.onclick = function () {
insertLatex(button.latex);
};
toolbarContainer.appendChild(btn);
});
// Fungsi untuk menambahkan simbol LaTeX ke editor
function insertLatex(latex) {
const mathInput = document.getElementById("math-input");
if (mathInput) {
const currentValue = mathInput.value;
mathInput.value = currentValue + latex;
}
}
// Fungsi untuk menambahkan soal baru
function addQuestion() {
const container = document.getElementById("questions-container");
const newQuestionHtml = createQuestionHtml();
container.insertAdjacentHTML("beforeend", newQuestionHtml);
}
});
The question is why the toolbar doesn't appear in the view
Please or to participate in this conversation.