mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Beginning of the documentation
This commit is contained in:
1
doc/_book/book_assets/gitbook-2.6.7/js/app.min.js
vendored
Normal file
1
doc/_book/book_assets/gitbook-2.6.7/js/app.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
doc/_book/book_assets/gitbook-2.6.7/js/clipboard.min.js
vendored
Normal file
7
doc/_book/book_assets/gitbook-2.6.7/js/clipboard.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
86
doc/_book/book_assets/gitbook-2.6.7/js/jquery.highlight.js
Normal file
86
doc/_book/book_assets/gitbook-2.6.7/js/jquery.highlight.js
Normal file
@ -0,0 +1,86 @@
|
||||
gitbook.require(["jQuery"], function(jQuery) {
|
||||
|
||||
/*
|
||||
* jQuery Highlight plugin
|
||||
*
|
||||
* Based on highlight v3 by Johann Burkard
|
||||
* http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
|
||||
*
|
||||
* Code a little bit refactored and cleaned (in my humble opinion).
|
||||
* Most important changes:
|
||||
* - has an option to highlight only entire words (wordsOnly - false by default),
|
||||
* - has an option to be case sensitive (caseSensitive - false by default)
|
||||
* - highlight element tag and class names can be specified in options
|
||||
*
|
||||
* Copyright (c) 2009 Bartek Szopka
|
||||
*
|
||||
* Licensed under MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
jQuery.extend({
|
||||
highlight: function (node, re, nodeName, className) {
|
||||
if (node.nodeType === 3) {
|
||||
var match = node.data.match(re);
|
||||
if (match) {
|
||||
var highlight = document.createElement(nodeName || 'span');
|
||||
highlight.className = className || 'highlight';
|
||||
var wordNode = node.splitText(match.index);
|
||||
wordNode.splitText(match[0].length);
|
||||
var wordClone = wordNode.cloneNode(true);
|
||||
highlight.appendChild(wordClone);
|
||||
wordNode.parentNode.replaceChild(highlight, wordNode);
|
||||
return 1; //skip added node in parent
|
||||
}
|
||||
} else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
|
||||
!/(script|style)/i.test(node.tagName) && // ignore script and style nodes
|
||||
!(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
|
||||
for (var i = 0; i < node.childNodes.length; i++) {
|
||||
i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.fn.unhighlight = function (options) {
|
||||
var settings = { className: 'highlight', element: 'span' };
|
||||
jQuery.extend(settings, options);
|
||||
|
||||
return this.find(settings.element + "." + settings.className).each(function () {
|
||||
var parent = this.parentNode;
|
||||
parent.replaceChild(this.firstChild, this);
|
||||
parent.normalize();
|
||||
}).end();
|
||||
};
|
||||
|
||||
jQuery.fn.highlight = function (words, options) {
|
||||
var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
|
||||
jQuery.extend(settings, options);
|
||||
|
||||
if (words.constructor === String) {
|
||||
words = [words];
|
||||
// also match 'foo-bar' if search for 'foo bar'
|
||||
if (/\s/.test(words[0])) words.push(words[0].replace(/\s+/, '-'));
|
||||
}
|
||||
words = jQuery.grep(words, function(word, i){
|
||||
return word !== '';
|
||||
});
|
||||
words = jQuery.map(words, function(word, i) {
|
||||
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
});
|
||||
if (words.length === 0) { return this; }
|
||||
|
||||
var flag = settings.caseSensitive ? "" : "i";
|
||||
var pattern = "(" + words.join("|") + ")";
|
||||
if (settings.wordsOnly) {
|
||||
pattern = "\\b" + pattern + "\\b";
|
||||
}
|
||||
var re = new RegExp(pattern, flag);
|
||||
|
||||
return this.each(function () {
|
||||
jQuery.highlight(this, re, settings.element, settings.className);
|
||||
});
|
||||
};
|
||||
|
||||
});
|
259
doc/_book/book_assets/gitbook-2.6.7/js/plugin-bookdown.js
Normal file
259
doc/_book/book_assets/gitbook-2.6.7/js/plugin-bookdown.js
Normal file
@ -0,0 +1,259 @@
|
||||
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
|
||||
|
||||
var gs = gitbook.storage;
|
||||
|
||||
gitbook.events.bind("start", function(e, config) {
|
||||
|
||||
// add the Edit button (edit on Github)
|
||||
var edit = config.edit;
|
||||
if (edit && edit.link) gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-edit',
|
||||
label: edit.text || 'Edit',
|
||||
position: 'left',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.open(edit.link);
|
||||
}
|
||||
});
|
||||
|
||||
// add the History button (file history on Github)
|
||||
var history = config.history;
|
||||
if (history && history.link) gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-history',
|
||||
label: history.text || 'History',
|
||||
position: 'left',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.open(history.link);
|
||||
}
|
||||
});
|
||||
|
||||
// add the View button (file view on Github)
|
||||
var view = config.view;
|
||||
if (view && view.link) gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-eye',
|
||||
label: view.text || 'View Source',
|
||||
position: 'left',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.open(view.link);
|
||||
}
|
||||
});
|
||||
|
||||
// add the Download button
|
||||
var down = config.download;
|
||||
var normalizeDownload = function() {
|
||||
if (!down || !(down instanceof Array) || down.length === 0) return;
|
||||
if (down[0] instanceof Array) return down;
|
||||
return $.map(down, function(file, i) {
|
||||
return [[file, file.replace(/.*[.]/g, '').toUpperCase()]];
|
||||
});
|
||||
};
|
||||
down = normalizeDownload(down);
|
||||
if (down) if (down.length === 1 && /[.]pdf$/.test(down[0][0])) {
|
||||
gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-file-pdf-o',
|
||||
label: down[0][1],
|
||||
position: 'left',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.open(down[0][0]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-download',
|
||||
label: 'Download',
|
||||
position: 'left',
|
||||
dropdown: $.map(down, function(item, i) {
|
||||
return {
|
||||
text: item[1],
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.open(item[0]);
|
||||
}
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// add the Information button
|
||||
var info = ['Keyboard shortcuts (<> indicates arrow keys):',
|
||||
'<left>/<right>: navigate to previous/next page',
|
||||
's: Toggle sidebar'];
|
||||
if (config.search !== false) info.push('f: Toggle search input ' +
|
||||
'(use <up>/<down>/Enter in the search input to navigate through search matches; ' +
|
||||
'press Esc to cancel search)');
|
||||
if (config.info !== false) gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-info',
|
||||
label: 'Information about the toolbar',
|
||||
position: 'left',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
window.alert(info.join('\n\n'));
|
||||
}
|
||||
});
|
||||
|
||||
// highlight the current section in TOC
|
||||
var href = window.location.pathname;
|
||||
href = href.substr(href.lastIndexOf('/') + 1);
|
||||
// accentuated characters need to be decoded (#819)
|
||||
href = decodeURIComponent(href);
|
||||
if (href === '') href = 'index.html';
|
||||
var li = $('a[href^="' + href + location.hash + '"]').parent('li.chapter').first();
|
||||
var summary = $('ul.summary'), chaps = summary.find('li.chapter');
|
||||
if (li.length === 0) li = chaps.first();
|
||||
li.addClass('active');
|
||||
chaps.on('click', function(e) {
|
||||
chaps.removeClass('active');
|
||||
$(this).addClass('active');
|
||||
gs.set('tocScrollTop', summary.scrollTop());
|
||||
});
|
||||
|
||||
var toc = config.toc;
|
||||
// collapse TOC items that are not for the current chapter
|
||||
if (toc && toc.collapse) (function() {
|
||||
var type = toc.collapse;
|
||||
if (type === 'none') return;
|
||||
if (type !== 'section' && type !== 'subsection') return;
|
||||
// sections under chapters
|
||||
var toc_sub = summary.children('li[data-level]').children('ul');
|
||||
if (type === 'section') {
|
||||
toc_sub.hide()
|
||||
.parent().has(li).children('ul').show();
|
||||
} else {
|
||||
toc_sub.children('li').children('ul').hide()
|
||||
.parent().has(li).children('ul').show();
|
||||
}
|
||||
li.children('ul').show();
|
||||
var toc_sub2 = toc_sub.children('li');
|
||||
if (type === 'section') toc_sub2.children('ul').hide();
|
||||
summary.children('li[data-level]').find('a')
|
||||
.on('click.bookdown', function(e) {
|
||||
if (href === $(this).attr('href').replace(/#.*/, ''))
|
||||
$(this).parent('li').children('ul').toggle();
|
||||
});
|
||||
})();
|
||||
|
||||
// add tooltips to the <a>'s that are truncated
|
||||
$('a').each(function(i, el) {
|
||||
if (el.offsetWidth >= el.scrollWidth) return;
|
||||
if (typeof el.title === 'undefined') return;
|
||||
el.title = el.text;
|
||||
});
|
||||
|
||||
// restore TOC scroll position
|
||||
var pos = gs.get('tocScrollTop');
|
||||
if (typeof pos !== 'undefined') summary.scrollTop(pos);
|
||||
|
||||
// highlight the TOC item that has same text as the heading in view as scrolling
|
||||
if (toc && toc.scroll_highlight !== false && li.length > 0) (function() {
|
||||
// scroll the current TOC item into viewport
|
||||
var ht = $(window).height(), rect = li[0].getBoundingClientRect();
|
||||
if (rect.top >= ht || rect.top <= 0 || rect.bottom <= 0) {
|
||||
summary.scrollTop(li[0].offsetTop);
|
||||
}
|
||||
// current chapter TOC items
|
||||
var items = $('a[href^="' + href + '"]').parent('li.chapter'),
|
||||
m = items.length;
|
||||
if (m === 0) {
|
||||
items = summary.find('li.chapter');
|
||||
m = items.length;
|
||||
}
|
||||
if (m === 0) return;
|
||||
// all section titles on current page
|
||||
var hs = bookInner.find('.page-inner').find('h1,h2,h3'), n = hs.length,
|
||||
ts = hs.map(function(i, el) { return $(el).text(); });
|
||||
if (n === 0) return;
|
||||
var scrollHandler = function(e) {
|
||||
var ht = $(window).height();
|
||||
clearTimeout($.data(this, 'scrollTimer'));
|
||||
$.data(this, 'scrollTimer', setTimeout(function() {
|
||||
// find the first visible title in the viewport
|
||||
for (var i = 0; i < n; i++) {
|
||||
var rect = hs[i].getBoundingClientRect();
|
||||
if (rect.top >= 0 && rect.bottom <= ht) break;
|
||||
}
|
||||
if (i === n) return;
|
||||
items.removeClass('active');
|
||||
for (var j = 0; j < m; j++) {
|
||||
if (items.eq(j).children('a').first().text() === ts[i]) break;
|
||||
}
|
||||
if (j === m) j = 0; // highlight the chapter title
|
||||
// search bottom-up for a visible TOC item to highlight; if an item is
|
||||
// hidden, we check if its parent is visible, and so on
|
||||
while (j > 0 && items.eq(j).is(':hidden')) j--;
|
||||
items.eq(j).addClass('active');
|
||||
}, 250));
|
||||
};
|
||||
bookInner.on('scroll.bookdown', scrollHandler);
|
||||
bookBody.on('scroll.bookdown', scrollHandler);
|
||||
})();
|
||||
|
||||
// do not refresh the page if the TOC item points to the current page
|
||||
$('a[href="' + href + '"]').parent('li.chapter').children('a')
|
||||
.on('click', function(e) {
|
||||
bookInner.scrollTop(0);
|
||||
bookBody.scrollTop(0);
|
||||
return false;
|
||||
});
|
||||
|
||||
var toolbar = config.toolbar;
|
||||
if (!toolbar || toolbar.position !== 'static') {
|
||||
var bookHeader = $('.book-header');
|
||||
bookBody.addClass('fixed');
|
||||
bookHeader.addClass('fixed')
|
||||
.css('background-color', bookBody.css('background-color'))
|
||||
.on('click.bookdown', function(e) {
|
||||
// the theme may have changed after user clicks the theme button
|
||||
bookHeader.css('background-color', bookBody.css('background-color'));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
gitbook.events.bind("page.change", function(e) {
|
||||
// store TOC scroll position
|
||||
var summary = $('ul.summary');
|
||||
gs.set('tocScrollTop', summary.scrollTop());
|
||||
});
|
||||
|
||||
var bookBody = $('.book-body'), bookInner = bookBody.find('.body-inner');
|
||||
var chapterTitle = function() {
|
||||
return bookInner.find('.page-inner').find('h1,h2').first().text();
|
||||
};
|
||||
var saveScrollPos = function(e) {
|
||||
// save scroll position before page is reloaded
|
||||
gs.set('bodyScrollTop', {
|
||||
body: bookBody.scrollTop(),
|
||||
inner: bookInner.scrollTop(),
|
||||
focused: document.hasFocus(),
|
||||
title: chapterTitle()
|
||||
});
|
||||
};
|
||||
$(document).on('servr:reload', saveScrollPos);
|
||||
|
||||
// check if the page is loaded in an iframe (e.g. the RStudio preview window)
|
||||
var inIFrame = function() {
|
||||
var inIframe = true;
|
||||
try { inIframe = window.self !== window.top; } catch (e) {}
|
||||
return inIframe;
|
||||
};
|
||||
if (inIFrame()) {
|
||||
$(window).on('blur unload', saveScrollPos);
|
||||
}
|
||||
|
||||
$(function(e) {
|
||||
var pos = gs.get('bodyScrollTop');
|
||||
if (pos) {
|
||||
if (pos.title === chapterTitle()) {
|
||||
if (pos.body !== 0) bookBody.scrollTop(pos.body);
|
||||
if (pos.inner !== 0) bookInner.scrollTop(pos.inner);
|
||||
}
|
||||
}
|
||||
if ((pos && pos.focused) || !inIFrame()) bookInner.find('.page-wrapper').focus();
|
||||
// clear book body scroll position
|
||||
gs.remove('bodyScrollTop');
|
||||
});
|
||||
|
||||
});
|
33
doc/_book/book_assets/gitbook-2.6.7/js/plugin-clipboard.js
Normal file
33
doc/_book/book_assets/gitbook-2.6.7/js/plugin-clipboard.js
Normal file
@ -0,0 +1,33 @@
|
||||
gitbook.require(["gitbook", "jQuery"], function(gitbook, $) {
|
||||
|
||||
var copyButton = '<button type="button" class="copy-to-clipboard-button" title="Copy to clipboard" aria-label="Copy to clipboard"><i class="fa fa-copy"></i></button>';
|
||||
var clipboard;
|
||||
|
||||
gitbook.events.bind("page.change", function() {
|
||||
|
||||
if (!ClipboardJS.isSupported()) return;
|
||||
|
||||
// the page.change event is thrown twice: before and after the page changes
|
||||
if (clipboard) {
|
||||
// clipboard is already defined but we are on the same page
|
||||
if (clipboard._prevPage === window.location.pathname) return;
|
||||
// clipboard is already defined and url path change
|
||||
// we can deduct that we are before page changes
|
||||
clipboard.destroy(); // destroy the previous events listeners
|
||||
clipboard = undefined; // reset the clipboard object
|
||||
return;
|
||||
}
|
||||
|
||||
$(copyButton).prependTo("div.sourceCode");
|
||||
|
||||
clipboard = new ClipboardJS(".copy-to-clipboard-button", {
|
||||
text: function(trigger) {
|
||||
return trigger.parentNode.textContent;
|
||||
}
|
||||
});
|
||||
|
||||
clipboard._prevPage = window.location.pathname
|
||||
|
||||
});
|
||||
|
||||
});
|
152
doc/_book/book_assets/gitbook-2.6.7/js/plugin-fontsettings.js
Normal file
152
doc/_book/book_assets/gitbook-2.6.7/js/plugin-fontsettings.js
Normal file
@ -0,0 +1,152 @@
|
||||
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
|
||||
var fontState;
|
||||
|
||||
var THEMES = {
|
||||
"white": 0,
|
||||
"sepia": 1,
|
||||
"night": 2
|
||||
};
|
||||
|
||||
var FAMILY = {
|
||||
"serif": 0,
|
||||
"sans": 1
|
||||
};
|
||||
|
||||
// Save current font settings
|
||||
function saveFontSettings() {
|
||||
gitbook.storage.set("fontState", fontState);
|
||||
update();
|
||||
}
|
||||
|
||||
// Increase font size
|
||||
function enlargeFontSize(e) {
|
||||
e.preventDefault();
|
||||
if (fontState.size >= 4) return;
|
||||
|
||||
fontState.size++;
|
||||
saveFontSettings();
|
||||
};
|
||||
|
||||
// Decrease font size
|
||||
function reduceFontSize(e) {
|
||||
e.preventDefault();
|
||||
if (fontState.size <= 0) return;
|
||||
|
||||
fontState.size--;
|
||||
saveFontSettings();
|
||||
};
|
||||
|
||||
// Change font family
|
||||
function changeFontFamily(index, e) {
|
||||
e.preventDefault();
|
||||
|
||||
fontState.family = index;
|
||||
saveFontSettings();
|
||||
};
|
||||
|
||||
// Change type of color
|
||||
function changeColorTheme(index, e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $book = $(".book");
|
||||
|
||||
if (fontState.theme !== 0)
|
||||
$book.removeClass("color-theme-"+fontState.theme);
|
||||
|
||||
fontState.theme = index;
|
||||
if (fontState.theme !== 0)
|
||||
$book.addClass("color-theme-"+fontState.theme);
|
||||
|
||||
saveFontSettings();
|
||||
};
|
||||
|
||||
function update() {
|
||||
var $book = gitbook.state.$book;
|
||||
|
||||
$(".font-settings .font-family-list li").removeClass("active");
|
||||
$(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active");
|
||||
|
||||
$book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
|
||||
$book.addClass("font-size-"+fontState.size);
|
||||
$book.addClass("font-family-"+fontState.family);
|
||||
|
||||
if(fontState.theme !== 0) {
|
||||
$book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
|
||||
$book.addClass("color-theme-"+fontState.theme);
|
||||
}
|
||||
};
|
||||
|
||||
function init(config) {
|
||||
var $bookBody, $book;
|
||||
|
||||
//Find DOM elements.
|
||||
$book = gitbook.state.$book;
|
||||
$bookBody = $book.find(".book-body");
|
||||
|
||||
// Instantiate font state object
|
||||
fontState = gitbook.storage.get("fontState", {
|
||||
size: config.size || 2,
|
||||
family: FAMILY[config.family || "sans"],
|
||||
theme: THEMES[config.theme || "white"]
|
||||
});
|
||||
|
||||
update();
|
||||
};
|
||||
|
||||
|
||||
gitbook.events.bind("start", function(e, config) {
|
||||
var opts = config.fontsettings;
|
||||
if (!opts) return;
|
||||
|
||||
// Create buttons in toolbar
|
||||
gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-font',
|
||||
label: 'Font Settings',
|
||||
className: 'font-settings',
|
||||
dropdown: [
|
||||
[
|
||||
{
|
||||
text: 'A',
|
||||
className: 'font-reduce',
|
||||
onClick: reduceFontSize
|
||||
},
|
||||
{
|
||||
text: 'A',
|
||||
className: 'font-enlarge',
|
||||
onClick: enlargeFontSize
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
text: 'Serif',
|
||||
onClick: _.partial(changeFontFamily, 0)
|
||||
},
|
||||
{
|
||||
text: 'Sans',
|
||||
onClick: _.partial(changeFontFamily, 1)
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
text: 'White',
|
||||
onClick: _.partial(changeColorTheme, 0)
|
||||
},
|
||||
{
|
||||
text: 'Sepia',
|
||||
onClick: _.partial(changeColorTheme, 1)
|
||||
},
|
||||
{
|
||||
text: 'Night',
|
||||
onClick: _.partial(changeColorTheme, 2)
|
||||
}
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
// Init current settings
|
||||
init(opts);
|
||||
});
|
||||
});
|
||||
|
||||
|
270
doc/_book/book_assets/gitbook-2.6.7/js/plugin-search.js
Normal file
270
doc/_book/book_assets/gitbook-2.6.7/js/plugin-search.js
Normal file
@ -0,0 +1,270 @@
|
||||
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
|
||||
var index = null;
|
||||
var fuse = null;
|
||||
var _search = {engine: 'lunr', opts: {}};
|
||||
var $searchInput, $searchLabel, $searchForm;
|
||||
var $highlighted = [], hi, hiOpts = { className: 'search-highlight' };
|
||||
var collapse = false, toc_visible = [];
|
||||
|
||||
function init(config) {
|
||||
// Instantiate search settings
|
||||
_search = gitbook.storage.get("search", {
|
||||
engine: config.search.engine || 'lunr',
|
||||
opts: config.search.options || {},
|
||||
});
|
||||
};
|
||||
|
||||
// Save current search settings
|
||||
function saveSearchSettings() {
|
||||
gitbook.storage.set("search", _search);
|
||||
}
|
||||
|
||||
// Use a specific index
|
||||
function loadIndex(data) {
|
||||
// [Yihui] In bookdown, I use a character matrix to store the chapter
|
||||
// content, and the index is dynamically built on the client side.
|
||||
// Gitbook prebuilds the index data instead: https://github.com/GitbookIO/plugin-search
|
||||
// We can certainly do that via R packages V8 and jsonlite, but let's
|
||||
// see how slow it really is before improving it. On the other hand,
|
||||
// lunr cannot handle non-English text very well, e.g. the default
|
||||
// tokenizer cannot deal with Chinese text, so we may want to replace
|
||||
// lunr with a dumb simple text matching approach.
|
||||
if (_search.engine === 'lunr') {
|
||||
index = lunr(function () {
|
||||
this.ref('url');
|
||||
this.field('title', { boost: 10 });
|
||||
this.field('body');
|
||||
});
|
||||
data.map(function(item) {
|
||||
index.add({
|
||||
url: item[0],
|
||||
title: item[1],
|
||||
body: item[2]
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
fuse = new Fuse(data.map((_data => {
|
||||
return {
|
||||
url: _data[0],
|
||||
title: _data[1],
|
||||
body: _data[2]
|
||||
};
|
||||
})), Object.assign(
|
||||
{
|
||||
includeScore: true,
|
||||
threshold: 0.1,
|
||||
ignoreLocation: true,
|
||||
keys: ["title", "body"]
|
||||
},
|
||||
_search.opts
|
||||
));
|
||||
}
|
||||
|
||||
// Fetch the search index
|
||||
function fetchIndex() {
|
||||
return $.getJSON(gitbook.state.basePath+"/search_index.json")
|
||||
.then(loadIndex); // [Yihui] we need to use this object later
|
||||
}
|
||||
|
||||
// Search for a term and return results
|
||||
function search(q) {
|
||||
let results = [];
|
||||
switch (_search.engine) {
|
||||
case 'fuse':
|
||||
if (!fuse) return;
|
||||
results = fuse.search(q).map(function(result) {
|
||||
var parts = result.item.url.split('#');
|
||||
return {
|
||||
path: parts[0],
|
||||
hash: parts[1]
|
||||
};
|
||||
});
|
||||
break;
|
||||
case 'lunr':
|
||||
default:
|
||||
if (!index) return;
|
||||
results = _.chain(index.search(q)).map(function(result) {
|
||||
var parts = result.ref.split("#");
|
||||
return {
|
||||
path: parts[0],
|
||||
hash: parts[1]
|
||||
};
|
||||
})
|
||||
.value();
|
||||
}
|
||||
|
||||
// [Yihui] Highlight the search keyword on current page
|
||||
$highlighted = $('.page-inner')
|
||||
.unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight');
|
||||
scrollToHighlighted(0);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// [Yihui] Scroll the chapter body to the i-th highlighted string
|
||||
function scrollToHighlighted(d) {
|
||||
var n = $highlighted.length;
|
||||
hi = hi === undefined ? 0 : hi + d;
|
||||
// navignate to the previous/next page in the search results if reached the top/bottom
|
||||
var b = hi < 0;
|
||||
if (d !== 0 && (b || hi >= n)) {
|
||||
var path = currentPath(), n2 = toc_visible.length;
|
||||
if (n2 === 0) return;
|
||||
for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) {
|
||||
if (toc_visible.eq(i).data('path') === path) break;
|
||||
}
|
||||
i += b ? -1 : 1;
|
||||
if (i < 0) i = n2 - 1;
|
||||
if (i >= n2) i = 0;
|
||||
var lnk = toc_visible.eq(i).find('a[href$=".html"]');
|
||||
if (lnk.length) lnk[0].click();
|
||||
return;
|
||||
}
|
||||
if (n === 0) return;
|
||||
var $p = $highlighted.eq(hi);
|
||||
$p[0].scrollIntoView();
|
||||
$highlighted.css('background-color', '');
|
||||
// an orange background color on the current item and removed later
|
||||
$p.css('background-color', 'orange');
|
||||
setTimeout(function() {
|
||||
$p.css('background-color', '');
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function currentPath() {
|
||||
var href = window.location.pathname;
|
||||
href = href.substr(href.lastIndexOf('/') + 1);
|
||||
return href === '' ? 'index.html' : href;
|
||||
}
|
||||
|
||||
// Create search form
|
||||
function createForm(value) {
|
||||
if ($searchForm) $searchForm.remove();
|
||||
if ($searchLabel) $searchLabel.remove();
|
||||
if ($searchInput) $searchInput.remove();
|
||||
|
||||
$searchForm = $('<div>', {
|
||||
'class': 'book-search',
|
||||
'role': 'search'
|
||||
});
|
||||
|
||||
$searchLabel = $('<label>', {
|
||||
'for': 'search-box',
|
||||
'aria-hidden': 'false',
|
||||
'hidden': ''
|
||||
});
|
||||
|
||||
$searchInput = $('<input>', {
|
||||
'id': 'search-box',
|
||||
'type': 'search',
|
||||
'class': 'form-control',
|
||||
'val': value,
|
||||
'placeholder': 'Type to search (Enter for navigation)',
|
||||
'title': 'Use Enter or the <Down> key to navigate to the next match, or the <Up> key to the previous match'
|
||||
});
|
||||
|
||||
$searchLabel.append("Type to search");
|
||||
$searchLabel.appendTo($searchForm);
|
||||
$searchInput.appendTo($searchForm);
|
||||
$searchForm.prependTo(gitbook.state.$book.find('.book-summary'));
|
||||
}
|
||||
|
||||
// Return true if search is open
|
||||
function isSearchOpen() {
|
||||
return gitbook.state.$book.hasClass("with-search");
|
||||
}
|
||||
|
||||
// Toggle the search
|
||||
function toggleSearch(_state) {
|
||||
if (isSearchOpen() === _state) return;
|
||||
if (!$searchInput) return;
|
||||
|
||||
gitbook.state.$book.toggleClass("with-search", _state);
|
||||
|
||||
// If search bar is open: focus input
|
||||
if (isSearchOpen()) {
|
||||
gitbook.sidebar.toggle(true);
|
||||
$searchInput.focus();
|
||||
} else {
|
||||
$searchInput.blur();
|
||||
$searchInput.val("");
|
||||
gitbook.storage.remove("keyword");
|
||||
gitbook.sidebar.filter(null);
|
||||
$('.page-inner').unhighlight(hiOpts);
|
||||
}
|
||||
}
|
||||
|
||||
function sidebarFilter(results) {
|
||||
gitbook.sidebar.filter(_.pluck(results, "path"));
|
||||
toc_visible = $('ul.summary').find('li:visible');
|
||||
}
|
||||
|
||||
// Recover current search when page changed
|
||||
function recoverSearch() {
|
||||
var keyword = gitbook.storage.get("keyword", "");
|
||||
|
||||
createForm(keyword);
|
||||
|
||||
if (keyword.length > 0) {
|
||||
if(!isSearchOpen()) {
|
||||
toggleSearch(true); // [Yihui] open the search box
|
||||
}
|
||||
sidebarFilter(search(keyword));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gitbook.events.bind("start", function(e, config) {
|
||||
// [Yihui] disable search
|
||||
if (config.search === false) return;
|
||||
init(config);
|
||||
collapse = !config.toc || config.toc.collapse === 'section' ||
|
||||
config.toc.collapse === 'subsection';
|
||||
|
||||
// Pre-fetch search index and create the form
|
||||
fetchIndex()
|
||||
// [Yihui] recover search after the page is loaded
|
||||
.then(recoverSearch);
|
||||
|
||||
|
||||
// Type in search bar
|
||||
$(document).on("keyup", ".book-search input", function(e) {
|
||||
var key = (e.keyCode ? e.keyCode : e.which);
|
||||
// [Yihui] Escape -> close search box; Up/Down/Enter: previous/next highlighted
|
||||
if (key == 27) {
|
||||
e.preventDefault();
|
||||
toggleSearch(false);
|
||||
} else if (key == 38) {
|
||||
scrollToHighlighted(-1);
|
||||
} else if (key == 40 || key == 13) {
|
||||
scrollToHighlighted(1);
|
||||
}
|
||||
}).on("input", ".book-search input", function(e) {
|
||||
var q = $(this).val().trim();
|
||||
if (q.length === 0) {
|
||||
gitbook.sidebar.filter(null);
|
||||
gitbook.storage.remove("keyword");
|
||||
$('.page-inner').unhighlight(hiOpts);
|
||||
} else {
|
||||
var results = search(q);
|
||||
sidebarFilter(results);
|
||||
gitbook.storage.set("keyword", q);
|
||||
}
|
||||
});
|
||||
|
||||
// Create the toggle search button
|
||||
gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-search',
|
||||
label: 'Search',
|
||||
position: 'left',
|
||||
onClick: toggleSearch
|
||||
});
|
||||
|
||||
// Bind keyboard to toggle search
|
||||
gitbook.keyboard.bind(['f'], toggleSearch);
|
||||
});
|
||||
|
||||
// [Yihui] do not try to recover search; always start fresh
|
||||
// gitbook.events.bind("page.change", recoverSearch);
|
||||
});
|
116
doc/_book/book_assets/gitbook-2.6.7/js/plugin-sharing.js
Normal file
116
doc/_book/book_assets/gitbook-2.6.7/js/plugin-sharing.js
Normal file
@ -0,0 +1,116 @@
|
||||
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
|
||||
var SITES = {
|
||||
'github': {
|
||||
'label': 'Github',
|
||||
'icon': 'fa fa-github',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
var repo = $('meta[name="github-repo"]').attr('content');
|
||||
if (typeof repo === 'undefined') throw("Github repo not defined");
|
||||
window.open("https://github.com/"+repo);
|
||||
}
|
||||
},
|
||||
'facebook': {
|
||||
'label': 'Facebook',
|
||||
'icon': 'fa fa-facebook',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(location.href));
|
||||
}
|
||||
},
|
||||
'twitter': {
|
||||
'label': 'Twitter',
|
||||
'icon': 'fa fa-twitter',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("http://twitter.com/intent/tweet?text="+encodeURIComponent(document.title)+"&url="+encodeURIComponent(location.href)+"&hashtags=rmarkdown,bookdown");
|
||||
}
|
||||
},
|
||||
'linkedin': {
|
||||
'label': 'LinkedIn',
|
||||
'icon': 'fa fa-linkedin',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
|
||||
}
|
||||
},
|
||||
'weibo': {
|
||||
'label': 'Weibo',
|
||||
'icon': 'fa fa-weibo',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title));
|
||||
}
|
||||
},
|
||||
'instapaper': {
|
||||
'label': 'Instapaper',
|
||||
'icon': 'fa fa-italic',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
|
||||
}
|
||||
},
|
||||
'vk': {
|
||||
'label': 'VK',
|
||||
'icon': 'fa fa-vk',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
|
||||
}
|
||||
},
|
||||
'whatsapp': {
|
||||
'label': 'Whatsapp',
|
||||
'icon': 'fa fa-whatsapp',
|
||||
'onClick': function(e) {
|
||||
e.preventDefault();
|
||||
var url = encodeURIComponent(location.href);
|
||||
window.open((isMobile() ? "whatsapp://send" : "https://web.whatsapp.com/send") + "?text=" + url);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function isMobile() {
|
||||
return !!navigator.maxTouchPoints;
|
||||
}
|
||||
|
||||
gitbook.events.bind("start", function(e, config) {
|
||||
var opts = config.sharing;
|
||||
if (!opts) return;
|
||||
|
||||
// Create dropdown menu
|
||||
var menu = _.chain(opts.all)
|
||||
.map(function(id) {
|
||||
var site = SITES[id];
|
||||
if (!site) return;
|
||||
return {
|
||||
text: site.label,
|
||||
onClick: site.onClick
|
||||
};
|
||||
})
|
||||
.compact()
|
||||
.value();
|
||||
|
||||
// Create main button with dropdown
|
||||
if (menu.length > 0) {
|
||||
gitbook.toolbar.createButton({
|
||||
icon: 'fa fa-share-alt',
|
||||
label: 'Share',
|
||||
position: 'right',
|
||||
dropdown: [menu]
|
||||
});
|
||||
}
|
||||
|
||||
// Direct actions to share
|
||||
_.each(SITES, function(site, sideId) {
|
||||
if (!opts[sideId]) return;
|
||||
|
||||
gitbook.toolbar.createButton({
|
||||
icon: site.icon,
|
||||
label: site.label,
|
||||
title: site.label,
|
||||
position: 'right',
|
||||
onClick: site.onClick
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user