Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcktip/9210265 to your computer and use it in GitHub Desktop.
Save arcktip/9210265 to your computer and use it in GitHub Desktop.
function HideCategory(id, IsAgent) {
// Function hides category
$j("div#category_" + id).hide('blind');
SetDownArrow(id, IsAgent);
$j.cookie('hide_category_' + id, 'yes', { expires: 180 });
$j("div#category_header_" + id).attr("onclick", "ShowCategory(" + id + "," +IsAgent+ ")");
};
function ShowCategory(id, IsAgent) {
// Function shows category
$j("div#category_" + id).show('blind');
SetUpArrow(id, IsAgent);
$j.cookie('hide_category_' + id, 'no', { expires: 180 });
$j("div#category_header_" + id).attr("onclick", "HideCategory(" + id + "," +IsAgent+ ")");
};
function SetUpArrow(id, IsAgent){
// Show Up arrow.
// Script uses image from Zendesk resources https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png
// Better to store it in other place
// Trick: agent's markup is different than end-users. We should insert arrow by different ways
if (IsAgent==1)
{
$j("div#category_header_" + id).children('div.category-name').css('background','#f8f8f8 url(https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png) no-repeat right 5px');
} else {
$j("div#category_header_" + id).children('div.category-header').css('background','#f8f8f8 url(https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png) no-repeat 90% 18px');
}
}
function SetDownArrow(id, IsAgent){
// Show Down arrow.
// Script uses image from Zendesk resources https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png
// Better to store it in other place
// Trick: agent's markup is different than end-users. We should insert arrow by different ways
if (IsAgent==1)
{
$j("div#category_header_" + id).children('div.category-name').css('background','#f8f8f8 url(https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png) no-repeat right -50px');
} else {
$j("div#category_header_" + id).children('div.category-header').css('background','#f8f8f8 url(https://www.zendesk.com/wp-content/themes/zendesk-twentyeleven/img/support/icons-toggle.png) no-repeat 90% -37px');
}
}
// 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') {
// Trick: replace #overview link
$j("p.forum-nav a#forum_nav_overview").attr("href","")
// Trick: replace #overview link
$j("span.follow_link").hide(); //remove follow link
// 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");
var IsAgent = 1;
if (base.length == 0) {
// Is non agent if that
base = $j(this);
IsAgent=0;
}
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.parent().attr("onclick","HideCategory(" + id_value + "," +IsAgent+ ")");
if (IsAgent==0)
{
// Trick: we should add ID because it absent in end-user markup
base.parent().attr("id","category_header_" + id_value);
}
// underline links
child.mouseover(function(){$j(this).css("text-decoration","underline")});
child.mouseleave(function(){$j(this).css("text-decoration","none")});
base.parent().css("cursor","hand");
base.parent().css("cursor","pointer");
if ($j.cookie('hide_category_' + id_value) == 'yes') {
HideCategory(id_value, IsAgent);
}else{
ShowCategory(id_value, IsAgent);
}
}
}
});
}
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