25 lines
821 B
JavaScript
25 lines
821 B
JavaScript
// Cairn - minimal client-side JS for interactive fragments
|
|
(function() {
|
|
'use strict';
|
|
|
|
// Helper: fetch an HTML fragment and swap into a target element
|
|
window.cairn = {
|
|
loadFragment: function(url, targetSelector) {
|
|
var target = document.querySelector(targetSelector);
|
|
if (!target) return;
|
|
|
|
fetch(url, { headers: { 'Accept': 'text/html' } })
|
|
.then(function(resp) {
|
|
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
|
return resp.text();
|
|
})
|
|
.then(function(html) {
|
|
target.innerHTML = html;
|
|
})
|
|
.catch(function(err) {
|
|
console.error('Fragment load failed:', err);
|
|
});
|
|
}
|
|
};
|
|
})();
|