Skip to content

Commit

Permalink
bump to v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Jan 9, 2019
1 parent b597909 commit 38badd1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
30 changes: 15 additions & 15 deletions dist/bootstrap-toc.css
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*!
* Bootstrap Table of Contents v1.0.0 (http://afeld.github.io/bootstrap-toc/)
* Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/)
* Copyright 2015 Aidan Feldman
* Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */

/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */

/* All levels of nav */
nav[data-toggle='toc'] .nav > li > a {
nav[data-toggle="toc"] .nav > li > a {
display: block;
padding: 4px 20px;
font-size: 13px;
font-weight: 500;
color: #767676;
}
nav[data-toggle='toc'] .nav > li > a:hover,
nav[data-toggle='toc'] .nav > li > a:focus {
nav[data-toggle="toc"] .nav > li > a:hover,
nav[data-toggle="toc"] .nav > li > a:focus {
padding-left: 19px;
color: #563d7c;
text-decoration: none;
background-color: transparent;
border-left: 1px solid #563d7c;
}
nav[data-toggle='toc'] .nav-link.active,
nav[data-toggle='toc'] .nav-link.active:hover,
nav[data-toggle='toc'] .nav-link.active:focus {
nav[data-toggle="toc"] .nav-link.active,
nav[data-toggle="toc"] .nav-link.active:hover,
nav[data-toggle="toc"] .nav-link.active:focus {
padding-left: 18px;
font-weight: bold;
color: #563d7c;
Expand All @@ -32,29 +32,29 @@ nav[data-toggle='toc'] .nav-link.active:focus {
}

/* Nav: second level (shown on .active) */
nav[data-toggle='toc'] .nav-link + ul {
nav[data-toggle="toc"] .nav-link + ul {
display: none; /* Hide by default, but at >768px, show it */
padding-bottom: 10px;
}

nav[data-toggle='toc'] .nav .nav > li > a {
nav[data-toggle="toc"] .nav .nav > li > a {
padding-top: 1px;
padding-bottom: 1px;
padding-left: 30px;
font-size: 12px;
font-weight: normal;
}
nav[data-toggle='toc'] .nav .nav > li > a:hover,
nav[data-toggle='toc'] .nav .nav > li > a:focus {
nav[data-toggle="toc"] .nav .nav > li > a:hover,
nav[data-toggle="toc"] .nav .nav > li > a:focus {
padding-left: 29px;
}
nav[data-toggle='toc'] .nav .nav > li > .active,
nav[data-toggle='toc'] .nav .nav > li > .active:hover,
nav[data-toggle='toc'] .nav .nav > li > .active:focus {
nav[data-toggle="toc"] .nav .nav > li > .active,
nav[data-toggle="toc"] .nav .nav > li > .active:hover,
nav[data-toggle="toc"] .nav .nav > li > .active:focus {
padding-left: 28px;
font-weight: 500;
}

nav[data-toggle='toc'] .nav-link.active + ul {
nav[data-toggle="toc"] .nav-link.active + ul {
display: block;
}
49 changes: 35 additions & 14 deletions dist/bootstrap-toc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* Bootstrap Table of Contents v1.0.0 (http://afeld.github.io/bootstrap-toc/)
* Bootstrap Table of Contents v1.0.1 (http://afeld.github.io/bootstrap-toc/)
* Copyright 2015 Aidan Feldman
* Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
(function($) {
'use strict';
"use strict";

window.Toc = {
helpers: {
Expand All @@ -12,13 +12,34 @@
// http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/
// http://stackoverflow.com/a/12731439/358804
var $descendants = $el.find(selector);
return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])');
return $el
.filter(selector)
.add($descendants)
.filter(":not([data-toc-skip])");
},

generateUniqueIdBase: function(el) {
var text = $(el).text();
var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-');
return anchor || el.tagName.toLowerCase();

// adapted from
// https://github.com/bryanbraun/anchorjs/blob/65fede08d0e4a705f72f1e7e6284f643d5ad3cf3/anchor.js#L237-L257

// Regex for finding the non-safe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\ (newlines, tabs, backspace, & vertical tabs)
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v]/g,
urlText;

// Note: we trim hyphens after truncating because truncating can cause dangling hyphens.
// Example string: // " ⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
urlText = text
.trim() // "⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(/\'/gi, "") // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(nonsafeChars, "-") // "⚡⚡-Dont-forget--URL-fragments-should-be-i18n-friendly--hyphenated--short--and-clean-"
.replace(/-{2,}/g, "-") // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-short-and-clean-"
.substring(0, 64) // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-"
.replace(/^-+|-+$/gm, "") // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated"
.toLowerCase(); // "⚡⚡-dont-forget-url-fragments-should-be-i18n-friendly-hyphenated"

return urlText || el.tagName.toLowerCase();
},

generateUniqueId: function(el) {
Expand All @@ -27,7 +48,7 @@
var anchor = anchorBase;
if (i > 0) {
// add suffix
anchor += '-' + i;
anchor += "-" + i;
}
// check if ID already exists
if (!document.getElementById(anchor)) {
Expand Down Expand Up @@ -58,24 +79,24 @@

generateNavEl: function(anchor, text) {
var $a = $('<a class="nav-link"></a>');
$a.attr('href', '#' + anchor);
$a.attr("href", "#" + anchor);
$a.text(text);
var $li = $('<li></li>');
var $li = $("<li></li>");
$li.append($a);
return $li;
},

generateNavItem: function(headingEl) {
var anchor = this.generateAnchor(headingEl);
var $heading = $(headingEl);
var text = $heading.data('toc-text') || $heading.text();
var text = $heading.data("toc-text") || $heading.text();
return this.generateNavEl(anchor, text);
},

// Find the first heading level (`<h1>`, then `<h2>`, etc.) that has more than one element. Defaults to 1 (for `<h1>`).
getTopLevel: function($scope) {
for (var i = 1; i <= 6; i++) {
var $headings = this.findOrFilter($scope, 'h' + i);
var $headings = this.findOrFilter($scope, "h" + i);
if ($headings.length > 1) {
return i;
}
Expand All @@ -86,12 +107,12 @@

// returns the elements for the top level, and the next below it
getHeadings: function($scope, topLevel) {
var topSelector = 'h' + topLevel;
var topSelector = "h" + topLevel;

var secondaryLevel = topLevel + 1;
var secondarySelector = 'h' + secondaryLevel;
var secondarySelector = "h" + secondaryLevel;

return this.findOrFilter($scope, topSelector + ',' + secondarySelector);
return this.findOrFilter($scope, topSelector + "," + secondarySelector);
},

getNavLevel: function(el) {
Expand Down Expand Up @@ -141,7 +162,7 @@
opts = this.helpers.parseOps(opts);

// ensure that the data attribute is in place for styling
opts.$nav.attr('data-toggle', 'toc');
opts.$nav.attr("data-toggle", "toc");

var $topContext = this.helpers.createChildNavList(opts.$nav);
var topLevel = this.helpers.getTopLevel(opts.$scope);
Expand Down
2 changes: 1 addition & 1 deletion dist/bootstrap-toc.min.css

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

4 changes: 2 additions & 2 deletions dist/bootstrap-toc.min.js

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

4 changes: 2 additions & 2 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ This page is an example of the plugin in action – the table of contents you se
<!-- add after bootstrap.min.css -->
<link
rel="stylesheet"
href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.0/dist/bootstrap-toc.min.css"
href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.css"
/>
<!-- add after bootstrap.min.js -->
<script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.0/dist/bootstrap-toc.min.js"></script>
<script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script>
```

1. Pick one of the two options below.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-toc",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"test": "gulp test"
Expand Down

0 comments on commit 38badd1

Please sign in to comment.