Skip to content

Instantly share code, notes, and snippets.

@Mikhail-Zakharov
Last active December 28, 2015 20:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Mikhail-Zakharov/3465257 to your computer and use it in GitHub Desktop.
Save Mikhail-Zakharov/3465257 to your computer and use it in GitHub Desktop.
Zendesk categories collapse widget
function HideCategory(id) {
$j("div#category_" + id).hide();
$j.cookie('hide_category_' + id, 'yes', { expires: 180 });
$j('span#hide_category_' + id).attr("onclick", "ShowCategory(" + id + ")");
$j('span#hide_category_' + id).text("[+]");
};
function ShowCategory(id) {
$j("div#category_" + id).show();
$j.cookie('hide_category_' + id, 'no', { expires: 180 });
$j('span#hide_category_' + id).attr("onclick", "HideCategory(" + id + ")");
$j('span#hide_category_' + id).text("[-]");
};
// Get current url
var s_url = window.location.pathname;
var s_urlparts = s_url.split('/');
var s_section = s_urlparts[1];
// Run if we in the "forums" section
if (s_section == 'forums' || s_section == 'home') {
// Get all sections from page
var cat_headers = $j("div.category-header");
$j.each(cat_headers, function () {
var base = $j(this).children("div.category-name");
if (base.length == 0) {
// Is non agent if that
base = $j(this);
}
var child = base.children("h2").children("a");
if (child.length != 0) {
// "0" means No Category Section
var id = child.attr("href")
var id_splitted = id.split("/");
if (id_splitted.length == 3) {
var id_value = id_splitted[2].split("-")[0];
base.children('h2').append("&nbsp;<span style='font-size: 13pt; cursor: hand; cursor: pointer;' id='hide_category_" + id_value + "' href='#' onclick='HideCategory(" + id_value + ")'>[-]</span>");
if ($j.cookie('hide_category_' + id_value) == 'yes') {
HideCategory(id_value);
}
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment