Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/browse/swhid-utils.js
- This file was moved from swh/web/assets/src/bundles/browse/swh-ids-utils.js.
Show All 12 Lines | |||||
export function swhIdObjectTypeToggled(event) { | export function swhIdObjectTypeToggled(event) { | ||||
event.preventDefault(); | event.preventDefault(); | ||||
$(event.target).tab('show'); | $(event.target).tab('show'); | ||||
} | } | ||||
export function swhIdContextOptionToggled(event) { | export function swhIdContextOptionToggled(event) { | ||||
event.stopPropagation(); | event.stopPropagation(); | ||||
let swhIdElt = $(event.target).closest('.swh-id-ui').find('.swh-id'); | let swhIdElt = $(event.target).closest('.swhid-ui').find('.swhid'); | ||||
let swhIdWithContext = $(event.target).data('swhid-with-context'); | let swhIdWithContext = $(event.target).data('swhid-with-context'); | ||||
let currentSwhId = swhIdElt.text(); | let currentSwhId = swhIdElt.text(); | ||||
if ($(event.target).prop('checked')) { | if ($(event.target).prop('checked')) { | ||||
currentSwhId = swhIdWithContext; | currentSwhId = swhIdWithContext; | ||||
} else { | } else { | ||||
const pos = currentSwhId.indexOf(';'); | const pos = currentSwhId.indexOf(';'); | ||||
if (pos !== -1) { | if (pos !== -1) { | ||||
currentSwhId = currentSwhId.slice(0, pos); | currentSwhId = currentSwhId.slice(0, pos); | ||||
} | } | ||||
} | } | ||||
swhIdElt.text(currentSwhId); | swhIdElt.text(currentSwhId); | ||||
swhIdElt.attr('href', '/' + currentSwhId + '/'); | swhIdElt.attr('href', '/' + currentSwhId + '/'); | ||||
addLinesInfo(); | addLinesInfo(); | ||||
} | } | ||||
function addLinesInfo() { | function addLinesInfo() { | ||||
let swhIdElt = $('#swh-id-tab-content').find('.swh-id'); | let swhIdElt = $('#swhid-tab-content').find('.swhid'); | ||||
let currentSwhId = swhIdElt.text(); | let currentSwhId = swhIdElt.text(); | ||||
let lines = []; | let lines = []; | ||||
let linesPart = ';lines='; | let linesPart = ';lines='; | ||||
let linesRegexp = new RegExp(/L(\d+)/g); | let linesRegexp = new RegExp(/L(\d+)/g); | ||||
let line = linesRegexp.exec(window.location.hash); | let line = linesRegexp.exec(window.location.hash); | ||||
while (line) { | while (line) { | ||||
lines.push(parseInt(line[1])); | lines.push(parseInt(line[1])); | ||||
line = linesRegexp.exec(window.location.hash); | line = linesRegexp.exec(window.location.hash); | ||||
} | } | ||||
if (lines.length > 0) { | if (lines.length > 0) { | ||||
linesPart += lines[0]; | linesPart += lines[0]; | ||||
} | } | ||||
if (lines.length > 1) { | if (lines.length > 1) { | ||||
linesPart += '-' + lines[1]; | linesPart += '-' + lines[1]; | ||||
} | } | ||||
if ($('#swh-id-context-option-content').prop('checked')) { | if ($('#swhid-context-option-content').prop('checked')) { | ||||
currentSwhId = currentSwhId.replace(/;lines=\d+-*\d*/g, ''); | currentSwhId = currentSwhId.replace(/;lines=\d+-*\d*/g, ''); | ||||
if (lines.length > 0) { | if (lines.length > 0) { | ||||
currentSwhId += linesPart; | currentSwhId += linesPart; | ||||
} | } | ||||
swhIdElt.text(currentSwhId); | swhIdElt.text(currentSwhId); | ||||
swhIdElt.attr('href', '/' + currentSwhId + '/'); | swhIdElt.attr('href', '/' + currentSwhId + '/'); | ||||
} | } | ||||
} | } | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
new ClipboardJS('.btn-swh-id-copy', { | new ClipboardJS('.btn-swhid-copy', { | ||||
text: trigger => { | text: trigger => { | ||||
let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text(); | let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text(); | ||||
return swhId; | return swhId; | ||||
} | } | ||||
}); | }); | ||||
new ClipboardJS('.btn-swh-id-url-copy', { | new ClipboardJS('.btn-swhid-url-copy', { | ||||
text: trigger => { | text: trigger => { | ||||
let swhId = $(trigger).closest('.swh-id-ui').find('.swh-id').text(); | let swhId = $(trigger).closest('.swhid-ui').find('.swhid').text(); | ||||
return window.location.origin + '/' + swhId + '/'; | return window.location.origin + '/' + swhId + '/'; | ||||
} | } | ||||
}); | }); | ||||
if (window.innerWidth * 0.7 > 1000) { | if (window.innerWidth * 0.7 > 1000) { | ||||
$('#swh-identifiers').css('width', '1000px'); | $('#swh-identifiers').css('width', '1000px'); | ||||
} | } | ||||
Show All 14 Lines | if (window.innerHeight < 600 || window.innerWidth < 500) { | ||||
tabSlideOptions['otherOffset'] = '20px'; | tabSlideOptions['otherOffset'] = '20px'; | ||||
} | } | ||||
// initiate the sliding identifiers tab | // initiate the sliding identifiers tab | ||||
$('#swh-identifiers').tabSlideOut(tabSlideOptions); | $('#swh-identifiers').tabSlideOut(tabSlideOptions); | ||||
// set the tab visible once the close animation is terminated | // set the tab visible once the close animation is terminated | ||||
$('#swh-identifiers').css('display', 'block'); | $('#swh-identifiers').css('display', 'block'); | ||||
$('.swh-id-context-option').trigger('click'); | $('.swhid-context-option').trigger('click'); | ||||
// highlighted code lines changed | // highlighted code lines changed | ||||
$(window).on('hashchange', () => { | $(window).on('hashchange', () => { | ||||
addLinesInfo(); | addLinesInfo(); | ||||
}); | }); | ||||
// highlighted code lines removed | // highlighted code lines removed | ||||
$('body').click(() => { | $('body').click(() => { | ||||
addLinesInfo(); | addLinesInfo(); | ||||
}); | }); | ||||
}); | }); |