Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snippet_embed.js « snippet « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6606271c4fa7bdd919254ec39a8e83ffe120189c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { __ } from '~/locale';

export default () => {
  const shareBtn = document.querySelector('.js-share-btn');

  if (shareBtn) {
    const { protocol, host, pathname } = window.location;

    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');
    });
  }
};