İçeriğe atla

MediaWiki:Common.js

Hukukipedia sitesinden
18.27, 31 Ağustos 2026 tarihinde Admin (mesaj | katkılar) tarafından oluşturulmuş 520 numaralı sürüm (Kanun maddesi URLlerini göreli yaparak Popups uyumunu düzelt)

Not: Yayımladıktan sonra değişiklikleri görmeniz için tarayıcınızın önbelleğini temizlemeniz gerekebilir.

  • Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R)
  • Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
  • Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5'e basın.
/* İşlem Rehberi PageForms: adım numaralarını otomatik sırala. */
(function () {
    var isProcedureForm = mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit' &&
        (mw.config.get('wgTitle') || '').indexOf('İşlem Rehberi') !== -1;
    if (!isProcedureForm) {
        return;
    }

    function renumberSteps() {
        var fields = Array.prototype.filter.call(document.querySelectorAll('input'), function (field) {
            return field.name.indexOf('İşlem Adımı[') === 0 && field.name.slice(-4) === '[no]';
        });
        fields.forEach(function (field, index) {
            field.value = String(index + 1);
            field.setAttribute('value', String(index + 1));
        });
    }

    document.addEventListener('click', function (event) {
        var text = (event.target.closest('button') || event.target).textContent || '';
        if (text.indexOf('örneği ekle') !== -1 || text.indexOf('örneği kaldır') !== -1 || text.indexOf('Adım ekle') !== -1) {
            window.setTimeout(function () {
                renumberSteps();
                bindImagePreviews();
            }, 250);
        }
    }, true);

    var form = document.querySelector('form');
    if (form) {
        form.addEventListener('submit', renumberSteps, true);
    }
    window.setTimeout(renumberSteps, 50);

    /* Ekran görüntüsü alanında mevcut dosyayı seçince küçük önizleme göster. */
    function previewBox(select) {
        var span = select.closest('.comboboxSpan') || select.parentNode;
        var box = span.querySelector('.islem-image-preview');
        if (!box) {
            box = document.createElement('div');
            box.className = 'islem-image-preview';
            box.style.cssText = 'margin-top:8px;min-height:20px;';
            span.appendChild(box);
        }
        return box;
    }

    function showExistingPreview(select) {
        var value = (select.getAttribute('data-value') || select.value || '').replace(/^File:/i, '');
        var span = select.closest('.comboboxSpan');
        if (!span) return;
        var image = span.querySelector('.simpleupload_prv');
        if (!image) {
            image = document.createElement('img');
            image.className = 'simpleupload_prv';
            span.insertBefore(image, span.firstChild);
        }
        if (!value) {
            image.style.display = 'none';
            return;
        }
        image.src = mw.util.getUrl('Special:Redirect/file/' + encodeURIComponent(value)) + '?width=800';
        image.alt = value;
        image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;margin:8px 0;';
    }

    function showLocalPreview(input) {
        var select = input.closest('.comboboxSpan') && input.closest('.comboboxSpan').querySelector('select');
        if (!select || !input.files || !input.files[0]) return;
        var oldImage = select.closest('.comboboxSpan').querySelector('.simpleupload_prv');
        if (oldImage) oldImage.style.display = 'none';
        var box = previewBox(select);
        box.textContent = '';
        var image = document.createElement('img');
        image.src = URL.createObjectURL(input.files[0]);
        image.alt = input.files[0].name;
        image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;';
        box.appendChild(image);
    }

    function decorateFileSuggestions() {
        document.querySelectorAll('.oo-ui-menuSelectWidget[role="listbox"] .oo-ui-optionWidget').forEach(function (item) {
            if (item.querySelector('.islem-file-thumb')) return;
            var label = item.querySelector('.oo-ui-labelElement-label');
            var name = label && (label.textContent || '').trim();
            if (!name || /^(Seç|Select)/i.test(name)) return;
            var image = document.createElement('img');
            image.className = 'islem-file-thumb';
            image.alt = '';
            image.src = mw.util.getUrl('Special:Redirect/file/' + encodeURIComponent(name)) + '?width=100';
            image.style.cssText = 'width:80px;height:80px;object-fit:contain;vertical-align:middle;margin-right:10px;border:1px solid #c8ccd1;background:#fff;';
            item.style.minHeight = '88px';
            item.insertBefore(image, item.firstChild);
        });
    }

    function bindImagePreviews() {
        decorateFileSuggestions();
        document.querySelectorAll('.simpleupload_prv').forEach(function (image) {
            image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;margin:8px 0;';
        });
        document.querySelectorAll('input.pf-string-type--value[autocompletesettings="File"]').forEach(function (select) {
            if (select.dataset.previewBound) return;
            select.dataset.previewBound = '1';
            select.addEventListener('change', function () { showExistingPreview(select); });
            select.addEventListener('input', function () { window.setTimeout(function () { showExistingPreview(select); }, 100); });
            if (select.value) showExistingPreview(select);
        });
        document.querySelectorAll('input[type="file"]').forEach(function (input) {
            if (input.dataset.previewBound) return;
            input.dataset.previewBound = '1';
            input.addEventListener('change', function () { showLocalPreview(input); });
        });
    }

    bindImagePreviews();
    if (window.MutationObserver) {
        new MutationObserver(bindImagePreviews).observe(document.body, { childList: true, subtree: true });
    }
}());

/* Dış bağlantıları güvenli biçimde yeni sekmede aç. İç wiki bağlantılarına dokunma. */
(function () {
    function openExternalLinksInNewTab() {
        document.querySelectorAll('a.external, a.extiw').forEach(function (link) {
            if (link.hostname && link.hostname !== window.location.hostname) {
                link.target = '_blank';
                link.rel = 'noopener noreferrer';
            }
        });
    }

    mw.hook('wikipage.content').add(openExternalLinksInNewTab);
    document.addEventListener('DOMContentLoaded', openExternalLinksInNewTab);
}());

/* Kanun maddeleri: numara arama, filtreleme ve ilgili maddeye odaklanma. */
(function () {
    function initLawArticleSearch() {
        var lists = document.querySelectorAll('.hk-law-articles-list');
        if (!lists.length) return;

        lists.forEach(function (list) {
            if (list.dataset.searchReady === '1') return;
            list.dataset.searchReady = '1';

            var box = document.createElement('div');
            box.className = 'hk-law-article-search';
            box.innerHTML = '<label for="hk-law-article-query">Madde numarasına git:</label>' +
                '<input id="hk-law-article-query" type="search" inputmode="numeric" placeholder="Örn. 285" autocomplete="off">' +
                '<button type="button">Git</button>' +
                '<span class="hk-law-article-search-status" aria-live="polite"></span>';
            list.parentNode.insertBefore(box, list);

            var input = box.querySelector('input');
            var button = box.querySelector('button');
            var status = box.querySelector('.hk-law-article-search-status');
            var links = Array.prototype.slice.call(list.querySelectorAll('a'));

            function clearState() {
                links.forEach(function (link) {
                    link.hidden = false;
                    link.classList.remove('hk-law-article-focus');
                });
            }

            function goToArticle() {
                var value = (input.value || '').trim().replace(/^madde\s*/i, '');
                if (!value) { clearState(); status.textContent = ''; return; }
                filterArticles();
                var target = links.find(function (link) {
                    return (link.textContent || '').trim().toLowerCase() === ('madde ' + value).toLowerCase();
                });
                if (!target) return;
                target.classList.add('hk-law-article-focus');
                target.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
                status.textContent = 'Madde ' + value + ' bulundu.';
            }

            function filterArticles() {
                var value = (input.value || '').trim().replace(/^madde\s*/i, '').toLowerCase();
                if (!value) { clearState(); status.textContent = ''; return; }
                var matches = links.filter(function (link) {
                    var number = (link.textContent || '').replace(/^madde\s*/i, '').trim().toLowerCase();
                    return number.indexOf(value) === 0;
                });
                links.forEach(function (link) {
                    link.hidden = matches.indexOf(link) === -1;
                    link.classList.remove('hk-law-article-focus');
                });
                status.textContent = matches.length ? matches.length + ' uygun madde gösteriliyor.' : 'Madde bulunamadı.';
            }

            button.addEventListener('click', goToArticle);
            input.addEventListener('keydown', function (event) {
                if (event.key === 'Enter') goToArticle();
                if (event.key === 'Escape') { input.value = ''; clearState(); status.textContent = ''; }
            });
            input.addEventListener('input', filterArticles);
        });
    }

    mw.hook('wikipage.content').add(initLawArticleSearch);
    document.addEventListener('DOMContentLoaded', initLawArticleSearch);
}());

/* Eksik kanun maddelerini PageForms ekranına yönlendir; Lua'da pahalı exists çağrısı yapma. */
(function () {
    function routeMissingLawArticles() {
        document.querySelectorAll('.hk-law-articles[data-law-title]').forEach(function (container) {
            if (container.dataset.formRoutingReady === '1') return;
            container.dataset.formRoutingReady = '1';
            var law = container.getAttribute('data-law-title') || '';
            container.querySelectorAll('.hk-law-articles-list a.new').forEach(function (link) {
                var text = (link.textContent || '').trim();
                var match = text.match(/^Madde\s+(\d+)$/i);
                if (!match || !law) return;
                var article = match[1];
                var target = 'Special:FormEdit/Kanun Maddesi/' + law + '/Madde ' + article;
                link.href = mw.util.getUrl(target, {
                    'Kanun Maddesi[kanun]': law,
                    'Kanun Maddesi[madde]': article
                });
                link.classList.add('hk-law-article-form-link');
                link.title = 'Madde sayfasını oluştur';
            });
        });
    }
    mw.hook('wikipage.content').add(routeMissingLawArticles);
    document.addEventListener('DOMContentLoaded', routeMissingLawArticles);
}());

/* Popups: aynı wikiye giden mevcut kanun maddelerini dış bağlantı sınıfından çıkar. */
(function () {
    function enableLawPagePreviews() {
        document.querySelectorAll('.hk-law-articles a.external[href]').forEach(function (link) {
            if (link.href.indexOf('/Special:FormEdit/') !== -1 || link.href.indexOf('Special%3AFormEdit') !== -1) return;
            if (link.hostname === window.location.hostname) {
                link.classList.remove('external', 'text');
                link.removeAttribute('rel');
                link.href = link.pathname + link.search + link.hash;
            }
        });
    }
    mw.hook('wikipage.content').add(enableLawPagePreviews);
    document.addEventListener('DOMContentLoaded', enableLawPagePreviews);
}());