closes its siblings natively in current browsers
(Chrome 120+, Safari 17.2+, Firefox 130+). Older engines ignore the attribute,
which would let both product-contact panels stand open at once, so this closes
the siblings by hand on every toggle.
On a browser with native support the work is a no-op: by the time `toggle`
fires the sibling is already shut, so the loop finds nothing to close. */
(function () {
// Self-contained scope: this block sits outside the module that defines $/$$,
// so it must query the DOM itself. Calling the outer helpers here threw
// "$$ is not defined" at load time, which killed every IIFE registered after
// it — including the listen button and the video controls.
var all = function (sel) { return Array.prototype.slice.call(document.querySelectorAll(sel)); };
var groups = {};
all("details[name]").forEach(function (d) {
var name = d.getAttribute("name");
if (!name) return;
(groups[name] = groups[name] || []).push(d);
});
Object.keys(groups).forEach(function (name) {
var items = groups[name];
if (items.length < 2) return;
items.forEach(function (item) {
item.addEventListener("toggle", function () {
// A `toggle` event also fires for the close we are about to cause; guard
// so the loop settles after one pass.
if (!item.open) return;
items.forEach(function (other) {
if (other !== item && other.open) other.open = false;
});
});
});
});
})();
/* ---------- article text-to-speech ----------
"Haberi dinle" reads the article with the browser's own speech synthesis.
No audio is generated server-side and nothing is downloaded, so the feature
costs one button and works offline once the page is loaded. It is removed
entirely when the browser has no voices, rather than showing a control that
does nothing. */
(function () {
var btn = document.querySelector("[data-tts]");
var body = document.querySelector("[data-article-body]");
if (!btn || !body) return;
if (!("speechSynthesis" in window) || !window.SpeechSynthesisUtterance) return;
var label = btn.querySelector("[data-tts-label]");
var speaking = false;
var original = label ? label.textContent : "";
// Strip markup, then split on sentence ends so a long article can be paused
// between sentences instead of as one 4-minute utterance.
function chunks() {
var text = (body.innerText || body.textContent || "").replace(/\s+/g, " ").trim();
if (!text) return [];
var out = [];
var buf = "";
for (var i = 0; i < text.length; i++) {
buf += text[i];
if (/[.!?…]/.test(text[i]) && buf.trim().length > 40) {
out.push(buf.trim());
buf = "";
}
}
if (buf.trim()) out.push(buf.trim());
return out;
}
function stop() {
window.speechSynthesis.cancel();
speaking = false;
if (label) label.textContent = original;
btn.classList.remove("is-speaking");
}
btn.hidden = false;
btn.addEventListener("click", function () {
if (speaking) { stop(); return; }
var parts = chunks();
if (!parts.length) return;
speaking = true;
btn.classList.add("is-speaking");
if (label) label.textContent = btn.getAttribute("data-stop-label") || "■";
var lang = document.documentElement.lang || "tr";
parts.forEach(function (part, i) {
var u = new SpeechSynthesisUtterance(part);
u.lang = lang;
u.rate = 1;
if (i === parts.length - 1) u.onend = stop;
window.speechSynthesis.speak(u);
});
});
// Navigating away must stop playback: a voice that keeps reading the previous
// article over the next page is the worst possible bug in this feature.
window.addEventListener("pagehide", stop);
document.addEventListener("visibilitychange", function () {
if (document.hidden) stop();
});
})();
/* ---------- article video: close, and never overlay ----------
The player is inline, so it never covers text by design. This adds the
one-tap close that the Better Ads Standards require for any floating player:
the article collapses the video instead of leaving a black box behind. */
(function () {
var wrap = document.querySelector("[data-video-player]");
if (!wrap) return;
var close = wrap.querySelector("[data-video-close]");
if (!close) return;
close.addEventListener("click", function () {
var v = wrap.querySelector("video");
if (v) { try { v.pause(); } catch (e) {} }
wrap.remove();
});
})();
/* ---------- checkout live quote on country change ----------
Picking a destination changes the shipping rate, the total, the delivery
promise and whether the wire transfer is offered at all. Reloading for that
wiped the half-filled form, so the page asks the server for the numbers and
repaints them. The order is still priced from the posted country on submit, so
nothing here can change what is charged.
The response also carries the bank accounts for the new country: the wire panel
is rebuilt from it, because a German buyer must not be shown a US IBAN. */
(function () {
var form = document.querySelector('form.checkout-form') || document.querySelector('.co-main form');
var countrySel = document.getElementById('billingCountry');
if (!countrySel) return;
var shipEl = document.querySelector('[data-ship-amount]');
var totalEl = document.querySelector('[data-total-amount]');
var bankPanel = document.querySelector('[data-bank-panel]');
var token = 0;
function currentShip() {
var r = document.querySelector('input[name="ship_method"]:checked');
return r ? r.value : 'standard';
}
window.dbCheckoutRequote = function () {
var my = ++token;
var q = '?country=' + encodeURIComponent(countrySel.value) +
'&ship=' + encodeURIComponent(currentShip());
fetch('/api/odeme/fiyat' + q, { headers: { Accept: 'application/json' } })
.then(function (r) { return r.json(); })
.then(function (d) {
if (my !== token) return; // a newer change won
/* A new country changes the shipping rate and the tax base. Instead of
writing the total here — which is how the old code lost the customs
fee, because this path did not know the box was ticked — the new
server numbers are written back into the same data attributes the
single calculator reads, then it repaints. One writer, one formula. */
var dl = document.querySelector('.co-totals');
if (dl) {
var setNum = function (attr, val) {
if (typeof val === 'number' && isFinite(val)) dl.setAttribute(attr, String(val));
};
setNum('data-base-shipping', d.shipping);
setNum('data-ship-standard', d.shipping);
setNum('data-ship-express', d.shipping + (d.express_cents || 0));
// The quote endpoint returns the total for the requested method; the
// tax slice is what the difference leaves once shipping is removed.
if (typeof d.total === 'number') {
var bt = dl.getAttribute('data-base-subtotal');
var bd = dl.getAttribute('data-base-discount');
var dx = dl.getAttribute('data-base-customs');
var subtotal = parseInt(bt || '0', 10) || 0;
var discount = parseInt(bd || '0', 10) || 0;
var customs = parseInt(dx || '0', 10) || 0;
var tax = d.total - subtotal + discount - (d.shipping || 0) - customs;
if (tax >= 0) dl.setAttribute('data-base-tax', String(tax));
}
}
if (window.dbCheckoutRepaint) window.dbCheckoutRepaint();
// The destination changed, so the Stripe accordion has to be repainted
// with the methods that serve it: iDEAL appears for NL, disappears for TR.
//
// The draft intent was created for the previous country, and Stripe fixes
// the method list on it, so it has to be rebuilt for the new one. Falling
// back to deferred mode on failure keeps the card fields on screen; the
// submit path creates the real intent anyway.
if (window.__dbRemountForCountry) {
window.__dbRemountForCountry(countrySel.value);
}
// The wire option follows the country: rebuild the panel when accounts
// arrive, hide it when none do.
if (bankPanel) {
var list = d.bank_accounts || [];
if (!list.length) {
bankPanel.hidden = true;
} else {
bankPanel.hidden = false;
var existing = bankPanel.querySelectorAll('.co-bank-account');
for (var i = 0; i < existing.length; i++) existing[i].remove();
list.forEach(function (a, idx) {
var box = document.createElement('div');
box.className = 'co-bank-account' + (idx ? ' co-bank-alt' : '');
var rows = '';
if (a.label) rows += '' + a.label + '
';
rows += '';
if (a.holder) rows += '- Hesap sahibi
- ' + a.holder + '
';
rows += '- IBAN
- ' + a.iban + '
';
if (a.bic) rows += '- BIC / SWIFT
- ' + a.bic + '
';
if (a.name) rows += '- Banka
- ' + a.name + '
';
if (a.address) rows += '- Adres
- ' + a.address + '
';
rows += '
';
if (a.note) rows += '' + a.note + '
';
box.innerHTML = rows;
bankPanel.appendChild(box);
});
}
}
})
.catch(function () { /* keep the previous numbers rather than blanking them */ });
};
})();