Skip to content

Commit dacea8a

Browse files
committedMay 6, 2017
bump: 3.6.6
1 parent da75d70 commit dacea8a

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.6.6 / 2017-05-06
4+
5+
* feat: support query string for the search, likes `https://docsify.js.org/#/?s=navbar`, fixed ([#156](https://github.com/QingWei-Li/docsify/issues/156)
6+
37
## 3.6.5 / 2017-04-28
48

59
* fix(util): fix crash, fixed ([#154](https://github.com/QingWei-Li/docsify/issues/154)

‎lib/docsify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function replaceHash (path) {
329329
var replaceSlug = cached(function (path) {
330330
return path
331331
.replace('#', '?id=')
332-
.replace(/\?(\w+)=/g, function (_, slug) { return slug === 'id' ? '?id=' : ("&" + slug + "="); })
332+
// .replace(/\?(\w+)=/g, (_, slug) => slug === 'id' ? '?id=' : `&${slug}=`)
333333
});
334334
/**
335335
* Normalize the current url

‎lib/docsify.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/plugins/search.js

+27-19
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ function style () {
178178
dom.appendTo(dom.head, style);
179179
}
180180

181-
function tpl (opts) {
181+
function tpl (opts, defaultValue) {
182+
if ( defaultValue === void 0 ) defaultValue = '';
183+
182184
var html =
183-
"<input type=\"search\" />" +
185+
"<input type=\"search\" value=\"" + defaultValue + "\" />" +
184186
'<div class="results-panel"></div>' +
185187
'</div>';
186188
var el = dom.create('div', html);
@@ -190,26 +192,29 @@ function tpl (opts) {
190192
dom.before(aside, el);
191193
}
192194

193-
function bindEvents () {
195+
function doSearch (value) {
194196
var $search = dom.find('div.search');
195-
var $input = dom.find($search, 'input');
196197
var $panel = dom.find($search, '.results-panel');
197-
var doSearch = function (value) {
198-
if (!value) {
199-
$panel.classList.remove('show');
200-
$panel.innerHTML = '';
201-
return
202-
}
203-
var matchs = search(value);
204198

205-
var html = '';
206-
matchs.forEach(function (post) {
207-
html += "<div class=\"matching-post\">\n <h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n <p>" + (post.content) + "</p>\n</div>";
208-
});
199+
if (!value) {
200+
$panel.classList.remove('show');
201+
$panel.innerHTML = '';
202+
return
203+
}
204+
var matchs = search(value);
209205

210-
$panel.classList.add('show');
211-
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
212-
};
206+
var html = '';
207+
matchs.forEach(function (post) {
208+
html += "<div class=\"matching-post\">\n<h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n<p>" + (post.content) + "</p>\n</div>";
209+
});
210+
211+
$panel.classList.add('show');
212+
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
213+
}
214+
215+
function bindEvents () {
216+
var $search = dom.find('div.search');
217+
var $input = dom.find($search, 'input');
213218

214219
var timeId;
215220
// Prevent to Fold sidebar
@@ -243,9 +248,12 @@ function updateNoData (text, path) {
243248

244249
function init$$1 (opts) {
245250
dom = Docsify.dom;
251+
var keywords = Docsify.route.parse().query.s;
252+
246253
style();
247-
tpl(opts);
254+
tpl(opts, keywords);
248255
bindEvents();
256+
keywords && setTimeout(function (_) { return doSearch(keywords); }, 500);
249257
}
250258

251259
function update (opts, vm) {

‎lib/plugins/search.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)