diff --git a/config.rb b/config.rb index a35eb15..d92c30e 100644 --- a/config.rb +++ b/config.rb @@ -50,7 +50,7 @@ set :images_dir, 'images' set :markdown_engine, :redcarpet -set :markdown, :fenced_code_blocks => true, :smartypants => true, :disable_indented_code_blocks => true, :prettify => true, :with_toc_data => true, :tables => true +set :markdown, :fenced_code_blocks => true, :smartypants => true, :disable_indented_code_blocks => true, :prettify => true, :tables => true # Activate the syntax highlighter activate :syntax diff --git a/source/images/logo.png b/source/images/logo.png new file mode 100644 index 0000000..abed9a7 Binary files /dev/null and b/source/images/logo.png differ diff --git a/source/images/tripit_72dpi_250px.png b/source/images/tripit_72dpi_250px.png new file mode 100644 index 0000000..900edb5 Binary files /dev/null and b/source/images/tripit_72dpi_250px.png differ diff --git a/source/javascripts/jquery.tocify.js b/source/javascripts/jquery.tocify.js index 3a451d0..1c6edf0 100644 --- a/source/javascripts/jquery.tocify.js +++ b/source/javascripts/jquery.tocify.js @@ -1,6 +1,11 @@ /* jquery Tocify - v1.8.0 - 2013-09-16 * http://www.gregfranko.com/jquery.tocify.js/ -* Copyright (c) 2013 Greg Franko; Licensed MIT */ +* Copyright (c) 2013 Greg Franko; Licensed MIT +* Modified lightly by Robert Lord to fix a bug I found, +* and also so it adds ids to headers +* also because I want height caching, since the +* height lookup for h1s and h2s was causing serious +* lag spikes below 30 fps */ // 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. (function(tocify) { @@ -149,6 +154,10 @@ // Generates the HTML for the dynamic table of contents self._generateToc(); + // Caches heights and anchors + self.cachedHeights = [], + self.cachedAnchors = []; + // Adds CSS classes to the newly generated table of contents HTML self._addCSSClasses(); @@ -377,6 +386,10 @@ hashValue = this._generateHashValue(arr, self, index); + // ADDED BY ROBERT + // actually add the hash value to the element's id + self.attr("id", "link-" + hashValue); + // Appends a list item HTML element to the last unordered list HTML element found within the HTML element calling the plugin item = $("
  • ", { @@ -414,10 +427,16 @@ hashGeneratorOption = this.options.hashGenerator; if (hashGeneratorOption === "pretty") { + // remove weird characters + // prettify the text hashValue = self.text().toLowerCase().replace(/\s/g, "-"); + // ADDED BY ROBERT + // remove weird characters + hashValue = hashValue.replace(/[^\x00-\x7F]/g, ""); + // fix double hyphens while (hashValue.indexOf("--") > -1) { hashValue = hashValue.replace(/--/g, "-"); @@ -645,28 +664,22 @@ // _Local variables_ // Stores the distance to the closest anchor - var closestAnchorDistance = null, - - // Stores the index of the closest anchor + var // Stores the index of the closest anchor closestAnchorIdx = null, - - // Keeps a reference to all anchors - anchors = $(self.options.context).find("div[data-unique]"), - anchorText; + self.calculateHeights(); + // Determines the index of the closest anchor - anchors.each(function(idx) { - var distance = /*Math.abs*/(($(this).next().length ? $(this).next() : $(this)).offset().top - winScrollTop - self.options.highlightOffset); - if (distance < 0) { - closestAnchorDistance = distance; + self.cachedAnchors.each(function(idx) { + if (self.cachedHeights[idx] - $(window).scrollTop() < 0) { closestAnchorIdx = idx; } else { return false; } }); - anchorText = $(anchors[closestAnchorIdx]).attr("data-unique"); + anchorText = $(self.cachedAnchors[closestAnchorIdx]).attr("data-unique"); // Stores the list item HTML element that corresponds to the currently traversed anchor tag elem = $('li[data-unique="' + anchorText + '"]'); @@ -684,9 +697,9 @@ if(self.options.scrollHistory) { - if(window.location.hash !== anchorText) { + if(window.location.hash !== "#" + anchorText) { - window.location.hash = anchorText; + window.location.replace("#" + anchorText); } @@ -707,6 +720,23 @@ }, + // calculateHeights + // ---- + // ADDED BY ROBERT + calculateHeights: function() { + var self = this; + if (self.cachedHeights.length == 0) { + self.cachedHeights = []; + self.cachedAnchors = []; + var anchors = $(self.options.context).find("div[data-unique]"); + anchors.each(function(idx) { + var distance = (($(this).next().length ? $(this).next() : $(this)).offset().top - self.options.highlightOffset); + self.cachedHeights[idx] = distance; + }); + self.cachedAnchors = anchors; + } + }, + // Show // ---- // Opens the current sub-header @@ -956,7 +986,7 @@ $("html, body").animate({ // Sets the jQuery `scrollTop` to the top offset of the HTML div tag that matches the current list item's `data-unique` tag - "scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px" + "scrollTop": $('div[data-unique="' + elem.attr("data-unique") + '"]').next().offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px" }, { diff --git a/source/javascripts/lang_selector.js b/source/javascripts/lang_selector.js index e9d5487..327b67c 100644 --- a/source/javascripts/lang_selector.js +++ b/source/javascripts/lang_selector.js @@ -1,15 +1,22 @@ +languages = [] function activateLanguage(language) { $("#lang-selector a").removeClass('active'); $("#lang-selector a[data-language-name='" + language + "']").addClass('active'); - $(".highlight").hide(); + for (var i=0; i < languages.length; i++) { + $(".highlight." + languages[i]).hide(); + } $(".highlight." + language).show(); - $(".highlight.text").show(); // always show text } -function setupLanguages(languages) { +function setupLanguages(l) { + languages = l; currentLanguage = languages[0]; - activateLanguage(languages[0]); + if (location.search.substr(1) != "") { + activateLanguage(location.search.substr(1)); + } else { + activateLanguage(languages[0]); + } $("#lang-selector a").bind("click", function() { activateLanguage($(this).data("language-name")); @@ -17,3 +24,4 @@ function setupLanguages(languages) { }); } + diff --git a/source/layouts/layout.erb b/source/layouts/layout.erb index 826873c..93f49fe 100644 --- a/source/layouts/layout.erb +++ b/source/layouts/layout.erb @@ -15,7 +15,7 @@