-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.html
More file actions
178 lines (157 loc) · 5.69 KB
/
index.html
File metadata and controls
178 lines (157 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
layout: default
description: A repository of modern and idiomatic C++ code patterns curated by the community.
---
<section class="sample featured">
<div class="row">
<h1 class="column-4">Featured pattern: <a href="{{ site.baseurl }}/patterns/{{ page.random_sample.name }}.html">{{ page.random_sample.primary.title }}</a></h1>
</div>
<div class="row">
<div class="column-2">
<a href="{{ site.baseurl }}/patterns/{{ page.random_sample.name }}.html">
{% codeblock cpp %}{{ page.random_sample.primary.code }}{% endcodeblock %}
</a>
<div class="code-overlay">
<a href="{{ site.baseurl }}/patterns/{{ page.random_sample.name }}.html" class="code-overlay">
Continue reading →
</a>
</div>
</div>
<div class="column-2">
{% assign min_spec = page.random_sample.min_spec %}
<div class="min-spec">
Requires
<span class="tag {{ min_spec }}"><a href="/#/search/tag:{{ min_spec }}">{{ min_spec }}</a></span>
{% if min_spec != 'experimental' %}or newer{% endif %}
</div>
<h2>Intent</h2>
{{ page.random_sample.primary | sample_intent }}
<h2>Description</h2>
{{ page.random_sample.primary | sample_description | truncatewords: 35 }}
<p><a href="{{ site.baseurl }}/patterns/{{ page.random_sample.name }}.html">Continue reading →</a></p>
</div>
</div>
</section>
{% if site.environment == 'production' %}
<div class="row">
<div class="column-4">
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6789411983750873" data-ad-slot="4105099934" data-ad-format="auto"></ins>
</div>
</div>
{% endif %}
<section class="samples-index">
<div class="row">
<h1 class="column-4">All patterns</h1>
</div>
{% for category in page.sample_categories %}
{% assign groupname = forloop.index %}
<section class="samples-section">
<div class="samples-section-header row">
<h1 class="column-4">{{ category[0].title }}</h1>
</div>
<div class="row">
{% for sample in category[1] %}
<div class="index-item column-1">
<h1><a href="{{ site.baseurl }}/patterns/{{ sample.name }}.html">{{ sample.primary.title }}</a></h1>
{% assign min_spec = sample.min_spec %}
<div class="min-spec">
Requires
<span class="tag {{ min_spec }}"><a href="/#/search/tag:{{ min_spec }}">{{ min_spec }}</a></span>
{% if min_spec != 'experimental' %}or newer{% endif %}
</div>
{{ sample.primary | sample_intent }}
</div>
{% cycle groupname: '', '', '', '</div><div class="row">' %}
{% endfor %}
</div>
</section>
{% endfor %}
</section>
<section class="search-results">
<div class="row">
<div class="column-4">
<a href="{{ site.baseurl }}/">← All patterns</a>
<h1>Search Results</h1>
</div>
</div>
<section id="results" class="samples-section"></div>
</section>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
var specs = ['{{ page.specs | join: "', '" }}']
function filterSamples(event) {
var query = $('#search').val();
if (query.length > 0) {
$('.featured').fadeOut(200);
$('.samples-index').fadeOut(200, function() {
$('.search-results').fadeIn(200);
});
$("#results").empty();
var tags = []
var words = query.split(/[ ,]+/).reduce(function(words, word) {
if (word.startsWith('tag:')) {
tags.push(word.slice(4))
} else {
words.push(word.toLowerCase())
}
return words
}, []);
var matchingItems = $('.index-item').filter(function() {
var content = ($(this).children('h1').text() + ' ' + $(this).children('p').text()).toLowerCase();
var tagContent = $(this).find('.tag').text();
var wordsMatch = words.every(function(word) {
return content.indexOf(word) != -1;
})
var tagsMatch = tags.every(function(tag) {
return specs.indexOf(tag) >= specs.indexOf(tagContent);
})
return wordsMatch && tagsMatch;
}).clone();
var rows = [];
if (matchingItems.length > 0) {
matchingItems.each(function(index) {
if (index % 4 == 0) {
rows.push($('<div class="row"></div>'));
}
rows[rows.length - 1].append($(this));
});
} else {
rows.push($('<div class="row"><div class="column-4"><p>No patterns found matching your query.</p></div></div>'));
}
$("#results").append(rows);
history.replaceState({query: query}, '', '/#/search/' + encodeURIComponent(query));
} else {
$('.search-results').fadeOut(200, function() {
$('.featured').fadeIn(200);
$('.samples-index').fadeIn(200);
});
history.replaceState({}, '', '/');
}
}
function clearSearch() {
$('#search').val('');
filterSamples();
}
function onHashChange() {
var match = window.location.hash.match(/^#\/search\/(.*)$/);
$('#search').val(match[1]);
filterSamples();
}
$(function() {
$('#search')
.on('input', filterSamples)
.keyup(function(event) {
if (event.keyCode == 27) {
clearSearch();
}
});
var currentState = history.state;
if (currentState && currentState.query) {
$('#search').val(currentState.query);
filterSamples();
} else if (window.location.hash) {
onHashChange();
}
$(window).on('hashchange', onHashChange);
});
</script>