Skip to content

Commit 43bbeac

Browse files
committed
Merge branch 'master' of https://github.com/canjs/bit-docs-html-canjs into 276-active-result-sticks-to-bottom
2 parents aa80df7 + 3a0d87c commit 43bbeac

File tree

6 files changed

+70
-63
lines changed

6 files changed

+70
-63
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bit-docs-html-canjs",
3-
"version": "1.0.1",
3+
"version": "1.0.3",
44
"description": "The plugins to produce the CanJS site",
55
"main": "static/canjs",
66
"scripts": {

static/canjs.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var $articleContainer,
4040
if (noModifierKeys && sameHostname && sameProtocol) {
4141
ev.preventDefault();
4242
var href = this.href;
43-
window.history.pushState(null, null, href);
4443
navigate(href);
4544
}
4645
});
@@ -92,10 +91,9 @@ function init() {
9291
if (!searchControl) {
9392
searchControl = new SearchControl(".search-bar", {
9493
navigate: function(href){
95-
window.history.pushState(null, null, href);
9694
navigate(href);
9795
},
98-
pathPrefix: '/doc',
96+
pathPrefix: window.pathPrefix,
9997
animateInOnStart: !hasShownSearch
10098
});
10199
}
@@ -152,6 +150,9 @@ function setScrollPosition() {
152150
}, 250);
153151
}
154152

153+
var $menuButton = $('[for="nav-trigger"]');
154+
var $navTrigger = $('#nav-trigger');
155+
155156
function navigate(href) {
156157
// make sure we're in the right spot
157158
if (href === "javascript://") { // jshint ignore:line
@@ -176,6 +177,10 @@ function navigate(href) {
176177

177178
loader.start();
178179

180+
if($menuButton.is(':visible')){
181+
$navTrigger.prop('checked', false);
182+
}
183+
179184
navigating = true;
180185
$.ajax(href, {
181186
dataType: "text",
@@ -194,7 +199,7 @@ function navigate(href) {
194199
ga('send', 'pageview', window.location.pathname);
195200

196201
// set new content
197-
var $content = $(content.match(/<body>(\r|\n|.)+<\/body>/g)[0]);
202+
var $content = $(content.match(/<body.*?>[\s\S]+<\/body>/g)[0]);
198203
if (!$content.length) {
199204
window.location.reload();
200205
}
@@ -237,8 +242,16 @@ function navigate(href) {
237242

238243
init();
239244
setDocTitle();
245+
246+
searchControl.options.pathPrefix = window.pathPrefix;
247+
if(searchControl.searchResultsCache){
248+
searchControl.renderSearchResults(searchControl.searchResultsCache);
249+
}
250+
251+
window.history.pushState(null, null, href);
240252
},
241253
error: function() {
254+
window.history.pushState(null, null, href);
242255
// just reload the page if this fails
243256
window.location.reload();
244257
},
@@ -457,4 +470,4 @@ function buildTOC() {
457470

458471
toc += Array(level - baseLevel + 1).join('</li></ol>') + "</li></ol>";
459472
$tableOfContents.append(toc);
460-
}
473+
}

static/content.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ article {
109109
margin-bottom: @gutter;
110110
&:before {
111111
display: inline-block;
112-
width: 1em;
113112
padding-right: 0.5em;
114113
font-weight: bold;
115114
text-align: right;

static/search.js

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var Search = Control.extend({
5959

6060
storageFallback: {},
6161
useLocalStorage: false,
62+
searchResultsCache: null,
6263

6364
// ---- END PROPERTIES ---- //
6465

@@ -462,21 +463,6 @@ var Search = Control.extend({
462463
self.clear();
463464
});
464465
}
465-
466-
// if we click the list item, navigate
467-
// if the target element is an anchor tag, simply clear
468-
if(this.$resultsContainer && this.$resultsContainer.length){
469-
this.$resultsContainer.on("click.search-component", ".search-results > ul > li", function(ev){
470-
var $target = $(ev.target),
471-
$a;
472-
473-
if(!$target.is("a")){
474-
$a = $target.closest("li").find("a");
475-
self.navigate($a.attr("href"));
476-
return;
477-
}
478-
});
479-
}
480466
},
481467
unbindResultsEvents: function(){
482468
//hide the search on cancel click
@@ -502,40 +488,45 @@ var Search = Control.extend({
502488
var self = this;
503489
this.searchDebounceHandle = setTimeout(function(){
504490
self.searchEngineSearch(value).then(function(results) {
505-
var numResults = results.length;
506-
if (numResults > 50) {
507-
numResults = '50+';
508-
results = results.slice(0, 50);
491+
self.searchResultsCache = results;
492+
self.renderSearchResults(results);
493+
});
494+
}, this.options.searchTimeout);
495+
},
496+
497+
renderSearchResults: function(results){
498+
var self = this;
499+
var numResults = results.length;
500+
if (numResults > 50) {
501+
numResults = '50+';
502+
results = results.slice(0, 50);
503+
}
504+
var resultsFrag = this.options.resultsRenderer({
505+
results: results,
506+
numResults: numResults,
507+
searchValue: this.searchTerm
508+
},{
509+
docUrl: function(){
510+
if(self.options.pathPrefix){
511+
return self.options.pathPrefix + "/" + this.url;
509512
}
510-
var resultsFrag = self.options.resultsRenderer({
511-
results: results,
512-
numResults: numResults,
513-
searchValue:value,
514-
pathPrefix: (self.options.pathPrefix === '.') ? '' : '/' + self.options.pathPrefix + '/'
515-
},{
516-
docUrl: function(){
517-
if(self.options.pathPrefix){
518-
return self.options.pathPrefix + "/" + this.url;
519-
}
520-
521-
if(this.url.substr(-1) === "/"){
522-
return this.url;
523-
}
524513

525-
return "/" + this.url;
526-
}
527-
});
514+
if(this.url.substr(-1) === "/"){
515+
return this.url;
516+
}
528517

529-
self.$resultsWrap.empty();
530-
self.$resultsWrap[0].appendChild(resultsFrag);
518+
return "/" + this.url;
519+
}
520+
});
531521

532-
//refresh necessary dom
533-
self.$resultsList = null;
534-
if(numResults){
535-
self.$resultsList = self.$resultsWrap.find(".search-results > ul");
536-
}
537-
});
538-
}, this.options.searchTimeout);
522+
this.$resultsWrap.empty();
523+
this.$resultsWrap[0].appendChild(resultsFrag);
524+
525+
//refresh necessary dom
526+
this.$resultsList = null;
527+
if(numResults){
528+
this.$resultsList = this.$resultsWrap.find(".search-results > ul");
529+
}
539530
},
540531

541532
// ---- SHOW/HIDE ---- //

static/search.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
a{
8585
color: @link-color;
8686
padding-bottom:0;
87+
&:hover {
88+
text-decoration: none;
89+
}
8790
}
8891
.name{
8992
line-height: 1;

templates/search-results.stache

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
<li>
1919
<a href="{{docUrl}}" title="{{result.name}}" class="result-name">
2020
{{#if result.title}}{{result.title}}{{else}}{{result.name}}{{/if}}
21-
</a>
21+
2222

23-
{{#if result.title}}
24-
<span class="name">
25-
({{result.name}})
26-
</span>
27-
{{/if}}
23+
{{#if result.title}}
24+
<span class="name">
25+
({{result.name}})
26+
</span>
27+
{{/if}}
2828

29-
{{#if result.description}}
30-
<div class="result-description" title="{{result.description}}">
31-
{{result.description}}
32-
</div>
33-
{{/if}}
29+
{{#if result.description}}
30+
<div class="result-description" title="{{result.description}}">
31+
{{result.description}}
32+
</div>
33+
{{/if}}
34+
</a>
3435
</li>
3536
{{/each}}
3637
</ul>

0 commit comments

Comments
 (0)