Skip to content

Commit

Permalink
Merge branch 'main' into make-context-a-context
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored May 31, 2021
2 parents 84614ac + 518ed50 commit 91a65dc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 88 deletions.
9 changes: 9 additions & 0 deletions options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,10 @@ pulls.manually_merged_as=此合併請求已被手動合併為 <a rel="nofollow"
pulls.is_closed=合併請求已被關閉。
pulls.has_merged=合併請求已合併。
pulls.title_wip_desc=`<a href="#">標題用 <strong>%s</strong> 開頭</a>以避免意外地合併此合併請求。`
pulls.cannot_merge_work_in_progress=此合併請求被標記為還在進行中(WIP)。
pulls.still_in_progress=還在進行中嗎?
pulls.add_prefix=加入 <strong>%s</strong> 前綴
pulls.remove_prefix=移除 <strong>%s</strong> 前綴
pulls.data_broken=此合併請求已損毀,因為遺失 Fork 資訊。
pulls.files_conflicted=此合併請求有變更和目標分支衝突。
pulls.is_checking=正在進行合併衝突檢查,請稍後再試。
Expand Down Expand Up @@ -1547,6 +1551,7 @@ settings.email_notifications.disable=關閉郵件通知
settings.email_notifications.submit=套用郵件偏好設定
settings.site=網站
settings.update_settings=更新設定
settings.branches.update_default_branch=更新預設分支
settings.advanced_settings=進階設定
settings.wiki_desc=啟用儲存庫 Wiki
settings.use_internal_wiki=使用內建 Wiki
Expand Down Expand Up @@ -1973,6 +1978,10 @@ branch.restore=還原分支「%s」
branch.download=下載分支 '%s'
branch.included_desc=此分支是預設分支的一部分
branch.included=包含
branch.create_new_branch=從下列分支建立分支:
branch.confirm_create_branch=建立分支
branch.new_branch=建立新分支
branch.new_branch_from=從「%s」建立新分支

tag.create_tag=建立標籤 <strong>%s</strong>
tag.create_success=已建立標籤「%s」。
Expand Down
67 changes: 0 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"@claviska/jquery-minicolors": "2.3.5",
"@primer/octicons": "13.0.0",
"add-asset-webpack-plugin": "2.0.1",
"clipboard": "2.0.8",
"codemirror": "5.61.0",
"css-loader": "5.2.4",
"dropzone": "5.9.2",
Expand Down
5 changes: 5 additions & 0 deletions routers/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.NotFound("blob.Data", err)
return
}

defer dataRc.Close()

ctx.Data["FileSize"] = blob.Size()
Expand All @@ -122,6 +123,10 @@ func editFile(ctx *context.Context, isNewFile bool) {
}

d, _ := ioutil.ReadAll(dataRc)
if err := dataRc.Close(); err != nil {
log.Error("Error whilst closing blob data: %v", err)
}

buf = append(buf, d...)
if content, err := charset.ToUTF8WithErr(buf); err != nil {
log.Error("ToUTF8WithErr: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/clone_buttons.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<input id="repo-clone-url" value="{{if $.PageIsWiki}}{{$.WikiCloneLink.SSH}}{{else}}{{$.CloneLink.SSH}}{{end}}" readonly>
{{end}}
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
<button class="ui basic icon button poping up" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
{{svg "octicon-clippy"}}
</button>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/view_content/context_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ else }}
{{ $referenceUrl = Printf "%s%s/pulls/%d/files#%s" AppUrl .ctx.Repository.FullName .ctx.Issue.Index .item.HashTag }}
{{ end }}
<div class="item context clipboard" data-clipboard-text="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
<div class="item context" data-clipboard-text="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.copy_link"}}</div>
<div class="item context quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.ID}}">{{.ctx.i18n.Tr "repo.issues.context.quote_reply"}}</div>
{{if not .ctx.UnitIssuesGlobalDisabled}}
<div class="item context reference-issue" data-target="{{.item.ID}}" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-reference="{{$referenceUrl}}">{{.ctx.i18n.Tr "repo.issues.context.reference_issue"}}</div>
Expand Down
52 changes: 34 additions & 18 deletions web_src/js/features/clipboard.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
export default async function initClipboard() {
const els = document.querySelectorAll('.clipboard');
if (!els || !els.length) return;
const selector = '[data-clipboard-target], [data-clipboard-text]';

const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
// TODO: replace these with toast-style notifications
function onSuccess(btn) {
if (!btn.dataset.content) return;
$(btn).popup('destroy');
btn.dataset.content = btn.dataset.success;
$(btn).popup('show');
btn.dataset.content = btn.dataset.original;
}
function onError(btn) {
if (!btn.dataset.content) return;
$(btn).popup('destroy');
btn.dataset.content = btn.dataset.error;
$(btn).popup('show');
btn.dataset.content = btn.dataset.original;
}

const clipboard = new ClipboardJS(els);
clipboard.on('success', (e) => {
e.clearSelection();
$(e.trigger).popup('destroy');
e.trigger.dataset.content = e.trigger.dataset.success;
$(e.trigger).popup('show');
e.trigger.dataset.content = e.trigger.dataset.original;
});
export default async function initClipboard() {
for (const btn of document.querySelectorAll(selector) || []) {
btn.addEventListener('click', async () => {
let text;
if (btn.dataset.clipboardText) {
text = btn.dataset.clipboardText;
} else if (btn.dataset.clipboardTarget) {
text = document.querySelector(btn.dataset.clipboardTarget)?.value;
}
if (!text) return;

clipboard.on('error', (e) => {
$(e.trigger).popup('destroy');
e.trigger.dataset.content = e.trigger.dataset.error;
$(e.trigger).popup('show');
e.trigger.dataset.content = e.trigger.dataset.original;
});
try {
await navigator.clipboard.writeText(text);
onSuccess(btn);
} catch {
onError(btn);
}
});
}
}

0 comments on commit 91a65dc

Please sign in to comment.