diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-04-16 10:56:16 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-04-16 10:56:16 +0000 |
commit | cee3df6c249ffbdd3b5f81367d8d69deafa646d7 (patch) | |
tree | 1a2e5362897d0433753bd54ca321d913dd2f5f8a /app/assets/javascripts/snippet | |
parent | 4ed152e4ba7efede082a9c8884fd94f0a113e398 (diff) | |
parent | 99f278f6fdf6e0577312afc3913a6bb376dfdd2b (diff) | |
download | gitlab-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.js | 23 |
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'; + }); +}; |