মিডিয়াউইকি:Common.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য
অবয়ব
জাভাস্ক্রিপ্ট মডেল সংশোধনের পর সাইট মডিউল পুনর্গঠন; তরিকার ড্রপডাউন পুনরুদ্ধার |
তরিকা ড্রপডাউন DOM প্রস্তুত হলেই তৈরি; লোডিং ক্রমের ওপর নির্ভরতা দূর ও পুনরায় চললেও নিরাপদ রাখা |
||
| ১ নং লাইন: | ১ নং লাইন: | ||
/* সুফিবাংলা: প্রধান পাতার | /* সুফিবাংলা: প্রধান পাতার বাছাই ও ফর্মের ছবির ক্যাপশন */ | ||
(function () { | |||
'use strict'; | |||
function init() { | |||
var list = document.getElementById('sb-tariqa-list'); | |||
if (list && !list.querySelector('select')) { | |||
var links = list.querySelectorAll('.sb-tariqa-opt a'); | |||
if (links.length) { | |||
var select = document.createElement('select'); | |||
select.className = 'sb-tariqa-select'; | |||
select.setAttribute('aria-label', 'তরিকা'); | |||
Array.prototype.forEach.call(links, function (link) { | |||
var option = document.createElement('option'); | |||
option.value = link.href; | |||
option.textContent = link.textContent; | |||
select.appendChild(option); | |||
}); | |||
var go = document.createElement('button'); | |||
go.type = 'button'; go.className = 'sb-tariqa-go'; | |||
go.textContent = 'শায়খদের তালিকা দেখুন'; | |||
go.addEventListener('click', function () { if (select.value) window.location.assign(select.value); }); | |||
list.textContent = ''; list.appendChild(select); list.appendChild(go); | |||
} | |||
} | |||
var rows = document.querySelectorAll('.sb-country-row'); | |||
var letters = document.querySelectorAll('.sb-letter'); | |||
function showFirst() { | |||
Array.prototype.forEach.call(rows, function (row, i) { row.classList.toggle('sb-hidden', i >= 5); }); | |||
Array.prototype.forEach.call(letters, function (letter) { letter.classList.remove('sb-active'); }); | |||
} | |||
if (rows.length && !document.querySelector('.sb-letter[data-sb-ready]')) { | |||
showFirst(); | |||
Array.prototype.forEach.call(letters, function (letter) { | |||
letter.setAttribute('data-sb-ready', '1'); letter.setAttribute('role', 'button'); letter.tabIndex = 0; | |||
} ); | function choose(event) { | ||
if (event.type === 'keydown' && event.key !== 'Enter' && event.key !== ' ') return; | |||
event.preventDefault(); | |||
if (letter.classList.contains('sb-active')) { showFirst(); return; } | |||
Array.prototype.forEach.call(rows, function (row) { row.classList.toggle('sb-hidden', row.getAttribute('data-letter') !== letter.getAttribute('data-letter')); }); | |||
Array.prototype.forEach.call(letters, function (item) { item.classList.remove('sb-active'); }); | |||
letter.classList.add('sb-active'); | |||
} | |||
letter.addEventListener('click', choose); letter.addEventListener('keydown', choose); | |||
}); | |||
} | |||
syncCaptions(); | |||
} | |||
function syncCaptions() { | |||
Array.prototype.forEach.call(document.querySelectorAll('.sb-cap'), function (caption) { | |||
var field = caption.previousElementSibling; | |||
} ); | var image = field && field.classList.contains('sb-img-field') ? field.querySelector('input') : null; | ||
var text = caption.querySelector('input'); | |||
var show = Boolean((image && image.value.trim()) || (text && text.value.trim())); | |||
caption.style.display = show ? '' : 'none'; | |||
}); | |||
} | |||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); | |||
else init(); | |||
if (window.mw && mw.hook) mw.hook('wikipage.content').add(init); | |||
document.addEventListener('input', function (event) { if (event.target.closest('.sb-img-field, .sb-cap')) syncCaptions(); }); | |||
document.addEventListener('change', function (event) { if (event.target.closest('.sb-img-field, .sb-cap')) syncCaptions(); }); | |||
window.setInterval(function () { if (document.querySelector('.sb-cap')) syncCaptions(); }, 1500); | |||
}()); | |||
২২:৩২, ২৭ অক্টোবর ২০২৬ তারিখে সংশোধিত সংস্করণ
/* সুফিবাংলা: প্রধান পাতার বাছাই ও ফর্মের ছবির ক্যাপশন */
(function () {
'use strict';
function init() {
var list = document.getElementById('sb-tariqa-list');
if (list && !list.querySelector('select')) {
var links = list.querySelectorAll('.sb-tariqa-opt a');
if (links.length) {
var select = document.createElement('select');
select.className = 'sb-tariqa-select';
select.setAttribute('aria-label', 'তরিকা');
Array.prototype.forEach.call(links, function (link) {
var option = document.createElement('option');
option.value = link.href;
option.textContent = link.textContent;
select.appendChild(option);
});
var go = document.createElement('button');
go.type = 'button'; go.className = 'sb-tariqa-go';
go.textContent = 'শায়খদের তালিকা দেখুন';
go.addEventListener('click', function () { if (select.value) window.location.assign(select.value); });
list.textContent = ''; list.appendChild(select); list.appendChild(go);
}
}
var rows = document.querySelectorAll('.sb-country-row');
var letters = document.querySelectorAll('.sb-letter');
function showFirst() {
Array.prototype.forEach.call(rows, function (row, i) { row.classList.toggle('sb-hidden', i >= 5); });
Array.prototype.forEach.call(letters, function (letter) { letter.classList.remove('sb-active'); });
}
if (rows.length && !document.querySelector('.sb-letter[data-sb-ready]')) {
showFirst();
Array.prototype.forEach.call(letters, function (letter) {
letter.setAttribute('data-sb-ready', '1'); letter.setAttribute('role', 'button'); letter.tabIndex = 0;
function choose(event) {
if (event.type === 'keydown' && event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
if (letter.classList.contains('sb-active')) { showFirst(); return; }
Array.prototype.forEach.call(rows, function (row) { row.classList.toggle('sb-hidden', row.getAttribute('data-letter') !== letter.getAttribute('data-letter')); });
Array.prototype.forEach.call(letters, function (item) { item.classList.remove('sb-active'); });
letter.classList.add('sb-active');
}
letter.addEventListener('click', choose); letter.addEventListener('keydown', choose);
});
}
syncCaptions();
}
function syncCaptions() {
Array.prototype.forEach.call(document.querySelectorAll('.sb-cap'), function (caption) {
var field = caption.previousElementSibling;
var image = field && field.classList.contains('sb-img-field') ? field.querySelector('input') : null;
var text = caption.querySelector('input');
var show = Boolean((image && image.value.trim()) || (text && text.value.trim()));
caption.style.display = show ? '' : 'none';
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
if (window.mw && mw.hook) mw.hook('wikipage.content').add(init);
document.addEventListener('input', function (event) { if (event.target.closest('.sb-img-field, .sb-cap')) syncCaptions(); });
document.addEventListener('change', function (event) { if (event.target.closest('.sb-img-field, .sb-cap')) syncCaptions(); });
window.setInterval(function () { if (document.querySelector('.sb-cap')) syncCaptions(); }, 1500);
}());