mirror of
https://github.com/danbulant/api_docs
synced 2026-05-22 13:48:59 +00:00
Merge pull request #78 from tripit/dev
Fix scrolling bugs, history bugs, and add search minimum score to display
This commit is contained in:
commit
0a8c73adab
5 changed files with 45 additions and 30 deletions
|
|
@ -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!)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,27 @@ 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++) {
|
||||
$(".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) {
|
||||
|
|
@ -33,8 +48,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));
|
||||
|
||||
|
|
@ -47,25 +62,14 @@ 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");
|
||||
pushURL(language);
|
||||
activateLanguage(language);
|
||||
return false;
|
||||
});
|
||||
window.onpopstate = function(event) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue