-
Notifications
You must be signed in to change notification settings - Fork 1
/
breadcrumb.min.js
1 lines (1 loc) · 2.5 KB
/
breadcrumb.min.js
1
var host=$(location).attr("host");function remapBreadcrumb(breadcrumb){new_breadcrumb_html="";for(var i=0;i<breadcrumb.length;i++){url_category=[];for(var j=0;j<=i;j++)url_category[j]=breadcrumb[j];var category_url="https://"+host+"/archive/category/"+url_category.join("-");new_breadcrumb_html+='<span class="breadcrumb-child""><a class="breadcrumb-child-link" href="'+category_url+'"><span>'+breadcrumb[i]+"</span></a></span>",i+1<breadcrumb.length&&(new_breadcrumb_html+='<span class="breadcrumb-gt"> ></span>')}""!=new_breadcrumb_html&&$("#top-box > div.breadcrumb > div.breadcrumb-inner > span.breadcrumb-child:first").prop("outerHTML",new_breadcrumb_html)}function remapArticleCategory(categories){for(var index=0;void 0!==categories[index+1]&&categories[index+1].text.includes("-");)index+=1;breadcrumb_array=categories[index].text.split("-"),remapBreadcrumb(breadcrumb_array),category_num=categories.length;for(var i=0;i<category_num;i++)category_branch=categories[i].text.split("-"),categories[i].text=category_branch[category_branch.length-1]}function remapCategoryBreadcrumb(breadcrumb){new_breadcrumb_html="";for(var i=0;i<breadcrumb.length;i++)if(i+1<breadcrumb.length){url_category=[];for(var j=0;j<=i;j++)url_category[j]=breadcrumb[j];var category_url="https://"+host+"/archive/category/"+url_category.join("-");new_breadcrumb_html+='<span class="breadcrumb-child"><a class="breadcrumb-child-link" href="'+category_url+'">'+breadcrumb[i]+"</span></a></span>",new_breadcrumb_html+='<span class="breadcrumb-gt"> ></span>'}else new_breadcrumb_html+='<span class="breadcrumb-child">'+breadcrumb[i]+"</span>";""!=new_breadcrumb_html&&$("#top-box > div.breadcrumb > div.breadcrumb-inner > span.breadcrumb-child:first").prop("outerHTML",new_breadcrumb_html)}function remapArchiveCategory(categories){for(var i=0;i<categories.length;i++)category_branch=categories[i].text.split("-"),categories[i].text=category_branch[category_branch.length-1]}$(document).ready(function(){var $entry_categories=$("#main-inner > article.entry > div.entry-inner > header > div.entry-categories > a");0<$entry_categories.length&&remapArticleCategory($entry_categories);var $archive_entries=$("#main-inner > div.archive-entries");0<$archive_entries.length&&($breadcrumb_child=$("#top-box > div.breadcrumb > div.breadcrumb-inner > span.breadcrumb-child:first"),breadcrumbs=$breadcrumb_child.find("span").text().split("-"),remapCategoryBreadcrumb(breadcrumbs),$archive_entries.each(function(){remapArchiveCategory($(this).find("section > div.categories > a"))}))});