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 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA AUTO-DESCRIPTION ( | 🧠 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; | ||
// | // 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 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); | |||
).fadeIn( | // 3. LOGIKA LIPAT (Jika teks lebih tinggi dari 85px) | ||
setTimeout(function() { | |||
if ($descBox.height() > 85) { | |||
$triggerCont.show(); | |||
} | } | ||
}, 600); | |||
} | } | ||
}, | } | ||
}); | |||
$descBox. | |||
// 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');
}
});
}
});
})();