Show hashtags in the page title
This commit is contained in:
parent
34ff6c48bd
commit
f0b2e205d9
1 changed files with 13 additions and 1 deletions
14
script.js
14
script.js
|
@ -100,11 +100,22 @@ const updateWall = function(posts) {
|
||||||
posts.forEach(post => displayPost(post));
|
posts.forEach(post => displayPost(post));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// hashtagsString returns a single string based on the given array of hashtags
|
||||||
|
const hashtagsString = function(hashtagsArray) {
|
||||||
|
return `${hashtagsArray.map(hashtag => `#${hashtag}`).join(' ')}`;
|
||||||
|
}
|
||||||
|
|
||||||
// updateHashtagsOnPage updates the displayed hashtags
|
// updateHashtagsOnPage updates the displayed hashtags
|
||||||
const updateHashtagsOnPage = function(hashtagsArray) {
|
const updateHashtagsOnPage = function(hashtagsArray) {
|
||||||
$('#hashtag-display').text(hashtagsArray.length > 0 ? `${hashtagsArray.map(hashtag => `#${hashtag}`).join(' ')}` : 'No hashtags set');
|
$('#hashtag-display').text(hashtagsArray.length > 0 ? hashtagsString(hashtagsArray) : 'No hashtags set');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// updateHashtagsOnPage updates the document title by appending the given array of hashtags
|
||||||
|
const updateHashtagsInTitle = function(hashtagsArray) {
|
||||||
|
const baseTitle = document.title;
|
||||||
|
document.title = `${baseTitle} | ${hashtagsString(hashtagsArray)}`;
|
||||||
|
}
|
||||||
|
|
||||||
// handleHashtagDisplayClick handles the event when the hashtag display is clicked
|
// handleHashtagDisplayClick handles the event when the hashtag display is clicked
|
||||||
const handleHashtagDisplayClick = function(serverUrl) {
|
const handleHashtagDisplayClick = function(serverUrl) {
|
||||||
$('#app-content').addClass('d-none');
|
$('#app-content').addClass('d-none');
|
||||||
|
@ -179,6 +190,7 @@ $(document).ready(async function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHashtagsOnPage(hashtagsArray);
|
updateHashtagsOnPage(hashtagsArray);
|
||||||
|
updateHashtagsInTitle(hashtagsArray);
|
||||||
|
|
||||||
$('#hashtag-form').on('submit', function(e) {
|
$('#hashtag-form').on('submit', function(e) {
|
||||||
handleHashtagFormSubmit(e, hashtagsArray);
|
handleHashtagFormSubmit(e, hashtagsArray);
|
||||||
|
|
Loading…
Reference in a new issue