superbara 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +4 -0
- data/docs/_FontAwesome/css/font-awesome.css +4 -0
- data/docs/_FontAwesome/fonts/FontAwesome.ttf +0 -0
- data/docs/_FontAwesome/fonts/fontawesome-webfont.eot +0 -0
- data/docs/_FontAwesome/fonts/fontawesome-webfont.svg +640 -0
- data/docs/_FontAwesome/fonts/fontawesome-webfont.ttf +0 -0
- data/docs/_FontAwesome/fonts/fontawesome-webfont.woff +0 -0
- data/docs/_FontAwesome/fonts/fontawesome-webfont.woff2 +0 -0
- data/docs/ayu-highlight.css +71 -0
- data/docs/book.css +1454 -0
- data/docs/book.js +590 -0
- data/docs/clipboard.min.js +7 -0
- data/docs/elasticlunr.min.js +10 -0
- data/docs/favicon.png +0 -0
- data/docs/getting_started/index.html +243 -0
- data/docs/getting_started/shell.png +0 -0
- data/docs/highlight.css +69 -0
- data/docs/highlight.js +2 -0
- data/docs/index.html +221 -0
- data/docs/install.html +227 -0
- data/docs/mark.min.js +7 -0
- data/docs/print.html +336 -0
- data/docs/reference/assert.html +258 -0
- data/docs/reference/dialogs/alert.html +225 -0
- data/docs/reference/dialogs/confirm.html +225 -0
- data/docs/reference/dialogs/index.html +230 -0
- data/docs/reference/dialogs/prompt.html +217 -0
- data/docs/reference/find.html +235 -0
- data/docs/reference/tests/has_text.html +241 -0
- data/docs/reference/tests/index.html +225 -0
- data/docs/reference/wait.html +245 -0
- data/docs/reference.html +225 -0
- data/docs/searcher.js +461 -0
- data/docs/searchindex.js +1 -0
- data/docs/superbara.html +222 -0
- data/docs/tomorrow-night.css +96 -0
- data/docs-src/book.toml +11 -0
- data/docs-src/src/SUMMARY.md +18 -0
- data/docs-src/src/getting_started/index.md +38 -0
- data/docs-src/src/getting_started/shell.png +0 -0
- data/docs-src/src/install.md +5 -0
- data/docs-src/src/reference/assert.md +48 -0
- data/docs-src/src/reference/dialogs/alert.md +1 -0
- data/docs-src/src/reference/dialogs/confirm.md +1 -0
- data/docs-src/src/reference/dialogs/index.md +5 -0
- data/docs-src/src/reference/dialogs/prompt.md +1 -0
- data/docs-src/src/reference/find.md +21 -0
- data/docs-src/src/reference/results.md +53 -0
- data/docs-src/src/reference/tests/has_text.md +24 -0
- data/docs-src/src/reference/tests/index.md +1 -0
- data/docs-src/src/reference/wait.md +33 -0
- data/docs-src/src/reference.md +2 -0
- data/docs-src/src/superbara.md +7 -0
- data/lib/capybara_monkey.rb +10 -5
- data/lib/selenium_monkey.rb +2 -17
- data/lib/superbara/cli.rb +16 -8
- data/lib/superbara/context.rb +5 -6
- data/lib/superbara/dsl.rb +25 -8
- data/lib/superbara/helpers.rb +24 -1
- data/lib/superbara/version.rb +1 -1
- data/lib/superbara.rb +12 -2
- data/superbara.gemspec +1 -0
- data/tests/features/screenshot.rb +30 -0
- metadata +55 -2
data/docs/reference.html
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html lang="en" class="sidebar-visible">
|
|
3
|
+
<head>
|
|
4
|
+
<!-- Book generated using mdBook -->
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Language Reference - Superbara</title>
|
|
7
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
8
|
+
<meta name="description" content="">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
<meta name="theme-color" content="#ffffff" />
|
|
11
|
+
|
|
12
|
+
<base href="">
|
|
13
|
+
|
|
14
|
+
<link rel="stylesheet" href="book.css">
|
|
15
|
+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
|
|
16
|
+
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
|
|
17
|
+
|
|
18
|
+
<link rel="shortcut icon" href="favicon.png">
|
|
19
|
+
|
|
20
|
+
<!-- Font Awesome -->
|
|
21
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
|
22
|
+
|
|
23
|
+
<link rel="stylesheet" href="highlight.css">
|
|
24
|
+
<link rel="stylesheet" href="tomorrow-night.css">
|
|
25
|
+
<link rel="stylesheet" href="ayu-highlight.css">
|
|
26
|
+
|
|
27
|
+
<!-- Custom theme -->
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<!-- Fetch Clipboard.js from CDN but have a local fallback -->
|
|
33
|
+
<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>
|
|
34
|
+
<script>
|
|
35
|
+
if (typeof Clipboard == 'undefined') {
|
|
36
|
+
document.write(unescape("%3Cscript src='clipboard.min.js'%3E%3C/script%3E"));
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<noscript>
|
|
41
|
+
<style type="text/css">
|
|
42
|
+
.javascript-only {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
46
|
+
</noscript>
|
|
47
|
+
|
|
48
|
+
</head>
|
|
49
|
+
<body class="light">
|
|
50
|
+
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
|
51
|
+
<script type="text/javascript">
|
|
52
|
+
try {
|
|
53
|
+
var theme = localStorage.getItem('mdbook-theme');
|
|
54
|
+
var sidebar = localStorage.getItem('mdbook-sidebar');
|
|
55
|
+
|
|
56
|
+
if (theme.startsWith('"') && theme.endsWith('"')) {
|
|
57
|
+
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
|
|
61
|
+
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
|
|
62
|
+
}
|
|
63
|
+
} catch (e) { }
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<!-- Set the theme before any content is loaded, prevents flash -->
|
|
67
|
+
<script type="text/javascript">
|
|
68
|
+
var theme;
|
|
69
|
+
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
|
70
|
+
if (theme === null || theme === undefined) { theme = 'light'; }
|
|
71
|
+
document.body.className = theme;
|
|
72
|
+
document.querySelector('html').className = theme;
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<!-- Hide / unhide sidebar before it is displayed -->
|
|
76
|
+
<script type="text/javascript">
|
|
77
|
+
var html = document.querySelector('html');
|
|
78
|
+
var sidebar = 'hidden';
|
|
79
|
+
if (document.body.clientWidth >= 1080) {
|
|
80
|
+
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
|
81
|
+
sidebar = sidebar || 'visible';
|
|
82
|
+
}
|
|
83
|
+
html.classList.remove('sidebar-visible');
|
|
84
|
+
html.classList.add("sidebar-" + sidebar);
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
|
88
|
+
<ol class="chapter"><li class="affix"><a href="superbara.html">Superbara</a></li><li><a href="install.html">Install</a></li><li><a href="getting_started/index.html">Getting Started</a></li><li><a href="reference.html" class="active">Language Reference</a></li><li><ol class="section"><li><a href="reference/assert.html">assert</a></li><li><a href="reference/find.html">find</a></li><li><a href="reference/wait.html">wait</a></li><li><a href="reference/tests/index.html">Tests</a></li><li><ol class="section"><li><a href="reference/tests/has_text.html">has_text?</a></li></ol></li><li><a href="reference/dialogs/index.html">Dialogs</a></li><li><ol class="section"><li><a href="reference/dialogs/alert.html">alert</a></li><li><a href="reference/dialogs/confirm.html">confirm</a></li><li><a href="reference/dialogs/prompt.html">prompt</a></li></ol></li></ol></li></ol>
|
|
89
|
+
</nav>
|
|
90
|
+
|
|
91
|
+
<div id="page-wrapper" class="page-wrapper">
|
|
92
|
+
|
|
93
|
+
<div class="page">
|
|
94
|
+
|
|
95
|
+
<div id="menu-bar" class="menu-bar">
|
|
96
|
+
<div id="menu-bar-sticky-container">
|
|
97
|
+
<div class="left-buttons javascript-only">
|
|
98
|
+
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
|
99
|
+
<i class="fa fa-bars"></i>
|
|
100
|
+
</button>
|
|
101
|
+
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
|
102
|
+
<i class="fa fa-paint-brush"></i>
|
|
103
|
+
</button>
|
|
104
|
+
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
|
105
|
+
<li role="none"><button role="menuitem" class="theme" id="light">Light <span class="default">(default)</span></button></li>
|
|
106
|
+
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
|
107
|
+
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
|
108
|
+
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
|
109
|
+
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
|
110
|
+
</ul>
|
|
111
|
+
|
|
112
|
+
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
|
113
|
+
<i class="fa fa-search"></i>
|
|
114
|
+
</button>
|
|
115
|
+
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<h1 class="menu-title">Superbara</h1>
|
|
119
|
+
|
|
120
|
+
<div class="right-buttons">
|
|
121
|
+
<a href="print.html" title="Print this book" aria-label="Print this book">
|
|
122
|
+
<i id="print-button" class="fa fa-print"></i>
|
|
123
|
+
</a>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
<div id="searchbar-outer" class="searchbar-outer">
|
|
130
|
+
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
|
131
|
+
</div>
|
|
132
|
+
<div id="searchresults-outer" class="searchresults-outer">
|
|
133
|
+
<div class="searchresults-header" id="searchresults-header"></div>
|
|
134
|
+
<ul id="searchresults">
|
|
135
|
+
</ul>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
|
140
|
+
<script type="text/javascript">
|
|
141
|
+
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
|
142
|
+
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
|
143
|
+
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
|
144
|
+
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
|
145
|
+
});
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<div id="content" class="content">
|
|
149
|
+
<main>
|
|
150
|
+
<a class="header" href="reference.html#language-reference" id="language-reference"><h1>Language Reference</h1></a>
|
|
151
|
+
|
|
152
|
+
</main>
|
|
153
|
+
|
|
154
|
+
<nav class="nav-wrapper" aria-label="Page navigation">
|
|
155
|
+
<!-- Mobile navigation buttons -->
|
|
156
|
+
|
|
157
|
+
<a rel="prev" href="getting_started/index.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
158
|
+
<i class="fa fa-angle-left"></i>
|
|
159
|
+
</a>
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
<a rel="next" href="reference/assert.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
164
|
+
<i class="fa fa-angle-right"></i>
|
|
165
|
+
</a>
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
<div style="clear: both"></div>
|
|
169
|
+
</nav>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
|
174
|
+
|
|
175
|
+
<a href="getting_started/index.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
176
|
+
<i class="fa fa-angle-left"></i>
|
|
177
|
+
</a>
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<a href="reference/assert.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
182
|
+
<i class="fa fa-angle-right"></i>
|
|
183
|
+
</a>
|
|
184
|
+
|
|
185
|
+
</nav>
|
|
186
|
+
|
|
187
|
+
</div>
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
<!-- Local fallback for Font Awesome -->
|
|
191
|
+
<script>
|
|
192
|
+
if (getComputedStyle(document.querySelector(".fa")).fontFamily !== "FontAwesome") {
|
|
193
|
+
var link = document.createElement('link');
|
|
194
|
+
link.rel = 'stylesheet';
|
|
195
|
+
link.type = 'text/css';
|
|
196
|
+
link.href = '_FontAwesome/css/font-awesome.css';
|
|
197
|
+
document.head.insertBefore(link, document.head.firstChild)
|
|
198
|
+
}
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
<script src="searchindex.js" type="text/javascript" charset="utf-8"></script>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
<script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
|
|
212
|
+
<script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
|
|
213
|
+
<script src="searcher.js" type="text/javascript" charset="utf-8"></script>
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
<script src="highlight.js"></script>
|
|
219
|
+
<script src="book.js"></script>
|
|
220
|
+
|
|
221
|
+
<!-- Custom JS script -->
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
</body>
|
|
225
|
+
</html>
|
data/docs/searcher.js
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
window.search = window.search || {};
|
|
2
|
+
(function search(search) {
|
|
3
|
+
// Search functionality
|
|
4
|
+
//
|
|
5
|
+
// You can use !hasFocus() to prevent keyhandling in your key
|
|
6
|
+
// event handlers while the user is typing his search.
|
|
7
|
+
|
|
8
|
+
if (!Mark || !elasticlunr) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var searchbar = document.getElementById('searchbar'),
|
|
13
|
+
searchbar_outer = document.getElementById('searchbar-outer'),
|
|
14
|
+
searchresults = document.getElementById('searchresults'),
|
|
15
|
+
searchresults_outer = document.getElementById('searchresults-outer'),
|
|
16
|
+
searchresults_header = document.getElementById('searchresults-header'),
|
|
17
|
+
searchicon = document.getElementById('search-toggle'),
|
|
18
|
+
content = document.getElementById('content'),
|
|
19
|
+
|
|
20
|
+
searchindex = null,
|
|
21
|
+
searchoptions = {
|
|
22
|
+
bool: "AND",
|
|
23
|
+
expand: true,
|
|
24
|
+
teaser_word_count: 30,
|
|
25
|
+
limit_results: 30,
|
|
26
|
+
fields: {
|
|
27
|
+
title: {boost: 1},
|
|
28
|
+
body: {boost: 1},
|
|
29
|
+
breadcrumbs: {boost: 0}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
mark_exclude = [],
|
|
33
|
+
marker = new Mark(content),
|
|
34
|
+
current_searchterm = "",
|
|
35
|
+
URL_SEARCH_PARAM = 'search',
|
|
36
|
+
URL_MARK_PARAM = 'highlight',
|
|
37
|
+
teaser_count = 0,
|
|
38
|
+
|
|
39
|
+
SEARCH_HOTKEY_KEYCODE = 83,
|
|
40
|
+
ESCAPE_KEYCODE = 27,
|
|
41
|
+
DOWN_KEYCODE = 40,
|
|
42
|
+
UP_KEYCODE = 38,
|
|
43
|
+
SELECT_KEYCODE = 13;
|
|
44
|
+
|
|
45
|
+
function hasFocus() {
|
|
46
|
+
return searchbar === document.activeElement;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function removeChildren(elem) {
|
|
50
|
+
while (elem.firstChild) {
|
|
51
|
+
elem.removeChild(elem.firstChild);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Helper to parse a url into its building blocks.
|
|
56
|
+
function parseURL(url) {
|
|
57
|
+
var a = document.createElement('a');
|
|
58
|
+
a.href = url;
|
|
59
|
+
return {
|
|
60
|
+
source: url,
|
|
61
|
+
protocol: a.protocol.replace(':',''),
|
|
62
|
+
host: a.hostname,
|
|
63
|
+
port: a.port,
|
|
64
|
+
params: (function(){
|
|
65
|
+
var ret = {};
|
|
66
|
+
var seg = a.search.replace(/^\?/,'').split('&');
|
|
67
|
+
var len = seg.length, i = 0, s;
|
|
68
|
+
for (;i<len;i++) {
|
|
69
|
+
if (!seg[i]) { continue; }
|
|
70
|
+
s = seg[i].split('=');
|
|
71
|
+
ret[s[0]] = s[1];
|
|
72
|
+
}
|
|
73
|
+
return ret;
|
|
74
|
+
})(),
|
|
75
|
+
file: (a.pathname.match(/\/([^/?#]+)$/i) || [,''])[1],
|
|
76
|
+
hash: a.hash.replace('#',''),
|
|
77
|
+
path: a.pathname.replace(/^([^/])/,'/$1')
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Helper to recreate a url string from its building blocks.
|
|
82
|
+
function renderURL(urlobject) {
|
|
83
|
+
var url = urlobject.protocol + "://" + urlobject.host;
|
|
84
|
+
if (urlobject.port != "") {
|
|
85
|
+
url += ":" + urlobject.port;
|
|
86
|
+
}
|
|
87
|
+
url += urlobject.path;
|
|
88
|
+
var joiner = "?";
|
|
89
|
+
for(var prop in urlobject.params) {
|
|
90
|
+
if(urlobject.params.hasOwnProperty(prop)) {
|
|
91
|
+
url += joiner + prop + "=" + urlobject.params[prop];
|
|
92
|
+
joiner = "&";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (urlobject.hash != "") {
|
|
96
|
+
url += "#" + urlobject.hash;
|
|
97
|
+
}
|
|
98
|
+
return url;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Helper to escape html special chars for displaying the teasers
|
|
102
|
+
var escapeHTML = (function() {
|
|
103
|
+
var MAP = {
|
|
104
|
+
'&': '&',
|
|
105
|
+
'<': '<',
|
|
106
|
+
'>': '>',
|
|
107
|
+
'"': '"',
|
|
108
|
+
"'": '''
|
|
109
|
+
};
|
|
110
|
+
var repl = function(c) { return MAP[c]; };
|
|
111
|
+
return function(s) {
|
|
112
|
+
return s.replace(/[&<>'"]/g, repl);
|
|
113
|
+
};
|
|
114
|
+
})();
|
|
115
|
+
|
|
116
|
+
function formatSearchMetric(count, searchterm) {
|
|
117
|
+
if (count == 1) {
|
|
118
|
+
return count + " search result for '" + searchterm + "':";
|
|
119
|
+
} else if (count == 0) {
|
|
120
|
+
return "No search results for '" + searchterm + "'.";
|
|
121
|
+
} else {
|
|
122
|
+
return count + " search results for '" + searchterm + "':";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function formatSearchResult(result, searchterms) {
|
|
127
|
+
var teaser = makeTeaser(escapeHTML(result.doc.body), searchterms);
|
|
128
|
+
teaser_count++;
|
|
129
|
+
|
|
130
|
+
// The ?URL_MARK_PARAM= parameter belongs inbetween the page and the #heading-anchor
|
|
131
|
+
var url = result.ref.split("#");
|
|
132
|
+
if (url.length == 1) { // no anchor found
|
|
133
|
+
url.push("");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return '<a href="' + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
|
|
137
|
+
+ '" aria-details="teaser_' + teaser_count + '">' + result.doc.breadcrumbs + '</a>'
|
|
138
|
+
+ '<span class="teaser" id="teaser_' + teaser_count + '" aria-label="Search Result Teaser">'
|
|
139
|
+
+ teaser + '</span>';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function makeTeaser(body, searchterms) {
|
|
143
|
+
// The strategy is as follows:
|
|
144
|
+
// First, assign a value to each word in the document:
|
|
145
|
+
// Words that correspond to search terms (stemmer aware): 40
|
|
146
|
+
// Normal words: 2
|
|
147
|
+
// First word in a sentence: 8
|
|
148
|
+
// Then use a sliding window with a constant number of words and count the
|
|
149
|
+
// sum of the values of the words within the window. Then use the window that got the
|
|
150
|
+
// maximum sum. If there are multiple maximas, then get the last one.
|
|
151
|
+
// Enclose the terms in <em>.
|
|
152
|
+
var stemmed_searchterms = searchterms.map(function(w) {
|
|
153
|
+
return elasticlunr.stemmer(w.toLowerCase());
|
|
154
|
+
});
|
|
155
|
+
var searchterm_weight = 40;
|
|
156
|
+
var weighted = []; // contains elements of ["word", weight, index_in_document]
|
|
157
|
+
// split in sentences, then words
|
|
158
|
+
var sentences = body.toLowerCase().split('. ');
|
|
159
|
+
var index = 0;
|
|
160
|
+
var value = 0;
|
|
161
|
+
var searchterm_found = false;
|
|
162
|
+
for (var sentenceindex in sentences) {
|
|
163
|
+
var words = sentences[sentenceindex].split(' ');
|
|
164
|
+
value = 8;
|
|
165
|
+
for (var wordindex in words) {
|
|
166
|
+
var word = words[wordindex];
|
|
167
|
+
if (word.length > 0) {
|
|
168
|
+
for (var searchtermindex in stemmed_searchterms) {
|
|
169
|
+
if (elasticlunr.stemmer(word).startsWith(stemmed_searchterms[searchtermindex])) {
|
|
170
|
+
value = searchterm_weight;
|
|
171
|
+
searchterm_found = true;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
weighted.push([word, value, index]);
|
|
175
|
+
value = 2;
|
|
176
|
+
}
|
|
177
|
+
index += word.length;
|
|
178
|
+
index += 1; // ' ' or '.' if last word in sentence
|
|
179
|
+
};
|
|
180
|
+
index += 1; // because we split at a two-char boundary '. '
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
if (weighted.length == 0) {
|
|
184
|
+
return body;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var window_weight = [];
|
|
188
|
+
var window_size = Math.min(weighted.length, searchoptions.teaser_word_count);
|
|
189
|
+
|
|
190
|
+
var cur_sum = 0;
|
|
191
|
+
for (var wordindex = 0; wordindex < window_size; wordindex++) {
|
|
192
|
+
cur_sum += weighted[wordindex][1];
|
|
193
|
+
};
|
|
194
|
+
window_weight.push(cur_sum);
|
|
195
|
+
for (var wordindex = 0; wordindex < weighted.length - window_size; wordindex++) {
|
|
196
|
+
cur_sum -= weighted[wordindex][1];
|
|
197
|
+
cur_sum += weighted[wordindex + window_size][1];
|
|
198
|
+
window_weight.push(cur_sum);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
if (searchterm_found) {
|
|
202
|
+
var max_sum = 0;
|
|
203
|
+
var max_sum_window_index = 0;
|
|
204
|
+
// backwards
|
|
205
|
+
for (var i = window_weight.length - 1; i >= 0; i--) {
|
|
206
|
+
if (window_weight[i] > max_sum) {
|
|
207
|
+
max_sum = window_weight[i];
|
|
208
|
+
max_sum_window_index = i;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
} else {
|
|
212
|
+
max_sum_window_index = 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// add <em/> around searchterms
|
|
216
|
+
var teaser_split = [];
|
|
217
|
+
var index = weighted[max_sum_window_index][2];
|
|
218
|
+
for (var i = max_sum_window_index; i < max_sum_window_index+window_size; i++) {
|
|
219
|
+
var word = weighted[i];
|
|
220
|
+
if (index < word[2]) {
|
|
221
|
+
// missing text from index to start of `word`
|
|
222
|
+
teaser_split.push(body.substring(index, word[2]));
|
|
223
|
+
index = word[2];
|
|
224
|
+
}
|
|
225
|
+
if (word[1] == searchterm_weight) {
|
|
226
|
+
teaser_split.push("<em>")
|
|
227
|
+
}
|
|
228
|
+
index = word[2] + word[0].length;
|
|
229
|
+
teaser_split.push(body.substring(word[2], index));
|
|
230
|
+
if (word[1] == searchterm_weight) {
|
|
231
|
+
teaser_split.push("</em>")
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return teaser_split.join('');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function init() {
|
|
239
|
+
searchoptions = window.search.searchoptions;
|
|
240
|
+
searchindex = elasticlunr.Index.load(window.search.index);
|
|
241
|
+
|
|
242
|
+
// Set up events
|
|
243
|
+
searchicon.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
|
|
244
|
+
searchbar.addEventListener('keyup', function(e) { searchbarKeyUpHandler(); }, false);
|
|
245
|
+
document.addEventListener('keydown', function (e) { globalKeyHandler(e); }, false);
|
|
246
|
+
// If the user uses the browser buttons, do the same as if a reload happened
|
|
247
|
+
window.onpopstate = function(e) { doSearchOrMarkFromUrl(); };
|
|
248
|
+
|
|
249
|
+
// If reloaded, do the search or mark again, depending on the current url parameters
|
|
250
|
+
doSearchOrMarkFromUrl();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function unfocusSearchbar() {
|
|
254
|
+
// hacky, but just focusing a div only works once
|
|
255
|
+
var tmp = document.createElement('input');
|
|
256
|
+
tmp.setAttribute('style', 'position: absolute; opacity: 0;');
|
|
257
|
+
searchicon.appendChild(tmp);
|
|
258
|
+
tmp.focus();
|
|
259
|
+
tmp.remove();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// On reload or browser history backwards/forwards events, parse the url and do search or mark
|
|
263
|
+
function doSearchOrMarkFromUrl() {
|
|
264
|
+
// Check current URL for search request
|
|
265
|
+
var url = parseURL(window.location.href);
|
|
266
|
+
if (url.params.hasOwnProperty(URL_SEARCH_PARAM)
|
|
267
|
+
&& url.params[URL_SEARCH_PARAM] != "") {
|
|
268
|
+
showSearch(true);
|
|
269
|
+
searchbar.value = decodeURIComponent(
|
|
270
|
+
(url.params[URL_SEARCH_PARAM]+'').replace(/\+/g, '%20'));
|
|
271
|
+
searchbarKeyUpHandler(); // -> doSearch()
|
|
272
|
+
} else {
|
|
273
|
+
showSearch(false);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (url.params.hasOwnProperty(URL_MARK_PARAM)) {
|
|
277
|
+
var words = url.params[URL_MARK_PARAM].split(' ');
|
|
278
|
+
marker.mark(words, {
|
|
279
|
+
exclude: mark_exclude
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
var markers = document.querySelectorAll("mark");
|
|
283
|
+
function hide() {
|
|
284
|
+
for (var i = 0; i < markers.length; i++) {
|
|
285
|
+
markers[i].classList.add("fade-out");
|
|
286
|
+
window.setTimeout(function(e) { marker.unmark(); }, 300);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (var i = 0; i < markers.length; i++) {
|
|
290
|
+
markers[i].addEventListener('click', hide);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Eventhandler for keyevents on `document`
|
|
296
|
+
function globalKeyHandler(e) {
|
|
297
|
+
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
|
298
|
+
|
|
299
|
+
if (e.keyCode == ESCAPE_KEYCODE) {
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
searchbar.classList.remove("active");
|
|
302
|
+
setSearchUrlParameters("",
|
|
303
|
+
(searchbar.value.trim() != "") ? "push" : "replace");
|
|
304
|
+
if (hasFocus()) {
|
|
305
|
+
unfocusSearchbar();
|
|
306
|
+
}
|
|
307
|
+
showSearch(false);
|
|
308
|
+
marker.unmark();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (!hasFocus() && e.keyCode == SEARCH_HOTKEY_KEYCODE) {
|
|
312
|
+
e.preventDefault();
|
|
313
|
+
showSearch(true);
|
|
314
|
+
window.scrollTo(0, 0);
|
|
315
|
+
searchbar.focus();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (hasFocus() && e.keyCode == DOWN_KEYCODE) {
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
unfocusSearchbar();
|
|
321
|
+
searchresults.children('li').first().classList.add("focus");
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!hasFocus() && (e.keyCode == DOWN_KEYCODE
|
|
325
|
+
|| e.keyCode == UP_KEYCODE
|
|
326
|
+
|| e.keyCode == SELECT_KEYCODE)) {
|
|
327
|
+
// not `:focus` because browser does annoying scrolling
|
|
328
|
+
var current_focus = search.searchresults.find("li.focus");
|
|
329
|
+
if (current_focus.length == 0) return;
|
|
330
|
+
e.preventDefault();
|
|
331
|
+
if (e.keyCode == DOWN_KEYCODE) {
|
|
332
|
+
var next = current_focus.next()
|
|
333
|
+
if (next.length > 0) {
|
|
334
|
+
current_focus.classList.remove("focus");
|
|
335
|
+
next.classList.add("focus");
|
|
336
|
+
}
|
|
337
|
+
} else if (e.keyCode == UP_KEYCODE) {
|
|
338
|
+
current_focus.classList.remove("focus");
|
|
339
|
+
var prev = current_focus.prev();
|
|
340
|
+
if (prev.length == 0) {
|
|
341
|
+
searchbar.focus();
|
|
342
|
+
} else {
|
|
343
|
+
prev.classList.add("focus");
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
window.location = current_focus.children('a').attr('href');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function showSearch(yes) {
|
|
352
|
+
if (yes) {
|
|
353
|
+
searchbar_outer.style.display = 'block';
|
|
354
|
+
content.style.display = 'none';
|
|
355
|
+
searchicon.setAttribute('aria-expanded', 'true');
|
|
356
|
+
} else {
|
|
357
|
+
content.style.display = 'block';
|
|
358
|
+
searchbar_outer.style.display = 'none';
|
|
359
|
+
searchresults_outer.style.display = 'none';
|
|
360
|
+
searchbar.value = '';
|
|
361
|
+
removeChildren(searchresults);
|
|
362
|
+
searchicon.setAttribute('aria-expanded', 'false');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function showResults(yes) {
|
|
367
|
+
if (yes) {
|
|
368
|
+
searchbar_outer.style.display = 'block';
|
|
369
|
+
content.style.display = 'none';
|
|
370
|
+
searchresults_outer.style.display = 'block';
|
|
371
|
+
} else {
|
|
372
|
+
content.style.display = 'block';
|
|
373
|
+
searchresults_outer.style.display = 'none';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Eventhandler for search icon
|
|
378
|
+
function searchIconClickHandler() {
|
|
379
|
+
if (searchbar_outer.style.display === 'block') {
|
|
380
|
+
showSearch(false);
|
|
381
|
+
} else {
|
|
382
|
+
showSearch(true);
|
|
383
|
+
window.scrollTo(0, 0);
|
|
384
|
+
searchbar.focus();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Eventhandler for keyevents while the searchbar is focused
|
|
389
|
+
function searchbarKeyUpHandler() {
|
|
390
|
+
var searchterm = searchbar.value.trim();
|
|
391
|
+
if (searchterm != "") {
|
|
392
|
+
searchbar.classList.add("active");
|
|
393
|
+
doSearch(searchterm);
|
|
394
|
+
} else {
|
|
395
|
+
searchbar.classList.remove("active");
|
|
396
|
+
showResults(false);
|
|
397
|
+
removeChildren(searchresults);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
setSearchUrlParameters(searchterm, "push_if_new_search_else_replace");
|
|
401
|
+
|
|
402
|
+
// Remove marks
|
|
403
|
+
marker.unmark();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Update current url with ?URL_SEARCH_PARAM= parameter, remove ?URL_MARK_PARAM and #heading-anchor .
|
|
407
|
+
// `action` can be one of "push", "replace", "push_if_new_search_else_replace"
|
|
408
|
+
// and replaces or pushes a new browser history item.
|
|
409
|
+
// "push_if_new_search_else_replace" pushes if there is no `?URL_SEARCH_PARAM=abc` yet.
|
|
410
|
+
function setSearchUrlParameters(searchterm, action) {
|
|
411
|
+
var url = parseURL(window.location.href);
|
|
412
|
+
var first_search = ! url.params.hasOwnProperty(URL_SEARCH_PARAM);
|
|
413
|
+
if (searchterm != "" || action == "push_if_new_search_else_replace") {
|
|
414
|
+
url.params[URL_SEARCH_PARAM] = searchterm;
|
|
415
|
+
delete url.params[URL_MARK_PARAM];
|
|
416
|
+
url.hash = "";
|
|
417
|
+
} else {
|
|
418
|
+
delete url.params[URL_SEARCH_PARAM];
|
|
419
|
+
}
|
|
420
|
+
// A new search will also add a new history item, so the user can go back
|
|
421
|
+
// to the page prior to searching. A updated search term will only replace
|
|
422
|
+
// the url.
|
|
423
|
+
if (action == "push" || (action == "push_if_new_search_else_replace" && first_search) ) {
|
|
424
|
+
history.pushState({}, document.title, renderURL(url));
|
|
425
|
+
} else if (action == "replace" || (action == "push_if_new_search_else_replace" && !first_search) ) {
|
|
426
|
+
history.replaceState({}, document.title, renderURL(url));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function doSearch(searchterm) {
|
|
431
|
+
|
|
432
|
+
// Don't search the same twice
|
|
433
|
+
if (current_searchterm == searchterm) { return; }
|
|
434
|
+
else { current_searchterm = searchterm; }
|
|
435
|
+
|
|
436
|
+
if (searchindex == null) { return; }
|
|
437
|
+
|
|
438
|
+
// Do the actual search
|
|
439
|
+
var results = searchindex.search(searchterm, searchoptions);
|
|
440
|
+
var resultcount = Math.min(results.length, searchoptions.limit_results);
|
|
441
|
+
|
|
442
|
+
// Display search metrics
|
|
443
|
+
searchresults_header.innerText = formatSearchMetric(resultcount, searchterm);
|
|
444
|
+
|
|
445
|
+
// Clear and insert results
|
|
446
|
+
var searchterms = searchterm.split(' ');
|
|
447
|
+
removeChildren(searchresults);
|
|
448
|
+
for(var i = 0; i < resultcount ; i++){
|
|
449
|
+
var resultElem = document.createElement('li');
|
|
450
|
+
resultElem.innerHTML = formatSearchResult(results[i], searchterms);
|
|
451
|
+
searchresults.appendChild(resultElem);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Display results
|
|
455
|
+
showResults(true);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
init();
|
|
459
|
+
// Exported functions
|
|
460
|
+
search.hasFocus = hasFocus;
|
|
461
|
+
})(window.search);
|