2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { parseUrlPathname, parseUrl } from '../lib/utils/common_utils';
|
|
|
|
|
|
|
|
function swapActiveState(activateBtn, deactivateBtn) {
|
|
|
|
activateBtn.classList.add('is-active');
|
|
|
|
deactivateBtn.classList.remove('is-active');
|
|
|
|
}
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
export default () => {
|
|
|
|
const shareBtn = document.querySelector('.js-share-btn');
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
if (shareBtn) {
|
|
|
|
const embedBtn = document.querySelector('.js-embed-btn');
|
|
|
|
const snippetUrlArea = document.querySelector('.js-snippet-url-area');
|
|
|
|
const embedAction = document.querySelector('.js-embed-action');
|
2020-01-01 13:55:28 +05:30
|
|
|
const dataUrl = snippetUrlArea.getAttribute('data-url');
|
|
|
|
|
|
|
|
snippetUrlArea.addEventListener('click', () => snippetUrlArea.select());
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
shareBtn.addEventListener('click', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
swapActiveState(shareBtn, embedBtn);
|
|
|
|
snippetUrlArea.value = dataUrl;
|
2019-12-21 20:55:43 +05:30
|
|
|
embedAction.innerText = __('Share');
|
|
|
|
});
|
|
|
|
|
|
|
|
embedBtn.addEventListener('click', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
const parser = parseUrl(dataUrl);
|
|
|
|
const url = `${parser.origin + parseUrlPathname(dataUrl)}`;
|
|
|
|
const params = parser.search;
|
|
|
|
const scriptTag = `<script src="${url}.js${params}"></script>`;
|
|
|
|
|
|
|
|
swapActiveState(embedBtn, shareBtn);
|
2019-12-21 20:55:43 +05:30
|
|
|
snippetUrlArea.value = scriptTag;
|
|
|
|
embedAction.innerText = __('Embed');
|
|
|
|
});
|
|
|
|
}
|
2018-10-15 14:42:47 +05:30
|
|
|
};
|