Skip to content

Instantly share code, notes, and snippets.

@Mikhail-Zakharov
Created August 25, 2012 12:51
Show Gist options
  • Save Mikhail-Zakharov/3465199 to your computer and use it in GitHub Desktop.
Save Mikhail-Zakharov/3465199 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 id = $j(this).attr("id")
var id_splitted = id.split("_");
var id_value = id_splitted[2];
$j(this).children(".category-name").children().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