forked from guillaumepotier/Garlic.js
/
index.html
349 lines (310 loc) · 17.9 KB
/
index.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Garlic.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="http://twitter.github.com/bootstrap/assets/css/docs.css" rel="stylesheet">
<link href="http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
body {
display: block;
padding: 10px 10%;
padding-top: 0;
margin: auto;
}
h1.affix {
display: block;
}
#head-download {
float: right;
}
.download a, .download a:hover {
text-decoration:none;
}
.container {
margin-top: 0;
}
pre {
margin: 10px 0 15px 0;
}
.affix {
position: fixed;
clear: both;
}
.bs-docs-sidenav.affix {
top: 200px;
}
#demonstration {
padding-top: 0;
}
</style>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="100">
<a href="https://github.com/guillaumepotier/garlic.js"><img style="position: fixed; top: 0; right: 0; border: 0; z-index:9999" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<a name="top"></top>
<div class="container">
<h1 class="">
Garlic.js
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://garlicjs.org" data-text="Garlic.js: allows you to automatically persist your forms' text field values locally, until the form is submitted" data-size="large"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</h1>
<div class="row well intro">
<div id="head-download" class="download">
<a href="https://github.com/guillaumepotier/Garlic.js/archive/0.0.10.zip">
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
<a href="https://github.com/guillaumepotier/Garlic.js/archive/0.0.10.tar.gz">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
</a>
</div>
<p>
Garlic.js allows you to automatically persist your forms' text field values locally, until the form is submitted. This way, your users don't lose any precious data if they accidentally close their tab or browser.
</p>
<p>
It strives to have a javascript agnostic interface for UI/UX developers that might want to use it. Just add some <code>data-persist="garlic"</code> in your form tags, and you're good to go!
</p>
</div>
<div class="row row-content">
<div class="span3 bs-docs-sidenav">
<ul class="nav nav-list bs-docs-sidenav affix">
<li><a href="#demonstration"><i class="icon-chevron-right"></i> Demonstration</a></li>
<li><a href="#requirements"><i class="icon-chevron-right"></i> Requirements / Compatibiliy</a></li>
<li><a href="#download"><i class="icon-chevron-right"></i> Download</a></li>
<li><a href="#usage"><i class="icon-chevron-right"></i> Usage</a></li>
<li><a href="#documentation"><i class="icon-chevron-right"></i> Documentation</a></li>
<li><a href="#they-use"><i class="icon-chevron-right"></i> They use Garlic.js!</a></li>
<li><a href="#other"><i class="icon-chevron-right"></i> Other stuff</a></li>
<li><a href="#licence"><i class="icon-chevron-right"></i> Version / Licence</a></li>
</ul>
</div>
<div class="span9 doc-content">
<section id="demonstration">
<div class="page-header">
<h1>Demonstration <small>some magic..</small></h1>
</div>
<form data-persist="garlic" method="POST">
<fieldset>
<legend>1 - Simple form</legend><br/>
<label for="field1">Forms are independent. All text data is localy persisted thanks to localStorage<br/>
if browser supports it. If you reload this page, quit and go back here, your<br/>
data will still be there. On simple validation, if you press the submit button<br/>
the presisted data will be destroyed, considering it has properly been submited</label>
<input type="text" name="mytext" id="field1"/><br/>
<textarea name="textarea"></textarea>
<br/>
<label for="select"></label>
<select id="select">
<option>Hello</option>
<option>World</option>
<option>I</option>
<option>Am</option>
<option>Persisted</option>
</select>
<br/>
<label class="radio">
yes <input type="radio" name="radio1" value="yes" />
</label>
<label class="radio">
no <input type="radio" name="radio1" value="no" />
</label>
<label class="radio">
maybe <input type="radio" name="radio1" value="maybe" />
</label>
<br/>
<label class="checkbox">
I <input type="checkbox" name="checkbox[]" value="I">
</label>
<label class="checkbox">
will <input type="checkbox" name="checkbox[]" value="will">
</label>
<label class="checkbox">
be <input type="checkbox" name="checkbox[]" value="be">
</label>
<label class="checkbox">
persisted <input type="checkbox" name="checkbox[]" value="persisted">
</label>
<br/>
Submit and Reset buttons will destroy the fields stored data. Try it out!<br/><br/>
<input type="submit" class="btn"/>
<input type="reset" class="btn"/>
</fieldset>
</form>
<a href="#top" class="pull-right">Top</a>
<form data-persist="garlic" method="POST">
<fieldset>
<legend>2 - Form with non-persisted fields</legend><br/>
This field will be localy persisted while submit button is not triggered<br/>
<input type="text" name="mytext" /><br/>
Thise textarea will never be persisted since it has the <code>data-storage="false"</code> attribute<br/>
<textarea name="textarea" data-storage="false"></textarea><br/>
<input type="submit" class="btn"/>
</fieldset>
</form>
<a href="#top" class="pull-right">Top</a>
<form data-persist="garlic" method="POST">
<fieldset>
<legend>3 - Custom javascript or ajax validation</legend><br/>
<label for="ajax-test">This field will be localy persisted while js test not ok. Could be usefull<br/>
with some AJAX behaviour. Here text will be persisted only if < 10 chars</label>
<input type="text" id="ajax-test" name="myajaxtext" /> <span id="indicator"></span><br/>
</fieldset>
</form>
<a href="#top" class="pull-right">Top</a>
<form data-persist="garlic" data-destroy="false" method="POST">
<fieldset>
<legend>4 - "Infinite" persistency</legend><br/>
<label for="ajax-test">Use <code>data-destroy="false"</code> in your <code><form></code> to never remove localStorage persistency</label>
<input type="text" id="infinite-persistency" name="infinite-persistency" /><br/>
<input type="submit" class="btn"/><br/><br/>
You still can destroy localStorage data on custom javascript events, try <u><a style="cursor:pointer;" onClick="javascript:$('#infinite-persistency').garlic('destroy');">this action</a></u> and then refresh the page to see the difference ;)
</fieldset>
</form>
<a href="#top" class="pull-right">Top</a>
</section>
<section id="requirements">
<div class="page-header">
<h1>Requirements / Compatibiliy</h1>
</div>
<ul>
<li>Requires jQuery or Zepto (with data module builded for Zepto, see <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">changelog 0.0.6</a>)</li>
<li>Compatible yet only with "modern browsers": IE9+, Chrome 4+, FF 4+, Safari 4+, Opera 11+. See more <a href="http://www.html5rocks.com/en/features/storage">here</a></li>
</ul>
<a href="#top" class="pull-right">Top</a>
</section>
<section id="download">
<div class="page-header">
<h1>Download</h1>
</div>
<div id="download" class="download">
<a href="https://github.com/guillaumepotier/Garlic.js/archive/0.0.10.zip" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','ZIP',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”" >
<img width="90" border="0" src="http://github.com/images/modules/download/zip.png">
</a>
<a href="https://github.com/guillaumepotier/Garlic.js/archive/0.0.10.tar.gz" onclick="onclick=”var that=this;_gaq.push(['_trackEvent','Download','TAR',this.href]);setTimeout(function(){location.href=that.href;},200);return false;”">
<img width="90" border="0" src="http://github.com/images/modules/download/tar.png">
</a>
</div>
</section>
<section id="usage">
<div class="page-header">
<h1>Usage</h1>
</div>
<ul>
<li>
<strong>Include jQuery or Zepto (if not already here) and garlic.js</strong><br/>
<pre>
<script src="jquery.js"></script>
<script src="garlic.js"></script></pre>
</li>
<li>
<strong>Add </strong><code>data-persist="garlic"</code><strong> to the forms you want to auto-persist</strong><br/>
<pre><form data-persist="garlic" method="POST"></form></script></pre>
</li>
</ul>
<h3>That's all! ;)</h3>
<a href="#top" class="pull-right">Top</a>
</section>
<section id="documentation">
<div class="page-header">
<h1>Documentation</h1>
</div>
<ul>
<li>
Want to specifically chart fields persisted by Garlic? Use the auto-added <code>class="garlic-auto-save"</code> class!<br/>
</li>
<li>
Never destroy localStorage for a form: use <code>data-destroy="false"</code> <strong>(don't work on inputs separately, only on whole form inputs)</strong>
</li>
<li>
Store form localStorage accross all domain <strong>(by default, storage is specific to each pages)</strong>, use <code>data-domain="true"</code><br/>
</li>
<li>
Manually call garlic in javascript<br/>
<pre>
<script type="text/javascript">
$('[rel=persist]').garlic();
</script></pre>
</li>
<li>
Destroy storage for an element <strong>(don't work on an entire form yet, only input by input)</strong><br/>
<pre>
<script type="text/javascript">
$('input.no_good').garlic('destroy');
</script></pre>
</li>
</ul>
<a href="#top" class="pull-right">Top</a>
</section>
<section id="they-use">
<div class="page-header">
<h1>They use Garlic.js</h1>
</div>
<ul>
<li>
<a href="http://wisembly.com/en/">Wisembly (Backend)</a>
</li>
<li>
<a href="https://chrome.google.com/webstore/detail/simple-form-recovery/cieifohdikchafcbdjbcmkdiabggalhp">Chrome extension</a> by <a href="https://twitter.com/kornnflake">@kornnflake</a>
</li>
<li>
Feel free to contact me if your website use Garlic in a smart way! ;)
</li>
</ul>
</section>
<section id="other">
<div class="page-header">
<h1>Other stuff</h1>
</div>
<a href="tests/">Here is the test suite, have a look!</a><br/><br/>
Please, feel free to fork and contribute to this plugin, or just discuss ideas, enhancement requests in an <a href="https://github.com/guillaumepotier/garlic.js/issues?state=open">issue</a>.<br/><br/>
You could also fix my english mistakes, add some more tests in the test suite, and much more! :)
<br/>
<a href="#top" class="pull-right">Top</a>
</section>
<section id="licence">
<div class="page-header">
<h1>Version / Licence</h1>
</div>
<a href="https://github.com/guillaumepotier/Garlic.js/blob/master/README.md">0.0.10 - MIT</a> - <a href="https://github.com/guillaumepotier/Garlic.js/blob/master/CHANGELOG.md">See changelog</a>
<a href="#top" class="pull-right">Top</a>
</section>
</div>
</div>
</div>
<br/>
<p>© <a href="http://twitter.com/guillaumepotier" target="_blank">@guillaumepotier</a> 2012 <a href="http://wisembly.com/en/#garlic">@wisembly</a></p>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="garlic.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-affix.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-scrollspy.js"></script>
<script type="text/javascript">
$('#ajax-test').keyup( function () {
if ($(this).val().length >= 10) {
$('#ajax-test').garlic('destroy');
$('#indicator').text("Won't be persisted!").removeClass("alert alert-success").addClass("alert alert-info");
return;
}
$('#indicator').text("Will be persisted!").removeClass("alert alert-info").addClass("alert alert-success");
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36239082-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>