aboutsummaryrefslogtreecommitdiffstats
path: root/web_src
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2020-02-08 00:03:42 +0100
committerGitHub <noreply@github.com>2020-02-08 00:03:42 +0100
commit4721d45c2aa9ea7f0587188938ea78bec584c5b6 (patch)
treed36344d00ea105f983680e1b3e701d7760e010d4 /web_src
parent0754ceca5b0dc532cc11f7a6fe162dddcc2e7d4f (diff)
downloadgitea-4721d45c2aa9ea7f0587188938ea78bec584c5b6.tar.gz
gitea-4721d45c2aa9ea7f0587188938ea78bec584c5b6.zip
move clipboard.js to npm/webpack (#10183)
- created lazy-loaded webpack chunk for clipboard.js - upgraded clipboard.js from 1.5.9 to 2.0.4 - parallelize initialization of all lazy-loaded features Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
Diffstat (limited to 'web_src')
-rw-r--r--web_src/js/features/clipboard.js23
-rw-r--r--web_src/js/index.js23
2 files changed, 27 insertions, 19 deletions
diff --git a/web_src/js/features/clipboard.js b/web_src/js/features/clipboard.js
new file mode 100644
index 0000000000..bd4a664c7a
--- /dev/null
+++ b/web_src/js/features/clipboard.js
@@ -0,0 +1,23 @@
+export default async function initClipboard() {
+ const els = document.querySelectorAll('.clipboard');
+ if (!els || !els.length) return;
+
+ const { default: ClipboardJS } = await import(/* webpackChunkName: "clipboard" */'clipboard');
+
+ const clipboard = new ClipboardJS(els);
+ clipboard.on('success', (e) => {
+ e.clearSelection();
+
+ $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
+ e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'));
+ $(`#${e.trigger.getAttribute('id')}`).popup('show');
+ e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
+ });
+
+ clipboard.on('error', (e) => {
+ $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
+ e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'));
+ $(`#${e.trigger.getAttribute('id')}`).popup('show');
+ e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
+ });
+}
diff --git a/web_src/js/index.js b/web_src/js/index.js
index 3fa6303c8a..128779c153 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -10,6 +10,7 @@ import './vendor/semanticDropdown.js';
import initContextPopups from './features/contextPopup.js';
import initHighlight from './features/highlight.js';
import initGitGraph from './features/gitGraph.js';
+import initClipboard from './features/clipboard.js';
import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
@@ -2453,24 +2454,6 @@ $(document).ready(async () => {
}
}
- // Clipboard JS
- const clipboard = new Clipboard('.clipboard');
- clipboard.on('success', (e) => {
- e.clearSelection();
-
- $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
- e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'));
- $(`#${e.trigger.getAttribute('id')}`).popup('show');
- e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
- });
-
- clipboard.on('error', (e) => {
- $(`#${e.trigger.getAttribute('id')}`).popup('destroy');
- e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'));
- $(`#${e.trigger.getAttribute('id')}`).popup('show');
- e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'));
- });
-
// Helpers.
$('.delete-button').click(showDeletePopup);
$('.add-all-button').click(showAddAllPopup);
@@ -2579,7 +2562,6 @@ $(document).ready(async () => {
initRepoStatusChecker();
initTemplateSearch();
initContextPopups(suburl);
- initGitGraph();
// Repo clone url.
if ($('#repo-clone-url').length > 0) {
@@ -2616,8 +2598,11 @@ $(document).ready(async () => {
}
});
+ // parallel init of lazy-loaded features
[hljs] = await Promise.all([
initHighlight(),
+ initGitGraph(),
+ initClipboard(),
]);
});