🔧 Feat: modify code edit button (#76)

This commit is contained in:
Cell
2022-03-06 14:24:12 +08:00
parent 70e5793bb8
commit 14df985a2d
7 changed files with 18 additions and 19 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -160,4 +160,4 @@ var _str2Array = (str) => {
---
{{</* gist spf13 7896402 */>}}
{{< gist spf13 7896402 >}}
+2 -2
View File
@@ -97,10 +97,10 @@ other = "en"
other = "Copy to clipboard"
[editLockTitle]
other = "Unlock editable code block"
other = "Lock editable code block"
[editUnLockTitle]
other = "Lock editable code block"
other = "Unlock editable code block"
[cookieconsentMessage]
other = "This website uses Cookies to improve your experience."
+2 -2
View File
@@ -104,10 +104,10 @@ other = "lib/lunr/lunr.segmentit.js"
other = "复制到剪贴板"
[editLockTitle]
other = "锁可编辑代码块"
other = "锁可编辑代码块"
[editUnLockTitle]
other = "锁可编辑代码块"
other = "锁可编辑代码块"
[cookieconsentMessage]
other = "本网站使用 Cookies 来改善您的浏览体验."
+2 -2
View File
@@ -104,10 +104,10 @@ other = "lib/lunr/lunr.segmentit.js"
other = "複製到剪貼板"
[editLockTitle]
other = "鎖可編輯代碼塊"
other = "鎖可編輯代碼塊"
[editUnLockTitle]
other = "鎖可編輯代碼塊"
other = "鎖可編輯代碼塊"
[cookieconsentMessage]
other = "本網站使用 Cookies 來改善您的流覽體驗."
+9 -10
View File
@@ -424,22 +424,21 @@ class Theme {
if (this.config.code.editable) {
const $edit = document.createElement('span');
$edit.classList.add('edit');
// this.config.code.editUnLockTitle
$edit.insertAdjacentHTML('afterbegin', `<i class="fas fa-lock fa-fw" title="${this.config.code.editLockTitle}"></i>`);
$edit.insertAdjacentHTML('afterbegin', `<i class="fas fa-key fa-fw" title="${this.config.code.editUnLockTitle}"></i>`);
$edit.addEventListener('click', () => {
const $iconKey = $edit.querySelector('.fa-key');
const $iconLock = $edit.querySelector('.fa-lock');
const $iconUnLock = $edit.querySelector('.fa-lock-open');
const $preChromas = $edit.parentElement.parentElement.querySelectorAll('pre.chroma');
const $preChroma = $preChromas.length === 2 ? $preChromas[1] : $preChromas[0];
if ($iconLock) {
$iconLock.classList.add('fa-lock-open');
$iconLock.classList.remove('fa-lock');
$iconLock.title = this.config.code.editUnLockTitle;
if ($iconKey) {
$iconKey.classList.add('fa-lock');
$iconKey.classList.remove('fa-key');
$iconKey.title = this.config.code.editLockTitle;
$preChroma.setAttribute('contenteditable', true);
} else {
$iconUnLock.classList.add('fa-lock');
$iconUnLock.classList.remove('fa-lock-open');
$iconUnLock.title = this.config.code.editLockTitle;
$iconLock.classList.add('fa-key');
$iconLock.classList.remove('fa-lock');
$iconLock.title = this.config.code.editUnLockTitle;
$preChroma.setAttribute('contenteditable', false);
}
}, false);