MediaWiki:Common.js: Perbedaan antara revisi

Tidak ada ringkasan suntingan
Tanda: Dikembalikan Suntingan perangkat seluler Suntingan peramban seluler
Tidak ada ringkasan suntingan
Tanda: Dikembalikan Suntingan perangkat seluler Suntingan peramban seluler
Baris 1: Baris 1:
/* ==========================================================
/* ==========================================================
   🧠 MIPPEDIA DATA - SMART PLACEHOLDER (FINAL)
   🧠 MIPPEDIA DATA - ZERO-CLUTTER EMPTY STATE
  Features: Chaining, Translate, Auto-Age, Smart Links,
            Auto-Create Suggestion (NEW)
   ========================================================== */
   ========================================================== */
(function() {
(function() {
     $(document).ready(function() {
     $(document).ready(function() {
         var $descSection = $('#mip-desc-section');
         var $descSection = $('#mip-desc-section');
        var $descTitle = $('#mip-desc-title');
         var $descBox = $('#mip-auto-description');
         var $descBox = $('#mip-auto-description');
         var $sourceInfo = $('#mip-source-info');
         var $sourceInfo = $('#mip-source-info');
Baris 25: Baris 24:
         ];
         ];


        // 🛠️ Fungsi kalau data BENER-BENER GAK ADA
         function showEmptyState() {
         function showEmptyState() {
            $descTitle.hide(); // Hilangin tulisan "Deskripsi :"
             $descBox.hide();
             $descBox.hide();
             $sourceInfo.hide();
             $sourceInfo.hide();
             $projectPortal.hide();
             $projectPortal.hide();
             // Link otomatis ke halaman edit di Mippedia Indonesia
              
             var createUrl = "https://id.mippedia.org/w/index.php?title=" + encodeURIComponent(pageTitle) + "&action=edit";
             var createUrl = "https://id.mippedia.org/w/index.php?title=" + encodeURIComponent(pageTitle) + "&action=edit";
             $createLink.attr('href', createUrl);
             $createLink.attr('href', createUrl);
             $emptyBox.fadeIn();
             $emptyBox.show(); // Munculin teks polos
            $descSection.show();
         }
         }


        // --- (Fungsi Helper: cleanExtract, applyAutoAge, applySummary, buildSmartLinks tetep sama) ---
         function cleanExtract(text) { return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); }
         function cleanExtract(text) { return text.replace(/\[\d+\]/g, '').replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim(); }
         function applyAutoAge(text) { return text.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(m, f, y) { return f + " – usia " + (currentYear - parseInt(y)) + " tahun"; }); }
         function applyAutoAge(text) { return text.replace(/(\d{1,2}\s(?:Januari|Februari|Maret|April|Mei|Juni|Juli|Agustus|September|Oktober|November|Desember)\s(\d{4}))/gi, function(m, f, y) { return f + " – usia " + (currentYear - parseInt(y)) + " tahun"; }); }
         function applySummary(text) { var limit = 250; if (text.length <= limit) return '<span>' + text + '</span>'; return '<span>' + text.substring(0, limit) + '</span><span class="mip-dots">... </span><span class="mip-more" style="display:none;">' + text.substring(limit) + '</span><span class="mip-read-btn" style="color: #6a5acd; cursor: pointer; font-weight: bold; margin-left: 5px;">Baca selengkapnya</span>'; }
       
         function applySummary(text) {  
            var limit = 250;  
            if (text.length <= limit) return '<span>' + text + '</span>';  
            return '<span>' + text.substring(0, limit) + '</span><span class="mip-dots">... </span><span class="mip-more" style="display:none;">' + text.substring(limit) + '</span><span class="mip-read-btn" style="color: #6a5acd; cursor: pointer; font-weight: bold; margin-left: 5px;">Baca selengkapnya</span>';  
        }


         function buildSmartLinks(currentId) {
         function buildSmartLinks(currentId) {
Baris 49: Baris 53:
             });
             });
             $.when.apply($, checkRequests).done(function() {
             $.when.apply($, checkRequests).done(function() {
                 if (validLinks.length > 0) { $portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> ')); $projectPortal.show(); }
                 if (validLinks.length > 0) {  
                    $portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> '));  
                    $projectPortal.fadeIn();  
                }
             });
             });
         }
         }
Baris 55: Baris 62:
         function renderAll(p, currentText, isTranslated, originalText) {
         function renderAll(p, currentText, isTranslated, originalText) {
             $emptyBox.hide();
             $emptyBox.hide();
            $descTitle.show();
             $descBox.show().html(applySummary(applyAutoAge(currentText)));
             $descBox.show().html(applySummary(applyAutoAge(currentText)));
           
             var footer = '<div style="font-size: 0.9em; color: #777;">Sumber Dari : <a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>';
             var footer = '<div style="font-size: 0.9em; color: #777;">Sumber Dari : <a href="' + p.base + encodeURIComponent(pageTitle) + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>';
             if (isTranslated) { footer += '<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis)</span> <span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>'; }
             if (isTranslated) { footer += '<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis)</span> <span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>'; }
             $sourceInfo.show().html(footer);
             $sourceInfo.show().html(footer);
           
             buildSmartLinks(p.id);
             buildSmartLinks(p.id);
           
             $(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { $(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); });
             $(document).off('click', '.mip-read-btn').on('click', '.mip-read-btn', function() { $(this).hide(); $('.mip-dots').hide(); $('.mip-more').fadeIn(); });
             $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { var isOrig = ($(this).text() === 'Tampilkan versi asli'); $descBox.html(applySummary(applyAutoAge(isOrig ? originalText : currentText))); $(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli'); });
             $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() {  
                var isOrig = ($(this).text() === 'Tampilkan versi asli');  
                $descBox.html(applySummary(applyAutoAge(isOrig ? originalText : currentText)));  
                $(this).text(isOrig ? 'Tampilkan terjemahan' : 'Tampilkan versi asli');  
            });
         }
         }


         function fetchDescription(index) {
         function fetchDescription(index) {
             if (index >= projects.length) {  
             if (index >= projects.length) { showEmptyState(); return; }
                showEmptyState(); // Jalankan empty state kalau semua index gagal
                return;  
            }
             var p = projects[index];
             var p = projects[index];
             $descSection.show();
             $descSection.show();
Baris 83: Baris 95:
                         if (extract !== "") {
                         if (extract !== "") {
                             if (p.id === 'en') {
                             if (p.id === 'en') {
                                 var urlTrans = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(extract);
                                 $.ajax({
                                $.ajax({ url: urlTrans, success: function(res) {  
                                    url: "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(extract),
                                    var trans = ""; res[0].forEach(function(s) { if (s[0]) trans += s[0]; });
                                    success: function(res) {  
                                    renderAll(p, trans, true, extract);  
                                        var trans = ""; res[0].forEach(function(s) { if (s[0]) trans += s[0]; });
                                 }});
                                        renderAll(p, trans, true, extract);  
                                    }
                                 });
                             } else { renderAll(p, extract, false); }
                             } else { renderAll(p, extract, false); }
                             return;
                             return;