|
5 | 5 | <link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
|
6 | 6 |
|
7 | 7 | <dom-module id="my-search-bar">
|
8 |
| -<!-- TODO: Fix title showing up above this --> |
9 | 8 |
|
10 | 9 | <style>
|
11 | 10 |
|
|
53 | 52 | display: block;
|
54 | 53 | }
|
55 | 54 |
|
56 |
| - #search #back-icon { |
| 55 | + #search #backIcon { |
57 | 56 | display: none;
|
58 | 57 | }
|
59 |
| - #search #search-icon { |
| 58 | + #search #searchIcon { |
60 | 59 | display: block;
|
61 | 60 | }
|
62 | 61 |
|
|
77 | 76 | -webkit-appearance: none;
|
78 | 77 | }
|
79 | 78 |
|
80 |
| - #results-container { |
| 79 | + #resultsContainer { |
81 | 80 | display: none;
|
82 | 81 | @apply(--paper-font-body1);
|
83 | 82 | color: var(--primary-text-color);
|
|
92 | 91 | }
|
93 | 92 |
|
94 | 93 | @media (max-width: 639px) {
|
95 |
| - #results-container { |
| 94 | + #resultsContainer { |
96 | 95 | top: 56px;
|
97 | 96 | height: calc(100vh - 56px);
|
98 | 97 | }
|
|
103 | 102 |
|
104 | 103 | <template>
|
105 | 104 | <div id="search" opened$="{{opened}}" on-click="toggleSearch">
|
106 |
| - <paper-icon-button icon="search" id="search-icon"></paper-icon-button> |
107 |
| - <paper-icon-button icon="arrow-back" id="back-icon"></paper-icon-button> |
| 105 | + <paper-icon-button icon="search" id="searchIcon"></paper-icon-button> |
| 106 | + <paper-icon-button icon="arrow-back" id="backIcon"></paper-icon-button> |
108 | 107 | <input is="iron-input" bind-value="{{searchInput}}" type="search" id="input" autocomplete="off">
|
109 | 108 | </div>
|
110 |
| - <div class="list" opened$="{{opened}}" id="results-container"></div> |
111 |
| - |
112 |
| - <script type="text/javascript"> |
113 |
| - /*jshint multistr: true */ |
114 |
| - // Do search with json file and make results appear |
115 |
| - SimpleJekyllSearch({ |
116 |
| - searchInput: document.getElementById('search-input'), |
117 |
| - resultsContainer: document.getElementById('results-container'), |
118 |
| - json: '{{searchjson}}', |
119 |
| - searchResultTemplate: |
120 |
| - '<a href="{url}" class="test"><paper-item> \ |
121 |
| - <paper-item-body two-line> \ |
122 |
| - <div>{title}</div> \ |
123 |
| - <div secondary>{date}</div> \ |
124 |
| - <paper-ripple></paper-ripple>\ |
125 |
| - </paper-item-body> \ |
126 |
| - </paper-item></a><hr/>', |
127 |
| - noResultsText: '<p>No posts found</p>', |
128 |
| - limit: 20, |
129 |
| - fuzzy: true |
130 |
| - }); |
131 |
| - </script> |
| 109 | + <div class="list" opened$="{{opened}}" id="resultsContainer"></div> |
132 | 110 | </template>
|
133 | 111 |
|
| 112 | + <script src="../../bower_components/simple-jekyll-search/dest/jekyll-search.js" type="text/javascript"></script> |
134 | 113 | <script>
|
| 114 | + /*jshint multistr: true */ |
| 115 | + // Do search with json file and make results appear |
| 116 | + |
135 | 117 | Polymer({
|
136 | 118 | is: 'my-search-bar',
|
137 | 119 |
|
|
148 | 130 | type: String,
|
149 | 131 | value: ''
|
150 | 132 | },
|
| 133 | + searchjson: { |
| 134 | + type: String, |
| 135 | + value: 'search.json' |
| 136 | + }, |
151 | 137 |
|
152 | 138 | animationConfig: {
|
153 | 139 | type: Object,
|
|
192 | 178 | },
|
193 | 179 |
|
194 | 180 | _onAnimationFinish: function() {
|
195 |
| - var results = document.querySelector('#results-container'); |
196 |
| - var searchIcon = document.querySelector('#search-icon'); |
197 |
| - var backIcon = document.querySelector('#back-icon'); |
| 181 | + var results = this.$.resultsContainer; |
| 182 | + var searchIcon = this.$.searchIcon; |
| 183 | + var backIcon = this.$.backIcon; |
198 | 184 | var middleBar = document.querySelector('#middleBar');
|
199 | 185 | var bottomBar = document.querySelector('#bottomBar');
|
200 | 186 | if (!this.opened) {
|
|
214 | 200 | },
|
215 | 201 |
|
216 | 202 | show: function() {
|
217 |
| - var results = document.querySelector('#results-container'); |
| 203 | + var results = this.$.resultsContainer; |
218 | 204 | results.style.display = 'block';
|
219 | 205 | this.playAnimation('entry');
|
220 | 206 | },
|
221 | 207 |
|
222 | 208 | hide: function() {
|
223 | 209 | this.playAnimation('exit');
|
224 | 210 | this.opened = false;
|
| 211 | + }, |
| 212 | + |
| 213 | + ready: function () { |
| 214 | + SimpleJekyllSearch({ |
| 215 | + searchInput: this.$.input, |
| 216 | + resultsContainer: this.$.resultsContainer, |
| 217 | + json: this.searchjson, |
| 218 | + searchResultTemplate: |
| 219 | + '<a href="{url}" class="test"><paper-item> \ |
| 220 | + <paper-item-body two-line> \ |
| 221 | + <div>{title}</div> \ |
| 222 | + <div secondary>{date}</div> \ |
| 223 | + <paper-ripple></paper-ripple>\ |
| 224 | + </paper-item-body> \ |
| 225 | + </paper-item></a><hr/>', |
| 226 | + noResultsText: '<p>No posts found</p>', |
| 227 | + limit: 20, |
| 228 | + fuzzy: true |
| 229 | + }); |
225 | 230 | }
|
226 | 231 | });
|
227 | 232 | </script>
|
|
0 commit comments