MediaWiki:Common.js: Perbedaan antara revisi
Tidak ada ringkasan suntingan Tanda: Pengembalian manual Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA - SMART CONTEXT + AUTO THUMBNAIL ( | 🧠 MIPPEDIA DATA - SMART CONTEXT + AUTO THUMBNAIL (V3) | ||
Features: Priority Check (ID > EN > CONCISE), Auto-Age, | Features: Priority Check (ID > EN > CONCISE), Auto-Age, | ||
Auto-Bold, Smart Links, Dynamic Context | Auto-Bold, Smart Links, Dynamic Context, | ||
Auto-Hide Empty State Engine (Real-Time Switch) | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 49: | Baris 50: | ||
} | } | ||
// --- | // --- SMART LINKS PORTAL BERBASIS INTERWIKI VALID --- | ||
function buildSmartLinks(currentId, validatedEnTitle) { | function buildSmartLinks(currentId, validatedEnTitle) { | ||
$portalLinks.empty(); | $portalLinks.empty(); | ||
| Baris 55: | Baris 56: | ||
var checkRequests = projects.filter(p => p.id !== currentId).map(function(p) { | var checkRequests = projects.filter(p => p.id !== currentId).map(function(p) { | ||
var targetTitle = (p.id === 'en' && validatedEnTitle) ? validatedEnTitle : pageTitle; | var targetTitle = (p.id === 'en' && validatedEnTitle) ? validatedEnTitle : pageTitle; | ||
if (p.id === 'en' && !validatedEnTitle) return $.Deferred().resolve(); | if (p.id === 'en' && !validatedEnTitle) return $.Deferred().resolve(); | ||
| Baris 72: | Baris 70: | ||
if (validLinks.length > 0) { $portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> ')); $projectPortal.fadeIn(); } | if (validLinks.length > 0) { $portalLinks.html(validLinks.join(' <span style="color:#ccc; margin: 0 5px;">•</span> ')); $projectPortal.fadeIn(); } | ||
}); | }); | ||
} | |||
// --- 🧠 FUNGSI PENGATUR SWITCH STATE (NORMAL VS EMPTY STATE) --- | |||
function toggleMippediaLayout(isEmpty) { | |||
// Kita targetkan elemen Infobox MediaWiki standar (.infobox) beserta seluruh tabel (.wikitable / table) di luar deskripsi utama | |||
var $targetElements = $('.infobox, table, .mip-hide-target'); | |||
var $existingNotice = $('#mip-empty-state-notice'); | |||
if (isEmpty) { | |||
// Sembunyikan infobox dan semua tabel di atas/bawah infobox | |||
$targetElements.hide(); | |||
$descSection.hide(); | |||
// Munculkan pesan peringatan kosong jika belum ada | |||
if (!$existingNotice.length) { | |||
var noticeHtml = | |||
'<div id="mip-empty-state-notice" style="margin: 20px 0; padding: 20px; border-left: 5px solid #d9534f; background-color: #fdf7f7; border-radius: 4px; font-family: sans-serif; line-height: 1.6;">' + | |||
'<h4 style="color: #d9534f; margin-top: 0; margin-bottom: 8px; font-size: 1.15em; font-weight: bold;">⚠️ Item Data Tidak Memiliki Sumber Artikel</h4>' + | |||
'<p style="color: #333; margin: 0 0 10px 0; font-size: 0.95em;">Item data ini saat ini <strong>tidak memiliki artikel rujukan satu pun</strong> di Mippedia Indonesia, Mippedia Inggris, maupun Mippedia Indonesia Ringkas.</p>' + | |||
'<div style="font-size: 0.88em; color: #777; border-top: 1px solid #eed3d3; padding-top: 8px; font-style: italic;">' + | |||
'Informasi: Item data yang tidak terikat dengan artikel ensiklopedia apa pun dalam ekosistem Mippedia akan dihapus secara otomatis oleh pengurus dalam waktu dekat.' + | |||
'</div>' + | |||
'</div>'; | |||
$('#mw-content-text').prepend(noticeHtml); | |||
} | |||
} else { | |||
// Jika normal / sudah ada artikel, pastikan notice hilang dan semua layout kembali normal | |||
if ($existingNotice.length) $existingNotice.remove(); | |||
$targetElements.show(); | |||
$descSection.show(); | |||
} | |||
} | } | ||
// --- SISTEM PRIORITAS (MIPPEDIA ID > EN > CONCISE) --- | // --- SISTEM PRIORITAS (MIPPEDIA ID > EN > CONCISE) --- | ||
var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | var cached = JSON.parse(localStorage.getItem(cacheKey) || "{}"); | ||
var globalEnTitle = cached.enTitle || ""; | var globalEnTitle = cached.enTitle || ""; | ||
function init() { | function init() { | ||
| Baris 89: | Baris 118: | ||
var thumbUrl = (id != "-1" && pg[id].thumbnail) ? pg[id].thumbnail.source : ""; | var thumbUrl = (id != "-1" && pg[id].thumbnail) ? pg[id].thumbnail.source : ""; | ||
if (id != "-1" && pg[id].langlinks && pg[id].langlinks[0]) { | if (id != "-1" && pg[id].langlinks && pg[id].langlinks[0]) { | ||
globalEnTitle = pg[id].langlinks[0]['*']; | globalEnTitle = pg[id].langlinks[0]['*']; | ||
} | } | ||
if (cached.content && cached.ts === latestTS && latestTS !== "0") { | // Jika cache mendeteksi keadaan kosong (isEmpty), kita tetap force run API untuk validasi real-time status barunya | ||
if (cached.content && cached.ts === latestTS && latestTS !== "0" && !cached.isEmpty) { | |||
toggleMippediaLayout(false); | |||
renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); | renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); | ||
} else { | } else { | ||
| Baris 100: | Baris 130: | ||
} | } | ||
}, | }, | ||
error: function() { if (cached.content) renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); } | error: function() { | ||
if (cached.content) { | |||
toggleMippediaLayout(cached.isEmpty || false); | |||
if (!cached.isEmpty) renderAll(cached.p, cached.content, cached.isTrans, cached.orig, cached.img, cached.customUrl, cached.enTitle); | |||
} | |||
} | |||
}); | }); | ||
} | } | ||
// --- | // --- ANTRIAN PRIORITAS DENGAN VALIDASI INTERWIKI DARI ID & CONCISE --- | ||
function fetchPriorityData(index, newTS, img) { | function fetchPriorityData(index, newTS, img) { | ||
if (index >= projects.length) return; | // 🧠 KONDISI JIKA KETIGA SUMBER DI-CHECK DAN SEBELUMNYA GAK ADA ARTIKEL SAMA SEKALI | ||
if (index >= projects.length) { | |||
// Simpan status kosong ke localstorage agar tidak membebani load berikutnya | |||
localStorage.setItem(cacheKey, JSON.stringify({isEmpty: true, ts: newTS, content: ""})); | |||
toggleMippediaLayout(true); | |||
return; | |||
} | |||
var p = projects[index]; | var p = projects[index]; | ||
if (p.id === 'en') { | if (p.id === 'en') { | ||
if (!globalEnTitle) { | if (!globalEnTitle) { | ||
$.ajax({ | $.ajax({ | ||
| Baris 117: | Baris 157: | ||
data: { action: 'query', prop: 'langlinks', lllang: 'en', titles: pageTitle, format: 'json', origin: '*' }, | data: { action: 'query', prop: 'langlinks', lllang: 'en', titles: pageTitle, format: 'json', origin: '*' }, | ||
dataType: 'json', | dataType: 'json', | ||
async: false, | async: false, | ||
success: function(cRes) { | success: function(cRes) { | ||
var cPg = cRes.query.pages, cId = Object.keys(cPg)[0]; | var cPg = cRes.query.pages, cId = Object.keys(cPg)[0]; | ||
| Baris 127: | Baris 167: | ||
} | } | ||
if (globalEnTitle) { | if (globalEnTitle) { | ||
$.ajax({ | $.ajax({ | ||
| Baris 145: | Baris 184: | ||
}); | }); | ||
} else { | } else { | ||
fetchPriorityData(index + 1, newTS, img); | fetchPriorityData(index + 1, newTS, img); | ||
} | } | ||
} else { | } else { | ||
$.ajax({ | $.ajax({ | ||
url: p.url, | url: p.url, | ||
| Baris 162: | Baris 199: | ||
fetchPriorityData(index + 1, newTS, img); | fetchPriorityData(index + 1, newTS, img); | ||
} | } | ||
} | }, | ||
error: function() { fetchPriorityData(index + 1, newTS, img); } | |||
}); | }); | ||
} | } | ||
| Baris 168: | Baris 206: | ||
function finalize(p, c, t, o, ts, img, customUrl, enTitle) { | function finalize(p, c, t, o, ts, img, customUrl, enTitle) { | ||
localStorage.setItem(cacheKey, JSON.stringify({p:p, content:c, isTrans:t, orig:o, ts:ts, img:img, customUrl: customUrl, enTitle: enTitle})); | localStorage.setItem(cacheKey, JSON.stringify({isEmpty: false, p:p, content:c, isTrans:t, orig:o, ts:ts, img:img, customUrl: customUrl, enTitle: enTitle})); | ||
toggleMippediaLayout(false); // Kembalikan layout ke normal | |||
renderAll(p, c, t, o, img, customUrl, enTitle); | renderAll(p, c, t, o, img, customUrl, enTitle); | ||
} | } | ||
| Baris 184: | Baris 223: | ||
$sourceInfo.show().html(footer); | $sourceInfo.show().html(footer); | ||
buildSmartLinks(p.id, enTitle); | buildSmartLinks(p.id, enTitle); | ||