MediaWiki:Common.js: Perbedaan antara revisi
Tidak ada ringkasan suntingan Tanda: Dikembalikan Suntingan perangkat seluler Suntingan peramban seluler |
Tidak ada ringkasan suntingan Tanda: Pengembalian manual Suntingan perangkat seluler Suntingan peramban seluler |
||
| Baris 1: | Baris 1: | ||
/* ========================================================== | /* ========================================================== | ||
🧠 MIPPEDIA DATA | 🧠 MIPPEDIA DATA SMART-FALLBACK + AUTO-TRANSLATE + ORIGINAL TEXT | ||
Priority: ID -> EN (Translate + Toggle) -> CONCISE | |||
========================================================== */ | ========================================================== */ | ||
(function() { | (function() { | ||
| Baris 6: | Baris 7: | ||
var $descSection = $('#mip-desc-section'); | var $descSection = $('#mip-desc-section'); | ||
var $descBox = $('#mip-auto-description'); | var $descBox = $('#mip-auto-description'); | ||
if (!$descBox.length) return; | if (!$descBox.length) return; | ||
| Baris 18: | Baris 16: | ||
{ id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' } | { id: 'concise', name: 'Mippedia bahasa Indonesia ringkas', url: 'https://concise.mippedia.org/api.php', base: 'https://concise.mippedia.org/wiki/' } | ||
]; | ]; | ||
function cleanExtract(text) { | function cleanExtract(text) { | ||
| Baris 34: | Baris 23: | ||
function translateText(text, callback) { | function translateText(text, callback) { | ||
var translateUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(text); | var translateUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=id&dt=t&q=" + encodeURIComponent(text); | ||
$.ajax({ url: translateUrl, success: function(res) { | $.ajax({ | ||
url: translateUrl, | |||
success: function(res) { | |||
var translated = ""; | |||
res[0].forEach(function(segment) { | |||
if (segment[0]) translated += segment[0]; | |||
}); | |||
callback(translated); | |||
}, | |||
error: function() { callback(text); } | |||
}); | |||
} | } | ||
function fetchDescription(index) { | function fetchDescription(index) { | ||
if (index >= projects.length) { $descSection.hide(); return; } | if (index >= projects.length) { | ||
$descSection.hide(); | |||
return; | |||
} | |||
var p = projects[index]; | var p = projects[index]; | ||
| Baris 61: | Baris 59: | ||
var sourceLink = p.base + encodeURIComponent(pageTitle); | var sourceLink = p.base + encodeURIComponent(pageTitle); | ||
// LOGIKA KHUSUS EN (DENGAN VERSI ASLI) | |||
if (p.id === 'en') { | |||
translateText(extract, function(translated) { | |||
var formattedContent = | |||
'<div id="mip-text-content" style="margin-bottom: 12px;">' + translated + '</div>' + | |||
'<div style="font-size: 0.9em; color: #777;">' + | |||
'Sumber Dari : <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>' + | |||
'<br><span style="font-size: 0.85em; font-style: italic;">(Diterjemahkan secara otomatis dari bahasa Inggris)</span> ' + | |||
'<span id="mip-toggle-orig" style="color: #6a5acd; cursor: pointer; font-size: 0.9em; text-decoration: underline; margin-left: 5px;">Tampilkan versi asli</span>' + | |||
'</div>'; | |||
$descBox.hide().html(formattedContent).fadeIn(400); | |||
// Event Klik Switch Text | |||
$(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | $(document).off('click', '#mip-toggle-orig').on('click', '#mip-toggle-orig', function() { | ||
var $content = $('#mip-text-content'); | var $content = $('#mip-text-content'); | ||
if ($(this).text() === 'Tampilkan versi asli') { $content.text(extract); $(this).text('Tampilkan terjemahan'); | if ($(this).text() === 'Tampilkan versi asli') { | ||
else { $content.text( | $content.text(extract); | ||
$(this).text('Tampilkan terjemahan'); | |||
} else { | |||
$content.text(translated); | |||
$(this).text('Tampilkan versi asli'); | |||
} | |||
}); | }); | ||
}); | }); | ||
} else { | } else { | ||
// NORMAL UNTUK ID & CONCISE | |||
var formattedContent = | |||
'<div style="margin-bottom: 12px;">' + extract + '</div>' + | |||
'<div style="font-size: 0.9em; color: #777;">' + | |||
'Sumber Dari : <a href="' + sourceLink + '" target="_blank" style="color: #6a5acd; font-weight: bold; text-decoration: none;">' + p.name + '.</a>' + | |||
'</div>'; | |||
$descBox.hide().html(formattedContent).fadeIn(400); | |||
} | |||
return; | return; | ||
} | } | ||
} | } | ||
fetchDescription(index + 1); | fetchDescription(index + 1); | ||
} | }, | ||
error: function() { fetchDescription(index + 1); } | |||
}); | }); | ||
} | } | ||
| Baris 99: | Baris 104: | ||
fetchDescription(0); | fetchDescription(0); | ||
if ($('#mip-shimmer-style').length === 0) { | if ($('#mip-shimmer-style').length === 0) { | ||
$('<style id="mip-shimmer-style">').text(` | $('<style id="mip-shimmer-style">').text(` | ||