مدیاویکی:Gadget-TranslationAssistant.js: تفاوت میان نسخهها
ظاهر
imported>Ebrahim بدون خلاصۀ ویرایش |
imported>Ebrahim بدون خلاصۀ ویرایش |
||
| خط ۵: | خط ۵: | ||
return; // only for edit mode for now | return; // only for edit mode for now | ||
} | } | ||
function getTitle(page, source) { | function getTitle(page, source) { | ||
| خط ۳۵: | خط ۲۴: | ||
'p-tb', | 'p-tb', | ||
'#', | '#', | ||
'کمک ترجمه', | |||
't-translationhelper' | 't-translationhelper' | ||
)); | )); | ||
$('a', link).click(function () { | $('a', link).click(function () { | ||
$('#translationhelper-helperpage').remove(); | |||
var source = $('#translationhelper-source-langcode').text(); | var source = $('#translationhelper-source-langcode').text(); | ||
getTitle(mw.config.get('wgPageName'), source).then(function (title) { | getTitle(mw.config.get('wgPageName'), source).then(function (title) { | ||
| خط ۶۰: | خط ۵۰: | ||
}); | }); | ||
var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', disabled: 'disabled' }); | var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', disabled: 'disabled' }); | ||
var helperPage = $('<div>').append( | var helperPage = $('<div>', { id: 'translationhelper-helperpage' }).append( | ||
$('<label>').append($('<input>', { type: 'checkbox' }).change(function () { | $('<label>').append($('<input>', { type: 'checkbox' }).change(function () { | ||
if (this.checked) { | if (this.checked) { | ||
enWikiFrame.hide(); | enWikiFrame.hide(); | ||
enWikiSource.show().val( | enWikiSource.show().val('صبر کنید…'); | ||
$.Deferred().resolve().then(function (result) { | $.Deferred().resolve().then(function (result) { | ||
return window.tofawikipassenwikisource | return window.tofawikipassenwikisource | ||
| خط ۷۸: | خط ۶۸: | ||
enWikiSource.hide(); | enWikiSource.hide(); | ||
} | } | ||
}), ' ' | }), ' نمایش ویکیکد'), '<br>', enWikiFrame, enWikiSource | ||
); | ); | ||
if (mw.config.get('tofawiki.sidebyside', true) === true) { | if (mw.config.get('tofawiki.sidebyside', true) === true) { | ||
نسخهٔ ۲۷ ژوئن ۲۰۱۸، ساعت ۰۹:۱۰
$(function () {
'use strict';
if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) === -1) {
return; // only for edit mode for now
}
function getTitle(page, source) {
return $.post('//tools.wmflabs.org/linkstranslator/', {
from: mw.config.get('wgDBname'),
to: source + 'wiki',
p: page
}).then(function (result) {
return Object.keys(result).map(function (x) { return result[x]; })[0];
});
}
var enName = new mw.Uri().query.enName;
if (new mw.Uri().query.enName !== undefined) {
run(enName);
} else {
var link = $(mw.util.addPortletLink(
'p-tb',
'#',
'کمک ترجمه',
't-translationhelper'
));
$('a', link).click(function () {
$('#translationhelper-helperpage').remove();
var source = $('#translationhelper-source-langcode').text();
getTitle(mw.config.get('wgPageName'), source).then(function (title) {
run(title, source);
});
}).css('font-weight', 'bold');
link.append(' ', $('<span contenteditable id="translationhelper-source-langcode">en</span>').keypress(function (e) {
if (e.which !== 13) return;
$(this).blur();
e.preventDefault();
}).click(function () {
document.execCommand('selectAll', false, null);
}));
}
function run(page, source) {
var enWikiFrame = $('<iframe>', {
src: 'https://' + source + '.wikipedia.org' + mw.util.getUrl(page) + '#tofawikiframe',
style: 'width: 100%; height: 100%;'
});
var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', disabled: 'disabled' });
var helperPage = $('<div>', { id: 'translationhelper-helperpage' }).append(
$('<label>').append($('<input>', { type: 'checkbox' }).change(function () {
if (this.checked) {
enWikiFrame.hide();
enWikiSource.show().val('صبر کنید…');
$.Deferred().resolve().then(function (result) {
return window.tofawikipassenwikisource
? window.tofawikipassenwikisource
: getRawPage(page, source).then(function (result) {
return window.tofawikipassenwikisource = result;
});
}).then(function (result) {
enWikiSource.val(result);
});
} else {
enWikiFrame.show();
enWikiSource.hide();
}
}), ' نمایش ویکیکد'), '<br>', enWikiFrame, enWikiSource
);
if (mw.config.get('tofawiki.sidebyside', true) === true) {
$('.wikiEditor-ui .wikiEditor-ui-view').css('width', '50%');
helperPage.attr('style', 'width: 50%; height: 500px; top: 0px; left: 0px; position: absolute;');
helperPage.insertAfter('.wikiEditor-ui .wikiEditor-ui-view');
} else {
helperPage.attr('style', 'width: 100%; height: 400px;');
helperPage.insertAfter('#wpTextbox1');
}
}
function getRawPage(page, source) {
return new mw.Api({ ajax: { url: '//' + source + '.wikipedia.org/w/api.php' } }).get({
action: 'query',
prop: 'revisions',
titles: page,
rvprop: 'content',
format: 'json',
origin: window.location.protocol + '//' + window.location.hostname
}).then(function (data) {
return data.query.pages && !data.query.pages[-1]
? Object.keys(data.query.pages).map(function (x) { return data.query.pages[x]; })[0].revisions[0]['*']
: '';
});
}
});