blocks 3.0.0.rc4 → 3.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -2
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.rdoc +7 -0
- data/Gemfile +10 -3
- data/README.md +25 -9
- data/_config.yml +20 -0
- data/bin/deploy_docs +2 -0
- data/docs/.gitignore +4 -0
- data/docs/404.html +23 -0
- data/docs/_includes/acknowledgements.md +13 -0
- data/docs/_includes/caller-id.md +3 -0
- data/docs/_includes/configuration.md +3 -0
- data/docs/_includes/custom-builders.md +3 -0
- data/docs/_includes/defining.md +615 -0
- data/docs/_includes/demos/hooks-and-wrappers-output.html +109 -0
- data/docs/_includes/hooks.md +1156 -0
- data/docs/_includes/installation.md +25 -0
- data/docs/_includes/introduction.md +18 -0
- data/docs/_includes/option-merging.md +5 -0
- data/docs/_includes/rendering.md +622 -0
- data/docs/_includes/reserved-keywords.md +59 -0
- data/docs/_includes/skipping.md +403 -0
- data/docs/_includes/slate/assets.html +34 -0
- data/docs/_includes/slate/language-tabs.html +11 -0
- data/docs/_includes/templating.md +48 -0
- data/docs/_includes/templating/bootstrap_4_cards.md +753 -0
- data/docs/_includes/use-cases.md +23 -0
- data/docs/_includes/wip.md +34 -0
- data/docs/_includes/wrappers.md +629 -0
- data/docs/_layouts/slate.html +75 -0
- data/docs/_plugins/gem_version.rb +11 -0
- data/docs/_plugins/highlight_with_div.rb +25 -0
- data/docs/_sass/_default_styling.scss +627 -0
- data/docs/_sass/_icon-font.scss +26 -0
- data/docs/_sass/_normalize.scss +427 -0
- data/docs/_sass/_styling_overrides.scss +31 -0
- data/docs/_sass/_syntax.scss +78 -0
- data/docs/_sass/_variable_overrides.scss +10 -0
- data/docs/_sass/_variables.scss +105 -0
- data/docs/assets/javascripts/script.js +18 -0
- data/docs/assets/stylesheets/formChanges.less +106 -0
- data/docs/assets/stylesheets/style.css +46 -0
- data/docs/fonts/slate.eot +0 -0
- data/docs/fonts/slate.svg +14 -0
- data/docs/fonts/slate.ttf +0 -0
- data/docs/fonts/slate.woff +0 -0
- data/docs/fonts/slate.woff2 +0 -0
- data/docs/hooks.html +149 -0
- data/docs/hooks_and_wrappers_demo.html +313 -0
- data/docs/images/favicon.ico +0 -0
- data/docs/images/logo.png +0 -0
- data/docs/images/navbar.png +0 -0
- data/docs/images/placeholder.jpg +0 -0
- data/docs/images/render_strategies.png +0 -0
- data/docs/images/templating.png +0 -0
- data/docs/index.md +32 -0
- data/docs/javascripts/all.js +4 -0
- data/docs/javascripts/all_nosearch.js +3 -0
- data/docs/javascripts/app/lang.js +166 -0
- data/docs/javascripts/app/search.js +75 -0
- data/docs/javascripts/app/toc.js +57 -0
- data/docs/javascripts/demos/hooks_and_wrappers.js +9 -0
- data/docs/javascripts/lib/energize.js +169 -0
- data/docs/javascripts/lib/imagesloaded.min.js +7 -0
- data/docs/javascripts/lib/jquery.highlight.js +108 -0
- data/docs/javascripts/lib/jquery.js +9831 -0
- data/docs/javascripts/lib/jquery.tocify.js +1042 -0
- data/docs/javascripts/lib/jquery_ui.js +566 -0
- data/docs/javascripts/lib/lunr.js +1910 -0
- data/docs/stylesheets/demos/hooks_and_wrappers.scss +32 -0
- data/docs/stylesheets/print.scss +150 -0
- data/docs/stylesheets/screen.scss +10 -0
- data/lib/blocks/action_view_extensions/view_extensions.rb +1 -0
- data/lib/blocks/renderers/renderer.rb +1 -0
- data/lib/blocks/renderers/runtime_context.rb +30 -17
- data/lib/blocks/utilities/hash_with_render_strategy.rb +3 -0
- data/lib/blocks/version.rb +1 -1
- metadata +70 -2
@@ -0,0 +1,313 @@
|
|
1
|
+
---
|
2
|
+
title: Hooks And Wrappers Demo
|
3
|
+
---
|
4
|
+
|
5
|
+
{% assign css_url = '/' | prepend: site.css_dir | prepend: '/' | prepend: include.site_url %}
|
6
|
+
{% assign js_url = '/' | prepend: site.js_dir | prepend: '/' | prepend: include.site_url %}
|
7
|
+
|
8
|
+
<!DOCTYPE html>
|
9
|
+
<html>
|
10
|
+
<head>
|
11
|
+
<title>BetterFormFor</title>
|
12
|
+
<link rel="stylesheet" media="all" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
|
13
|
+
<link href="{{ 'demos/hooks_and_wrappers.css' | prepend: css_url }}" media="screen" rel="stylesheet" type="text/css">
|
14
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
15
|
+
<script src="{{ 'demos/hooks_and_wrappers.js' | prepend: js_url }}"></script>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<div class="container">
|
19
|
+
<div class="row">
|
20
|
+
<div class="col-xs-4">
|
21
|
+
<div class="checkbox">
|
22
|
+
<label>
|
23
|
+
<input type="checkbox" data-hideable="1" data-class="prepend1" data-toggle-class="bg-primary"> Prepend 1
|
24
|
+
</label>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<div class="col-xs-4">
|
28
|
+
<div class="checkbox">
|
29
|
+
<label>
|
30
|
+
<input type="checkbox" data-hideable="1" data-class="prepend2" data-toggle-class="bg-primary"> Prepend 2
|
31
|
+
</label>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="row">
|
37
|
+
<div class="col-xs-4">
|
38
|
+
<div class="checkbox">
|
39
|
+
<label>
|
40
|
+
<input type="checkbox" data-hideable="1" data-class="before1" data-toggle-class="bg-success"> Before 1
|
41
|
+
</label>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
<div class="col-xs-4">
|
45
|
+
<div class="checkbox">
|
46
|
+
<label>
|
47
|
+
<input type="checkbox" data-hideable="1" data-class="before2" data-toggle-class="bg-success"> Before 2
|
48
|
+
</label>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
<div class="row">
|
54
|
+
<div class="col-xs-4">
|
55
|
+
<div class="checkbox">
|
56
|
+
<label>
|
57
|
+
<input type="checkbox" data-hideable="1" data-class="before_all1" data-toggle-class="bg-danger"> Before All 1
|
58
|
+
</label>
|
59
|
+
</div>
|
60
|
+
</div>
|
61
|
+
<div class="col-xs-4">
|
62
|
+
<div class="checkbox">
|
63
|
+
<label>
|
64
|
+
<input type="checkbox" data-hideable="1" data-class="before_all2" data-toggle-class="bg-danger"> Before All 2
|
65
|
+
</label>
|
66
|
+
</div>
|
67
|
+
</div>
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<div class="row">
|
71
|
+
<div class="col-xs-4">
|
72
|
+
<div class="checkbox">
|
73
|
+
<label>
|
74
|
+
<input type="checkbox" data-hideable="1" data-class="append1" data-toggle-class="bg-primary"> Append 1
|
75
|
+
</label>
|
76
|
+
</div>
|
77
|
+
</div>
|
78
|
+
<div class="col-xs-4">
|
79
|
+
<div class="checkbox">
|
80
|
+
<label>
|
81
|
+
<input type="checkbox" data-hideable="1" data-class="append2" data-toggle-class="bg-primary"> Append 2
|
82
|
+
</label>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<div class="row">
|
88
|
+
<div class="col-xs-4">
|
89
|
+
<div class="checkbox">
|
90
|
+
<label>
|
91
|
+
<input type="checkbox" data-hideable="1" data-class="after1" data-toggle-class="bg-success"> After 1
|
92
|
+
</label>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
<div class="col-xs-4">
|
96
|
+
<div class="checkbox">
|
97
|
+
<label>
|
98
|
+
<input type="checkbox" data-hideable="1" data-class="after2" data-toggle-class="bg-success"> After 2
|
99
|
+
</label>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<div class="row">
|
105
|
+
<div class="col-xs-4">
|
106
|
+
<div class="checkbox">
|
107
|
+
<label>
|
108
|
+
<input type="checkbox" data-hideable="1" data-class="after_all1" data-toggle-class="bg-danger"> After All 1
|
109
|
+
</label>
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
<div class="col-xs-4">
|
113
|
+
<div class="checkbox">
|
114
|
+
<label>
|
115
|
+
<input type="checkbox" data-hideable="1" data-class="after_all2" data-toggle-class="bg-danger"> After All 2
|
116
|
+
</label>
|
117
|
+
</div>
|
118
|
+
</div>
|
119
|
+
</div>
|
120
|
+
|
121
|
+
<div class="row">
|
122
|
+
<div class="col-xs-4">
|
123
|
+
<div class="checkbox">
|
124
|
+
<label>
|
125
|
+
<input type="checkbox" data-class="surround1" data-toggle-class="bg-info"> Surround 1
|
126
|
+
</label>
|
127
|
+
</div>
|
128
|
+
</div>
|
129
|
+
<div class="col-xs-4">
|
130
|
+
<div class="checkbox">
|
131
|
+
<label>
|
132
|
+
<input type="checkbox" data-class="surround2" data-toggle-class="bg-success"> Surround 2
|
133
|
+
</label>
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
<div class="row">
|
139
|
+
<div class="col-xs-4">
|
140
|
+
<div class="checkbox">
|
141
|
+
<label>
|
142
|
+
<input type="checkbox" data-class="around1" data-toggle-class="bg-info"> Around 1
|
143
|
+
</label>
|
144
|
+
</div>
|
145
|
+
</div>
|
146
|
+
<div class="col-xs-4">
|
147
|
+
<div class="checkbox">
|
148
|
+
<label>
|
149
|
+
<input type="checkbox" data-class="around2" data-toggle-class="bg-success"> Around 2
|
150
|
+
</label>
|
151
|
+
</div>
|
152
|
+
</div>
|
153
|
+
</div>
|
154
|
+
|
155
|
+
<div class="row">
|
156
|
+
<div class="col-xs-4">
|
157
|
+
<div class="checkbox">
|
158
|
+
<label>
|
159
|
+
<input type="checkbox" data-class="around_all1" data-toggle-class="bg-warning"> Around All 1
|
160
|
+
</label>
|
161
|
+
</div>
|
162
|
+
</div>
|
163
|
+
<div class="col-xs-4">
|
164
|
+
<div class="checkbox">
|
165
|
+
<label>
|
166
|
+
<input type="checkbox" data-class="around_all2" data-toggle-class="bg-danger"> Around All 2
|
167
|
+
</label>
|
168
|
+
</div>
|
169
|
+
</div>
|
170
|
+
</div>
|
171
|
+
|
172
|
+
<div class="row">
|
173
|
+
<div class="col-xs-4">
|
174
|
+
<div class="checkbox">
|
175
|
+
<label>
|
176
|
+
<input type="checkbox" data-class="wrapper" data-toggle-class="bg-info"> :wrapper
|
177
|
+
</label>
|
178
|
+
</div>
|
179
|
+
</div>
|
180
|
+
<div class="col-xs-4">
|
181
|
+
<div class="checkbox">
|
182
|
+
<label>
|
183
|
+
<input type="checkbox" data-class="item-wrapper" data-toggle-class="bg-info"> :wrap_each
|
184
|
+
</label>
|
185
|
+
</div>
|
186
|
+
</div>
|
187
|
+
<div class="col-xs-4">
|
188
|
+
<div class="checkbox">
|
189
|
+
<label>
|
190
|
+
<input type="checkbox" data-class="container-wrapper" data-toggle-class="bg-info"> :wrap_all
|
191
|
+
</label>
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
</div>
|
196
|
+
|
197
|
+
<pre>
|
198
|
+
<%= blocks.render :test_block, collection: [1, 2] %>
|
199
|
+
</pre>
|
200
|
+
|
201
|
+
<div id="blocks">
|
202
|
+
<div class="before_all2 bg-danger hide">
|
203
|
+
Second Before All
|
204
|
+
</div>
|
205
|
+
<div class="before_all1 bg-danger hide">
|
206
|
+
First Before All
|
207
|
+
</div>
|
208
|
+
<div class="around_all2">
|
209
|
+
Second Around All
|
210
|
+
<div class="around_all1">
|
211
|
+
First Around All
|
212
|
+
<div class="container-wrapper">
|
213
|
+
Test Block Wrapper for all
|
214
|
+
<div class="item-wrapper">
|
215
|
+
Test Block Wrapper for each item
|
216
|
+
<div class="around2">
|
217
|
+
Second Around for item 1
|
218
|
+
<div class="around1">
|
219
|
+
First Around for item 1
|
220
|
+
<div class="before2 bg-success hide">
|
221
|
+
Second Before for item 1
|
222
|
+
</div>
|
223
|
+
<div class="before1 bg-success hide">
|
224
|
+
First Before for item 1
|
225
|
+
</div>
|
226
|
+
<div class="wrapper">
|
227
|
+
Test Block Wrapper for item 1
|
228
|
+
<div class="surround2">
|
229
|
+
Second Surround for item 1
|
230
|
+
<div class="surround1">
|
231
|
+
First Surround for item 1
|
232
|
+
<div class="prepend2 bg-primary hide">Second Prepended block 1</div>
|
233
|
+
<div class="prepend1 bg-primary hide">First Prepended block 1</div>
|
234
|
+
<div id="actual_block" class="bg-primary">Actual block 1</div>
|
235
|
+
<div class="append1 bg-primary hide">First Appended block 1</div>
|
236
|
+
<div class="append2 bg-primary hide">Second Appended block 1</div>
|
237
|
+
|
238
|
+
</div>
|
239
|
+
|
240
|
+
</div>
|
241
|
+
|
242
|
+
</div>
|
243
|
+
<div class="after1 bg-success hide">
|
244
|
+
First After for item 1
|
245
|
+
</div>
|
246
|
+
<div class="after2 bg-success hide">
|
247
|
+
Second After for item 1
|
248
|
+
</div>
|
249
|
+
|
250
|
+
</div>
|
251
|
+
|
252
|
+
</div>
|
253
|
+
|
254
|
+
</div>
|
255
|
+
<div class="item-wrapper">
|
256
|
+
Test Block Wrapper for each item
|
257
|
+
<div class="around2">
|
258
|
+
Second Around for item 2
|
259
|
+
<div class="around1">
|
260
|
+
First Around for item 2
|
261
|
+
<div class="before2 bg-success hide">
|
262
|
+
Second Before for item 2
|
263
|
+
</div>
|
264
|
+
<div class="before1 bg-success hide">
|
265
|
+
First Before for item 2
|
266
|
+
</div>
|
267
|
+
<div class="wrapper">
|
268
|
+
Test Block Wrapper for item 2
|
269
|
+
<div class="surround2">
|
270
|
+
Second Surround for item 2
|
271
|
+
<div class="surround1">
|
272
|
+
First Surround for item 2
|
273
|
+
<div class="prepend2 bg-primary hide">Second Prepended block 2</div>
|
274
|
+
<div class="prepend1 bg-primary hide">First Prepended block 2</div>
|
275
|
+
<div id="actual_block" class="bg-primary">Actual block 2</div>
|
276
|
+
<div class="append1 bg-primary hide">First Appended block 2</div>
|
277
|
+
<div class="append2 bg-primary hide">Second Appended block 2</div>
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
</div>
|
282
|
+
|
283
|
+
</div>
|
284
|
+
<div class="after1 bg-success hide">
|
285
|
+
First After for item 2
|
286
|
+
</div>
|
287
|
+
<div class="after2 bg-success hide">
|
288
|
+
Second After for item 2
|
289
|
+
</div>
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
</div>
|
296
|
+
|
297
|
+
</div>
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
</div>
|
302
|
+
<div class="after_all1 bg-danger hide">
|
303
|
+
First After All
|
304
|
+
</div>
|
305
|
+
<div class="after_all2 bg-danger hide">
|
306
|
+
Second After All
|
307
|
+
</div>
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
|
312
|
+
</body>
|
313
|
+
</html>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/docs/index.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
title: Blocks Docs
|
3
|
+
|
4
|
+
language_tabs:
|
5
|
+
- erb
|
6
|
+
- haml
|
7
|
+
- ruby
|
8
|
+
|
9
|
+
toc_footers:
|
10
|
+
- <a href='https://github.com/tripit/slate'>Documentation Powered by Slate</a>
|
11
|
+
|
12
|
+
includes:
|
13
|
+
- introduction
|
14
|
+
- installation
|
15
|
+
- defining
|
16
|
+
- rendering
|
17
|
+
- hooks
|
18
|
+
- wrappers
|
19
|
+
- skipping
|
20
|
+
- reserved-keywords
|
21
|
+
- templating
|
22
|
+
- configuration
|
23
|
+
- custom-builders
|
24
|
+
- option-merging
|
25
|
+
- caller-id
|
26
|
+
- use-cases
|
27
|
+
- acknowledgements
|
28
|
+
|
29
|
+
search: true
|
30
|
+
layout: slate
|
31
|
+
---
|
32
|
+
|
@@ -0,0 +1,166 @@
|
|
1
|
+
//= require ../lib/_jquery
|
2
|
+
|
3
|
+
/*
|
4
|
+
Copyright 2008-2013 Concur Technologies, Inc.
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
7
|
+
not use this file except in compliance with the License. You may obtain
|
8
|
+
a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
+
License for the specific language governing permissions and limitations
|
16
|
+
under the License.
|
17
|
+
*/
|
18
|
+
(function (global) {
|
19
|
+
'use strict';
|
20
|
+
|
21
|
+
var languages = [];
|
22
|
+
|
23
|
+
global.setupLanguages = setupLanguages;
|
24
|
+
global.activateLanguage = activateLanguage;
|
25
|
+
|
26
|
+
function activateLanguage(language) {
|
27
|
+
if (!language) return;
|
28
|
+
if (language === "") return;
|
29
|
+
|
30
|
+
$(".lang-selector a").removeClass('active');
|
31
|
+
$(".lang-selector a[data-language-name='" + language + "']").addClass('active');
|
32
|
+
for (var i=0; i < languages.length; i++) {
|
33
|
+
$(".highlighter-rouge.language-" + languages[i]).hide();
|
34
|
+
$(".lang-specific." + languages[i]).hide();
|
35
|
+
}
|
36
|
+
$(".highlighter-rouge.language-" + language).show();
|
37
|
+
$(".lang-specific." + language).show();
|
38
|
+
|
39
|
+
global.toc.calculateHeights();
|
40
|
+
|
41
|
+
// scroll to the new location of the position
|
42
|
+
if ($(window.location.hash).get(0)) {
|
43
|
+
$(window.location.hash).get(0).scrollIntoView(true);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// parseURL and stringifyURL are from https://github.com/sindresorhus/query-string
|
48
|
+
// MIT licensed
|
49
|
+
// https://github.com/sindresorhus/query-string/blob/7bee64c16f2da1a326579e96977b9227bf6da9e6/license
|
50
|
+
function parseURL(str) {
|
51
|
+
if (typeof str !== 'string') {
|
52
|
+
return {};
|
53
|
+
}
|
54
|
+
|
55
|
+
str = str.trim().replace(/^(\?|#|&)/, '');
|
56
|
+
|
57
|
+
if (!str) {
|
58
|
+
return {};
|
59
|
+
}
|
60
|
+
|
61
|
+
return str.split('&').reduce(function (ret, param) {
|
62
|
+
var parts = param.replace(/\+/g, ' ').split('=');
|
63
|
+
var key = parts[0];
|
64
|
+
var val = parts[1];
|
65
|
+
|
66
|
+
key = decodeURIComponent(key);
|
67
|
+
// missing `=` should be `null`:
|
68
|
+
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
69
|
+
val = val === undefined ? null : decodeURIComponent(val);
|
70
|
+
|
71
|
+
if (!ret.hasOwnProperty(key)) {
|
72
|
+
ret[key] = val;
|
73
|
+
} else if (Array.isArray(ret[key])) {
|
74
|
+
ret[key].push(val);
|
75
|
+
} else {
|
76
|
+
ret[key] = [ret[key], val];
|
77
|
+
}
|
78
|
+
|
79
|
+
return ret;
|
80
|
+
}, {});
|
81
|
+
};
|
82
|
+
|
83
|
+
function stringifyURL(obj) {
|
84
|
+
return obj ? Object.keys(obj).sort().map(function (key) {
|
85
|
+
var val = obj[key];
|
86
|
+
|
87
|
+
if (Array.isArray(val)) {
|
88
|
+
return val.sort().map(function (val2) {
|
89
|
+
return encodeURIComponent(key) + '=' + encodeURIComponent(val2);
|
90
|
+
}).join('&');
|
91
|
+
}
|
92
|
+
|
93
|
+
return encodeURIComponent(key) + '=' + encodeURIComponent(val);
|
94
|
+
}).join('&') : '';
|
95
|
+
};
|
96
|
+
|
97
|
+
// gets the language set in the query string
|
98
|
+
function getLanguageFromQueryString() {
|
99
|
+
if (location.search.length >= 1) {
|
100
|
+
var language = parseURL(location.search).language
|
101
|
+
if (language) {
|
102
|
+
return language;
|
103
|
+
} else if (jQuery.inArray(location.search.substr(1), languages) != -1) {
|
104
|
+
return location.search.substr(1);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
|
111
|
+
// returns a new query string with the new language in it
|
112
|
+
function generateNewQueryString(language) {
|
113
|
+
var url = parseURL(location.search);
|
114
|
+
if (url.language) {
|
115
|
+
url.language = language;
|
116
|
+
return stringifyURL(url);
|
117
|
+
}
|
118
|
+
return language;
|
119
|
+
}
|
120
|
+
|
121
|
+
// if a button is clicked, add the state to the history
|
122
|
+
function pushURL(language) {
|
123
|
+
if (!history) { return; }
|
124
|
+
var hash = window.location.hash;
|
125
|
+
if (hash) {
|
126
|
+
hash = hash.replace(/^#+/, '');
|
127
|
+
}
|
128
|
+
history.pushState({}, '', '?' + generateNewQueryString(language) + '#' + hash);
|
129
|
+
|
130
|
+
// save language as next default
|
131
|
+
localStorage.setItem("language", language);
|
132
|
+
}
|
133
|
+
|
134
|
+
function setupLanguages(l) {
|
135
|
+
var defaultLanguage = localStorage.getItem("language");
|
136
|
+
|
137
|
+
languages = l;
|
138
|
+
|
139
|
+
var presetLanguage = getLanguageFromQueryString();
|
140
|
+
if (presetLanguage) {
|
141
|
+
// the language is in the URL, so use that language!
|
142
|
+
activateLanguage(presetLanguage);
|
143
|
+
|
144
|
+
localStorage.setItem("language", presetLanguage);
|
145
|
+
} else if ((defaultLanguage !== null) && (jQuery.inArray(defaultLanguage, languages) != -1)) {
|
146
|
+
// the language was the last selected one saved in localstorage, so use that language!
|
147
|
+
activateLanguage(defaultLanguage);
|
148
|
+
} else {
|
149
|
+
// no language selected, so use the default
|
150
|
+
activateLanguage(languages[0]);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
// if we click on a language tab, activate that language
|
155
|
+
$(function() {
|
156
|
+
$(".lang-selector a").on("click", function() {
|
157
|
+
var language = $(this).data("language-name");
|
158
|
+
pushURL(language);
|
159
|
+
activateLanguage(language);
|
160
|
+
return false;
|
161
|
+
});
|
162
|
+
window.onpopstate = function() {
|
163
|
+
activateLanguage(getLanguageFromQueryString());
|
164
|
+
};
|
165
|
+
});
|
166
|
+
})(window);
|