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 (ULTIMATUM EDITION)
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (GOOGLE STYLE)
   ========================================================== */
   ========================================================== */
(function() {
(function() {
     $(document).ready(function() {
     $(document).ready(function() {
         var $descBox = $('#mip-auto-description');
         var $descBox = $('#mip-auto-description');
         var $wrapper = $('#mip-desc-wrapper');
         var $triggerWrap = $('#mip-trigger-wrapper');
        var $triggerCont = $('#mip-trigger-container');
         var $triggerBtn = $('#mip-desc-trigger');
         var $triggerBtn = $('#mip-desc-trigger');
        var $sourcePre = $('#mip-source-pre');
          
          
         if ($descBox.length) {
         if ($descBox.length) {
             var pageTitle = mw.config.get('wgPageName');
             var pageTitle = mw.config.get('wgPageName');
             var apiUrl = 'https://id.mippedia.org/w/api.php';
             var apiUrl = 'https://id.mippedia.org/api.php';


             $.ajax({
             $.ajax({
                 url: apiUrl,
                 url: apiUrl,
                 data: {
                 data: {
                     action: 'query',
                     action: 'query', prop: 'extracts', exintro: true, explaintext: true,
                    prop: 'extracts',
                     titles: pageTitle, format: 'json', origin: '*'
                    exintro: true,
                    explaintext: true,
                     titles: pageTitle,
                    format: 'json',
                    origin: '*'
                 },
                 },
                 dataType: 'json',
                 dataType: 'json',
Baris 32: Baris 27:
                         var extract = pages[pageId].extract;
                         var extract = pages[pageId].extract;


                         // 1. PEMBERSIHAN TOTAL
                         // PEMBERSIHAN TEMPLATE & KURUNG KOSONG
                         extract = extract.replace(/\{\{[^}]+\}\}/g, ''); // Hapus {{Template}}
                         extract = extract.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim();
                        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 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 fullText = extract;
                        var shortText = extract.substring(0, 180); // Potongan awal gaya Google


                         // 2. TAMPILKAN
                         if (extract.length > 180) {
                         $descBox.html(fullContent);
                            $descBox.attr('data-full', fullText).attr('data-short', shortText + '...');
                            $descBox.text(shortText + '...');
                            $triggerWrap.show();
                         } else {
                            $descBox.html(fullText + ' <a href="' + sourceLink + '" target="_blank" style="color: #1a0dab; text-decoration: none;">Dari Mippedia</a>');
                        }


                         // 3. CEK TINGGI (Dikasih delay biar render beres dulu)
                         // EVENT CLICK GAYA GOOGLE
                         setTimeout(function() {
                         $triggerBtn.on('click', function() {
                             var actualHeight = $descBox[0].scrollHeight;
                             if ($(this).text() === 'Tampilkan') {
                             if (actualHeight > 95) {
                                // Mode Expand
                                 $triggerCont.show();
                                $descBox.html(fullText + ' <a href="' + sourceLink + '" target="_blank" style="color: #1a0dab; text-decoration: none;">Dari Mippedia</a>');
                                $(this).text('Sembunyikan');
                                $sourcePre.hide(); // Ilangin "- Mippedia" karena udah ada "Dari Mippedia"
                             } else {
                                // Mode Collapse
                                $descBox.text($descBox.attr('data-short'));
                                $(this).text('Tampilkan');
                                 $sourcePre.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');
                 }
                 }
             });
             });

Revisi per 14 April 2026 22.02

/* ==========================================================
   🧠 MIPPEDIA DATA AUTO-DESCRIPTION (GOOGLE STYLE)
   ========================================================== */
(function() {
    $(document).ready(function() {
        var $descBox = $('#mip-auto-description');
        var $triggerWrap = $('#mip-trigger-wrapper');
        var $triggerBtn = $('#mip-desc-trigger');
        var $sourcePre = $('#mip-source-pre');
        
        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;

                        // PEMBERSIHAN TEMPLATE & KURUNG KOSONG
                        extract = extract.replace(/\{\{[^}]+\}\}/g, '').replace(/\(\s*\)/g, '').replace(/\s\s+/g, ' ').trim();

                        var sourceLink = 'https://id.mippedia.org/wiki/' + encodeURIComponent(pageTitle);
                        var fullText = extract;
                        var shortText = extract.substring(0, 180); // Potongan awal gaya Google

                        if (extract.length > 180) {
                            $descBox.attr('data-full', fullText).attr('data-short', shortText + '...');
                            $descBox.text(shortText + '...');
                            $triggerWrap.show();
                        } else {
                            $descBox.html(fullText + ' <a href="' + sourceLink + '" target="_blank" style="color: #1a0dab; text-decoration: none;">Dari Mippedia</a>');
                        }

                        // EVENT CLICK GAYA GOOGLE
                        $triggerBtn.on('click', function() {
                            if ($(this).text() === 'Tampilkan') {
                                // Mode Expand
                                $descBox.html(fullText + ' <a href="' + sourceLink + '" target="_blank" style="color: #1a0dab; text-decoration: none;">Dari Mippedia</a>');
                                $(this).text('Sembunyikan');
                                $sourcePre.hide(); // Ilangin "- Mippedia" karena udah ada "Dari Mippedia"
                            } else {
                                // Mode Collapse
                                $descBox.text($descBox.attr('data-short'));
                                $(this).text('Tampilkan');
                                $sourcePre.show();
                            }
                        });
                    }
                }
            });
        }
    });
})();