Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Release 0.1.1

  • Loading branch information...
commit ff3b941d4709588427824e1f0a9f81b19dc271cd 1 parent fa25a28
@jgallen23 authored
View
7 History.md
@@ -1,4 +1,11 @@
+0.1.1 / 2012-10-05
+==================
+
+ * updated example
+ * code cleanup, fixed onHighlight, removed console.log
+ * Add headerText and itemClass options
+
0.1.0 / 2012-07-05
==================
View
26 dist/jquery.toc.js
@@ -1,6 +1,6 @@
/*!
* jquery.toc.js - A jQuery plugin that will automatically generate a table of contents.
- * v0.0.3
+ * v0.1.1
* https://github.com/jgallen23/toc
* copyright JGA 2012
* MIT License
@@ -86,16 +86,16 @@ $.fn.toc = function(options) {
//build TOC item
var a = $('<a/>')
- .text($h.text())
- .attr('href', '#' + opts.anchorName(i, heading, opts.prefix))
- .bind('click', function(e) {
- scrollTo(e);
- el.trigger('selected', $(this).attr('href'));
- });
+ .text(opts.headerText(i, heading, $h))
+ .attr('href', '#' + opts.anchorName(i, heading, opts.prefix))
+ .bind('click', function(e) {
+ scrollTo(e);
+ el.trigger('selected', $(this).attr('href'));
+ });
var li = $('<li/>')
- .addClass(opts.prefix+'-'+$h[0].tagName.toLowerCase())
- .append(a);
+ .addClass(opts.itemClass(i, heading, $h, opts.prefix))
+ .append(a);
ul.append(li);
});
@@ -109,11 +109,17 @@ jQuery.fn.toc.defaults = {
selectors: 'h1,h2,h3',
smoothScrolling: true,
prefix: 'toc',
- onHighlighted: function() {},
+ onHighlight: function() {},
highlightOnScroll: true,
highlightOffset: 100,
anchorName: function(i, heading, prefix) {
return prefix+i;
+ },
+ headerText: function(i, heading, $heading) {
+ return $heading.text();
+ },
+ itemClass: function(i, heading, $heading, prefix) {
+ return prefix + '-' + $heading[0].tagName.toLowerCase();
}
};
View
4 dist/jquery.toc.min.js
@@ -1,8 +1,8 @@
/*!
* jquery.toc.js - A jQuery plugin that will automatically generate a table of contents.
- * v0.0.3
+ * v0.1.1
* https://github.com/jgallen23/toc
* copyright JGA 2012
* MIT License
*/
-!function(e){e.fn.toc=function(t){var n=this,r=e.extend({},jQuery.fn.toc.defaults,t),i=e(r.container),s=e(r.selectors,i),o=[],u=r.prefix+"-active",a=function(t){for(var n=0,r=arguments.length;n<r;n++){var i=arguments[n],s=e(i);if(s.scrollTop()>0)return s;s.scrollTop(1);var o=s.scrollTop()>0;s.scrollTop(0);if(o)return s}return[]},f=a(r.container,"body","html"),l=function(t){if(r.smoothScrolling){t.preventDefault();var i=e(t.target).attr("href"),s=e(i);f.animate({scrollTop:s.offset().top},400,"swing",function(){location.hash=i})}e("li",n).removeClass(u),e(t.target).parent().addClass(u)},c,h=function(t){c&&clearTimeout(c),c=setTimeout(function(){var t=e(window).scrollTop(),i;for(var s=0,a=o.length;s<a;s++)if(o[s]>=t){e("li",n).removeClass(u),i=e("li:eq("+(s-1)+")",n).addClass(u),r.onHighlight(i);break}},50)};return r.highlightOnScroll&&(e(window).bind("scroll",h),h()),this.each(function(){var t=e(this),n=e("<ul/>");s.each(function(i,s){var u=e(s);o.push(u.offset().top-r.highlightOffset);var a=e("<span/>").attr("id",r.anchorName(i,s,r.prefix)).insertBefore(u),f=e("<a/>").text(u.text()).attr("href","#"+r.anchorName(i,s,r.prefix)).bind("click",function(n){l(n),t.trigger("selected",e(this).attr("href"))}),c=e("<li/>").addClass(r.prefix+"-"+u[0].tagName.toLowerCase()).append(f);n.append(c)}),t.html(n)})},jQuery.fn.toc.defaults={container:"body",selectors:"h1,h2,h3",smoothScrolling:!0,prefix:"toc",onHighlighted:function(){},highlightOnScroll:!0,highlightOffset:100,anchorName:function(e,t,n){return n+e}}}(jQuery)
+!function(e){e.fn.toc=function(t){var n=this,r=e.extend({},jQuery.fn.toc.defaults,t),i=e(r.container),s=e(r.selectors,i),o=[],u=r.prefix+"-active",a=function(t){for(var n=0,r=arguments.length;n<r;n++){var i=arguments[n],s=e(i);if(s.scrollTop()>0)return s;s.scrollTop(1);var o=s.scrollTop()>0;s.scrollTop(0);if(o)return s}return[]},f=a(r.container,"body","html"),l=function(t){if(r.smoothScrolling){t.preventDefault();var i=e(t.target).attr("href"),s=e(i);f.animate({scrollTop:s.offset().top},400,"swing",function(){location.hash=i})}e("li",n).removeClass(u),e(t.target).parent().addClass(u)},c,h=function(t){c&&clearTimeout(c),c=setTimeout(function(){var t=e(window).scrollTop(),i;for(var s=0,a=o.length;s<a;s++)if(o[s]>=t){e("li",n).removeClass(u),i=e("li:eq("+(s-1)+")",n).addClass(u),r.onHighlight(i);break}},50)};return r.highlightOnScroll&&(e(window).bind("scroll",h),h()),this.each(function(){var t=e(this),n=e("<ul/>");s.each(function(i,s){var u=e(s);o.push(u.offset().top-r.highlightOffset);var a=e("<span/>").attr("id",r.anchorName(i,s,r.prefix)).insertBefore(u),f=e("<a/>").text(r.headerText(i,s,u)).attr("href","#"+r.anchorName(i,s,r.prefix)).bind("click",function(n){l(n),t.trigger("selected",e(this).attr("href"))}),c=e("<li/>").addClass(r.itemClass(i,s,u,r.prefix)).append(f);n.append(c)}),t.html(n)})},jQuery.fn.toc.defaults={container:"body",selectors:"h1,h2,h3",smoothScrolling:!0,prefix:"toc",onHighlight:function(){},highlightOnScroll:!0,highlightOffset:100,anchorName:function(e,t,n){return n+e},headerText:function(e,t,n){return n.text()},itemClass:function(e,t,n,r){return r+"-"+n[0].tagName.toLowerCase()}}}(jQuery)
View
2  lib/copyright.js
@@ -1,6 +1,6 @@
/*!
* jquery.toc.js - A jQuery plugin that will automatically generate a table of contents.
- * v0.1.0
+ * v0.1.1
* https://github.com/jgallen23/toc
* copyright JGA 2012
* MIT License
Please sign in to comment.
Something went wrong with that request. Please try again.