pyfedi/app/static/js/scripts.js
2023-09-03 16:30:20 +12:00

28 lines
No EOL
766 B
JavaScript

// fires after DOM is ready for manipulation
document.addEventListener("DOMContentLoaded", function () {
setupCommunityNameInput();
});
// fires after all resources have loaded, including stylesheets and js files
window.addEventListener("load", function () {
});
function setupCommunityNameInput() {
var communityNameInput = document.getElementById('community_name');
if (communityNameInput) {
communityNameInput.addEventListener('keyup', function() {
var urlInput = document.getElementById('url');
urlInput.value = titleToURL(communityNameInput.value);
});
}
}
function titleToURL(title) {
// Convert the title to lowercase and replace spaces with hyphens
return title.toLowerCase().replace(/\s+/g, '-');
}