summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/snippet
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-04-16 10:56:16 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-04-16 10:56:16 +0000
commitcee3df6c249ffbdd3b5f81367d8d69deafa646d7 (patch)
tree1a2e5362897d0433753bd54ca321d913dd2f5f8a /app/assets/javascripts/snippet
parent4ed152e4ba7efede082a9c8884fd94f0a113e398 (diff)
parent99f278f6fdf6e0577312afc3913a6bb376dfdd2b (diff)
downloadgitlab-ce-cee3df6c249ffbdd3b5f81367d8d69deafa646d7.tar.gz
Merge branch '8088_embedded_snippets_support' into 'master'
Embedded Snippets Support Closes #8088 See merge request gitlab-org/gitlab-ce!15695
Diffstat (limited to 'app/assets/javascripts/snippet')
-rw-r--r--app/assets/javascripts/snippet/snippet_embed.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/assets/javascripts/snippet/snippet_embed.js b/app/assets/javascripts/snippet/snippet_embed.js
new file mode 100644
index 00000000000..81ec483f2d9
--- /dev/null
+++ b/app/assets/javascripts/snippet/snippet_embed.js
@@ -0,0 +1,23 @@
+export default () => {
+ const { protocol, host, pathname } = location;
+ const shareBtn = document.querySelector('.js-share-btn');
+ const embedBtn = document.querySelector('.js-embed-btn');
+ const snippetUrlArea = document.querySelector('.js-snippet-url-area');
+ const embedAction = document.querySelector('.js-embed-action');
+ const url = `${protocol}//${host + pathname}`;
+
+ shareBtn.addEventListener('click', () => {
+ shareBtn.classList.add('is-active');
+ embedBtn.classList.remove('is-active');
+ snippetUrlArea.value = url;
+ embedAction.innerText = 'Share';
+ });
+
+ embedBtn.addEventListener('click', () => {
+ embedBtn.classList.add('is-active');
+ shareBtn.classList.remove('is-active');
+ const scriptTag = `<script src="${url}.js"></script>`;
+ snippetUrlArea.value = scriptTag;
+ embedAction.innerText = 'Embed';
+ });
+};