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 (PRO EDITION)
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (ULTIMATUM EDITION)
  - Clean Template: Hapus {{Lahir}}, {{Lang}}, dll
  - Smart Spacing: Perbaikan spasi berantakan
  - Accordion: Fitur Tampilkan/Lipat dengan animasi
   ========================================================== */
   ========================================================== */
(function() {
(function() {
Baris 14: Baris 11:
         if ($descBox.length) {
         if ($descBox.length) {
             var pageTitle = mw.config.get('wgPageName');
             var pageTitle = mw.config.get('wgPageName');
             var apiUrl = 'https://id.mippedia.org/api.php';
             var apiUrl = 'https://id.mippedia.org/w/api.php';


             $.ajax({
             $.ajax({
Baris 35: Baris 32:
                         var extract = pages[pageId].extract;
                         var extract = pages[pageId].extract;


                         // 1. BERSIHKAN TEMPLATE & SPASI (REGEX SAKTI)
                         // 1. PEMBERSIHAN TOTAL
                        // Hapus konten di dalam kurung kurawal {{...}}
                         extract = extract.replace(/\{\{[^}]+\}\}/g, ''); // Hapus {{Template}}
                         extract = extract.replace(/\{\{[^}]+\}\}/g, '');
                         extract = extract.replace(/\(\s*\)/g, '');      // Hapus kurung kosong ( ) sisa template
                         // Hapus spasi ganda atau renggang yang gak jelas
                         extract = extract.replace(/\s\s+/g, ' ');      // Benerin spasi renggang
                         extract = extract.replace(/\s\s+/g, ' ').trim();
                        extract = extract.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>';
                         var fullContent = extract + ' <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">Dari Mippedia ↗️</a>';


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


                         // 3. LOGIKA LIPAT (Jika teks lebih tinggi dari 85px)
                         // 3. CEK TINGGI (Dikasih delay biar render beres dulu)
                         setTimeout(function() {
                         setTimeout(function() {
                             if ($descBox.height() > 85) {
                             var actualHeight = $descBox[0].scrollHeight;
                            if (actualHeight > 95) {
                                 $triggerCont.show();
                                 $triggerCont.show();
                             }
                             }
                         }, 600);
                         }, 800);
                     }
                     }
                 }
                 }
             });
             });


             // 4. EVENT CLICK (Tampilkan / Sembunyikan)
             // 4. EVENT KLIK SMOOTH
             $triggerBtn.on('click', function() {
             $triggerBtn.on('click', function() {
                 if ($wrapper.css('max-height') === '85px') {
                var actualHeight = $descBox[0].scrollHeight;
                     $wrapper.css('max-height', $descBox.height() + 50 + 'px');
                 if ($wrapper.css('max-height') === '95px') {
                     $(this).text('- Lipat Deskripsi');
                     $wrapper.css('max-height', (actualHeight + 40) + 'px');
                     $(this).text('- Lipat Deskripsi').css('background', '#6a5acd').css('color', '#fff');
                 } else {
                 } else {
                     $wrapper.css('max-height', '85px');
                     $wrapper.css('max-height', '95px');
                     $(this).text('+ Tampilkan Selengkapnya');
                     $(this).text('+ Tampilkan Selengkapnya').css('background', '#f1f0ff').css('color', '#6a5acd');
                 }
                 }
             });
             });

Revisi per 14 April 2026 21.55

/* ==========================================================
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (ULTIMATUM EDITION)
   ========================================================== */
(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/w/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. PEMBERSIHAN TOTAL
                        extract = extract.replace(/\{\{[^}]+\}\}/g, ''); // Hapus {{Template}}
                        extract = extract.replace(/\(\s*\)/g, '');      // Hapus kurung kosong ( ) sisa template
                        extract = extract.replace(/\s\s+/g, ' ');       // Benerin spasi renggang
                        extract = extract.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
                        $descBox.html(fullContent);

                        // 3. CEK TINGGI (Dikasih delay biar render beres dulu)
                        setTimeout(function() {
                            var actualHeight = $descBox[0].scrollHeight;
                            if (actualHeight > 95) {
                                $triggerCont.show();
                            }
                        }, 800);
                    }
                }
            });

            // 4. EVENT KLIK SMOOTH
            $triggerBtn.on('click', function() {
                var actualHeight = $descBox[0].scrollHeight;
                if ($wrapper.css('max-height') === '95px') {
                    $wrapper.css('max-height', (actualHeight + 40) + 'px');
                    $(this).text('- Lipat Deskripsi').css('background', '#6a5acd').css('color', '#fff');
                } else {
                    $wrapper.css('max-height', '95px');
                    $(this).text('+ Tampilkan Selengkapnya').css('background', '#f1f0ff').css('color', '#6a5acd');
                }
            });
        }
    });
})();