diff --git a/src/javascripts/jquery.tocify.js b/src/javascripts/jquery.tocify.js
index f464d95..eb7f80f 100644
--- a/src/javascripts/jquery.tocify.js
+++ b/src/javascripts/jquery.tocify.js
@@ -130,8 +130,11 @@
// **highlightDefault**: Accepts a boolean: true or false
// Set's the first TOC item as active if no other TOC item is active.
- highlightDefault: true
+ highlightDefault: true,
+ // **highlightSubheader**: Accepts a boolean: true or false
+ // Set's the subheader of the active TOC item as active.
+ highlightSubheader: true
},
// _Create
@@ -318,6 +321,11 @@
// Highlights the current list item that was clicked
elem.addClass(self.focusClass);
+ // If the `highlightSubheader` option is true
+ if(self.options.highlightSubheader) {
+ self._highlightSubheader(elem);
+ }
+
// If the showAndHide option is true
if(self.options.showAndHide) {
@@ -501,7 +509,7 @@
},
- // _setEventHandlers
+ // _setEventHandlers
// ----------------
// Adds jQuery event handlers to the newly generated table of contents
_setEventHandlers: function() {
@@ -530,7 +538,12 @@
self.element.find("." + self.focusClass).removeClass(self.focusClass);
// Highlights the current list item that was clicked
- $(this).addClass(self.focusClass);
+ var elem = $(this).addClass(self.focusClass);
+
+ // If the `highlightSubheader` option is true
+ if(self.options.highlightSubheader) {
+ self._highlightSubheader(elem);
+ }
// If the showAndHide option is true
if(self.options.showAndHide) {
@@ -683,6 +696,11 @@
// Highlights the corresponding list item
elem.addClass(self.focusClass);
+ // If the `highlightSubheader` option is true
+ if(self.options.highlightSubheader) {
+ self._highlightSubheader(elem);
+ }
+
}
if(self.options.scrollHistory) {
@@ -980,6 +998,23 @@
// Maintains chainability
return self;
+ },
+
+ // _highlightSubheader
+ // ---------
+ // Highlights the subheader of the active element
+ _highlightSubheader: function($elem) {
+
+ var self = this,
+ $subheader = $elem.parent(subheaderClass);
+
+ if(!!$subheader.length) {
+ $subheader.siblings(itemClass).addClass(this.focusClass);
+ }
+
+ // Maintains chainability
+ return self;
+
}
});
diff --git a/src/javascripts/jquery.tocify.min.js b/src/javascripts/jquery.tocify.min.js
index 0fc0442..40b28de 100644
--- a/src/javascripts/jquery.tocify.min.js
+++ b/src/javascripts/jquery.tocify.min.js
@@ -1,4 +1,4 @@
-/*! jquery.tocify - v1.9.0 - 2013-10-01
+/*! jquery.tocify - v1.9.0 - 2016-04-13
* http://gregfranko.com/jquery.tocify.js/
-* Copyright (c) 2013 Greg Franko; Licensed MIT*/
-(function(e){"use strict";e(window.jQuery,window,document)})(function(e,t,s){"use strict";var i="tocify",o="tocify-focus",n="tocify-hover",a="tocify-hide",l="tocify-header",h="."+l,r="tocify-subheader",d="."+r,c="tocify-item",f="."+c,u="tocify-extend-page",p="."+u;e.widget("toc.tocify",{version:"1.9.0",options:{context:"body",ignoreSelector:null,selectors:"h1, h2, h3",showAndHide:!0,showEffect:"slideDown",showEffectSpeed:"medium",hideEffect:"slideUp",hideEffectSpeed:"medium",smoothScroll:!0,smoothScrollSpeed:"medium",scrollTo:0,showAndHideOnScroll:!0,highlightOnScroll:!0,highlightOffset:40,theme:"bootstrap",extendPage:!0,extendPageOffset:100,history:!0,scrollHistory:!1,hashGenerator:"compact",highlightDefault:!0},_create:function(){var s=this;s.extendPageScroll=!0,s.items=[],s._generateToc(),s._addCSSClasses(),s.webkit=function(){for(var e in t)if(e&&-1!==e.toLowerCase().indexOf("webkit"))return!0;return!1}(),s._setEventHandlers(),e(t).load(function(){s._setActiveElement(!0),e("html, body").promise().done(function(){setTimeout(function(){s.extendPageScroll=!1},0)})})},_generateToc:function(){var t,s,o=this,n=o.options.ignoreSelector;return t=-1!==this.options.selectors.indexOf(",")?e(this.options.context).find(this.options.selectors.replace(/ /g,"").substr(0,this.options.selectors.indexOf(","))):e(this.options.context).find(this.options.selectors.replace(/ /g,"")),t.length?(o.element.addClass(i),t.each(function(t){e(this).is(n)||(s=e("
",{id:l+t,"class":l}).append(o._nestElements(e(this),t)),o.element.append(s),e(this).nextUntil(this.nodeName.toLowerCase()).each(function(){0===e(this).find(o.options.selectors).length?e(this).filter(o.options.selectors).each(function(){e(this).is(n)||o._appendSubheaders.call(this,o,s)}):e(this).find(o.options.selectors).each(function(){e(this).is(n)||o._appendSubheaders.call(this,o,s)})}))}),undefined):(o.element.addClass(a),undefined)},_setActiveElement:function(e){var s=this,i=t.location.hash.substring(1),o=s.element.find('li[data-unique="'+i+'"]');return i.length?(s.element.find("."+s.focusClass).removeClass(s.focusClass),o.addClass(s.focusClass),s.options.showAndHide&&o.click()):(s.element.find("."+s.focusClass).removeClass(s.focusClass),!i.length&&e&&s.options.highlightDefault&&s.element.find(f).first().addClass(s.focusClass)),s},_nestElements:function(t,s){var i,o,n;return i=e.grep(this.items,function(e){return e===t.text()}),i.length?this.items.push(t.text()+s):this.items.push(t.text()),n=this._generateHashValue(i,t,s),o=e("",{"class":c,"data-unique":n}).append(e("",{text:t.text()})),t.before(e("",{name:n,"data-unique":n})),o},_generateHashValue:function(e,t,s){var i="",o=this.options.hashGenerator;if("pretty"===o){for(i=t.text().toLowerCase().replace(/\s/g,"-");i.indexOf("--")>-1;)i=i.replace(/--/g,"-");for(;i.indexOf(":-")>-1;)i=i.replace(/:-/g,"-")}else i="function"==typeof o?o(t.text(),t):t.text().replace(/\s/g,"");return e.length&&(i+=""+s),i},_appendSubheaders:function(t,s){var i=e(this).index(t.options.selectors),o=e(t.options.selectors).eq(i-1),n=+e(this).prop("tagName").charAt(1),a=+o.prop("tagName").charAt(1);a>n?t.element.find(d+"[data-tag="+n+"]").last().append(t._nestElements(e(this),i)):n===a?s.find(f).last().after(t._nestElements(e(this),i)):s.find(f).last().after(e("",{"class":r,"data-tag":n})).next(d).append(t._nestElements(e(this),i))},_setEventHandlers:function(){var i=this;this.element.on("click.tocify","li",function(){if(i.options.history&&(t.location.hash=e(this).attr("data-unique")),i.element.find("."+i.focusClass).removeClass(i.focusClass),e(this).addClass(i.focusClass),i.options.showAndHide){var s=e('li[data-unique="'+e(this).attr("data-unique")+'"]');i._triggerShow(s)}i._scrollTo(e(this))}),this.element.find("li").on({"mouseenter.tocify":function(){e(this).addClass(i.hoverClass),e(this).css("cursor","pointer")},"mouseleave.tocify":function(){"bootstrap"!==i.options.theme&&e(this).removeClass(i.hoverClass)}}),(i.options.extendPage||i.options.highlightOnScroll||i.options.scrollHistory||i.options.showAndHideOnScroll)&&e(t).on("scroll.tocify",function(){e("html, body").promise().done(function(){var o,n,a,l,h=e(t).scrollTop(),r=e(t).height(),d=e(s).height(),c=e("body")[0].scrollHeight;if(i.options.extendPage&&(i.webkit&&h>=c-r-i.options.extendPageOffset||!i.webkit&&r+h>d-i.options.extendPageOffset)&&!e(p).length){if(n=e('div[data-unique="'+e(f).last().attr("data-unique")+'"]'),!n.length)return;a=n.offset().top,e(i.options.context).append(e("",{"class":u,height:Math.abs(a-h)+"px","data-unique":u})),i.extendPageScroll&&(l=i.element.find("li.active"),i._scrollTo(e('div[data-unique="'+l.attr("data-unique")+'"]')))}setTimeout(function(){var s,n=null,a=null,l=e(i.options.context).find("div[data-unique]");l.each(function(t){var s=Math.abs((e(this).next().length?e(this).next():e(this)).offset().top-h-i.options.highlightOffset);return null==n||n>s?(n=s,a=t,undefined):!1}),s=e(l[a]).attr("data-unique"),o=e('li[data-unique="'+s+'"]'),i.options.highlightOnScroll&&o.length&&(i.element.find("."+i.focusClass).removeClass(i.focusClass),o.addClass(i.focusClass)),i.options.scrollHistory&&t.location.hash!=="#"+s&&t.location.replace("#"+s),i.options.showAndHideOnScroll&&i.options.showAndHide&&i._triggerShow(o,!0)},0)})})},show:function(t){var s=this;if(!t.is(":visible"))switch(t.find(d).length||t.parent().is(h)||t.parent().is(":visible")?t.children(d).length||t.parent().is(h)||(t=t.closest(d)):t=t.parents(d).add(t),s.options.showEffect){case"none":t.show();break;case"show":t.show(s.options.showEffectSpeed);break;case"slideDown":t.slideDown(s.options.showEffectSpeed);break;case"fadeIn":t.fadeIn(s.options.showEffectSpeed);break;default:t.show()}return t.parent().is(h)?s.hide(e(d).not(t)):s.hide(e(d).not(t.closest(h).find(d).not(t.siblings()))),s},hide:function(e){var t=this;switch(t.options.hideEffect){case"none":e.hide();break;case"hide":e.hide(t.options.hideEffectSpeed);break;case"slideUp":e.slideUp(t.options.hideEffectSpeed);break;case"fadeOut":e.fadeOut(t.options.hideEffectSpeed);break;default:e.hide()}return t},_triggerShow:function(e,t){var s=this;return e.parent().is(h)||e.next().is(d)?s.show(e.next(d),t):e.parent().is(d)&&s.show(e.parent(),t),s},_addCSSClasses:function(){return"jqueryui"===this.options.theme?(this.focusClass="ui-state-default",this.hoverClass="ui-state-hover",this.element.addClass("ui-widget").find(".toc-title").addClass("ui-widget-header").end().find("li").addClass("ui-widget-content")):"bootstrap"===this.options.theme?(this.element.find(h+","+d).addClass("nav nav-list"),this.focusClass="active"):(this.focusClass=o,this.hoverClass=n),this},setOption:function(){e.Widget.prototype._setOption.apply(this,arguments)},setOptions:function(){e.Widget.prototype._setOptions.apply(this,arguments)},_scrollTo:function(t){var s=this,i=s.options.smoothScroll||0,o=s.options.scrollTo,n=e('div[data-unique="'+t.attr("data-unique")+'"]');return n.length?(e("html, body").promise().done(function(){e("html, body").animate({scrollTop:n.offset().top-(e.isFunction(o)?o.call():o)+"px"},{duration:i})}),s):s}})});
\ No newline at end of file
+* Copyright (c) 2016 Greg Franko; Licensed MIT*/
+!function(a){"use strict";a(window.jQuery,window,document)}(function(a,b,c,d){"use strict";var e="tocify",f="tocify-focus",g="tocify-hover",h="tocify-hide",i="tocify-header",j="."+i,k="tocify-subheader",l="."+k,m="tocify-item",n="."+m,o="tocify-extend-page",p="."+o;a.widget("toc.tocify",{version:"1.9.0",options:{context:"body",ignoreSelector:null,selectors:"h1, h2, h3",showAndHide:!0,showEffect:"slideDown",showEffectSpeed:"medium",hideEffect:"slideUp",hideEffectSpeed:"medium",smoothScroll:!0,smoothScrollSpeed:"medium",scrollTo:0,showAndHideOnScroll:!0,highlightOnScroll:!0,highlightOffset:40,theme:"bootstrap",extendPage:!0,extendPageOffset:100,history:!0,scrollHistory:!1,hashGenerator:"compact",highlightDefault:!0,highlightSubheader:!0},_create:function(){var c=this;c.extendPageScroll=!0,c.items=[],c._generateToc(),c._addCSSClasses(),c.webkit=function(){for(var a in b)if(a&&-1!==a.toLowerCase().indexOf("webkit"))return!0;return!1}(),c._setEventHandlers(),a(b).load(function(){c._setActiveElement(!0),a("html, body").promise().done(function(){setTimeout(function(){c.extendPageScroll=!1},0)})})},_generateToc:function(){var b,c,d=this,f=d.options.ignoreSelector;return b=-1!==this.options.selectors.indexOf(",")?a(this.options.context).find(this.options.selectors.replace(/ /g,"").substr(0,this.options.selectors.indexOf(","))):a(this.options.context).find(this.options.selectors.replace(/ /g,"")),b.length?(d.element.addClass(e),void b.each(function(b){a(this).is(f)||(c=a("",{id:i+b,"class":i}).append(d._nestElements(a(this),b)),d.element.append(c),a(this).nextUntil(this.nodeName.toLowerCase()).each(function(){0===a(this).find(d.options.selectors).length?a(this).filter(d.options.selectors).each(function(){a(this).is(f)||d._appendSubheaders.call(this,d,c)}):a(this).find(d.options.selectors).each(function(){a(this).is(f)||d._appendSubheaders.call(this,d,c)})}))})):void d.element.addClass(h)},_setActiveElement:function(a){var c=this,d=b.location.hash.substring(1),e=c.element.find('li[data-unique="'+d+'"]');return d.length?(c.element.find("."+c.focusClass).removeClass(c.focusClass),e.addClass(c.focusClass),c.options.highlightSubheader&&c._highlightSubheader(e),c.options.showAndHide&&e.click()):(c.element.find("."+c.focusClass).removeClass(c.focusClass),!d.length&&a&&c.options.highlightDefault&&c.element.find(n).first().addClass(c.focusClass)),c},_nestElements:function(b,c){var d,e,f;return d=a.grep(this.items,function(a){return a===b.text()}),d.length?this.items.push(b.text()+c):this.items.push(b.text()),f=this._generateHashValue(d,b,c),e=a("",{"class":m,"data-unique":f}).append(a("",{text:b.text()})),b.before(a("",{name:f,"data-unique":f})),e},_generateHashValue:function(a,b,c){var d="",e=this.options.hashGenerator;if("pretty"===e){for(d=b.text().toLowerCase().replace(/\s/g,"-");d.indexOf("--")>-1;)d=d.replace(/--/g,"-");for(;d.indexOf(":-")>-1;)d=d.replace(/:-/g,"-")}else d="function"==typeof e?e(b.text(),b):b.text().replace(/\s/g,"");return a.length&&(d+=""+c),d},_appendSubheaders:function(b,c){var d=a(this).index(b.options.selectors),e=a(b.options.selectors).eq(d-1),f=+a(this).prop("tagName").charAt(1),g=+e.prop("tagName").charAt(1);g>f?b.element.find(l+"[data-tag="+f+"]").last().append(b._nestElements(a(this),d)):f===g?c.find(n).last().after(b._nestElements(a(this),d)):c.find(n).last().after(a("",{"class":k,"data-tag":f})).next(l).append(b._nestElements(a(this),d))},_setEventHandlers:function(){var d=this;this.element.on("click.tocify","li",function(c){d.options.history&&(b.location.hash=a(this).attr("data-unique")),d.element.find("."+d.focusClass).removeClass(d.focusClass);var e=a(this).addClass(d.focusClass);if(d.options.highlightSubheader&&d._highlightSubheader(e),d.options.showAndHide){var e=a('li[data-unique="'+a(this).attr("data-unique")+'"]');d._triggerShow(e)}d._scrollTo(a(this))}),this.element.find("li").on({"mouseenter.tocify":function(){a(this).addClass(d.hoverClass),a(this).css("cursor","pointer")},"mouseleave.tocify":function(){"bootstrap"!==d.options.theme&&a(this).removeClass(d.hoverClass)}}),(d.options.extendPage||d.options.highlightOnScroll||d.options.scrollHistory||d.options.showAndHideOnScroll)&&a(b).on("scroll.tocify",function(){a("html, body").promise().done(function(){var e,f,g,h,i=a(b).scrollTop(),j=a(b).height(),k=a(c).height(),l=a("body")[0].scrollHeight;if(d.options.extendPage&&(d.webkit&&i>=l-j-d.options.extendPageOffset||!d.webkit&&j+i>k-d.options.extendPageOffset)&&!a(p).length){if(f=a('div[data-unique="'+a(n).last().attr("data-unique")+'"]'),!f.length)return;g=f.offset().top,a(d.options.context).append(a("",{"class":o,height:Math.abs(g-i)+"px","data-unique":o})),d.extendPageScroll&&(h=d.element.find("li.active"),d._scrollTo(a('div[data-unique="'+h.attr("data-unique")+'"]')))}setTimeout(function(){var c,f=null,g=null,h=a(d.options.context).find("div[data-unique]");h.each(function(b){var c=Math.abs((a(this).next().length?a(this).next():a(this)).offset().top-i-d.options.highlightOffset);return null==f||f>c?(f=c,void(g=b)):!1}),c=a(h[g]).attr("data-unique"),e=a('li[data-unique="'+c+'"]'),d.options.highlightOnScroll&&e.length&&(d.element.find("."+d.focusClass).removeClass(d.focusClass),e.addClass(d.focusClass),d.options.highlightSubheader&&d._highlightSubheader(e)),d.options.scrollHistory&&b.location.hash!=="#"+c&&b.location.replace("#"+c),d.options.showAndHideOnScroll&&d.options.showAndHide&&d._triggerShow(e,!0)},0)})})},show:function(b,c){var d=this;if(!b.is(":visible"))switch(b.find(l).length||b.parent().is(j)||b.parent().is(":visible")?b.children(l).length||b.parent().is(j)||(b=b.closest(l)):b=b.parents(l).add(b),d.options.showEffect){case"none":b.show();break;case"show":b.show(d.options.showEffectSpeed);break;case"slideDown":b.slideDown(d.options.showEffectSpeed);break;case"fadeIn":b.fadeIn(d.options.showEffectSpeed);break;default:b.show()}return b.parent().is(j)?d.hide(a(l).not(b)):d.hide(a(l).not(b.closest(j).find(l).not(b.siblings()))),d},hide:function(a){var b=this;switch(b.options.hideEffect){case"none":a.hide();break;case"hide":a.hide(b.options.hideEffectSpeed);break;case"slideUp":a.slideUp(b.options.hideEffectSpeed);break;case"fadeOut":a.fadeOut(b.options.hideEffectSpeed);break;default:a.hide()}return b},_triggerShow:function(a,b){var c=this;return a.parent().is(j)||a.next().is(l)?c.show(a.next(l),b):a.parent().is(l)&&c.show(a.parent(),b),c},_addCSSClasses:function(){return"jqueryui"===this.options.theme?(this.focusClass="ui-state-default",this.hoverClass="ui-state-hover",this.element.addClass("ui-widget").find(".toc-title").addClass("ui-widget-header").end().find("li").addClass("ui-widget-content")):"bootstrap"===this.options.theme?(this.element.find(j+","+l).addClass("nav nav-list"),this.focusClass="active"):(this.focusClass=f,this.hoverClass=g),this},setOption:function(){a.Widget.prototype._setOption.apply(this,arguments)},setOptions:function(){a.Widget.prototype._setOptions.apply(this,arguments)},_scrollTo:function(b){var c=this,d=c.options.smoothScroll||0,e=c.options.scrollTo,f=a('div[data-unique="'+b.attr("data-unique")+'"]');return f.length?(a("html, body").promise().done(function(){a("html, body").animate({scrollTop:f.offset().top-(a.isFunction(e)?e.call():e)+"px"},{duration:d})}),c):c},_highlightSubheader:function(a){var b=this,c=a.parent(l);return c.length&&c.siblings(n).addClass(this.focusClass),b}})});
\ No newline at end of file