Lompat ke isi

MediaWiki:Common.js: Perbedaan antara revisi

Dari Mippedia Data
Tidak ada ringkasan suntingan
Tanda: Suntingan perangkat seluler Suntingan peramban seluler
Tidak ada ringkasan suntingan
Tanda: Suntingan perangkat seluler Suntingan peramban seluler
Baris 1: Baris 1:
/* ==========================================================
/* ==========================================================
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (CLEAN UI EDITION)
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (PRO EDITION)
  - Clean Template: Hapus {{Lahir}}, {{Lang}}, dll
  - Smart Spacing: Perbaikan spasi berantakan
  - Accordion: Fitur Tampilkan/Lipat dengan animasi
   ========================================================== */
   ========================================================== */
(function() {
(function() {
     $(document).ready(function() {
     $(document).ready(function() {
         var $descBox = $('#mip-auto-description');
         var $descBox = $('#mip-auto-description');
        var $wrapper = $('#mip-desc-wrapper');
        var $triggerCont = $('#mip-trigger-container');
        var $triggerBtn = $('#mip-desc-trigger');
          
          
         if ($descBox.length) {
         if ($descBox.length) {
Baris 28: Baris 34:
                     if (pageId != "-1") {
                     if (pageId != "-1") {
                         var extract = pages[pageId].extract;
                         var extract = pages[pageId].extract;
                          
 
                         // Potong teks jika terlalu panjang agar tetap rapi
                         // 1. BERSIHKAN TEMPLATE & SPASI (REGEX SAKTI)
                         if (extract.length > 450) {
                         // Hapus konten di dalam kurung kurawal {{...}}
                            extract = extract.substring(0, 450) + '...';
                         extract = extract.replace(/\{\{[^}]+\}\}/g, '');
                        }
                        // Hapus spasi ganda atau renggang yang gak jelas
                        extract = extract.replace(/\s\s+/g, ' ').trim();


                         var sourceLink = 'https://id.mippedia.org/wiki/' + encodeURIComponent(pageTitle);
                         var sourceLink = 'https://id.mippedia.org/wiki/' + encodeURIComponent(pageTitle);
                          
                         var fullContent = extract + ' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari Mippedia ↗️</a>';
                        // Output dengan styling yang bersih
 
                        $descBox.hide().html(
                        // 2. TAMPILKAN DATA
                            extract +  
                         $descBox.hide().html(fullContent).fadeIn(500);
                            ' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none; border-bottom: 1px solid transparent; transition: 0.2s;">Dari Mippedia.</a>'
 
                         ).fadeIn(400); // Kasih efek halus pas muncul
                        // 3. LOGIKA LIPAT (Jika teks lebih tinggi dari 85px)
                    } else {
                        setTimeout(function() {
                        if ($descBox.text().includes('Mengambil')) {
                            if ($descBox.height() > 85) {
                            $descBox.html('<span style="color:#888; font-size: 0.9em;">(Deskripsi belum tersedia di Mippedia utama)</span>');
                                $triggerCont.show();
                         }
                            }
                         }, 600);
                     }
                     }
                 },
                 }
                 error: function() {
            });
                     $descBox.html('<span style="color:#e74c3c;">Gagal memuat deskripsi.</span>');
 
            // 4. EVENT CLICK (Tampilkan / Sembunyikan)
            $triggerBtn.on('click', function() {
                 if ($wrapper.css('max-height') === '85px') {
                     $wrapper.css('max-height', $descBox.height() + 50 + 'px');
                    $(this).text('- Lipat Deskripsi');
                } else {
                    $wrapper.css('max-height', '85px');
                    $(this).text('+ Tampilkan Selengkapnya');
                 }
                 }
             });
             });

Revisi per 14 April 2026 21.50

/* ==========================================================
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (PRO EDITION)
   - Clean Template: Hapus {{Lahir}}, {{Lang}}, dll
   - Smart Spacing: Perbaikan spasi berantakan
   - Accordion: Fitur Tampilkan/Lipat dengan animasi
   ========================================================== */
(function() {
    $(document).ready(function() {
        var $descBox = $('#mip-auto-description');
        var $wrapper = $('#mip-desc-wrapper');
        var $triggerCont = $('#mip-trigger-container');
        var $triggerBtn = $('#mip-desc-trigger');
        
        if ($descBox.length) {
            var pageTitle = mw.config.get('wgPageName');
            var apiUrl = 'https://id.mippedia.org/api.php';

            $.ajax({
                url: apiUrl,
                data: {
                    action: 'query',
                    prop: 'extracts',
                    exintro: true,
                    explaintext: true,
                    titles: pageTitle,
                    format: 'json',
                    origin: '*'
                },
                dataType: 'json',
                success: function(data) {
                    var pages = data.query.pages;
                    var pageId = Object.keys(pages)[0];
                    
                    if (pageId != "-1") {
                        var extract = pages[pageId].extract;

                        // 1. BERSIHKAN TEMPLATE & SPASI (REGEX SAKTI)
                        // Hapus konten di dalam kurung kurawal {{...}}
                        extract = extract.replace(/\{\{[^}]+\}\}/g, '');
                        // Hapus spasi ganda atau renggang yang gak jelas
                        extract = extract.replace(/\s\s+/g, ' ').trim();

                        var sourceLink = 'https://id.mippedia.org/wiki/' + encodeURIComponent(pageTitle);
                        var fullContent = extract + ' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari Mippedia ↗️</a>';

                        // 2. TAMPILKAN DATA
                        $descBox.hide().html(fullContent).fadeIn(500);

                        // 3. LOGIKA LIPAT (Jika teks lebih tinggi dari 85px)
                        setTimeout(function() {
                            if ($descBox.height() > 85) {
                                $triggerCont.show();
                            }
                        }, 600);
                    }
                }
            });

            // 4. EVENT CLICK (Tampilkan / Sembunyikan)
            $triggerBtn.on('click', function() {
                if ($wrapper.css('max-height') === '85px') {
                    $wrapper.css('max-height', $descBox.height() + 50 + 'px');
                    $(this).text('- Lipat Deskripsi');
                } else {
                    $wrapper.css('max-height', '85px');
                    $(this).text('+ Tampilkan Selengkapnya');
                }
            });
        }
    });
})();