Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/webapp/webapp-utils.js
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | $(document).ready(() => { | ||||
scrollThreshold += $('.navbar').height() || 0; | scrollThreshold += $('.navbar').height() || 0; | ||||
$(window).scroll(() => { | $(window).scroll(() => { | ||||
if ($(window).scrollTop() > scrollThreshold) { | if ($(window).scrollTop() > scrollThreshold) { | ||||
$('#back-to-top').css('display', 'block'); | $('#back-to-top').css('display', 'block'); | ||||
} else { | } else { | ||||
$('#back-to-top').css('display', 'none'); | $('#back-to-top').css('display', 'none'); | ||||
} | } | ||||
}); | }); | ||||
// navbar search form submission callback | |||||
$('#swh-origins-search-top').submit(event => { | |||||
event.preventDefault(); | |||||
let searchQueryText = $('#swh-origins-search-top-input').val().trim(); | |||||
let queryParameters = new URLSearchParams(); | |||||
queryParameters.append('q', searchQueryText); | |||||
queryParameters.append('with_visit', true); | |||||
queryParameters.append('with_content', true); | |||||
window.location = `${Urls.browse_search()}?${queryParameters.toString()}`; | |||||
}); | |||||
}); | }); | ||||
export function initPage(page) { | export function initPage(page) { | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
// set relevant sidebar link to page active | // set relevant sidebar link to page active | ||||
$(`.swh-${page}-item`).addClass('active'); | $(`.swh-${page}-item`).addClass('active'); | ||||
$(`.swh-${page}-link`).addClass('active'); | $(`.swh-${page}-link`).addClass('active'); | ||||
// triggered when unloading the current page | // triggered when unloading the current page | ||||
$(window).on('unload', () => { | $(window).on('unload', () => { | ||||
// backup current browse page | // backup current browse page | ||||
if (page === 'browse') { | if (page === 'browse') { | ||||
sessionStorage.setItem('last-browse-page', window.location); | sessionStorage.setItem('last-browse-page', window.location); | ||||
} | } | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
export function initHomePage() { | export function initHomePage() { | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
$('.swh-coverage-list').iFrameResize({heightCalculationMethod: 'taggedElement'}); | $('.swh-coverage-list').iFrameResize({heightCalculationMethod: 'taggedElement'}); | ||||
fetch(Urls.stat_counters()) | fetch(Urls.stat_counters()) | ||||
.then(response => response.json()) | .then(response => response.json()) | ||||
▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines |