From b67a494fe8b12ed45e9e3d5edbf07d70b6409e60 Mon Sep 17 00:00:00 2001 From: Brad Mallow Date: Wed, 13 Apr 2016 11:46:46 -0400 Subject: [PATCH 1/2] create new option to allow highlighting subheader --- src/javascripts/jquery.tocify.js | 41 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) 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; + } }); From c085c56f7b7c01f6c186dca5e12d6d78e0f5b918 Mon Sep 17 00:00:00 2001 From: Brad Mallow Date: Wed, 13 Apr 2016 11:50:23 -0400 Subject: [PATCH 2/2] grunt build --- src/javascripts/jquery.tocify.min.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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("