From f9c4195f23b2b7c8e7233c78ac2824c5d938a008 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sun, 27 Apr 2014 16:32:11 -0400 Subject: [PATCH 1/8] Don't crash on invalid language --- source/javascripts/app/lang.js | 1 + 1 file changed, 1 insertion(+) diff --git a/source/javascripts/app/lang.js b/source/javascripts/app/lang.js index 9c7fe91..2764e6f 100644 --- a/source/javascripts/app/lang.js +++ b/source/javascripts/app/lang.js @@ -20,6 +20,7 @@ under the License. global.activateLanguage = activateLanguage; function activateLanguage(language) { + if (!language) return; $("#lang-selector a").removeClass('active'); $("#lang-selector a[data-language-name='" + language + "']").addClass('active'); for (var i=0; i < languages.length; i++) { From 2f617a2160adc4cb50dea592b02938b1d16dfacb Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sun, 27 Apr 2014 18:49:55 -0400 Subject: [PATCH 2/8] Scroll to closest header --- source/javascripts/lib/jquery.tocify.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/javascripts/lib/jquery.tocify.js b/source/javascripts/lib/jquery.tocify.js index ac16993..d122048 100644 --- a/source/javascripts/lib/jquery.tocify.js +++ b/source/javascripts/lib/jquery.tocify.js @@ -147,6 +147,7 @@ var self = this; + self.tocifyWrapper = $('.tocify-wrapper'); self.extendPageScroll = true; // Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings) @@ -703,6 +704,20 @@ // Highlights the corresponding list item elem.addClass(self.focusClass); + // Scroll to highlighted element's header + var tocifyWrapper = self.tocifyWrapper; + var scrollToElem = $(elem).closest('.tocify-header'); + + var elementOffset = scrollToElem.offset().top, + wrapperOffset = tocifyWrapper.offset().top; + var offset = elementOffset - wrapperOffset; + + if (offset >= $(window).height()) { + var scrollPosition = offset + tocifyWrapper.scrollTop(); + tocifyWrapper.scrollTop(scrollPosition); + } else if (offset < 0) { + tocifyWrapper.scrollTop(0); + } } if(self.options.scrollHistory) { @@ -1021,4 +1036,4 @@ }); -})); //end of plugin +})); //end of plugin \ No newline at end of file From e0cee862d932f942233a8511216519c45bb20b36 Mon Sep 17 00:00:00 2001 From: Christopher Rogers Date: Wed, 7 May 2014 19:33:52 -0700 Subject: [PATCH 3/8] Fixes a variable leak and simplifies low score filtration Signed-off-by: Christopher Rogers --- source/javascripts/app/search.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/source/javascripts/app/search.js b/source/javascripts/app/search.js index 411aad9..1521304 100644 --- a/source/javascripts/app/search.js +++ b/source/javascripts/app/search.js @@ -71,18 +71,13 @@ if (this.value) { sections.hide(); // results are sorted by score in descending order - var tmpResults = index.search(this.value); - var results = []; - - // remove low score matches - $.each(tmpResults, function (index, item) { - if (item.score >= 0.0001) results.push(item); - }); + var results = index.search(this.value); if (results.length) { - lastRef = null; resetHeaderLocations(); + var lastRef; $.each(results, function (index, item) { + if (item.score <= 0.0001) return; // remove low-score results var itemRef = item.ref; $('#section-' + itemRef).show(); // headers must be repositioned in the DOM From a35e1341b6c4b84f3c0b8ed29b91bcbf2911f022 Mon Sep 17 00:00:00 2001 From: Mark Stetzer Date: Thu, 15 May 2014 16:13:34 -0400 Subject: [PATCH 4/8] Adding link to Emerging Threats API docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1db2185..5762494 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Examples of Slate in the Wild * [ChaiOne Gameplan API docs](http://chaione.github.io/gameplanb2b/#introduction) * [Drcaban's Build a Quine tutorial](http://drcabana.github.io/build-a-quine/#introduction) * [PricePlow API docs](https://www.priceplow.com/api/documentation) +* [Emerging Threats API docs](http://apidocs.emergingthreats.net/) (Feel free to add your site to this list in a pull request!) From 1e341563fb90beb38c52a6bf9cdb510b4d9e521a Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Sun, 18 May 2014 12:26:58 -0400 Subject: [PATCH 5/8] Fix language on load --- source/javascripts/app/lang.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/source/javascripts/app/lang.js b/source/javascripts/app/lang.js index 2764e6f..7c30056 100644 --- a/source/javascripts/app/lang.js +++ b/source/javascripts/app/lang.js @@ -21,6 +21,12 @@ under the License. function activateLanguage(language) { if (!language) return; + + var hash = window.location.hash; + if (hash) hash = hash.replace(/^#+/, ''); + // do not reload the page every time the language is changed + if (history) history.pushState({}, '', '?' + language + '#' + hash); + $("#lang-selector a").removeClass('active'); $("#lang-selector a[data-language-name='" + language + "']").addClass('active'); for (var i=0; i < languages.length; i++) { @@ -48,25 +54,13 @@ under the License. // no language selected, so use the default activateLanguage(languages[0]); } - - // if we click on a language tab, reload the page with that language in the URL - $("#lang-selector a").bind("click", function() { - window.location.replace("?" + $(this).data("language-name") + window.location.hash); - return false; - }); - } // if we click on a language tab, activate that language $(function() { $("#lang-selector a").on("click", function() { - var lang = $(this).data("language-name"); - var hash = window.location.hash; - if (hash) hash = hash.replace(/^#+/, ''); - // do not reload the page every time the language is changed - if (history) history.pushState({}, '', '?' + lang + '#' + hash); - - activateLanguage(lang); + var language = $(this).data("language-name"); + activateLanguage(language); return false; }); window.onpopstate = function(event) { From d71ae97f7a6e3e2c5c4768628d2bdf6ebeb4c06c Mon Sep 17 00:00:00 2001 From: Robert Lord Date: Wed, 11 Jun 2014 21:15:26 -0700 Subject: [PATCH 6/8] Remove excess whitespace, add extra equal sign to lang.js --- source/javascripts/app/lang.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/javascripts/app/lang.js b/source/javascripts/app/lang.js index 7c30056..111c67e 100644 --- a/source/javascripts/app/lang.js +++ b/source/javascripts/app/lang.js @@ -40,8 +40,8 @@ under the License. var defaultLanguage = localStorage.getItem("language"); languages = l; - - if ((location.search.substr(1) != "") && (jQuery.inArray(location.search.substr(1), languages)) != -1) { + + if ((location.search.substr(1) !== "") && (jQuery.inArray(location.search.substr(1), languages)) != -1) { // the language is in the URL, so use that language! activateLanguage(location.search.substr(1)); From 7dead4c392d13d8f707ec7a062fe77359a54928a Mon Sep 17 00:00:00 2001 From: Robert Lord Date: Wed, 11 Jun 2014 21:21:28 -0700 Subject: [PATCH 7/8] Update selected tab to not darken on mousedown --- source/stylesheets/screen.css.scss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/stylesheets/screen.css.scss b/source/stylesheets/screen.css.scss index 7d9a656..f760f8f 100644 --- a/source/stylesheets/screen.css.scss +++ b/source/stylesheets/screen.css.scss @@ -226,15 +226,15 @@ html, body { padding: 0 10px; line-height: 30px; - &.active { - background-color: $lang-select-active-bg; - color: $lang-select-active-text; - } - &:active { background-color: $lang-select-pressed-bg; color: $lang-select-pressed-text; } + + &.active { + background-color: $lang-select-active-bg; + color: $lang-select-active-text; + } } &:after { From b363be873b5caaca014ebfe4e7dde99ca32645ff Mon Sep 17 00:00:00 2001 From: Robert Lord Date: Wed, 11 Jun 2014 21:49:37 -0700 Subject: [PATCH 8/8] Update language tabs to properly stay in section, and fix history navigation bug --- source/javascripts/app/lang.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source/javascripts/app/lang.js b/source/javascripts/app/lang.js index 111c67e..3b02e09 100644 --- a/source/javascripts/app/lang.js +++ b/source/javascripts/app/lang.js @@ -22,17 +22,25 @@ under the License. function activateLanguage(language) { if (!language) return; - var hash = window.location.hash; - if (hash) hash = hash.replace(/^#+/, ''); - // do not reload the page every time the language is changed - if (history) history.pushState({}, '', '?' + language + '#' + hash); - $("#lang-selector a").removeClass('active'); $("#lang-selector a[data-language-name='" + language + "']").addClass('active'); for (var i=0; i < languages.length; i++) { $(".highlight." + languages[i]).hide(); } $(".highlight." + language).show(); + + // scroll to the new location of the position + $(window.location.hash).get(0).scrollIntoView(true); + } + + // if a button is clicked, add the state to the history + function pushURL(language) { + if (!history) { return; } + var hash = window.location.hash; + if (hash) { + hash = hash.replace(/^#+/, ''); + } + history.pushState({}, '', '?' + language + '#' + hash); } function setupLanguages(l) { @@ -60,6 +68,7 @@ under the License. $(function() { $("#lang-selector a").on("click", function() { var language = $(this).data("language-name"); + pushURL(language); activateLanguage(language); return false; });