MediaWiki:Common.js: Revizyonlar arasındaki fark
Görünüm
k Dış bağlantıları yeni sekmede aç |
İşlem rehberinde seçilen ekran görüntüsünü önizle |
||
| 20. satır: | 20. satır: | ||
var text = (event.target.closest('button') || event.target).textContent || ''; | var text = (event.target.closest('button') || event.target).textContent || ''; | ||
if (text.indexOf('örneği ekle') !== -1 || text.indexOf('örneği kaldır') !== -1 || text.indexOf('Adım ekle') !== -1) { | if (text.indexOf('örneği ekle') !== -1 || text.indexOf('örneği kaldır') !== -1 || text.indexOf('Adım ekle') !== -1) { | ||
window.setTimeout(renumberSteps, 250); | window.setTimeout(function () { | ||
renumberSteps(); | |||
bindImagePreviews(); | |||
}, 250); | |||
} | } | ||
}, true); | }, true); | ||
| 29. satır: | 32. satır: | ||
} | } | ||
window.setTimeout(renumberSteps, 50); | window.setTimeout(renumberSteps, 50); | ||
/* Ekran görüntüsü alanında mevcut dosyayı seçince küçük önizleme göster. */ | |||
function previewBox(select) { | |||
var span = select.closest('.comboboxSpan') || select.parentNode; | |||
var box = span.querySelector('.islem-image-preview'); | |||
if (!box) { | |||
box = document.createElement('div'); | |||
box.className = 'islem-image-preview'; | |||
box.style.cssText = 'margin-top:8px;min-height:20px;'; | |||
span.appendChild(box); | |||
} | |||
return box; | |||
} | |||
function showExistingPreview(select) { | |||
var value = (select.value || '').replace(/^File:/i, ''); | |||
var box = previewBox(select); | |||
box.textContent = ''; | |||
if (!value) return; | |||
var loading = document.createElement('span'); | |||
loading.textContent = 'Önizleme yükleniyor...'; | |||
loading.style.color = '#54595d'; | |||
box.appendChild(loading); | |||
new mw.Api().get({ | |||
action: 'query', | |||
titles: 'File:' + value, | |||
prop: 'imageinfo', | |||
iiprop: 'url', | |||
iiurlwidth: 500, | |||
format: 'json' | |||
}).done(function (data) { | |||
var pages = data.query && data.query.pages; | |||
var page = pages && pages[Object.keys(pages)[0]]; | |||
var info = page && page.imageinfo && page.imageinfo[0]; | |||
box.textContent = ''; | |||
if (!info || !info.thumburl && !info.url) { | |||
box.textContent = 'Bu dosya için önizleme bulunamadı.'; | |||
return; | |||
} | |||
var image = document.createElement('img'); | |||
image.src = info.thumburl || info.url; | |||
image.alt = value; | |||
image.style.cssText = 'display:block;max-width:500px;max-height:280px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;'; | |||
box.appendChild(image); | |||
}).fail(function () { | |||
box.textContent = 'Önizleme yüklenemedi.'; | |||
}); | |||
} | |||
function showLocalPreview(input) { | |||
var select = input.closest('.comboboxSpan') && input.closest('.comboboxSpan').querySelector('select'); | |||
if (!select || !input.files || !input.files[0]) return; | |||
var box = previewBox(select); | |||
box.textContent = ''; | |||
var image = document.createElement('img'); | |||
image.src = URL.createObjectURL(input.files[0]); | |||
image.alt = input.files[0].name; | |||
image.style.cssText = 'display:block;max-width:500px;max-height:280px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;'; | |||
box.appendChild(image); | |||
} | |||
function bindImagePreviews() { | |||
document.querySelectorAll('select.pfComboBox[autocompletesettings="File"]').forEach(function (select) { | |||
if (select.dataset.previewBound) return; | |||
select.dataset.previewBound = '1'; | |||
select.addEventListener('change', function () { showExistingPreview(select); }); | |||
if (select.value) showExistingPreview(select); | |||
}); | |||
document.querySelectorAll('input[type="file"]').forEach(function (input) { | |||
if (input.dataset.previewBound) return; | |||
input.dataset.previewBound = '1'; | |||
input.addEventListener('change', function () { showLocalPreview(input); }); | |||
}); | |||
} | |||
bindImagePreviews(); | |||
if (window.MutationObserver) { | |||
new MutationObserver(bindImagePreviews).observe(document.body, { childList: true, subtree: true }); | |||
} | |||
}()); | }()); | ||
10.37, 28 Ağustos 2026 tarihindeki hâli
/* İşlem Rehberi PageForms: adım numaralarını otomatik sırala. */
(function () {
var isProcedureForm = mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit' &&
(mw.config.get('wgTitle') || '').indexOf('İşlem Rehberi') !== -1;
if (!isProcedureForm) {
return;
}
function renumberSteps() {
var fields = Array.prototype.filter.call(document.querySelectorAll('input'), function (field) {
return field.name.indexOf('İşlem Adımı[') === 0 && field.name.slice(-4) === '[no]';
});
fields.forEach(function (field, index) {
field.value = String(index + 1);
field.setAttribute('value', String(index + 1));
});
}
document.addEventListener('click', function (event) {
var text = (event.target.closest('button') || event.target).textContent || '';
if (text.indexOf('örneği ekle') !== -1 || text.indexOf('örneği kaldır') !== -1 || text.indexOf('Adım ekle') !== -1) {
window.setTimeout(function () {
renumberSteps();
bindImagePreviews();
}, 250);
}
}, true);
var form = document.querySelector('form');
if (form) {
form.addEventListener('submit', renumberSteps, true);
}
window.setTimeout(renumberSteps, 50);
/* Ekran görüntüsü alanında mevcut dosyayı seçince küçük önizleme göster. */
function previewBox(select) {
var span = select.closest('.comboboxSpan') || select.parentNode;
var box = span.querySelector('.islem-image-preview');
if (!box) {
box = document.createElement('div');
box.className = 'islem-image-preview';
box.style.cssText = 'margin-top:8px;min-height:20px;';
span.appendChild(box);
}
return box;
}
function showExistingPreview(select) {
var value = (select.value || '').replace(/^File:/i, '');
var box = previewBox(select);
box.textContent = '';
if (!value) return;
var loading = document.createElement('span');
loading.textContent = 'Önizleme yükleniyor...';
loading.style.color = '#54595d';
box.appendChild(loading);
new mw.Api().get({
action: 'query',
titles: 'File:' + value,
prop: 'imageinfo',
iiprop: 'url',
iiurlwidth: 500,
format: 'json'
}).done(function (data) {
var pages = data.query && data.query.pages;
var page = pages && pages[Object.keys(pages)[0]];
var info = page && page.imageinfo && page.imageinfo[0];
box.textContent = '';
if (!info || !info.thumburl && !info.url) {
box.textContent = 'Bu dosya için önizleme bulunamadı.';
return;
}
var image = document.createElement('img');
image.src = info.thumburl || info.url;
image.alt = value;
image.style.cssText = 'display:block;max-width:500px;max-height:280px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;';
box.appendChild(image);
}).fail(function () {
box.textContent = 'Önizleme yüklenemedi.';
});
}
function showLocalPreview(input) {
var select = input.closest('.comboboxSpan') && input.closest('.comboboxSpan').querySelector('select');
if (!select || !input.files || !input.files[0]) return;
var box = previewBox(select);
box.textContent = '';
var image = document.createElement('img');
image.src = URL.createObjectURL(input.files[0]);
image.alt = input.files[0].name;
image.style.cssText = 'display:block;max-width:500px;max-height:280px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;';
box.appendChild(image);
}
function bindImagePreviews() {
document.querySelectorAll('select.pfComboBox[autocompletesettings="File"]').forEach(function (select) {
if (select.dataset.previewBound) return;
select.dataset.previewBound = '1';
select.addEventListener('change', function () { showExistingPreview(select); });
if (select.value) showExistingPreview(select);
});
document.querySelectorAll('input[type="file"]').forEach(function (input) {
if (input.dataset.previewBound) return;
input.dataset.previewBound = '1';
input.addEventListener('change', function () { showLocalPreview(input); });
});
}
bindImagePreviews();
if (window.MutationObserver) {
new MutationObserver(bindImagePreviews).observe(document.body, { childList: true, subtree: true });
}
}());
/* Dış bağlantıları güvenli biçimde yeni sekmede aç. İç wiki bağlantılarına dokunma. */
(function () {
function openExternalLinksInNewTab() {
document.querySelectorAll('a.external, a.extiw').forEach(function (link) {
if (link.hostname && link.hostname !== window.location.hostname) {
link.target = '_blank';
link.rel = 'noopener noreferrer';
}
});
}
mw.hook('wikipage.content').add(openExternalLinksInNewTab);
document.addEventListener('DOMContentLoaded', openExternalLinksInNewTab);
}());