2021-02-22 17:27:13 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
|
|
|
|
export default function initClonePanel() {
|
|
|
|
const $cloneOptions = $('ul.clone-options-dropdown');
|
|
|
|
if ($cloneOptions.length) {
|
|
|
|
const $cloneUrlField = $('#clone_url');
|
|
|
|
const $cloneBtnLabel = $('.js-git-clone-holder .js-clone-dropdown-label');
|
|
|
|
const mobileCloneField = document.querySelector(
|
|
|
|
'.js-mobile-git-clone .js-clone-dropdown-label',
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectedCloneOption = $cloneBtnLabel.text().trim();
|
|
|
|
if (selectedCloneOption.length > 0) {
|
|
|
|
$(`a:contains('${selectedCloneOption}')`, $cloneOptions).addClass('is-active');
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
$('a', $cloneOptions).on('click', (e) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const $this = $(e.currentTarget);
|
|
|
|
const url = $this.attr('href');
|
2022-07-16 23:28:13 +05:30
|
|
|
if (
|
|
|
|
url &&
|
|
|
|
(url.startsWith('vscode://') ||
|
|
|
|
url.startsWith('xcode://') ||
|
|
|
|
url.startsWith('jetbrains://'))
|
|
|
|
) {
|
2021-03-11 19:13:27 +05:30
|
|
|
// Clone with "..." should open like a normal link
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2021-02-22 17:27:13 +05:30
|
|
|
const cloneType = $this.data('cloneType');
|
|
|
|
|
|
|
|
$('.is-active', $cloneOptions).removeClass('is-active');
|
|
|
|
$(`a[data-clone-type="${cloneType}"]`).each(function switchProtocol() {
|
|
|
|
const $el = $(this);
|
|
|
|
const activeText = $el.find('.dropdown-menu-inner-title').text();
|
|
|
|
const $container = $el.closest('.js-git-clone-holder, .js-mobile-git-clone');
|
|
|
|
const $label = $container.find('.js-clone-dropdown-label');
|
|
|
|
|
|
|
|
$el.toggleClass('is-active');
|
|
|
|
$label.text(activeText);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (mobileCloneField) {
|
|
|
|
mobileCloneField.dataset.clipboardText = url;
|
|
|
|
} else {
|
|
|
|
$cloneUrlField.val(url);
|
|
|
|
}
|
|
|
|
$('.js-git-empty .js-clone').text(url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|