Skip to content

Commit

Permalink
⚡ Perf: remove third-party library clipboard.js (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Mar 16, 2022
1 parent 66efd4d commit 22a6157
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 27 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file.

## v0.2.14

- **Full Changelog:** @Lruihao [`v0.2.13...v0.2.14`](https://github.com/Lruihao/FixIt/compare/v0.2.11...v0.2.12-beta)
- :zap: Perf: remove third-party library clipboard.js ([#84](https://github.com/Lruihao/FixIt/issues/84))
- **Full Changelog:** @Lruihao [`v0.2.13...v0.2.14`](https://github.com/Lruihao/FixIt/compare/v0.2.13...v0.2.14)

## v0.2.13 [2022.3.14]

Expand Down Expand Up @@ -63,6 +64,7 @@ All notable changes to this project will be documented in this file.
- :wrench: Chore(i18n): change some translations
- :arrow_up: Chore: update all third-party libraries
- **Full Changelog:** @Lruihao [`v0.2.11...v0.2.12`](https://github.com/Lruihao/FixIt/compare/v0.2.11...v0.2.12)

## v0.2.11 [2021-12-19]

> :tada: The beginning of FixIt to fix the theme LoveIt.
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ Thanks to the authors of following resources included in the theme:
* [object-fit-images](https://github.com/fregante/object-fit-images)
* [Twemoji](https://github.com/twitter/twemoji)
* [lightgallery.js](https://github.com/sachinchoolur/lightgallery.js)
* [clipboard.js](https://github.com/zenorocha/clipboard.js)
* [Sharer.js](https://github.com/ellisonleao/sharer.js)
* [TypeIt](https://typeitjs.com/)
* [KaTeX](https://katex.org/)
Expand Down
1 change: 0 additions & 1 deletion README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ FixIt 主题中用到了以下项目,感谢它们的作者:
* [object-fit-images](https://github.com/fregante/object-fit-images)
* [Twemoji](https://github.com/twitter/twemoji)
* [lightgallery.js](https://github.com/sachinchoolur/lightgallery.js)
* [clipboard.js](https://github.com/zenorocha/clipboard.js)
* [Sharer.js](https://github.com/ellisonleao/sharer.js)
* [TypeIt](https://typeitjs.com/)
* [KaTeX](https://katex.org/)
Expand Down
2 changes: 0 additions & 2 deletions assets/data/cdn/jsdelivr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ libFiles:
autocompleteJS: autocomplete.js@0.38.1/dist/autocomplete.min.js
# cell-watermark@1.0.3 https://github.com/Lruihao/watermark
cellWatermarkJS: cell-watermark@1.0.3/src/watermark.min.js
# clipboard.js@2.0.8 https://github.com/zenorocha/clipboard.js
clipboardJS: clipboard@2.0.8/dist/clipboard.min.js
# cookieconsent@3.1.1 https://github.com/osano/cookieconsent
cookieconsentCSS: cookieconsent@3.1.1/build/cookieconsent.min.css
cookieconsentJS: cookieconsent@3.1.1/build/cookieconsent.min.js
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion assets/lib/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ aplayer@1.10.1 https://github.com/MoePlayer/APlayer
artalk@2.1.4 https://github.com/ArtalkJS/Artalk
autocomplete.js@0.38.1 https://github.com/algolia/autocomplete.js
cell-watermark@1.0.3 https://github.com/Lruihao/watermark
clipboard.js@2.0.8 https://github.com/zenorocha/clipboard.js
cookieconsent@3.1.1 https://github.com/osano/cookieconsent
echarts@5.2.2 https://github.com/apache/echarts
fontawesome-free@5.14.0 https://github.com/FortAwesome/Font-Awesome
Expand Down
7 changes: 0 additions & 7 deletions assets/lib/clipboard/clipboard.min.js

This file was deleted.

1 change: 0 additions & 1 deletion exampleSite/content/about/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Thanks to the authors of following resources included in the theme:
* [object-fit-images](https://github.com/fregante/object-fit-images)
* [Twemoji](https://github.com/twitter/twemoji)
* [lightgallery.js](https://github.com/sachinchoolur/lightgallery.js)
* [clipboard.js](https://github.com/zenorocha/clipboard.js)
* [Sharer.js](https://github.com/ellisonleao/sharer.js)
* [TypeIt](https://typeitjs.com/)
* [$ \KaTeX $](https://katex.org/)
Expand Down
1 change: 0 additions & 1 deletion exampleSite/content/about/index.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ FixIt 主题中用到了以下项目,感谢它们的作者:
* [object-fit-images](https://github.com/fregante/object-fit-images)
* [Twemoji](https://github.com/twitter/twemoji)
* [lightgallery.js](https://github.com/sachinchoolur/lightgallery.js)
* [clipboard.js](https://github.com/zenorocha/clipboard.js)
* [Sharer.js](https://github.com/ellisonleao/sharer.js)
* [TypeIt](https://typeitjs.com/)
* [$ \KaTeX $](https://katex.org/)
Expand Down
4 changes: 1 addition & 3 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@
{{- $config = dict "editable" true "editLockTitle" (T "editLockTitle") "editUnLockTitle" (T "editUnLockTitle") | dict "code" | merge $config -}}
{{- end -}}

{{- /* clipboard.js */ -}}
{{- /* copy code */ -}}
{{- if ne $code.copy false -}}
{{- $source := $cdn.clipboardJS | default "lib/clipboard/clipboard.min.js" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $config = T "copyToClipboard" | dict "copyTitle" | dict "code" | merge $config -}}
{{- end -}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "0.2.13" -}}
{{- .Scratch.Set "version" "0.2.14" -}}

{{- /* FixIt theme version detection */ -}}
{{- $VERSION := "0.2.X" -}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fixit-src",
"version": "0.2.13",
"version": "0.2.14",
"description": "FixIt theme source file",
"private": true,
"dependencies": {},
Expand Down
12 changes: 7 additions & 5 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,14 @@ class Theme {
if (this.config.code.maxShownLines < 0 || code.split('\n').length < this.config.code.maxShownLines + 2) {
$chroma.classList.add('open');
}
$copy.setAttribute('data-clipboard-text', code);
$copy.title = this.config.code.copyTitle;
const clipboard = new ClipboardJS($copy);
clipboard.on('success', (_e) => {
this.util.animateCSS($code, 'animate__flash');
});
$copy.addEventListener('click', () => {
navigator.clipboard.writeText(code).then(() => {
this.util.animateCSS($code, 'animate__flash');
}, () => {
console.error('Clipboard write failed!', 'Your browser does not support clipboard API!');
});
}, false);
$header.appendChild($copy);
}
$chroma.insertBefore($header, $chroma.firstChild);
Expand Down

1 comment on commit 22a6157

@vercel
Copy link

@vercel vercel bot commented on 22a6157 Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.