Skip to content

Commit 82a1122

Browse files
committed
Releasing Tocify v1.6.0
1 parent 449a048 commit 82a1122

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

README.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ If you find that you need a feature that Tocify does not currently support, eith
5454

5555
##Change Log
5656

57+
`1.6.0` - July 24, 2013
58+
59+
- Updated the **scrollTo** option to accept a function [#33](https://github.com/gfranko/jquery.tocify.js/issues/33)
60+
- Improved scroll highlighting accuracy [#33](https://github.com/gfranko/jquery.tocify.js/issues/33) [#34](https://github.com/gfranko/jquery.tocify.js/issues/34) Special thanks to [Andre Kampert](https://github.com/andrekampert) for this improvement
61+
5762
`1.5.0` - July 5, 2013
5863

5964
- Added **ignoreSelector** option[#27](https://github.com/gfranko/jquery.tocify.js/issues/27)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jquery.tocify",
33
"title": "jquery Tocify",
44
"description": "A jQuery plugin that creates a dynamic table of contents",
5-
"version": "1.5.0",
5+
"version": "1.6.0",
66
"homepage": "http://gregfranko.com/jquery.tocify.js/",
77
"author": {
88
"name": "Greg Franko",

src/javascripts/jquery.tocify.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* jquery Tocify - v1.5.0 - 2012-04-07
1+
/* jquery Tocify - v1.6.0 - 2013-07-24
22
* http://www.gregfranko.com/jquery.tocify.js/
3-
* Copyright (c) 2012 Greg Franko; Licensed MIT */
3+
* Copyright (c) 2013 Greg Franko; Licensed MIT */
44

55
// Immediately-Invoked Function Expression (IIFE) [Ben Alman Blog Post](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) that calls another IIFE that contains all of the plugin logic. I used this pattern so that anyone viewing this code would not have to scroll to the bottom of the page to view the local parameters that were passed to the main IIFE.
66
(function(tocify) {
@@ -23,7 +23,7 @@
2323
$.widget("toc.tocify", {
2424

2525
//Plugin version
26-
version: "1.5.0",
26+
version: "1.6.0",
2727

2828
// These options will be used as defaults
2929
options: {
@@ -626,14 +626,14 @@
626626

627627
// Determines the index of the closest anchor
628628
anchors.each(function(idx) {
629-
var distance = Math.abs($(this).next().offset().top - winScrollTop - self.options.highlightOffset);
629+
var distance = Math.abs(($(this).next().length ? $(this).next() : $(this)).offset().top - winScrollTop - self.options.highlightOffset);
630630
if (closestAnchorDistance == null || distance < closestAnchorDistance) {
631631
closestAnchorDistance = distance;
632632
closestAnchorIdx = idx;
633633
} else {
634634
return false;
635635
}
636-
})
636+
});
637637

638638
// Stores the list item HTML element that corresponds to the currently traversed anchor tag
639639
elem = $('li[data-unique="' + $(anchors[closestAnchorIdx]).attr("data-unique") + '"]');
@@ -916,7 +916,8 @@
916916
_scrollTo: function(elem) {
917917

918918
var self = this,
919-
duration = self.options.smoothScroll || 0;
919+
duration = self.options.smoothScroll || 0,
920+
scrollTo = self.options.scrollTo;
920921

921922
// Once all animations on the page are complete, this callback function will be called
922923
$("html, body").promise().done(function() {
@@ -925,7 +926,7 @@
925926
$("html, body").animate({
926927

927928
// Sets the jQuery `scrollTop` to the top offset of the HTML div tag that matches the current list item's `data-unique` tag
928-
"scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').offset().top - self.options.scrollTo + "px"
929+
"scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px"
929930

930931
}, {
931932

@@ -943,4 +944,4 @@
943944

944945
});
945946

946-
})); //end of plugin
947+
})); //end of plugin

src/javascripts/jquery.tocify.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)