Revision | 616ab7044653846bc4f62a2fdcd6dfe8a58f791a (tree) |
---|---|
Zeit | 2017-09-24 22:09:30 |
Autor | umorigu <umorigu@gmai...> |
Commiter | umorigu |
search2: Shor page summary
@@ -642,12 +642,19 @@ tr.bugtrack_state_undef td { | ||
642 | 642 | } |
643 | 643 | |
644 | 644 | /* search2.inc.php */ |
645 | -input#_plugin_search2_detail:checked ~ ul > pre { | |
645 | +input#_plugin_search2_detail:checked ~ ul > div.search-result-detail { | |
646 | 646 | display: block; |
647 | 647 | } |
648 | -input#_plugin_search2_detail ~ ul > pre { | |
648 | +input#_plugin_search2_detail ~ ul > div.search-result-detail { | |
649 | 649 | display: none; |
650 | 650 | } |
651 | +.search-result-page-summary { | |
652 | + font-size: 70%; | |
653 | + color: gray; | |
654 | + overflow: hidden; | |
655 | + text-overflow: ellipsis; | |
656 | + white-space: nowrap; | |
657 | +} | |
651 | 658 | |
652 | 659 | @media print { |
653 | 660 | a:link, |
@@ -148,14 +148,23 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
148 | 148 | } else { |
149 | 149 | updatedAt = val.updated_at; |
150 | 150 | } |
151 | - li.innerHTML = '<a href="' + href + '">' + decoratedName + '</a> ' + getPassage(now, updatedAt); | |
151 | + var liHtml = '<a href="' + href + '">' + decoratedName + '</a> ' + | |
152 | + getPassage(now, updatedAt); | |
153 | + li.innerHTML = liHtml; | |
152 | 154 | fragment.appendChild(li); |
155 | + var div = document.createElement('div'); | |
156 | + div.classList.add('search-result-detail'); | |
157 | + var head = document.createElement('div'); | |
158 | + head.classList.add('search-result-page-summary'); | |
159 | + head.innerHTML = escapeHTML(getBodySummary(val.body)); | |
160 | + div.appendChild(head); | |
153 | 161 | var summary = getSummary(val.body, searchRegex); |
154 | 162 | for (var i = 0; i < summary.length; i++) { |
155 | 163 | var pre = document.createElement('pre'); |
156 | 164 | pre.innerHTML = summary[i].lines.join('\n'); |
157 | - fragment.appendChild(pre); | |
165 | + div.appendChild(pre); | |
158 | 166 | } |
167 | + fragment.appendChild(div); | |
159 | 168 | ul.appendChild(fragment); |
160 | 169 | }); |
161 | 170 | if (!obj.search_done && obj.next_start_index) { |
@@ -362,6 +371,40 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( | ||
362 | 371 | } |
363 | 372 | } |
364 | 373 | } |
374 | + function getBodySummary(body) { | |
375 | + var lines = body.split('\n'); | |
376 | + var isInAuthorHeader = true; | |
377 | + var summary = []; | |
378 | + var lineCount = 0; | |
379 | + for (var index = 0, length = lines.length; index < length; index++) { | |
380 | + var line = lines[index]; | |
381 | + if (isInAuthorHeader) { | |
382 | + // '#author line is not search target' | |
383 | + if (line.match(/^#author\(/)) { | |
384 | + // Remove this line from search target | |
385 | + continue; | |
386 | + } else if (line.match(/^#freeze(\W|$)/)) { | |
387 | + continue; | |
388 | + // Still in header | |
389 | + } else { | |
390 | + // Already in body | |
391 | + isInAuthorHeader = false; | |
392 | + } | |
393 | + } | |
394 | + line = line.replace(/^\s+|\s+$/g, ''); | |
395 | + if (line.length === 0) continue; // Empty line | |
396 | + if (line.match(/^#\w+/)) continue; // Block-type plugin | |
397 | + if (line.match(/^\/\//)) continue; // Comment | |
398 | + if (line.substr(0, 1) === '*') { | |
399 | + line = line.replace(/\s*\[\#\w+\]$/, ''); // Remove anchor | |
400 | + } | |
401 | + summary.push(line); | |
402 | + if (summary.length >= 10) { | |
403 | + continue; | |
404 | + } | |
405 | + } | |
406 | + return summary.join(' ').substring(0, 150); | |
407 | + } | |
365 | 408 | function removeEncodeHint() { |
366 | 409 | var form = document.querySelector('form'); |
367 | 410 | if (form && form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) { |
@@ -518,12 +518,19 @@ tr.bugtrack_state_undef td { | ||
518 | 518 | } |
519 | 519 | |
520 | 520 | /* search2.inc.php */ |
521 | -input#_plugin_search2_detail:checked ~ ul > pre { | |
521 | +input#_plugin_search2_detail:checked ~ ul > div.search-result-detail { | |
522 | 522 | display: block; |
523 | 523 | } |
524 | -input#_plugin_search2_detail ~ ul > pre { | |
524 | +input#_plugin_search2_detail ~ ul > div.search-result-detail { | |
525 | 525 | display: none; |
526 | 526 | } |
527 | +.search-result-page-summary { | |
528 | + font-size: 70%; | |
529 | + color: gray; | |
530 | + overflow: hidden; | |
531 | + text-overflow: ellipsis; | |
532 | + white-space: nowrap; | |
533 | +} | |
527 | 534 | |
528 | 535 | @media print { |
529 | 536 | img#logo, |