Last active
March 4, 2018 03:42
-
-
Save toru-takahashi/e53205813986ed99e47102a9b882056d to your computer and use it in GitHub Desktop.
Articles in Category for Zendesk Guide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// For Articles in Category | |
if(document.URL.match(/\/articles\//)) { | |
var category_id = $(".breadcrumbs li:nth-child(2) a").attr("href").match(/[0-9]+/); | |
var locale = window.location.pathname.split('/')[2]; | |
var Zendesk = { | |
sections: function(category_id) { | |
var defer = $.Deferred(); | |
$.ajax({ | |
url: "/api/v2/help_center/"+locale+"/categories/"+ category_id +"/sections.json?include=translations", | |
type: "GET", | |
localCache: true, | |
cacheTTL: 24, | |
cacheKey: locale+category_id, | |
dataType: 'json', | |
success: defer.resolve, | |
error: defer.reject | |
}); | |
return defer.promise(); | |
}, | |
articles: function(section_id) { | |
var defer = $.Deferred(); | |
$.ajax({ | |
url: "/api/v2/help_center/"+locale+"/sections/"+ section_id +"/articles.json", | |
type: "GET", | |
localCache: true, | |
cacheTTL: 24, | |
cacheKey: locale+section_id, | |
dataType: 'json', | |
success: defer.resolve, | |
error: defer.reject | |
}); | |
return defer.promise(); | |
} | |
}; | |
Zendesk.sections(category_id).done(function(category) { | |
$.each(category.sections, function(i,v){ | |
// Section is hidden? | |
var hidden = true; | |
v.translations.filter(function(translation, index){ | |
if (translation.locale == locale && translation.hidden == true) { | |
hidden = true; | |
} else if(translation.locale == locale && translation.hidden == false) { | |
hidden = false; | |
} | |
}); | |
if (hidden) return true; | |
$('#siderbar-articles-in-category').append('<h3 id='+v.id+'><a href='+v.html_url+' class="collapsible-sidebar-title sidenav-title">'+v.name+'</a></h3>'); | |
Zendesk.articles(v.id).done(function(section) { | |
var nesting = $("<ul>"); | |
$.each(section.articles, function(j,x){ | |
if (x.draft) { | |
return true; | |
} | |
nesting.append('<li id='+x.id+'><a href='+x.html_url+' class="sidenav-item '+ (x.html_url==window.location ? "current-article" : "") +'">'+x.name+'</a></li>'); | |
}); | |
$('#siderbar-articles-in-category > #'+v.id).append(nesting); | |
}); | |
}); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media (min-width: 1024px) { | |
.article-sidebar { | |
border: 0; | |
flex: 0 0 20%; | |
height: 1200px; | |
overflow: hidden; | |
overflow-y: scroll; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment