Skip to content

Commit a2735e0

Browse files
committed
Releasing Tocify v1.8.0
1 parent 3c8b12a commit a2735e0

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
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.8.0` - September 16, 2013
58+
59+
- Added the **scrollHistory** option [#41](https://github.com/gfranko/jquery.tocify.js/issues/41)
60+
- Fixed a non-linear nesting bug [#40](https://github.com/gfranko/jquery.tocify.js/issues/40)
61+
5762
`1.7.0` - August 13, 2013
5863

5964
- Improved the CSS class naming convention and implementation

demos/default.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ <h3>Options</h3>
322322
<td>true</td>
323323
<td>true or false</td>
324324
</tr>
325+
<tr>
326+
<td class="optionName" title="scrollHistory" data-content="Adds a hash to the page url, to maintain history, when scrolling to a TOC item."><a href="#">scrollHistory</a></td>
327+
<td>Boolean</td>
328+
<td>false</td>
329+
<td>true or false</td>
330+
</tr>
325331
</table>
326332
<br />
327333
<h3>Setting Options</h3>
@@ -431,7 +437,7 @@ <h2>Donation</h2>
431437
<script>
432438
$(function() {
433439

434-
var toc = $("#toc").tocify({ selectors: "h2,h3,h4,h5" }).data("toc-tocify");
440+
var toc = $("#toc").tocify({ selectors: "h2,h3,h4,h5", scrollHistory: true }).data("toc-tocify");
435441

436442
prettyPrint();
437443
$(".optionName").popover({ trigger: "hover" });

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.7.0",
5+
"version": "1.8.0",
66
"homepage": "http://gregfranko.com/jquery.tocify.js/",
77
"author": {
88
"name": "Greg Franko",

src/javascripts/jquery.tocify.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* jquery Tocify - v1.7.0 - 2013-07-24
1+
/* jquery Tocify - v1.8.0 - 2013-09-16
22
* http://www.gregfranko.com/jquery.tocify.js/
33
* Copyright (c) 2013 Greg Franko; Licensed MIT */
44

@@ -38,7 +38,7 @@
3838
$.widget("toc.tocify", {
3939

4040
//Plugin version
41-
version: "1.7.0",
41+
version: "1.8.0",
4242

4343
// These options will be used as defaults
4444
options: {
@@ -115,6 +115,10 @@
115115
// Adds a hash to the page url to maintain history
116116
history: true,
117117

118+
// **scrollHistory**: Accepts a boolean: true or false
119+
// Adds a hash to the page url, to maintain history, when scrolling to a TOC item
120+
scrollHistory: false,
121+
118122
// **hashGenerator**: How the hash value (the anchor segment of the URL, following the
119123
// # character) will be generated.
120124
//
@@ -643,11 +647,13 @@
643647
// Stores the distance to the closest anchor
644648
var closestAnchorDistance = null,
645649

646-
// Stores the index of the closest anchor
650+
// Stores the index of the closest anchor
647651
closestAnchorIdx = null,
648652

649-
// Keeps a reference to all anchors
650-
anchors = $(self.options.context).find("div[data-unique]");
653+
// Keeps a reference to all anchors
654+
anchors = $(self.options.context).find("div[data-unique]"),
655+
656+
anchorText;
651657

652658
// Determines the index of the closest anchor
653659
anchors.each(function(idx) {
@@ -660,8 +666,10 @@
660666
}
661667
});
662668

669+
anchorText = $(anchors[closestAnchorIdx]).attr("data-unique");
670+
663671
// Stores the list item HTML element that corresponds to the currently traversed anchor tag
664-
elem = $('li[data-unique="' + $(anchors[closestAnchorIdx]).attr("data-unique") + '"]');
672+
elem = $('li[data-unique="' + anchorText + '"]');
665673

666674
// If the `highlightOnScroll` option is true and a next element is found
667675
if(self.options.highlightOnScroll && elem.length) {
@@ -671,6 +679,17 @@
671679

672680
// Highlights the corresponding list item
673681
elem.addClass(self.focusClass);
682+
683+
}
684+
685+
if(self.options.scrollHistory) {
686+
687+
if(window.location.hash !== anchorText) {
688+
689+
window.location.hash = anchorText;
690+
691+
}
692+
674693
}
675694

676695
// If the `showAndHideOnScroll` option is true
@@ -680,25 +699,12 @@
680699

681700
}
682701

683-
684702
}, 0);
685703

686704
});
687705

688706
});
689707

690-
// If the hash change event is supported
691-
if ("onhashchange" in window) {
692-
693-
// Sets the onhashevent event to a function
694-
window.onhashchange = function() {
695-
696-
self._setActiveElement();
697-
698-
};
699-
700-
}
701-
702708
},
703709

704710
// Show
@@ -719,7 +725,6 @@
719725
// Sets the current element to all of the subheaders within the current header
720726
elem = elem.parents(subheaderClass).add(elem);
721727

722-
723728
}
724729

725730
// If the current element does not have any nested subheaders and is not a header

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.

src/stylesheets/Tocify/jquery.tocify.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jquery.tocify.css 1.7.0
2+
* jquery.tocify.css 1.8.0
33
* Author: @gregfranko
44
*/
55

0 commit comments

Comments
 (0)