|
140 | 140 | * @type {jQuery}
|
141 | 141 | */
|
142 | 142 | this.$body = $('#lunr-search-body');
|
| 143 | + |
| 144 | + /** |
| 145 | + * @summary The Bootstrap modals' body's left column found in the lunr-search-modal.tmpl. |
| 146 | + * @type {jQuery} |
| 147 | + */ |
| 148 | + this.$bodyLeft = $('#lunr-search-body').find('.modal-body__left'); |
| 149 | + |
| 150 | + /** |
| 151 | + * @summary The Bootstrap modals' body's right column found in the lunr-search-modal.tmpl. |
| 152 | + * @type {jQuery} |
| 153 | + */ |
| 154 | + this.$bodyRight = $('#lunr-search-body').find('.modal-body__right'); |
| 155 | + |
143 | 156 | /**
|
144 | 157 | * @summary The Bootstrap modals' footer found in the lunr-search-modal.tmpl.
|
145 | 158 | * @type {jQuery}
|
|
154 | 167 | * @summary The maximum number of results to display per page.
|
155 | 168 | * @type {number}
|
156 | 169 | */
|
157 |
| - this.limit = 5; |
| 170 | + this.limit = 10; |
158 | 171 | }
|
159 | 172 |
|
160 | 173 | /**
|
|
202 | 215 | var self = this;
|
203 | 216 | return this.db.search(query).then(function (results) {
|
204 | 217 | var pages = [], index = -1;
|
205 |
| - // first split the results into pages using the limit |
206 | 218 |
|
| 219 | + // first split the results into pages using the limit |
207 | 220 |
|
208 |
| - // Here we can perform one last sort, in case we need to. |
209 |
| - var __actions = []; |
210 |
| - var __qualifiers = []; |
211 |
| - var __namespaces = []; |
212 |
| - var __methods = []; |
213 |
| - var __classes = []; |
214 |
| - var __sdk = []; |
215 |
| - var __rest = []; |
| 221 | + var all = {}; |
| 222 | + var summaries = ['action', 'qualifier', 'namespace','sdk', 'test',' config', 'method', 'class'] |
216 | 223 |
|
217 | 224 | results.forEach(function(doclet){
|
218 |
| - if (doclet.summary === 'action') { |
219 |
| - __actions.push(doclet); |
220 |
| - return; |
221 |
| - } |
222 |
| - |
223 |
| - if (doclet.summary === 'qualifier') { |
224 |
| - __qualifiers.push(doclet); |
225 |
| - return; |
| 225 | + for (var i = 0; i < summaries.length; i++) { |
| 226 | + var summaryKey = summaries[i]; |
| 227 | + if (summaryKey === doclet.summary) { |
| 228 | + all[summaryKey] = all[summaryKey] || []; |
| 229 | + all[summaryKey].push(doclet); |
| 230 | + return; |
| 231 | + } else if (summaryKey === doclet.kind) { |
| 232 | + all[summaryKey] = all[summaryKey] || []; |
| 233 | + all[summaryKey].push(doclet); |
| 234 | + return; |
| 235 | + } |
226 | 236 | }
|
227 | 237 |
|
228 |
| - if (doclet.summary.toLowerCase() === 'sdk') { |
229 |
| - __sdk.push(doclet); |
230 |
| - return; |
231 |
| - } |
| 238 | + // if nothing was found |
| 239 | + all['rest'] = all['rest'] || []; |
| 240 | + all['rest'].push(doclet); |
| 241 | + }); |
232 | 242 |
|
233 |
| - if (doclet.kind === 'function') { |
234 |
| - __methods.push(doclet); |
235 |
| - return; |
236 |
| - } |
| 243 | + var sortedResults = []; |
237 | 244 |
|
238 |
| - if (doclet.kind === 'classes') { |
239 |
| - __classes.push(doclet); |
240 |
| - return; |
| 245 | + summaries.forEach(function(summaryKey) { |
| 246 | + // make sure it exists, it might not! |
| 247 | + if (all[summaryKey]) { |
| 248 | + all[summaryKey].forEach(function(doclet){ sortedResults.push(doclet); }); |
241 | 249 | }
|
242 |
| - |
243 |
| - if (doclet.kind === 'namespace') { |
244 |
| - __namespaces.push(doclet); |
245 |
| - return; |
246 |
| - } |
247 |
| - __rest.push(doclet); |
248 | 250 | });
|
249 | 251 |
|
250 |
| - results = [].concat(__namespaces, __actions, __qualifiers, __sdk, __classes, __methods, __rest); |
| 252 | + if (all['rest']) { |
| 253 | + all['rest'].forEach(function(doclet){ sortedResults.push(doclet); }); |
| 254 | + } |
251 | 255 |
|
252 |
| - $.each(results, function (i, result) { |
| 256 | + $.each(sortedResults, function (i, result) { |
253 | 257 | if (i % self.limit === 0) {
|
254 | 258 | index = pages.push([]) - 1;
|
255 | 259 | }
|
256 | 260 | pages[index].push(result);
|
257 | 261 | });
|
258 | 262 | // once done clear the body and generate each page as it's own ul
|
259 |
| - self.$body.empty(); |
260 |
| - |
261 |
| - var $div = $('<h4/>', {'style': 'font-weight:bold'}).text('Legend:'); |
262 |
| - self.$body.append($div); |
263 |
| - |
264 |
| - var $div = $('<div/>'); |
265 |
| - $div.append($('<span/>', {'class': 'lunr-search-result-pill action'}).text('action')); |
266 |
| - $div.append($('<span/>', {'class': ''}).text(' - Contains the foo bar')); |
267 |
| - self.$body.append($div); |
268 |
| - |
269 |
| - var $div = $('<div/>'); |
270 |
| - $div.append($('<span/>', {'class': 'lunr-search-result-pill qualifier'}).text('qualifier')); |
271 |
| - $div.append($('<span/>', {'class': ''}).text(' - Contains the foo bar')); |
272 |
| - self.$body.append($div); |
273 |
| - |
274 |
| - var $div = $('<div/>'); |
275 |
| - $div.append($('<span/>', {'class': 'lunr-search-result-pill namespace'}).text('namespace')); |
276 |
| - $div.append($('<span/>', {'class': ''}).text(' - Contains the foo bar')); |
277 |
| - self.$body.append($div); |
278 |
| - |
279 |
| - var $div = $('<h4/>', {'style': 'font-weight:bold'}).text('Results:'); |
280 |
| - self.$body.append($div); |
| 263 | + self.$bodyLeft.empty(); |
281 | 264 |
|
282 | 265 | $.each(pages, function (i, page) {
|
283 | 266 | var $ul = $('<ul/>', {'class': 'lunr-search-results-page', id: 'lunr-search-result-page-' + i});
|
|
289 | 272 | var $li = $('<li/>');
|
290 | 273 | $li.addClass('search-result-line-item');
|
291 | 274 |
|
292 |
| - |
293 |
| - console.log(result); |
294 |
| - |
295 |
| - // var summary = result.summary; |
296 |
| - // var isBuilder = summary.indexOf('@builder') >= 0; |
| 275 | + // sanitize the id, it can have .html, or .html#foobar, we want use use each part as a a searchable item, but without the html |
| 276 | + // Foo.Bar.Zoo.html#qwerty -> [Foo, Bar, Zoo, querty] |
297 | 277 | var docletNamespace = result.id.replace('.html#', '.').replace('.html', '.').split('.').filter(function (a) {
|
298 | 278 | return a;
|
299 | 279 | });
|
300 |
| - var type = docletNamespace[0]; // Actions, Values, SDK - master namespace |
301 |
| - var masterType; |
302 |
| - |
303 |
| - // if (type === 'Actions' && isBuilder) { |
304 |
| - // masterType = 'Action builder'; |
305 |
| - // } else if ( type === 'Values' && isBuilder) { |
306 |
| - // masterType = 'Qualifier builder'; |
307 |
| - // } else if (kind === 'namespace') { |
308 |
| - // masterType = 'Namespace'; |
309 |
| - // } else { |
310 |
| - // masterType = docletNamespace[0]+ kind; |
311 |
| - // } |
312 |
| - |
313 |
| - masterType = docletNamespace[0] + ' -> ' + kind; |
314 | 280 |
|
315 | 281 | var $div = $('<div/>');
|
316 |
| - var group = docletNamespace[1]; // Delivery, Resize etc. |
317 |
| - |
318 |
| - console.log(docletNamespace); |
319 |
| - |
320 |
| - // MasterType -> _Group_ -> Method? |
321 |
| - // Master type |
322 |
| - |
323 |
| - var colors = ['black', 'black', 'black', 'teal']; |
324 | 282 |
|
325 | 283 | (result.summary || kind).split(' ').forEach(function (pillText) {
|
326 | 284 | if (pillText) {
|
327 | 285 | $div.append($('<span/>', {'class': 'lunr-search-result-pill' + ' ' + pillText.toLowerCase()}).text(pillText));
|
328 | 286 | }
|
329 | 287 | })
|
330 | 288 |
|
331 |
| - |
332 | 289 | docletNamespace.forEach(function (namespaceChunk, i) {
|
333 |
| - $div.append($('<span/>', {'style': 'color:' + colors[i] || 'black' + ';font-weight:bold'}).text(namespaceChunk)); |
| 290 | + var nextItemAsSpan = $('<span/>', {'style': 'font-weight:bold'}); |
| 291 | + |
334 | 292 | if (docletNamespace[i + 1]) {
|
| 293 | + $div.append($('<span/>', nextItemAsSpan).text(namespaceChunk)); |
335 | 294 | $div.append($('<span/>').text(' -> '));
|
| 295 | + } else { |
| 296 | + var nextItemAsLink = $('<a/>', { |
| 297 | + href: result.id, |
| 298 | + 'style': 'font-weight:bold', |
| 299 | + target: 'blank' |
| 300 | + }).text(namespaceChunk); |
| 301 | + $div.append(nextItemAsLink); |
336 | 302 | }
|
337 | 303 | });
|
338 | 304 |
|
339 | 305 | $li.append($div);
|
340 |
| - var $a = $('<a/>', { |
341 |
| - href: result.id, |
342 |
| - 'class': 'lunr-search-result-title' |
343 |
| - }).html(result.title).prepend($('<span/>', {'class': 'lunr-search-result-kind', text: result.kind + ': '})); |
344 |
| - $li.append($a); |
345 | 306 | $li.append($('<div/>', {'class': 'lunr-search-result-desc'}).text(result.description))
|
346 | 307 | $ul.append($li);
|
347 | 308 | });
|
348 | 309 |
|
349 |
| - self.$body.append($ul); |
| 310 | + self.$bodyLeft.append($ul); |
350 | 311 | });
|
351 | 312 | // if there is a pagination component from a previous search remove it now before we lose the reference to it
|
352 | 313 | if (self.$pagination.length) {
|
|
0 commit comments