@@ -38,179 +38,6 @@ jQuery(function($) {
38
38
}
39
39
} ) ;
40
40
41
- /* ==========================================================================
42
- Search
43
- ========================================================================== */
44
-
45
- function search ( ) {
46
- 'use strict' ;
47
- if (
48
- typeof gh_search_key == 'undefined' ||
49
- gh_search_key == ''
50
- )
51
- return ;
52
-
53
- html . addClass ( 'has-search' ) ;
54
-
55
- var searchInput = $ ( '.search-field' ) ;
56
- var searchButton = $ ( '.search-button' ) ;
57
- var searchResult = $ ( '.search-result' ) ;
58
- var popular = $ ( '.popular-wrapper' ) ;
59
- var includeContent = typeof gh_search_content == 'undefined' || gh_search_content == true ? true : false ;
60
-
61
- var url =
62
- siteUrl +
63
- '/ghost/api/v3/content/posts/?key=' +
64
- gh_search_key +
65
- '&limit=all&fields=id,title,excerpt,url,updated_at,visibility&order=updated_at%20desc&formats=plaintext' ;
66
- var indexDump = JSON . parse ( localStorage . getItem ( 'ease_search_index' ) ) ;
67
- var index ;
68
-
69
- elasticlunr . clearStopWords ( ) ;
70
-
71
- localStorage . removeItem ( 'ease_index' ) ;
72
- localStorage . removeItem ( 'ease_last' ) ;
73
-
74
- function update ( data ) {
75
- data . posts . forEach ( function ( post ) {
76
- index . addDoc ( post ) ;
77
- } ) ;
78
-
79
- try {
80
- localStorage . setItem ( 'ease_search_index' , JSON . stringify ( index ) ) ;
81
- localStorage . setItem ( 'ease_search_last' , data . posts [ 0 ] . updated_at ) ;
82
- } catch ( e ) {
83
- console . error ( 'Your browser local storage is full. Update your search settings following the instruction at https://github.com/TryGhost/Dawn#disable-content-search' ) ;
84
- }
85
- }
86
-
87
- if (
88
- ! indexDump
89
- ) {
90
- $ . get ( url , function ( data ) {
91
- if ( data . posts . length > 0 ) {
92
- index = elasticlunr ( function ( ) {
93
- this . addField ( 'title' ) ;
94
- this . addField ( 'plaintext' ) ;
95
- this . setRef ( 'id' ) ;
96
- } ) ;
97
-
98
- update ( data ) ;
99
- }
100
- } ) ;
101
- } else {
102
- index = elasticlunr . Index . load ( indexDump ) ;
103
-
104
- $ . get (
105
- url +
106
- "&filter=updated_at:>'" +
107
- localStorage
108
- . getItem ( 'ease_search_last' )
109
- . replace ( / \. .* / , '' )
110
- . replace ( / T / , ' ' ) +
111
- "'" ,
112
- function ( data ) {
113
- if ( data . posts . length > 0 ) {
114
- update ( data ) ;
115
- }
116
- }
117
- ) ;
118
- }
119
-
120
- searchInput . on ( 'keyup' , function ( e ) {
121
- var result = index . search ( e . target . value , { expand : true } ) ;
122
- var output = '' ;
123
-
124
- result . forEach ( function ( post ) {
125
- output +=
126
- '<div class="search-result-row">' +
127
- '<a class="search-result-row-link" href="' +
128
- post . doc . url +
129
- '">' +
130
- '<div class="search-result-row-title">' +
131
- post . doc . title +
132
- '</div><div class="search-result-row-excerpt">' +
133
- post . doc . excerpt +
134
- '</div></a>' +
135
- '</div>' ;
136
- console . log ( post ) ;
137
- } ) ;
138
-
139
- searchResult . html ( output ) ;
140
-
141
- if ( e . target . value . length > 0 ) {
142
- searchButton . addClass ( 'search-button-clear' ) ;
143
- } else {
144
- searchButton . removeClass ( 'search-button-clear' ) ;
145
- }
146
-
147
- if ( result . length > 0 ) {
148
- popular . hide ( ) ;
149
- } else {
150
- popular . show ( ) ;
151
- }
152
- } ) ;
153
-
154
- $ ( '.search-form' ) . on ( 'submit' , function ( e ) {
155
- e . preventDefault ( ) ;
156
- } ) ;
157
-
158
- searchButton . on ( 'click' , function ( ) {
159
- if ( $ ( this ) . hasClass ( 'search-button-clear' ) ) {
160
- searchInput . val ( '' ) . focus ( ) . keyup ( ) ;
161
- }
162
- } ) ;
163
- }
164
- search ( ) ;
165
-
166
- /* ==========================================================================
167
- Search Overlay
168
- ========================================================================== */
169
-
170
- function modal ( ) {
171
- 'use strict' ;
172
- var modalOverlay = $ ( '.search-wrapper' ) ;
173
- var modal = $ ( '.search' ) ;
174
- var modalInput = $ ( '.search-field' ) ;
175
-
176
- $ ( '.nav-search' ) . on ( 'click' , function ( e ) {
177
- e . preventDefault ( ) ;
178
- modalOverlay . show ( ) . outerWidth ( ) ;
179
- html . addClass ( 'search-active' ) ;
180
- modalInput . focus ( ) ;
181
-
182
- if ( html . hasClass ( 'menu-active' ) ) {
183
- html . removeClass ( 'menu-active' ) ;
184
- }
185
- } ) ;
186
-
187
- $ ( '.search-wrapper-close, .search-wrapper' ) . on ( 'click' , function ( ) {
188
- html . removeClass ( 'search-active' ) ;
189
- } ) ;
190
-
191
- modal . on ( 'click' , function ( e ) {
192
- e . stopPropagation ( ) ;
193
- } ) ;
194
-
195
- $ ( document ) . keyup ( function ( e ) {
196
- if ( e . keyCode === 27 && html . hasClass ( 'search-active' ) ) {
197
- html . removeClass ( 'search-active' ) ;
198
- modalInput . val ( '' ) . keyup ( ) ;
199
- }
200
- } ) ;
201
-
202
- modalOverlay . on ( 'transitionend' , function ( e ) {
203
- if ( ! html . hasClass ( 'search-active' ) ) {
204
- modalOverlay . hide ( ) ;
205
- }
206
- } ) ;
207
-
208
- modal . on ( 'transitionend' , function ( e ) {
209
- e . stopPropagation ( ) ;
210
- } ) ;
211
- }
212
- modal ( ) ;
213
-
214
41
/* ==========================================================================
215
42
Parallax cover
216
43
========================================================================== */
0 commit comments