Merge pull request #5 from optikfluffel/show-hashtags-in-title
Show hashtags in the page title
This commit is contained in:
commit
a043940301
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));
|
||||
};
|
||||
|
||||
// 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
|
||||
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
|
||||
const handleHashtagDisplayClick = function(serverUrl) {
|
||||
$('#app-content').addClass('d-none');
|
||||
|
@ -179,6 +190,7 @@ $(document).ready(async function() {
|
|||
}
|
||||
|
||||
updateHashtagsOnPage(hashtagsArray);
|
||||
updateHashtagsInTitle(hashtagsArray);
|
||||
|
||||
$('#hashtag-form').on('submit', function(e) {
|
||||
handleHashtagFormSubmit(e, hashtagsArray);
|
||||
|
|
Loading…
Reference in a new issue