Code: Select all
let dragScript = """
const dragItems = document.querySelectorAll('.drag-item');
const dropZones = document.querySelectorAll('.drop-zone');
let draggedItem = null;
dragItems.forEach(item => {
item.addEventListener('dragstart', () => {
draggedItem = item;
});
item.addEventListener('dragend', () => {
draggedItem = null;
});
});
dropZones.forEach(zone => {
zone.addEventListener('dragover', e => {
e.preventDefault();
});
zone.addEventListener('drop', () => {
if (zone.children.length === 0) {
zone.appendChild(draggedItem);
}
});
});
function checkAnswers() {
dropZones.forEach(zone => {
const answer = zone.querySelector('.drag-item');
if (answer && answer.dataset.answer === zone.dataset.correct) {
zone.classList.add('correct');
zone.classList.remove('wrong');
} else {
zone.classList.add('wrong');
zone.classList.remove('correct');
}
});
}
"""
webView.evaluateJavaScript(dragScript) { _, error in
if let error = error {
print("Error injecting drag script: \(error.localizedDescription)")
}
}
Code: Select all
1776
George Washington
Boston Tea Party
Treaty of Paris
Year the Declaration of Independence was signed:
Leader of the Continental Army:
Event where colonists protested by dumping tea:
Agreement that ended the American Revolution:
Code: Select all
private func setupWebView() {
// Initialize the web view with a configuration
webView = WKWebView(frame: CGRect(x: 0, y: progressBar.frame.maxY + 5, width: view.bounds.width, height: view.bounds.height - progressBar.frame.maxY + 5))
webView.navigationDelegate = self
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}