Skip to content
This repository was archived by the owner on Sep 26, 2024. It is now read-only.

Commit bc79a65

Browse files
committed
More changes
1 parent 6c077ba commit bc79a65

File tree

8 files changed

+159
-56
lines changed

8 files changed

+159
-56
lines changed

config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
set :markdown_engine, :redcarpet
5252

53-
set :markdown, :fenced_code_blocks => true, :smartypants => true, :disable_indented_code_blocks => true, :prettify => true, :with_toc_data => true, :tables => true
53+
set :markdown, :fenced_code_blocks => true, :smartypants => true, :disable_indented_code_blocks => true, :prettify => true, :tables => true
5454

5555
# Activate the syntax highlighter
5656
activate :syntax

source/images/logo.png

4.87 KB
Loading
4.88 KB
Loading

source/javascripts/jquery.tocify.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* jquery Tocify - v1.8.0 - 2013-09-16
22
* http://www.gregfranko.com/jquery.tocify.js/
3-
* Copyright (c) 2013 Greg Franko; Licensed MIT */
3+
* Copyright (c) 2013 Greg Franko; Licensed MIT
4+
* Modified lightly by Robert Lord to fix a bug I found,
5+
* and also so it adds ids to headers
6+
* also because I want height caching, since the
7+
* height lookup for h1s and h2s was causing serious
8+
* lag spikes below 30 fps */
49

510
// 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.
611
(function(tocify) {
@@ -149,6 +154,10 @@
149154
// Generates the HTML for the dynamic table of contents
150155
self._generateToc();
151156

157+
// Caches heights and anchors
158+
self.cachedHeights = [],
159+
self.cachedAnchors = [];
160+
152161
// Adds CSS classes to the newly generated table of contents HTML
153162
self._addCSSClasses();
154163

@@ -377,6 +386,10 @@
377386

378387
hashValue = this._generateHashValue(arr, self, index);
379388

389+
// ADDED BY ROBERT
390+
// actually add the hash value to the element's id
391+
self.attr("id", "link-" + hashValue);
392+
380393
// Appends a list item HTML element to the last unordered list HTML element found within the HTML element calling the plugin
381394
item = $("<li/>", {
382395

@@ -414,10 +427,16 @@
414427
hashGeneratorOption = this.options.hashGenerator;
415428

416429
if (hashGeneratorOption === "pretty") {
430+
// remove weird characters
431+
417432

418433
// prettify the text
419434
hashValue = self.text().toLowerCase().replace(/\s/g, "-");
420435

436+
// ADDED BY ROBERT
437+
// remove weird characters
438+
hashValue = hashValue.replace(/[^\x00-\x7F]/g, "");
439+
421440
// fix double hyphens
422441
while (hashValue.indexOf("--") > -1) {
423442
hashValue = hashValue.replace(/--/g, "-");
@@ -645,28 +664,22 @@
645664
// _Local variables_
646665

647666
// Stores the distance to the closest anchor
648-
var closestAnchorDistance = null,
649-
650-
// Stores the index of the closest anchor
667+
var // Stores the index of the closest anchor
651668
closestAnchorIdx = null,
652-
653-
// Keeps a reference to all anchors
654-
anchors = $(self.options.context).find("div[data-unique]"),
655-
656669
anchorText;
657670

671+
self.calculateHeights();
672+
658673
// Determines the index of the closest anchor
659-
anchors.each(function(idx) {
660-
var distance = /*Math.abs*/(($(this).next().length ? $(this).next() : $(this)).offset().top - winScrollTop - self.options.highlightOffset);
661-
if (distance < 0) {
662-
closestAnchorDistance = distance;
674+
self.cachedAnchors.each(function(idx) {
675+
if (self.cachedHeights[idx] - $(window).scrollTop() < 0) {
663676
closestAnchorIdx = idx;
664677
} else {
665678
return false;
666679
}
667680
});
668681

669-
anchorText = $(anchors[closestAnchorIdx]).attr("data-unique");
682+
anchorText = $(self.cachedAnchors[closestAnchorIdx]).attr("data-unique");
670683

671684
// Stores the list item HTML element that corresponds to the currently traversed anchor tag
672685
elem = $('li[data-unique="' + anchorText + '"]');
@@ -684,9 +697,9 @@
684697

685698
if(self.options.scrollHistory) {
686699

687-
if(window.location.hash !== anchorText) {
700+
if(window.location.hash !== "#" + anchorText) {
688701

689-
window.location.hash = anchorText;
702+
window.location.replace("#" + anchorText);
690703

691704
}
692705

@@ -707,6 +720,23 @@
707720

708721
},
709722

723+
// calculateHeights
724+
// ----
725+
// ADDED BY ROBERT
726+
calculateHeights: function() {
727+
var self = this;
728+
if (self.cachedHeights.length == 0) {
729+
self.cachedHeights = [];
730+
self.cachedAnchors = [];
731+
var anchors = $(self.options.context).find("div[data-unique]");
732+
anchors.each(function(idx) {
733+
var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset);
734+
self.cachedHeights[idx] = distance;
735+
});
736+
self.cachedAnchors = anchors;
737+
}
738+
},
739+
710740
// Show
711741
// ----
712742
// Opens the current sub-header
@@ -956,7 +986,7 @@
956986
$("html, body").animate({
957987

958988
// Sets the jQuery `scrollTop` to the top offset of the HTML div tag that matches the current list item's `data-unique` tag
959-
"scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px"
989+
"scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').next().offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px"
960990

961991
}, {
962992

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1+
languages = []
12
function activateLanguage(language) {
23
$("#lang-selector a").removeClass('active');
34
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
4-
$(".highlight").hide();
5+
for (var i=0; i < languages.length; i++) {
6+
$(".highlight." + languages[i]).hide();
7+
}
58
$(".highlight." + language).show();
6-
$(".highlight.text").show(); // always show text
79
}
810

9-
function setupLanguages(languages) {
11+
function setupLanguages(l) {
12+
languages = l;
1013
currentLanguage = languages[0];
1114

12-
activateLanguage(languages[0]);
15+
if (location.search.substr(1) != "") {
16+
activateLanguage(location.search.substr(1));
17+
} else {
18+
activateLanguage(languages[0]);
19+
}
1320

1421
$("#lang-selector a").bind("click", function() {
1522
activateLanguage($(this).data("language-name"));
1623
return false;
1724
});
1825

1926
}
27+

source/layouts/layout.erb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<script>
1717
$(function() {
18-
$("#toc").tocify({
18+
var toc = $("#toc").tocify({
1919
selectors: "h1,h2",
2020
extendPage: false,
2121
theme: "none",
@@ -25,11 +25,12 @@
2525
ignoreSelector: ".toc-ignore",
2626
hashGenerator: 'pretty',
2727
highlightOffset: 60,
28+
scrollTo: -2,
2829
scrollHistory: true
2930
});
3031
setupLanguages([
3132
<% current_page.data.languages.each do |lang| %>
32-
['<%= lang %>'],
33+
['<%= lang[0] %>'],
3334
<% end %>
3435
]);
3536
});
@@ -38,20 +39,18 @@
3839

3940
<body class="<%= page_classes %>">
4041
<div id="toc">
41-
<div class="toc-bottom">
42-
<%= current_page.data.external_links %>
43-
</div>
42+
<%= image_tag "logo.png" %>
4443
<!-- table of contents will be inserted here -->
4544
</div>
4645
<div class="page-wrapper">
4746
<div class="content">
48-
<h1 id="bigtitle" class="bigtitle toc-ignore"><%= current_page.data.title || "API Documentation" %></h1>
47+
<!-- <h1 id="bigtitle" class="bigtitle toc-ignore"><%= current_page.data.title || "API Documentation" %></h1> -->
4948
<%= yield %>
5049
</div>
5150
<div class="dark-box">
5251
<div id="lang-selector">
5352
<% current_page.data.languages.each do |lang| %>
54-
<a href="#" data-language-name="<%= lang %>"><%= lang %></a>
53+
<a href="#" data-language-name="<%= lang[0] %>"><%= lang[1] %></a>
5554
<% end %>
5655
</div>
5756
</div>

0 commit comments

Comments
 (0)