diff options
Diffstat (limited to 'app/assets/javascripts/snippet/snippet_embed.js')
-rw-r--r-- | app/assets/javascripts/snippet/snippet_embed.js | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/app/assets/javascripts/snippet/snippet_embed.js b/app/assets/javascripts/snippet/snippet_embed.js index fe08d2c7ebb..6606271c4fa 100644 --- a/app/assets/javascripts/snippet/snippet_embed.js +++ b/app/assets/javascripts/snippet/snippet_embed.js @@ -1,25 +1,30 @@ import { __ } from '~/locale'; export default () => { - const { protocol, host, pathname } = window.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'); - }); + if (shareBtn) { + const { protocol, host, pathname } = window.location; - 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'); - }); + 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'); + }); + } }; |