Search fixes and cleanup, sorting (#32)

* Add classes and data

* Change chart to only search compatibility column

* Remove no longer necessary data attribute

* Cleanup indentation

* Remove no longer necessary metadata element

* Revert "Remove no longer necessary metadata element"

* Add manual search

* Remove section headers

* Implement dynamic headers
This commit is contained in:
BynariStar 2017-07-09 20:04:05 +03:00 committed by Flame Sage
parent cf6a415dd5
commit fa6fc6375f
2 changed files with 50 additions and 26 deletions

View File

@ -43,40 +43,35 @@
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th>Title</th> <th class="sort" data-sort="title">Title</th>
<th>Type</th> <th class="sort" data-sort="type">Type</th>
<th>Compatibility</th> <th class="sort" data-sort="compatibility">Compatibility</th>
<th>Date Tested</th> <th class="sort" data-sort="date-tested">Date Tested</th>
</tr> </tr>
</thead> </thead>
<tbody class="list"> <tbody class="list">
{{ range .Data.Pages.GroupByParam "section_id" }} {{ range .Data.Pages.GroupByParam "section_id" }}
<tr>
<td id="game-section-header">
<h3 id="{{ .Key }}">{{ .Key }}</h3>
</td>
</tr>
{{ range .Pages }} {{ range .Pages }}
{{- $rating := index .Site.Data.compatibility .Params.compatibility }} {{- $rating := index .Site.Data.compatibility .Params.compatibility }}
{{- $type := index .Site.Data.gameTypes (.Params.game_type | default "3ds") }} {{- $type := index .Site.Data.gameTypes (.Params.game_type | default "3ds") }}
<tr data-compatibility="{{ $rating.name }}"> <tr data-key="{{ .Key }}">
<td class="hidden listing-metadata"> <td class="hidden listing-metadata">
{{ .Params.title }} {{ $type.name }} {{ $rating.name }} {{ dateFormat "January 2, 2006" .Params.testcase_date }} {{ .Params.title }} {{ $type.name }} {{ $rating.name }} {{ dateFormat "January 2, 2006" .Params.testcase_date }}
</td> </td>
<td class="col-md-1"> <td class="col-md-1 icon">
<img src="/images/game/icons/{{ .File.BaseFileName }}.png" /> <img src="/images/game/icons/{{ .File.BaseFileName }}.png" />
</td> </td>
<td class="col-md-6"> <td class="col-md-6 title">
<a href="{{ .Permalink }}">{{ .Params.title }}</a> <a href="{{ .Permalink }}">{{ .Params.title }}</a>
</td> </td>
<td class="col-md-1"> <td class="col-md-1 type">
<img src="/images/game/types/{{ $type.key }}.png" title="{{ $type.name }}" /> <img src="/images/game/types/{{ $type.key }}.png" title="{{ $type.name }}" />
</td> </td>
<td class="col-md-1"> <td class="col-md-1 compatibility">
<div class="square-icon" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }} <div class="square-icon" style="background-color: {{ $rating.color }}"></div> {{ $rating.name }}
</td> </td>
<td class="col-md-3"> <td class="col-md-3 date-tested">
{{ dateFormat "January 2, 2006" .Params.testcase_date }} {{ dateFormat "January 2, 2006" .Params.testcase_date }}
</td> </td>
</tr> </tr>
@ -94,7 +89,7 @@
<script type="text/javascript"> <script type="text/javascript">
var options = { var options = {
valueNames: ['listing-metadata'], valueNames: ['listing-metadata', 'icon', 'title', 'type', 'compatibility', 'date-tested'],
pagination: true, pagination: true,
indexAsync: true, indexAsync: true,
page: 50 page: 50
@ -102,11 +97,30 @@
var list = new List('game-listing', options); var list = new List('game-listing', options);
list.sort("title", {order: "asc"});
$('#search-box').keyup(function() {
var searchString = $(this).val();
list.fuzzySearch(searchString, ['listing-metadata']);
});
list.on("updated", function(){
$("#compatibility-list tbody tr.key").removeClass("key");
if ($("#compatibility-list thead").find("th.asc[data-sort='title'], th.desc[data-sort='title']").length){
$("#compatibility-list tbody tr[data-key]").each(function(){
var key = $(this).attr("data-key")
if ($("tr[data-key='" + key + "']:first").is($(this))){
$(this).addClass("key");
}
})
}
})
function filterTable(_) { function filterTable(_) {
var rating = this.name; var rating = this.name;
$("#search-box").val(rating); $("#search-box").val(rating);
list.fuzzySearch(rating); list.search(rating, ['compatibility']);
} }
function clearSearch() { function clearSearch() {

View File

@ -348,3 +348,13 @@ a:hover, a:focus {
.search-box { .search-box {
margin: 0 20px; margin: 0 20px;
} }
tr.key:after {
content: attr(data-key);
position: absolute;
left: -10px;
font-family: Dosis,"Helvetica Neue",Helvetica,Arial,sans-serif;
color: #888;
margin: 15px 0;
font-size: 24px;
}