Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #120 #167

Merged
merged 8 commits into from Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions i18n/languages.json
Expand Up @@ -71,6 +71,7 @@
"redirect-summary": "Quick redirect",
"redirect-question-to": "Which page do you want to redirect $1 to?",
"redirect-question-from": "Which page do you want to redirect to $1?",
"redirect-question-fragment": "Which section of this page do you want to redirect to? (optional)",
"redirect-title": "Quick Redirect",
"notify-redirect-success": "Redirect successful.",
"notify-redirect-error": "Some error(s) occurred while creating redirect",
Expand Down Expand Up @@ -1114,6 +1115,7 @@
"redirect-summary": "快速重定向到",
"redirect-question-to": "要将$1重定向到哪个页面?",
"redirect-question-from": "将哪个页面重定向到$1?",
"redirect-question-fragment": "要重定向到页面的哪个章节?(可选)",
"redirect-title": "快速重定向",
"notify-redirect-success": "创建重定向成功!",
"notify-redirect-error": "创建重定向时出现错误。",
Expand Down
18 changes: 17 additions & 1 deletion src/module/quickRedirect.js
Expand Up @@ -38,7 +38,6 @@ var quickRedirect = function (type = 'to') {
'<b>' + config.wgPageName.replace(/_/g, ' ') + '</b>'
)
summary = _msg('redirect-summary') + ' → [[:' + config.wgPageName + ']]'
json.text = text.replace('$1', config.wgPageName)
} else {
console.error('[InPageEdit] quickRedirect only accept "from" or "to"')
return
Expand All @@ -60,6 +59,16 @@ var quickRedirect = function (type = 'to') {
$(this).css('box-shadow', '')
}
),
...(type === 'from'
? [
$br,
$('<label>', {
for: 'redirect-fragment',
text: _msg('redirect-question-fragment'),
}),
$('<input>', { id: 'redirect-fragment', style: 'width:96%' }),
]
: []),
$br,
$('<label>', { for: 'redirect-reason', text: _msg('editSummary') }),
$('<input>', { id: 'redirect-reason', style: 'width:96%' })
Expand Down Expand Up @@ -89,7 +98,14 @@ var quickRedirect = function (type = 'to') {
summary = _msg('redirect-summary') + ' → [[:' + target + ']]'
json.text = text.replace('$1', target)
} else if (type === 'from') {
let fragment = $('.in-page-edit.quick-redirect #redirect-fragment')
.val()
.trim()
if (fragment && !fragment.startsWith('#')) {
fragment = `#${fragment}`
}
json.title = target
json.text = text.replace('$1', `${config.wgPageName}${fragment}`)
}
if ($('.in-page-edit.quick-redirect #redirect-reason').val() !== '') {
summary =
Expand Down