Skip to content

Commit

Permalink
Releasing Tocify v1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gfranko committed Sep 17, 2013
1 parent 3c8b12a commit a2735e0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ If you find that you need a feature that Tocify does not currently support, eith

##Change Log

`1.8.0` - September 16, 2013

- Added the **scrollHistory** option [#41](https://github.com/gfranko/jquery.tocify.js/issues/41)
- Fixed a non-linear nesting bug [#40](https://github.com/gfranko/jquery.tocify.js/issues/40)

`1.7.0` - August 13, 2013

- Improved the CSS class naming convention and implementation
Expand Down
8 changes: 7 additions & 1 deletion demos/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ <h3>Options</h3>
<td>true</td>
<td>true or false</td>
</tr>
<tr>
<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>
<td>Boolean</td>
<td>false</td>
<td>true or false</td>
</tr>
</table>
<br />
<h3>Setting Options</h3>
Expand Down Expand Up @@ -431,7 +437,7 @@ <h2>Donation</h2>
<script>
$(function() {

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

prettyPrint();
$(".optionName").popover({ trigger: "hover" });
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jquery.tocify",
"title": "jquery Tocify",
"description": "A jQuery plugin that creates a dynamic table of contents",
"version": "1.7.0",
"version": "1.8.0",
"homepage": "http://gregfranko.com/jquery.tocify.js/",
"author": {
"name": "Greg Franko",
Expand Down
45 changes: 25 additions & 20 deletions src/javascripts/jquery.tocify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* jquery Tocify - v1.7.0 - 2013-07-24
/* jquery Tocify - v1.8.0 - 2013-09-16
* http://www.gregfranko.com/jquery.tocify.js/
* Copyright (c) 2013 Greg Franko; Licensed MIT */

Expand Down Expand Up @@ -38,7 +38,7 @@
$.widget("toc.tocify", {

//Plugin version
version: "1.7.0",
version: "1.8.0",

// These options will be used as defaults
options: {
Expand Down Expand Up @@ -115,6 +115,10 @@
// Adds a hash to the page url to maintain history
history: true,

// **scrollHistory**: Accepts a boolean: true or false
// Adds a hash to the page url, to maintain history, when scrolling to a TOC item
scrollHistory: false,

// **hashGenerator**: How the hash value (the anchor segment of the URL, following the
// # character) will be generated.
//
Expand Down Expand Up @@ -643,11 +647,13 @@
// Stores the distance to the closest anchor
var closestAnchorDistance = null,

// Stores the index of the closest anchor
// Stores the index of the closest anchor
closestAnchorIdx = null,

// Keeps a reference to all anchors
anchors = $(self.options.context).find("div[data-unique]");
// Keeps a reference to all anchors
anchors = $(self.options.context).find("div[data-unique]"),

anchorText;

// Determines the index of the closest anchor
anchors.each(function(idx) {
Expand All @@ -660,8 +666,10 @@
}
});

anchorText = $(anchors[closestAnchorIdx]).attr("data-unique");

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

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

// Highlights the corresponding list item
elem.addClass(self.focusClass);

}

if(self.options.scrollHistory) {

if(window.location.hash !== anchorText) {

window.location.hash = anchorText;

}

}

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

}


}, 0);

});

});

// If the hash change event is supported
if ("onhashchange" in window) {

// Sets the onhashevent event to a function
window.onhashchange = function() {

self._setActiveElement();

};

}

},

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


}

// If the current element does not have any nested subheaders and is not a header
Expand Down
4 changes: 2 additions & 2 deletions src/javascripts/jquery.tocify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/stylesheets/Tocify/jquery.tocify.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jquery.tocify.css 1.7.0
* jquery.tocify.css 1.8.0
* Author: @gregfranko
*/

Expand Down

0 comments on commit a2735e0

Please sign in to comment.