%PDF- %PDF-
| Direktori : /home2/rezakur1/devita.rezakurnia.com/X9KQ7MW2RT8PY4ND6LV3JH5CG8BF2ZM7QW4/scene8b/ |
| Current File : /home2/rezakur1/devita.rezakurnia.com/X9KQ7MW2RT8PY4ND6LV3JH5CG8BF2ZM7QW4/scene8b/scene8b.js |
/* ===========================
HEADER COMPONENT
=========================== */
fetch('../components/header.html')
.then(response => response.text())
.then(data => {
document.getElementById(
'header-container'
).innerHTML = data;
});
/* ===========================
REVEAL ON SCROLL
=========================== */
const reveals =
document.querySelectorAll('.reveal');
function revealElements(){
reveals.forEach(item=>{
const top =
item.getBoundingClientRect().top;
const trigger =
window.innerHeight - 120;
if(top < trigger){
item.classList.add('show');
}
});
}
window.addEventListener(
'scroll',
revealElements
);
revealElements();
/* ===========================
QUESTION FLOW
=========================== */
const questionCards =
document.querySelectorAll(
'.question-card'
);
const nextButtons =
document.querySelectorAll(
'.next-question'
);
const progressFill =
document.getElementById(
'progressFill'
);
const progressText =
document.getElementById(
'progressText'
);
const submitBtn =
document.getElementById(
'submitAllBtn'
);
let currentQuestion = 1;
function updateProgress(){
const percent =
(currentQuestion / 5) * 100;
progressFill.style.width =
percent + '%';
progressText.innerText =
`Pertanyaan ${currentQuestion} dari 5`;
}
/* ===========================
NEXT QUESTION
=========================== */
nextButtons.forEach(btn=>{
btn.addEventListener(
'click',
()=>{
const currentCard =
btn.closest(
'.question-card'
);
const textarea =
currentCard.querySelector(
'textarea'
);
if(
textarea.value.trim() === ''
){
alert(
'Silakan isi jawaban terlebih dahulu.'
);
return;
}
saveAnswers();
currentCard.classList.remove(
'active'
);
currentQuestion++;
if(currentQuestion <= 5){
document
.querySelector(
`.question-card[data-question="${currentQuestion}"]`
)
.classList.add(
'active'
);
updateProgress();
window.scrollTo({
top:
document
.querySelector(
`.question-card[data-question="${currentQuestion}"]`
)
.offsetTop - 120,
behavior:'smooth'
});
}
checkSubmitStatus();
}
);
});
/* ===========================
LOCAL STORAGE
=========================== */
function saveAnswers(){
const answers = {
q1:
document.getElementById('q1')?.value || '',
q2:
document.getElementById('q2')?.value || '',
q3:
document.getElementById('q3')?.value || '',
q4:
document.getElementById('q4')?.value || '',
q5:
document.getElementById('q5')?.value || ''
};
localStorage.setItem(
'scene8b_answers',
JSON.stringify(
answers
)
);
}
function loadAnswers(){
// const data =
// localStorage.getItem(
// 'scene8b_answers'
// );
// if(!data) return;
const answers =
JSON.parse(data);
Object.keys(answers)
.forEach(key=>{
const el =
document.getElementById(
key
);
if(el){
el.value =
answers[key];
}
});
}
// loadAnswers();
/* ===========================
AUTO SAVE
=========================== */
document
.querySelectorAll('textarea')
.forEach(textarea=>{
textarea.addEventListener(
'input',
saveAnswers
);
});
/* ===========================
CHECK SUBMIT
=========================== */
function checkSubmitStatus(){
const q1 =
document.getElementById('q1').value.trim();
const q2 =
document.getElementById('q2').value.trim();
const q3 =
document.getElementById('q3').value.trim();
const q4 =
document.getElementById('q4').value.trim();
const q5 =
document.getElementById('q5').value.trim();
submitBtn.disabled = !(
q1 &&
q2 &&
q3 &&
q4 &&
q5
);
}
document
.querySelectorAll('textarea')
.forEach(el=>{
el.addEventListener(
'input',
checkSubmitStatus
);
});
checkSubmitStatus();
/* ===========================
SUBMIT
=========================== */
/* ===========================
SUBMIT
=========================== */
submitBtn.addEventListener(
'click',
async () => {
const answers = [
{
questionKey: 'q1',
questionTitle: 'Mengapa [Choline][ClUrea] bisa cair meski tersusun dari ion-ion?',
answer: document.getElementById('q1').value.trim(),
},
{
questionKey: 'q2',
questionTitle: 'Apa yang membuat [Choline][ClUrea] memiliki titik leleh lebih rendah daripada NaCl?',
answer: document.getElementById('q2').value.trim(),
},
{
questionKey: 'q3',
questionTitle: 'Dengan membandingkan gambar dan video antara NaCl dan [Choline][ClUrea], perbedaan apa yang dapat Anda amati?',
answer: document.getElementById('q3').value.trim(),
},
{
questionKey: 'q4',
questionTitle: 'Bagaimana perbedaan pergerakan atau mobilitas dari kation dan anion pada NaCl dan [Bmim]BF₄?',
answer: document.getElementById('q4').value.trim(),
},
{
questionKey: 'q5',
questionTitle: 'Senyawa manakah, NaCl atau [Bmim]BF₄, yang memberikan gaya tarik elektrostatik paling besar? Jelaskan alasannya dengan menghubungkan pada Persamaan Coulomb.',
answer: document.getElementById('q5').value.trim(),
},
];
try {
submitBtn.disabled = true;
const originalText =
submitBtn.innerText;
submitBtn.innerText =
'Menyimpan...';
await ParticipantAnswerService.saveMultiple(
82,
answers
);
saveAnswers();
const panel =
document.getElementById(
'feedbackPanel'
);
panel.classList.add(
'show'
);
panel.scrollIntoView({
behavior:'smooth'
});
submitBtn.innerText =
'Berhasil Disimpan';
setTimeout(() => {
submitBtn.innerText =
originalText;
submitBtn.disabled =
false;
}, 1500);
} catch (error) {
console.error(error);
alert(
'Gagal menyimpan jawaban error: ' + error.message
);
submitBtn.disabled =
false;
submitBtn.innerText =
'Kirim Jawaban';
}
}
);
/* ===========================
EXPORT PDF
=========================== */
document
.getElementById(
'savePdfBtn'
)
.addEventListener(
'click',
()=>{
const {
jsPDF
} = window.jspdf;
const doc =
new jsPDF();
// const answers =
// JSON.parse(
// localStorage.getItem(
// 'scene8b_answers'
// )
// );
let y = 20;
doc.setFontSize(16);
doc.text(
'Jawaban Scene 8B',
20,
y
);
y += 15;
Object.entries(
''
).forEach(
([key,value],index)=>{
const text =
`Pertanyaan ${index+1}: ${value}`;
const lines =
doc.splitTextToSize(
text,
170
);
doc.setFontSize(
11
);
doc.text(
lines,
20,
y
);
y +=
lines.length * 7 + 10;
if(y > 260){
doc.addPage();
y = 20;
}
}
);
doc.save(
'Jawaban-Scene8B.pdf'
);
}
);
/* ===========================
INIT
=========================== */
loadAnswers();
updateProgress();
checkSubmitStatus();
/* ===========================
LAST QUESTION HANDLER
=========================== */
const q5 =
document.getElementById('q5');
if(q5){
q5.addEventListener(
'input',
()=>{
saveAnswers();
checkSubmitStatus();
progressFill.style.width =
'100%';
progressText.innerText =
'Pertanyaan 5 dari 5';
}
);
}