docbrown/app/assets/javascripts/initializers/initializeBaseUserData.js
Ben Halpern 2771a2e866
Add Algolia to comments, modify button styles, add comments tab to reading list area (#32)
* Add Algolia to search and add Only My Posts filter

* Actually fix Algolia index possible issue

* Fix search issue

* Make minor adjustments to sponsorship sidebar

* Make submission rules headsup html allowed and remove devise trackable

* Remove devise_trackable from application_controller

* Adjust login CTA for /new

* Adjust string in test to reflect changes

* Quick fix for internal navigatioon draft caching issue

* Add ID to internal/articles

* Fix auth with Twitter in two places

* Added comments to algolia and modified design

* Update sidebar styles and make other small adjustments

* Clean up tag styling and other small improvements

* Finalize design adjustments

* Add indexing condition for comments

* Fix Algolia typo

* Fix Algolia indexing on comment
2018-03-04 22:25:08 -05:00

39 lines
1.9 KiB
JavaScript

function initializeBaseUserData(){
var user = userData()
var userProfileLinkHTML = '<a href="/'+user.username+'"><div class="option prime-option">@'+user.username+'</div></a>'
document.getElementById("user-profile-link-placeholder").innerHTML = userProfileLinkHTML;
document.getElementById("nav-profile-image").src = user.profile_image_90;
initializeUserSidebar(user);
}
function initializeUserSidebar(user) {
if (document.getElementById("sidebar-nav")) {
initializeUserProfileContent(user);
var tagHTML = "";
var renderedTagsCount = 0;
var followedTags = JSON.parse(user.followed_tags);
if (followedTags.length === 0) {
document.getElementById("tag-separator").innerHTML = "Follow tags to improve your feed"
}
followedTags.forEach(function(t){
renderedTagsCount++
tagHTML = tagHTML + '<div class="sidebar-nav-element" id="sidebar-element-'+t.name+'">\
<a class="sidebar-nav-link" href="/t/'+t.name+'">\
<span class="sidebar-nav-tag-text">#'+t.name+'</span>\
</a>\
</div>';
if (document.getElementById("default-sidebar-element-"+t.name)){
document.getElementById("default-sidebar-element-"+t.name).remove();
}
});
document.getElementById("sidebar-nav-followed-tags").innerHTML = tagHTML;
document.getElementById("sidebar-nav-default-tags").classList.add("showing");
}
}
function initializeUserProfileContent(user) {
document.getElementById("sidebar-profile-pic").innerHTML = '<img class="sidebar-profile-pic-img" src="'+user.profile_image_90+'" />'
document.getElementById("sidebar-profile-name").innerHTML = user.name
document.getElementById("sidebar-profile-username").innerHTML = '@'+user.username
document.getElementById("sidebar-profile-snapshot-inner").href = "/"+user.username;
}