MediaWiki:Common.js: Perbedaan antara revisi
Tampilan
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 153: | Baris 153: | ||
}); | }); | ||
/* | |||
/* 1. Lazy Loading Gambar - Kecepatan Maksimal */ | |||
$(document).ready(function() { | $(document).ready(function() { | ||
if (mw.config.get('wgIsArticle')) { | if (mw.config.get('wgIsArticle')) { | ||
$('img').each(function() { | |||
$(' | var $img = $(this); | ||
var $ | if ($img.attr('src')) { | ||
$ | $img.attr('data-src', $img.attr('src')); | ||
$img.removeAttr('src'); | |||
$img.css('opacity', '0.3'); | |||
} | |||
$ | }); | ||
var | |||
$(window).on('scroll.lazyload', function() { | |||
$ | $('img[data-src]').each(function() { | ||
var $img = $(this); | |||
if ($img.offset().top < $(window).scrollTop() + $(window).height() + 200) { | |||
}, | $img.attr('src', $img.attr('data-src')); | ||
} | $img.removeAttr('data-src'); | ||
$img.animate({opacity: 1}, 500); | |||
} | |||
}); | }); | ||
}); | }); | ||
} | } | ||
}); | |||
/* 2. Floating Share Button (Khusus Mobile) */ | |||
$(document).ready(function() { | |||
if (mw.config.get('wgIsArticle') && mw.config.get('wgNamespaceNumber') === 0) { | |||
var shareHtml = '<div id="floating-share" style="position:fixed; bottom:20px; left:50%; transform:translateX(-50%); z-index:9997; display:flex; gap:10px; background:rgba(255,255,255,0.9); padding:8px 15px; border-radius:30px; box-shadow:0 4px 10px rgba(0,0,0,0.1); backdrop-filter:blur(5px);">' + | |||
'<a href="https://api.whatsapp.com/send?text=' + encodeURIComponent(document.title + ' - ' + window.location.href) + '" target="_blank" style="color:#25D366; font-size:18px;">WA</a>' + | |||
'<div style="width:1px; background:#ddd;"></div>' + | |||
'<a href="https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href) + '" target="_blank" style="color:#1877F2; font-size:18px;">FB</a>' + | |||
'</div>'; | |||
// Muncul kalau sudah scroll dikit | |||
$(window).scroll(function() { | |||
if ($(this).scrollTop() > 500) { $('#floating-share').fadeIn(); } else { $('#floating-share').fadeOut(); } | |||
}); | |||
$('body').append(shareHtml); | |||
} | |||
}); | |||
/* 3. Notifikasi Link Luar */ | |||
$(document).ready(function() { | |||
$('a.external').click(function(e) { | |||
var url = $(this).attr('href'); | |||
if (!confirm('Anda akan meninggalkan Mippedia menuju situs luar:\n' + url + '\n\nLanjutkan?')) { | |||
e.preventDefault(); | |||
} | |||
}); | |||
}); | |||
/* 4. Reading Progress Circle (Indikator Pojok) */ | |||
$(document).ready(function() { | |||
var circleHtml = '<div id="read-circle" style="position:fixed; top:15px; right:15px; width:40px; height:40px; z-index:10002; display:none;">' + | |||
'<svg width="40" height="40"><circle cx="20" cy="20" r="18" fill="none" stroke="#ddd" stroke-width="4" /><circle id="progress-circle" cx="20" cy="20" r="18" fill="none" stroke="#36c" stroke-width="4" stroke-dasharray="113.1" stroke-dashoffset="113.1" transform="rotate(-90 20 20)" /></svg>' + | |||
'</div>'; | |||
$('body').append(circleHtml); | |||
$(window).scroll(function() { | |||
var scrollPercent = ($(window).scrollTop() / ($(document).height() - $(window).height())) * 100; | |||
var offset = 113.1 - (scrollPercent / 100) * 113.1; | |||
$('#progress-circle').css('stroke-dashoffset', offset); | |||
if ($(window).scrollTop() > 100) { $('#read-circle').fadeIn(); } else { $('#read-circle').fadeOut(); } | |||
}); | |||
}); | }); | ||
Revisi per 9 April 2026 20.56
/* Script Estimasi Waktu Baca - Spesialis Mobile (Minerva) & Desktop */
$(document).ready(function() {
// Hanya jalan di halaman artikel asli
if (mw.config.get('wgIsArticle') && mw.config.get('wgAction') === 'view' && mw.config.get('wgNamespaceNumber') === 0) {
function hitungWaktuBaca() {
// Ambil teks dari konten utama
var content = $('#mw-content-text').text();
// Hitung jumlah kata (asumsi rata-rata orang baca 200 kata per menit)
var wordsPerMinute = 200;
var textLength = content.split(/\s+/).length; // Pecah berdasarkan spasi
var readingTime = Math.ceil(textLength / wordsPerMinute);
// Bikin elemen tampilannya
var icon = '🕒'; // Emoji jam biar simpel dan ringan
var label = (readingTime <= 1) ? 'Kurang dari 1 menit' : readingTime + ' menit';
var html = '<div id="reading-time-auto" style="font-size: 0.9em; color: #54595d; margin-bottom: 15px; display: flex; align-items: center; font-family: sans-serif;">';
html += '<span style="margin-right: 5px;">' + icon + '</span>';
html += '<span>Estimasi waktu baca: <b>' + label + '</b></span>';
html += '</div>';
// PENEMPELAN TARGET:
// Di Minerva (HP), judul biasanya ada di .page-heading
// Di Vector (Desktop), judul ada di #firstHeading
if ($('.page-heading').length) {
$('.page-heading').after(html); // Target Mobile
} else if ($('#firstHeading').length) {
$('#firstHeading').after(html); // Target Desktop
}
}
// Jalankan fungsi
hitungWaktuBaca();
}
});
/* Script Tombol Back to Top (Spesial Mobile) */
$(document).ready(function() {
// Bikin tombolnya lewat JS biar gak ribet edit CSS/HTML
var btnHtml = '<div id="backToTop" style="display:none; position:fixed; bottom:80px; right:20px; z-index:9999; background:#36c; color:#fff; width:45px; height:45px; border-radius:50%; text-align:center; line-height:45px; font-size:24px; cursor:pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.3); opacity: 0.8;">↑</div>';
$('body').append(btnHtml);
// Fungsi munculin tombol pas di-scroll
$(window).scroll(function() {
if ($(this).scrollTop() > 300) {
$('#backToTop').fadeIn();
} else {
$('#backToTop').fadeOut();
}
});
// Fungsi pas tombol diklik
$('#backToTop').click(function() {
$('html, body').animate({scrollTop: 0}, 600);
return false;
});
});
/* Smart Glossary Pop-up (Pratinjau Link Ringan) */
$(document).ready(function() {
if (mw.config.get('wgIsArticle') && mw.config.get('wgAction') === 'view') {
var timer;
// Targetkan link di dalam konten artikel saja
$('#mw-content-text a').on('mouseenter touchstart', function(e) {
var $link = $(this);
var title = $link.attr('title');
// Jangan jalan kalau link-nya bukan artikel (misal link luar atau redlink)
if (!title || $link.hasClass('new') || $link.hasClass('external')) return;
timer = setTimeout(function() {
$.getJSON(mw.util.wikiScript('api'), {
action: 'query',
prop: 'extracts',
exintro: true,
exsentences: 2, // Ambil 2 kalimat aja biar singkat
titles: title,
explaintext: true,
format: 'json'
}, function(data) {
var pages = data.query.pages;
var pageId = Object.keys(pages)[0];
var extract = pages[pageId].extract;
if (extract) {
// Hapus pop-up lama kalau ada
$('.wiki-preview').remove();
var preview = $('<div class="wiki-preview" style="position:absolute; background:#fff; color:#202122; border:1px solid #a2a9b1; padding:12px; border-radius:8px; box-shadow:0 4px 12px rgba(0,0,0,0.2); z-index:10001; font-size:13px; max-width:250px; line-height:1.4; opacity:0; transition:opacity 0.3s ease;"></div>');
preview.text(extract);
$('body').append(preview);
// Atur posisi pop-up di deket link
var offset = $link.offset();
preview.css({
top: offset.top + 25,
left: Math.min(offset.left, $(window).width() - 270),
opacity: 1
});
// Hilang kalau klik di mana aja atau setelah 5 detik
setTimeout(function() { $('.wiki-preview').fadeOut(function() { $(this).remove(); }); }, 5000);
}
});
}, 600); // Delay 0.6 detik biar gak ganggu kalau cuma scrolling lewat
}).on('mouseleave', function() {
clearTimeout(timer);
});
$(document).on('mousedown touchstart', function() {
$('.wiki-preview').remove();
});
}
});
/* 1. Auto-Hide Header (Minerva Mobile Optimized) */
$(document).ready(function() {
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('.header-container').outerHeight() || 50;
$(window).scroll(function() {
var st = $(this).scrollTop();
// Cek scroll harus lebih dari delta
if(Math.abs(lastScrollTop - st) <= delta) return;
// Scroll ke bawah & sudah lewat navbar
if (st > lastScrollTop && st > navbarHeight){
// Sembunyiin Header
$('.header-container, .minerva-header').css({
'transform': 'translateY(-100%)',
'transition': 'transform 0.3s ease-in-out'
});
} else {
// Scroll ke atas
if(st + $(window).height() < $(document).height()) {
$('.header-container, .minerva-header').css({
'transform': 'translateY(0)',
'transition': 'transform 0.3s ease-in-out'
});
}
}
lastScrollTop = st;
});
});
/* 1. Lazy Loading Gambar - Kecepatan Maksimal */
$(document).ready(function() {
if (mw.config.get('wgIsArticle')) {
$('img').each(function() {
var $img = $(this);
if ($img.attr('src')) {
$img.attr('data-src', $img.attr('src'));
$img.removeAttr('src');
$img.css('opacity', '0.3');
}
});
$(window).on('scroll.lazyload', function() {
$('img[data-src]').each(function() {
var $img = $(this);
if ($img.offset().top < $(window).scrollTop() + $(window).height() + 200) {
$img.attr('src', $img.attr('data-src'));
$img.removeAttr('data-src');
$img.animate({opacity: 1}, 500);
}
});
});
}
});
/* 2. Floating Share Button (Khusus Mobile) */
$(document).ready(function() {
if (mw.config.get('wgIsArticle') && mw.config.get('wgNamespaceNumber') === 0) {
var shareHtml = '<div id="floating-share" style="position:fixed; bottom:20px; left:50%; transform:translateX(-50%); z-index:9997; display:flex; gap:10px; background:rgba(255,255,255,0.9); padding:8px 15px; border-radius:30px; box-shadow:0 4px 10px rgba(0,0,0,0.1); backdrop-filter:blur(5px);">' +
'<a href="https://api.whatsapp.com/send?text=' + encodeURIComponent(document.title + ' - ' + window.location.href) + '" target="_blank" style="color:#25D366; font-size:18px;">WA</a>' +
'<div style="width:1px; background:#ddd;"></div>' +
'<a href="https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href) + '" target="_blank" style="color:#1877F2; font-size:18px;">FB</a>' +
'</div>';
// Muncul kalau sudah scroll dikit
$(window).scroll(function() {
if ($(this).scrollTop() > 500) { $('#floating-share').fadeIn(); } else { $('#floating-share').fadeOut(); }
});
$('body').append(shareHtml);
}
});
/* 3. Notifikasi Link Luar */
$(document).ready(function() {
$('a.external').click(function(e) {
var url = $(this).attr('href');
if (!confirm('Anda akan meninggalkan Mippedia menuju situs luar:\n' + url + '\n\nLanjutkan?')) {
e.preventDefault();
}
});
});
/* 4. Reading Progress Circle (Indikator Pojok) */
$(document).ready(function() {
var circleHtml = '<div id="read-circle" style="position:fixed; top:15px; right:15px; width:40px; height:40px; z-index:10002; display:none;">' +
'<svg width="40" height="40"><circle cx="20" cy="20" r="18" fill="none" stroke="#ddd" stroke-width="4" /><circle id="progress-circle" cx="20" cy="20" r="18" fill="none" stroke="#36c" stroke-width="4" stroke-dasharray="113.1" stroke-dashoffset="113.1" transform="rotate(-90 20 20)" /></svg>' +
'</div>';
$('body').append(circleHtml);
$(window).scroll(function() {
var scrollPercent = ($(window).scrollTop() / ($(document).height() - $(window).height())) * 100;
var offset = 113.1 - (scrollPercent / 100) * 113.1;
$('#progress-circle').css('stroke-dashoffset', offset);
if ($(window).scrollTop() > 100) { $('#read-circle').fadeIn(); } else { $('#read-circle').fadeOut(); }
});
});