gitlab-org--gitlab-foss/app/assets/javascripts/snippet/snippet_embed.js

26 lines
907 B
JavaScript
Raw Normal View History

import { __ } from '~/locale';
2018-03-03 01:41:19 -05:00
export default () => {
const { protocol, host, pathname } = window.location;
2018-03-07 08:06:16 -05:00
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');
2018-03-06 13:44:57 -05:00
const url = `${protocol}//${host + pathname}`;
2018-02-06 08:33:18 -05:00
2018-03-03 03:00:08 -05:00
shareBtn.addEventListener('click', () => {
2018-03-03 01:41:19 -05:00
shareBtn.classList.add('is-active');
embedBtn.classList.remove('is-active');
2018-03-06 13:44:57 -05:00
snippetUrlArea.value = url;
embedAction.innerText = __('Share');
2018-03-03 01:41:19 -05:00
});
2018-02-06 08:33:18 -05:00
2018-03-03 03:00:08 -05:00
embedBtn.addEventListener('click', () => {
2018-03-03 01:41:19 -05:00
embedBtn.classList.add('is-active');
shareBtn.classList.remove('is-active');
2018-03-06 13:44:57 -05:00
const scriptTag = `<script src="${url}.js"></script>`;
2018-03-03 01:41:19 -05:00
snippetUrlArea.value = scriptTag;
embedAction.innerText = __('Embed');
2018-02-06 08:33:18 -05:00
});
2018-03-03 01:41:19 -05:00
};