Skip to content

Commit

Permalink
bump: 3.6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 6, 2017
1 parent da75d70 commit dacea8a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.6.6 / 2017-05-06

* feat: support query string for the search, likes `https://docsify.js.org/#/?s=navbar`, fixed ([#156](https://github.com/QingWei-Li/docsify/issues/156)

## 3.6.5 / 2017-04-28

* fix(util): fix crash, fixed ([#154](https://github.com/QingWei-Li/docsify/issues/154)
Expand Down
2 changes: 1 addition & 1 deletion lib/docsify.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function replaceHash (path) {
var replaceSlug = cached(function (path) {
return path
.replace('#', '?id=')
.replace(/\?(\w+)=/g, function (_, slug) { return slug === 'id' ? '?id=' : ("&" + slug + "="); })
// .replace(/\?(\w+)=/g, (_, slug) => slug === 'id' ? '?id=' : `&${slug}=`)
});
/**
* Normalize the current url
Expand Down
4 changes: 2 additions & 2 deletions lib/docsify.min.js

Large diffs are not rendered by default.

46 changes: 27 additions & 19 deletions lib/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ function style () {
dom.appendTo(dom.head, style);
}

function tpl (opts) {
function tpl (opts, defaultValue) {
if ( defaultValue === void 0 ) defaultValue = '';

var html =
"<input type=\"search\" />" +
"<input type=\"search\" value=\"" + defaultValue + "\" />" +
'<div class="results-panel"></div>' +
'</div>';
var el = dom.create('div', html);
Expand All @@ -190,26 +192,29 @@ function tpl (opts) {
dom.before(aside, el);
}

function bindEvents () {
function doSearch (value) {
var $search = dom.find('div.search');
var $input = dom.find($search, 'input');
var $panel = dom.find($search, '.results-panel');
var doSearch = function (value) {
if (!value) {
$panel.classList.remove('show');
$panel.innerHTML = '';
return
}
var matchs = search(value);

var html = '';
matchs.forEach(function (post) {
html += "<div class=\"matching-post\">\n <h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n <p>" + (post.content) + "</p>\n</div>";
});
if (!value) {
$panel.classList.remove('show');
$panel.innerHTML = '';
return
}
var matchs = search(value);

$panel.classList.add('show');
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
};
var html = '';
matchs.forEach(function (post) {
html += "<div class=\"matching-post\">\n<h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n<p>" + (post.content) + "</p>\n</div>";
});

$panel.classList.add('show');
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
}

function bindEvents () {
var $search = dom.find('div.search');
var $input = dom.find($search, 'input');

var timeId;
// Prevent to Fold sidebar
Expand Down Expand Up @@ -243,9 +248,12 @@ function updateNoData (text, path) {

function init$$1 (opts) {
dom = Docsify.dom;
var keywords = Docsify.route.parse().query.s;

style();
tpl(opts);
tpl(opts, keywords);
bindEvents();
keywords && setTimeout(function (_) { return doSearch(keywords); }, 500);
}

function update (opts, vm) {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dacea8a

Please sign in to comment.