Skip to content

Commit 299dc6b

Browse files
authored
Merge pull request #302 from canjs/fix-sidebar-animation
Fix opening search animation
2 parents 30f3bb1 + a240991 commit 299dc6b

File tree

6 files changed

+39
-58
lines changed

6 files changed

+39
-58
lines changed

static/layout.less

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
position: fixed;
1313
width: @sidebar-width;
1414
min-width: 0;
15-
transition: min-width 0.4s ease;
15+
transition: min-width @transition-speed ease;
1616
@media screen and (min-width: @breakpoint){
1717
flex-shrink: 0;
1818
padding: 0px;
1919
position: relative;
2020
width: auto;
21+
22+
&.search-showing {
23+
min-width: 300px !important;
24+
}
2125
}
2226
}
23-
#left.search-showing {
24-
min-width: 300px !important;
25-
}
2627
#right {
2728
height: 100%;
2829
min-height: 100%;

static/search.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var Search = Control.extend({
3030
keyboardActiveClass: "keyboard-active",
3131

3232
//search options
33+
searchAnimation: 250,// matches @transition-speed in variables.less
3334
searchTimeout: 400,
3435

3536
localStorageKeyPrefix: "search",
@@ -85,7 +86,7 @@ var Search = Control.extend({
8586

8687
//show the search input when the search engine is ready
8788
if(self.options.animateInOnStart){
88-
self.$inputWrap.fadeIn(400);
89+
self.$inputWrap.fadeIn(self.options.searchAnimation);
8990
}else{
9091
self.$inputWrap.show();
9192
}
@@ -472,11 +473,8 @@ var Search = Control.extend({
472473
},
473474

474475
//cancel search on cancel click
475-
".search-icon-cancel click": function(el, ev){
476-
ev.preventDefault();
477-
ev.stopPropagation();
478-
this.clear();
479-
},
476+
".search-icon-cancel click": "clear",
477+
".search-icon-cancel touchend": "clear",
480478

481479
// ---- END EVENTS ---- //
482480

@@ -573,7 +571,11 @@ var Search = Control.extend({
573571
// function clear
574572
// - clears & focuses the input
575573
// - unsets the search state
576-
clear: function(){
574+
clear: function(element, event) {
575+
if (event) {
576+
event.preventDefault();
577+
event.stopPropagation();
578+
}
577579
this.$input.val("").trigger("focus");
578580
this.unsetSearchState();
579581
},
@@ -599,7 +601,7 @@ var Search = Control.extend({
599601
this.deactivateResult();
600602
$('#left').removeClass('search-showing');
601603
this.$resultsContainer.stop().addClass("is-hiding").fadeOut({
602-
duration: 400,
604+
duration: this.options.searchAnimation,
603605
complete: function(){
604606
self.$resultsContainer.removeClass("is-hiding");
605607
if(!self.$resultsContainer.is(".is-showing")){
@@ -626,7 +628,7 @@ var Search = Control.extend({
626628
}
627629
this.$resultsContainerParent.stop().addClass("search-active");
628630
this.$resultsContainer.addClass("is-showing").fadeIn({
629-
duration: 400,
631+
duration: this.options.searchAnimation,
630632
complete: function(){
631633
if(!self.$resultsContainer.is(".is-hiding")){
632634
self.$resultsContainer.removeClass("is-showing");

static/search.less

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
cursor:pointer;
77

88
.search-wrap{
9+
display: flex;
910
position: relative;
10-
padding: 0 1.5em;
11+
top: 1px;
12+
1113
.search-icon{
1214
display: block;
13-
position: absolute;
14-
top: 1px;
15-
left: 0;
1615
height: 1em;
1716
width: 1em;
1817
font-size: 1em;
@@ -22,30 +21,26 @@
2221
background-repeat: no-repeat;
2322
}
2423
.search-icon-cancel{
25-
display: block;
26-
position: absolute;
27-
right: 0;
24+
position: relative;
2825
height: 1em;
2926
width: 1em;
3027
font-size: .8em;
31-
top: 0.25em;
28+
top: 0.125em;
3229
cursor: pointer;
3330
background-color: @code-color;
3431
background-image: url(img/icon-x-white.svg);
3532
background-size: cover;
3633
background-repeat: no-repeat;
3734
display:none;
3835
}
39-
36+
4037
.search{
41-
transition: width 0.4s ease;
38+
transition: width @transition-speed ease;
4239
background: @code-color;
4340
color: #ffffff;
4441
border: none;
45-
padding: 0;
46-
position: relative;
47-
bottom: 2px;
48-
width: 40px;
42+
padding: 0 .5em;
43+
flex: 1;
4944
.placeholder(@gray);
5045
&:focus{
5146
outline:none;
@@ -55,19 +50,7 @@
5550
&.has-value .search-icon-cancel{
5651
display:block;
5752
}
58-
@media screen and (max-width: @breakpoint) {
59-
&.has-value{
60-
width: 200px;
61-
}
62-
}
6353
}
64-
@media screen and (min-width: @breakpoint) {
65-
display: block;
66-
}
67-
}
68-
69-
#left.search-showing .search-bar .search-wrap .search {
70-
width: 100%;
7154
}
7255

7356
.bottom-left{
@@ -82,6 +65,7 @@
8265
left: 0;
8366
overflow-y: auto;
8467
padding: 2em 0;
68+
transition: -webkit-backdrop-filter backdrop-filter background @transition-speed ease;
8569
z-index: 1;
8670
.search-cancel{
8771
color: @code-color;
@@ -90,9 +74,6 @@
9074
padding: .5em;
9175
font-size: 1em;
9276
line-height: 1;
93-
position: absolute;
94-
top: 0;
95-
right: 0;
9677
}
9778

9879
ul{
@@ -157,3 +138,11 @@
157138
position:relative;
158139
}
159140
}
141+
142+
@supports (-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px)) {
143+
.bottom-left .search-results-container {
144+
-webkit-backdrop-filter: @backdrop-blur;
145+
backdrop-filter: @backdrop-blur;
146+
background: rgba(100%, 100%, 100%, .65);
147+
}
148+
}

static/sidebar.less

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
.search-bar {
2-
background: @code-color;
3-
padding: @gutter @gutter*2;
4-
height: 48px;
5-
p {
6-
border: none;
7-
margin: 0px;
8-
color: white;
9-
font-weight: 300;
10-
}
11-
@media screen and (min-width: @breakpoint) {
12-
display: block;
13-
}
14-
}
15-
161
// ----- SOCIAL BUTTONS FOR MOBILE VIEW -----
172
ul.social-side{
183
margin: 0;

static/variables.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
/*----- TYPE -----*/
2020
@font-weight-heading: 500;
21+
22+
/*----- OTHER -----*/
23+
@backdrop-blur: saturate(180%) blur(20px);

templates/search-bar.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<div class="search-bar">
22
<div class="search-wrap" style="display:none;">
33
<span class="search-icon"></span>
4-
<span class="search-icon-cancel"></span>
54
<input
65
type="text"
6+
size="6"
77
class="search"
88
placeholder="Search"
99
autocomplete="off"
1010
autocorrect="off"
1111
autocapitalize="none"
1212
spellcheck="false"/>
13+
<span class="search-icon-cancel"></span>
1314
</div>
1415
</div>

0 commit comments

Comments
 (0)