Merge branch 'hotfix/4.2.1'

This commit is contained in:
Cotes Chung 2021-09-16 21:01:16 +08:00
commit da9881a47f
11 changed files with 104 additions and 38 deletions

View file

@ -76,7 +76,11 @@ post:
button: button:
next: Newer next: Newer
previous: Older previous: Older
copy: Copied! copy_code:
succeed: Copied!
share_link:
title: Copy link
succeed: Link copied successfully!
# pinned prompt of posts list on homepage # pinned prompt of posts list on homepage
pin_prompt: Pinned pin_prompt: Pinned

View file

@ -76,7 +76,11 @@ post:
button: button:
next: Terbaru next: Terbaru
previous: Terlama previous: Terlama
copy: Disalin! copy_code:
succeed: Disalin!
share_link:
title: Salin tautan
succeed: Tautan berhasil disalin!
# pinned prompt of posts list on homepage # pinned prompt of posts list on homepage
pin_prompt: Disematkan pin_prompt: Disematkan

View file

@ -75,7 +75,11 @@ post:
button: button:
next: 下一篇 next: 下一篇
previous: 上一篇 previous: 上一篇
copy: 已复制! copy_code:
succeed: 已复制!
share_link:
title: 分享链接
succeed: 链接已复制!
# pinned prompt of posts list on homepage # pinned prompt of posts list on homepage
pin_prompt: 顶置 pin_prompt: 顶置

View file

@ -16,9 +16,10 @@
</a> </a>
{% endfor %} {% endfor %}
<i class="fa-fw fas fa-link small" onclick="copyLink('', '{{ site.data.locales[lang].post.button.copy.succeed }}')" <i id="copy-link" class="fa-fw fas fa-link small"
data-toggle="tooltip" data-placement="top" data-toggle="tooltip" data-placement="top"
title="{{ site.data.locales[lang].post.button.copy.title }}"> title="{{ site.data.locales[lang].post.button.share_link.title }}"
title-succeed="{{ site.data.locales[lang].post.button.share_link.succeed }}">
</i> </i>
</span> </span>

View file

@ -127,7 +127,7 @@
| append: '<div class="code-header" text-data="' | append: '<div class="code-header" text-data="'
| append: _text | append: _text
| append: '"><button data-original-title="' | append: '"><button data-original-title="'
| append: site.data.locales[lang].post.button.copy | append: site.data.locales[lang].post.button.copy_code.succeed
| append: '"><i class="far fa-clone"></i></button></div>' | append: '"><i class="far fa-clone"></i></button></div>'
| append: '<div class="highlight"><code>' | append: '<div class="highlight"><code>'
%} %}

View file

@ -1,5 +1,5 @@
/* /*
* Initial the clipboard.js object * Clipboard functions
* *
* Dependencies: * Dependencies:
* - popper.js (https://github.com/popperjs/popper-core) * - popper.js (https://github.com/popperjs/popper-core)
@ -9,12 +9,34 @@
$(function() { $(function() {
const btnSelector = '.code-header>button'; const btnSelector = '.code-header>button';
const ICON_SUCCESS = 'fas fa-check'; const ICON_SUCCESS = 'fas fa-check';
const ATTR_LOCKED = 'locked'; const ATTR_TIMEOUT = 'timeout';
const TIMEOUT = 2000; // in milliseconds const TIMEOUT = 2000; // in milliseconds
function isLocked(node) {
if ($(node)[0].hasAttribute(ATTR_TIMEOUT)) {
let timeout = $(node).attr(ATTR_TIMEOUT);
if (Number(timeout) > Date.now()) {
return true;
}
}
return false;
}
function lock(node) {
$(node).attr(ATTR_TIMEOUT, Date.now() + TIMEOUT);
}
function unlock(node) {
$(node).removeAttr(ATTR_TIMEOUT);
}
/* --- Copy code block --- */
// Initial the clipboard.js object
const clipboard = new ClipboardJS(btnSelector, { const clipboard = new ClipboardJS(btnSelector, {
target(trigger) { target(trigger) {
return trigger.parentNode.nextElementSibling; let codeBlock = trigger.parentNode.nextElementSibling;
return codeBlock.querySelector('code .rouge-code');
} }
}); });
@ -30,51 +52,79 @@ $(function() {
const ICON_DEFAULT = getIcon(btnSelector); const ICON_DEFAULT = getIcon(btnSelector);
function setTooltip(btn) { function showTooltip(btn) {
$(btn).tooltip('hide') $(btn).tooltip('show');
.tooltip('show');
} }
function hideTooltip(btn) { function hideTooltip(btn) {
setTimeout(function() { $(btn).tooltip('hide');
$(btn).tooltip('hide'); unlock(btn);
}, TIMEOUT);
} }
function setSuccessIcon(btn) { function setSuccessIcon(btn) {
let btnNode = $(btn); let btnNode = $(btn);
let iconNode = btnNode.children(); let iconNode = btnNode.children();
btnNode.attr(ATTR_LOCKED, true);
iconNode.attr('class', ICON_SUCCESS); iconNode.attr('class', ICON_SUCCESS);
lock(btn);
} }
function resumeIcon(btn) { function resumeIcon(btn) {
let btnNode = $(btn); let btnNode = $(btn);
let iconNode = btnNode.children(); let iconNode = btnNode.children();
iconNode.attr('class', ICON_DEFAULT);
setTimeout(function() { unlock(btn);
btnNode.removeAttr(ATTR_LOCKED);
iconNode.attr('class', ICON_DEFAULT);
}, TIMEOUT);
}
function isLocked(btn) {
let locked = $(btn).attr(ATTR_LOCKED);
return locked === 'true';
} }
clipboard.on('success', (e) => { clipboard.on('success', (e) => {
e.clearSelection(); e.clearSelection();
if (isLocked(e.trigger)) { const trigger = e.trigger;
if (isLocked(trigger)) {
return; return;
} }
setTooltip(e.trigger); setSuccessIcon(trigger);
hideTooltip(e.trigger); showTooltip(trigger);
setSuccessIcon(e.trigger); setTimeout(() => {
resumeIcon($(e.trigger)); hideTooltip(trigger);
resumeIcon(trigger);
}, TIMEOUT);
});
/* --- Post link sharing --- */
$('#copy-link').click((e) => {
let target = $(e.target);
if (isLocked(target)) {
return;
}
// Copy URL to clipboard
const url = window.location.href;
const $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
// Switch tooltip title
const defaultTitle = target.attr('data-original-title');
const succeedTitle = target.attr('title-succeed');
target.attr('data-original-title', succeedTitle).tooltip('show');
lock(target);
setTimeout(() => {
target.attr('data-original-title', defaultTitle);
unlock(target);
}, TIMEOUT);
}); });

View file

@ -199,12 +199,12 @@ div {
background-color: inherit; background-color: inherit;
color: var(--highlight-lineno-color); color: var(--highlight-lineno-color);
&[locked=true] { &[timeout] {
color: var(--clipboard-checked-color); color: var(--clipboard-checked-color);
border-color: var(--clipboard-checked-color); border-color: var(--clipboard-checked-color);
} }
&:not([locked]):hover { &:not([timeout]):hover {
background-color: gray; background-color: gray;
color: white; color: white;
} }

View file

@ -240,7 +240,8 @@
} }
} }
> i { > i {
padding-top: 0.35rem; position: relative;
bottom: 1px;
&:hover { &:hover {
@extend %btn-share-hovor; @extend %btn-share-hovor;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -128,10 +128,12 @@ release() {
git checkout -b "$_release_branch" git checkout -b "$_release_branch"
_new_release_branch=true _new_release_branch=true
else else
# cherry-pick the latest commit from default branch to release branch
_last_commit="$(git rev-parse $DEFAULT_BRANCH)"
git checkout "$_release_branch" git checkout "$_release_branch"
# cherry-pick the latest commit from master branch to release branch git cherry-pick "$_last_commit" -m 1
git cherry-pick "$(git rev-parse $DEFAULT_BRANCH)"
fi fi
fi fi
echo -e "Bump version to $_version\n" echo -e "Bump version to $_version\n"