-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadme.html
987 lines (853 loc) · 41 KB
/
readme.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@font-face {
font-family: octicons-anchor;
src: url(https://cdnjs.cloudflare.com/ajax/libs/octicons/4.4.0/font/octicons.woff) format('woff');
}
* {
box-sizing: border-box;
}
body {
width: 980px;
margin-right: auto;
margin-left: auto;
color: #333;
background: #fff;
}
body .markdown-body {
padding: 45px;
border: 1px solid #ddd;
border-radius: 3px;
word-wrap: break-word;
}
pre {
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.markdown-body {
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
color: #333;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
}
.markdown-body a {
background-color: transparent;
}
.markdown-body a:active,
.markdown-body a:hover {
outline: 0;
}
.markdown-body strong {
font-weight: bold;
}
.markdown-body h1 {
font-size: 2em;
margin: 0.67em 0;
}
.markdown-body img {
border: 0;
}
.markdown-body hr {
box-sizing: content-box;
height: 0;
}
.markdown-body pre {
overflow: auto;
}
.markdown-body code,
.markdown-body kbd,
.markdown-body pre {
font-family: monospace, monospace;
font-size: 1em;
}
.markdown-body input {
color: inherit;
font: inherit;
margin: 0;
}
.markdown-body html input[disabled] {
cursor: default;
}
.markdown-body input {
line-height: normal;
}
.markdown-body input[type="checkbox"] {
box-sizing: border-box;
padding: 0;
}
.markdown-body table {
border-collapse: collapse;
border-spacing: 0;
}
.markdown-body td,
.markdown-body th {
padding: 0;
}
.markdown-body input {
font: 13px / 1.4 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.markdown-body a {
color: #4078c0;
text-decoration: none;
}
.markdown-body a:hover,
.markdown-body a:active {
text-decoration: underline;
}
.markdown-body hr {
height: 0;
margin: 15px 0;
overflow: hidden;
background: transparent;
border: 0;
border-bottom: 1px solid #ddd;
}
.markdown-body hr:before {
display: table;
content: "";
}
.markdown-body hr:after {
display: table;
clear: both;
content: "";
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 15px;
margin-bottom: 15px;
line-height: 1.1;
}
.markdown-body h1 {
font-size: 30px;
}
.markdown-body h2 {
font-size: 21px;
}
.markdown-body h3 {
font-size: 16px;
}
.markdown-body h4 {
font-size: 14px;
}
.markdown-body h5 {
font-size: 12px;
}
.markdown-body h6 {
font-size: 11px;
}
.markdown-body blockquote {
margin: 0;
}
.markdown-body ul,
.markdown-body ol {
padding: 0;
margin-top: 0;
margin-bottom: 0;
}
.markdown-body ol ol,
.markdown-body ul ol {
list-style-type: lower-roman;
}
.markdown-body ul ul ol,
.markdown-body ul ol ol,
.markdown-body ol ul ol,
.markdown-body ol ol ol {
list-style-type: lower-alpha;
}
.markdown-body dd {
margin-left: 0;
}
.markdown-body code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 12px;
}
.markdown-body pre {
margin-top: 0;
margin-bottom: 0;
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.markdown-body .select::-ms-expand {
opacity: 0;
}
.markdown-body .octicon {
font: normal normal normal 16px/1 octicons-anchor;
display: inline-block;
text-decoration: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.markdown-body .octicon-link:before {
content: '\f05c';
}
.markdown-body:before {
display: table;
content: "";
}
.markdown-body:after {
display: table;
clear: both;
content: "";
}
.markdown-body>*:first-child {
margin-top: 0 !important;
}
.markdown-body>*:last-child {
margin-bottom: 0 !important;
}
.markdown-body a:not([href]) {
color: inherit;
text-decoration: none;
}
.markdown-body .anchor {
display: inline-block;
padding-right: 2px;
margin-left: -18px;
}
.markdown-body .anchor:focus {
outline: none;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 1em;
margin-bottom: 16px;
font-weight: bold;
line-height: 1.4;
}
.markdown-body h1 .octicon-link,
.markdown-body h2 .octicon-link,
.markdown-body h3 .octicon-link,
.markdown-body h4 .octicon-link,
.markdown-body h5 .octicon-link,
.markdown-body h6 .octicon-link {
color: #000;
vertical-align: middle;
visibility: hidden;
}
.markdown-body h1:hover .anchor,
.markdown-body h2:hover .anchor,
.markdown-body h3:hover .anchor,
.markdown-body h4:hover .anchor,
.markdown-body h5:hover .anchor,
.markdown-body h6:hover .anchor {
text-decoration: none;
}
.markdown-body h1:hover .anchor .octicon-link,
.markdown-body h2:hover .anchor .octicon-link,
.markdown-body h3:hover .anchor .octicon-link,
.markdown-body h4:hover .anchor .octicon-link,
.markdown-body h5:hover .anchor .octicon-link,
.markdown-body h6:hover .anchor .octicon-link {
visibility: visible;
}
.markdown-body h1 {
padding-bottom: 0.3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
.markdown-body h1 .anchor {
line-height: 1;
}
.markdown-body h2 {
padding-bottom: 0.3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
.markdown-body h2 .anchor {
line-height: 1;
}
.markdown-body h3 {
font-size: 1.5em;
line-height: 1.43;
}
.markdown-body h3 .anchor {
line-height: 1.2;
}
.markdown-body h4 {
font-size: 1.25em;
}
.markdown-body h4 .anchor {
line-height: 1.2;
}
.markdown-body h5 {
font-size: 1em;
}
.markdown-body h5 .anchor {
line-height: 1.1;
}
.markdown-body h6 {
font-size: 1em;
color: #777;
}
.markdown-body h6 .anchor {
line-height: 1.1;
}
.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre {
margin-top: 0;
margin-bottom: 16px;
}
.markdown-body hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
}
.markdown-body ul,
.markdown-body ol {
padding-left: 2em;
}
.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
margin-top: 0;
margin-bottom: 0;
}
.markdown-body li>p {
margin-top: 16px;
}
.markdown-body dl {
padding: 0;
}
.markdown-body dl dt {
padding: 0;
margin-top: 16px;
font-size: 1em;
font-style: italic;
font-weight: bold;
}
.markdown-body dl dd {
padding: 0 16px;
margin-bottom: 16px;
}
.markdown-body blockquote {
padding: 0 15px;
color: #777;
border-left: 4px solid #ddd;
}
.markdown-body blockquote>:first-child {
margin-top: 0;
}
.markdown-body blockquote>:last-child {
margin-bottom: 0;
}
.markdown-body table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}
.markdown-body table th {
font-weight: bold;
}
.markdown-body table th,
.markdown-body table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
.markdown-body table tr {
background-color: #fff;
border-top: 1px solid #ccc;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f8f8f8;
}
.markdown-body img {
max-width: 100%;
box-sizing: content-box;
background-color: #fff;
}
.markdown-body code {
padding: 0;
padding-top: 0.2em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0, 0, 0, 0.04);
border-radius: 3px;
}
.markdown-body code:before,
.markdown-body code:after {
letter-spacing: -0.2em;
content: "\00a0";
}
.markdown-body pre>code {
padding: 0;
margin: 0;
font-size: 100%;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}
.markdown-body .highlight {
margin-bottom: 16px;
}
.markdown-body .highlight pre,
.markdown-body pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}
.markdown-body .highlight pre {
margin-bottom: 0;
word-break: normal;
}
.markdown-body pre {
word-wrap: normal;
}
.markdown-body pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}
.markdown-body pre code:before,
.markdown-body pre code:after {
content: normal;
}
.markdown-body kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.markdown-body .pl-c {
color: #969896;
}
.markdown-body .pl-c1,
.markdown-body .pl-s .pl-v {
color: #0086b3;
}
.markdown-body .pl-e,
.markdown-body .pl-en {
color: #795da3;
}
.markdown-body .pl-s .pl-s1,
.markdown-body .pl-smi {
color: #333;
}
.markdown-body .pl-ent {
color: #63a35c;
}
.markdown-body .pl-k {
color: #a71d5d;
}
.markdown-body .pl-pds,
.markdown-body .pl-s,
.markdown-body .pl-s .pl-pse .pl-s1,
.markdown-body .pl-sr,
.markdown-body .pl-sr .pl-cce,
.markdown-body .pl-sr .pl-sra,
.markdown-body .pl-sr .pl-sre {
color: #183691;
}
.markdown-body .pl-v {
color: #ed6a43;
}
.markdown-body .pl-id {
color: #b52a1d;
}
.markdown-body .pl-ii {
background-color: #b52a1d;
color: #f8f8f8;
}
.markdown-body .pl-sr .pl-cce {
color: #63a35c;
font-weight: bold;
}
.markdown-body .pl-ml {
color: #693a17;
}
.markdown-body .pl-mh,
.markdown-body .pl-mh .pl-en,
.markdown-body .pl-ms {
color: #1d3e81;
font-weight: bold;
}
.markdown-body .pl-mq {
color: #008080;
}
.markdown-body .pl-mi {
color: #333;
font-style: italic;
}
.markdown-body .pl-mb {
color: #333;
font-weight: bold;
}
.markdown-body .pl-md {
background-color: #ffecec;
color: #bd2c00;
}
.markdown-body .pl-mi1 {
background-color: #eaffea;
color: #55a532;
}
.markdown-body .pl-mdr {
color: #795da3;
font-weight: bold;
}
.markdown-body .pl-mo {
color: #1d3e81;
}
.markdown-body kbd {
display: inline-block;
padding: 3px 5px;
font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.markdown-body .plan-price-unit {
color: #767676;
font-weight: normal;
}
.markdown-body .task-list-item {
list-style-type: none;
}
.markdown-body .task-list-item+.task-list-item {
margin-top: 3px;
}
.markdown-body .task-list-item input {
margin: 0 0.35em 0.25em -1.6em;
vertical-align: middle;
}
.markdown-body .plan-choice {
padding: 15px;
padding-left: 40px;
display: block;
border: 1px solid #e0e0e0;
position: relative;
font-weight: normal;
background-color: #fafafa;
}
.markdown-body .plan-choice.open {
background-color: #fff;
}
.markdown-body .plan-choice.open .plan-choice-seat-breakdown {
display: block;
}
.markdown-body .plan-choice-free {
border-radius: 3px 3px 0 0;
}
.markdown-body .plan-choice-paid {
border-radius: 0 0 3px 3px;
border-top: 0;
margin-bottom: 20px;
}
.markdown-body .plan-choice-radio {
position: absolute;
left: 15px;
top: 18px;
}
.markdown-body .plan-choice-exp {
color: #999;
font-size: 12px;
margin-top: 5px;
}
.markdown-body .plan-choice-seat-breakdown {
margin-top: 10px;
display: none;
}
.markdown-body:checked+.radio-label {
z-index: 1;
position: relative;
border-color: #4078c0;
}
@media print {
body .markdown-body {
padding: 0;
border: none;
}
}
</style>
<title>readme</title>
</head>
<body>
<article class="markdown-body">
<h1>
<a id="user-content-form-saver" class="anchor" href="#form-saver" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Form Saver</h1>
<p>FS (Form Saver) is made to save your users time while filling short or long forms. It uses localStorage (by default) to register locally datas given by the user while completing your page forms. In case of browser crash, the script re-fill forms (automatically or by asking to user depending on you settings, again) to avoid user frustration.</p>
<h2>
<a id="user-content-how-to-use-it" class="anchor" href="#how-to-use-it" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>How to use it</h2>
<h3>
<a id="user-content-to-start" class="anchor" href="#to-start" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>To start</h3>
<p>First of all, you need to get the <code>src</code> folder content. Choose your own way to do so (clone this repository, download it manually, choose a dependencies manager, etc.)</p>
<p>Then link the script to your document, the one with a form to save, putting those lines of code before the <code></body></code> tag.</p>
<div class="highlight highlight-text-html-basic"><pre><<span class="pl-ent">script</span> <span class="pl-e">src</span>=<span class="pl-s"><span class="pl-pds">"</span>/assets/src/form-saver.min.js<span class="pl-pds">"</span></span>></<span class="pl-ent">script</span>>
<<span class="pl-ent">script</span>><span class="pl-s1"></span>
<span class="pl-s1"> <span class="pl-k">const</span> <span class="pl-c1">fs</span> <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">FormSaver</span>( <span class="pl-s"><span class="pl-pds">'</span>myform<span class="pl-pds">'</span></span> );</span>
<span class="pl-s1"> <span class="pl-smi">fs</span>.<span class="pl-en">init</span>();</span>
<span class="pl-s1"></span></<span class="pl-ent">script</span>></pre></div>
<p>Replace <code>/assets/src/</code> by the right folder, and remove <code>.min</code> from the file name if you need to test things in development. Keep <code>.min</code> to get the minified version which is better for performance.</p>
<p><code>myform</code> is the <code>id</code> or <code>name</code> attribute value of the form you need to declare before initiating the script.</p>
<h3>
<a id="user-content-optional-arguments" class="anchor" href="#optional-arguments" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Optional arguments</h3>
<div class="highlight highlight-source-js"><pre><span class="pl-k">const</span> <span class="pl-c1">fs</span> <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">FormSaver</span>( <span class="pl-s"><span class="pl-pds">'</span>myform<span class="pl-pds">'</span></span>, {
storageType <span class="pl-k">:</span> <span class="pl-s"><span class="pl-pds">'</span>local<span class="pl-pds">'</span></span>,
storageID <span class="pl-k">:</span> <span class="pl-s"><span class="pl-pds">'</span>ID123<span class="pl-pds">'</span></span>,
storageDuration <span class="pl-k">:</span> <span class="pl-c1">30</span>, <span class="pl-c"><span class="pl-c">//</span> not supported yet.</span>
} );</pre></div>
<h3>
<a id="user-content-multiple-forms-to-save" class="anchor" href="#multiple-forms-to-save" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Multiple forms to save</h3>
<p>In case you need to save multiple form, or have a generic way to declare FormSaver on complexe forms (yeah remember not to use FormSaver on small forms, it's really not necessary), this is an example of code.</p>
<div class="highlight highlight-text-html-basic"><pre><<span class="pl-ent">script</span> <span class="pl-e">src</span>=<span class="pl-s"><span class="pl-pds">"</span>/assets/src/form-saver.min.js<span class="pl-pds">"</span></span>></<span class="pl-ent">script</span>>
<<span class="pl-ent">script</span>><span class="pl-s1"></span>
<span class="pl-s1"> <span class="pl-k">const</span> <span class="pl-c1">fs</span> <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">FormSaver</span>( <span class="pl-s"><span class="pl-pds">'</span>myform<span class="pl-pds">'</span></span> );</span>
<span class="pl-s1"> <span class="pl-smi">fs</span>.<span class="pl-en">init</span>();</span>
<span class="pl-s1"></span></<span class="pl-ent">script</span>></pre></div>
<h3>
<a id="user-content-api--methods" class="anchor" href="#api--methods" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>API / Methods</h3>
<ul>
<li>
<code>init</code>
<br>The only way to make Form Saver work.</li>
</ul>
<div class="highlight highlight-source-js"><pre><span class="pl-k">const</span> <span class="pl-c1">fs</span> <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-en">FormSaver</span>( <span class="pl-s"><span class="pl-pds">'</span>form-name<span class="pl-pds">'</span></span> );
<span class="pl-smi">fs</span>.<span class="pl-en">init</span>();</pre></div>
<ul>
<li>
<code>stop</code>/<code>pause</code>
<br>Stop Form Saver saving the value of your form fields.</li>
</ul>
<div class="highlight highlight-source-js"><pre><span class="pl-k">if</span> ( <span class="pl-en">somethingHappens</span>() ) {
<span class="pl-smi">fs</span>.<span class="pl-c1">pause</span>();
}</pre></div>
<p>If you need to save things after a stop/pause, just use <code>init()</code> method.</p>
<div class="highlight highlight-source-js"><pre><span class="pl-k">if</span> ( <span class="pl-en">IneedToSaveAgain</span>() ) {
<span class="pl-smi">fs</span>.<span class="pl-en">init</span>();
}</pre></div>
<ul>
<li>
<code>save</code>
<br>Save all the fields of your form.</li>
</ul>
<div class="highlight highlight-source-js"><pre><span class="pl-c1">setInterval</span>( <span class="pl-k">function</span>(){
<span class="pl-smi">fs</span>.<span class="pl-en">save</span>();
}, <span class="pl-c1">10000</span>);</pre></div>
<p>When you want to save all the form field every 10s. Be careful with the performance, that's not ideal. Oftentime you need this when you enter in a long duration edition in a textarea or similar. Try to trigger this interval at the right time and clear it as soon as you don't need it.</p>
<ul>
<li>
<code>destroy</code>
<br>Destroy all datas stored.</li>
</ul>
<div class="highlight highlight-source-js"><pre><span class="pl-k">if</span> ( <span class="pl-en">somethingHappens</span>() ) {
<span class="pl-smi">fs</span>.<span class="pl-en">destroy</span>();
}</pre></div>
<p>Use it when you don't need datas anymore. <em>e.i after form validation.</em></p>
<ul>
<li>
<code>getDatas</code>
<br>Get all the datas stored.</li>
</ul>
<div class="highlight highlight-source-js"><pre><span class="pl-k">if</span> ( <span class="pl-en">somethingHappens</span>() ) {
<span class="pl-k">const</span> <span class="pl-c1">datas</span> <span class="pl-k">=</span> <span class="pl-smi">fs</span>.<span class="pl-en">getDatas</span>();
<span class="pl-en">console</span>.<span class="pl-c1">log</span>( datas );
<span class="pl-c"><span class="pl-c">//</span> return an object with stored values.</span>
<span class="pl-en">console</span>.<span class="pl-c1">log</span>( datas[<span class="pl-s"><span class="pl-pds">'</span>my-form-name<span class="pl-pds">'</span></span>] );
<span class="pl-c"><span class="pl-c">//</span> return the value of `#name` field from `#my-form` form.</span>
}</pre></div>
<h2>
<a id="user-content-forms-good-practices" class="anchor" href="#forms-good-practices" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Forms Good Practices</h2>
<h3>
<a id="user-content-security-concern" class="anchor" href="#security-concern" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Security concern</h3>
<p>Some fields/datas should never be saved to avoid security issues. I have in mind:</p>
<ul>
<li>Credit Card information (save the big number, but not the security code)</li>
<li>Password field (in "show my password" mode)</li>
<li>Sensitive datas (security number, unique tokens, etc.)</li>
</ul>
<p>To prevent those fields from being automatically saved, you can use different tricks:</p>
<ul>
<li>
<code>type="password"</code> won't be saved,</li>
<li>fields with <code>data-fs-save="false"</code> attribute won't be saved,</li>
<li>fields with those <code>autocomplete</code> attribute values won't be saved
<ul>
<li>
<a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-cc-csc" rel="nofollow"><code>cc-csc</code></a>: Security code for the payment instrument (also known as the card security code (CSC), card validation code (CVC), card verification value (CVV), signature panel code (SPC), credit card ID (CCID), etc)</li>
<li>
<a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-current-password" rel="nofollow"><code>new-password</code></a>: a new password (e.g. when creating an account or changing a password)</li>
<li>
<a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete-new-password" rel="nofollow"><code>current-password</code></a>: The current password for the account identified by the username field (e.g. when logging in)</li>
</ul>
</li>
</ul>
<p>In case you have a doubt about the sensitivity of a data, just use <code>data-fs-save="false"</code> on that <code>input</code>.</p>
<h3>
<a id="user-content-form-nameid" class="anchor" href="#form-nameid" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Form name/ID</h3>
<p>A form should always be distinguishable thanks to a uniq identifier: <code>id</code> attribute or <code>name</code> attribute are the keys to make FS work. You need to fill one of them.</p>
<h3>
<a id="user-content-keep-the-user-in-mind" class="anchor" href="#keep-the-user-in-mind" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Keep the user in mind</h3>
<p>Filling forms fields with user datas is kind of creepy when you think of that. Of course you can't access those datas, but the user is not supposed to know that. That's why FS propose by default a little message informing user when the page with the form is opening again with datas stored. The user have the possibility to use saved datas, or to use a new blank form.</p>
<p>From the outside, as developer, you have access to methods to make the User Experience even better. For example, you could suggest to the users to choose if they want their datas being saved or not at the beginning. <code>stop</code>, <code>pause</code> and <code>destroy</code> method will help you.</p>
<h2>
<a id="user-content-specific-behaviours" class="anchor" href="#specific-behaviours" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Specific behaviours</h2>
<p>This script has some basic "automatic" behaviours you should know.</p>
<h3>
<a id="user-content-name-and-id-attributes" class="anchor" href="#name-and-id-attributes" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><code>name</code> and <code>id</code> attributes</h3>
<p>As you should know, <code>name</code> and <code>id</code> attributes should always be provided for each input, select, textarea or whatever-form element you use.</p>
<ul>
<li>to compose the <strong>field key</strong> of the value saved, the script uses by default the <code>id</code> attribute in its methods for not grouped inputs, and <code>name</code> as fallback if <code>id</code> is not provided.</li>
<li>to do the same with grouped inputs (checkboxes, radios), the script uses only the <code>name</code> attribute as <strong>field key</strong>.</li>
<li>the global key of an item (localStorage or sessionStorage item) is composed with the <strong>form unique ID</strong> and the <strong>field key</strong>
</li>
</ul>
<p>Example if you want to get the value of a field in that form (that would be already saved):</p>
<div class="highlight highlight-text-html-basic"><pre><<span class="pl-ent">form</span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>my-form<span class="pl-pds">"</span></span>>
<<span class="pl-ent">p</span>>
<<span class="pl-ent">label</span> <span class="pl-e">for</span>=<span class="pl-s"><span class="pl-pds">"</span>name<span class="pl-pds">"</span></span>>Name</<span class="pl-ent">label</span>>
<<span class="pl-ent">input</span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>text<span class="pl-pds">"</span></span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>name<span class="pl-pds">"</span></span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>the-name<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>>
</<span class="pl-ent">p</span>>
<<span class="pl-ent">p</span>>
<<span class="pl-ent">span</span> <span class="pl-e">class</span>=<span class="pl-s"><span class="pl-pds">"</span>label-like<span class="pl-pds">"</span></span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>color-label<span class="pl-pds">"</span></span>>Colors:</<span class="pl-ent">span</span>>
<<span class="pl-ent">input</span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>checkbox<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>Red<span class="pl-pds">"</span></span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>colors<span class="pl-pds">"</span></span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>color-red<span class="pl-pds">"</span></span> <span class="pl-e">aria-labelledby</span>=<span class="pl-s"><span class="pl-pds">"</span>color-label<span class="pl-pds">"</span></span>>
<<span class="pl-ent">label</span> <span class="pl-e">for</span>=<span class="pl-s"><span class="pl-pds">"</span>color-red<span class="pl-pds">"</span></span>>Red</<span class="pl-ent">label</span>>
<<span class="pl-ent">input</span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>checkbox<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>Green<span class="pl-pds">"</span></span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>colors<span class="pl-pds">"</span></span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>color-green<span class="pl-pds">"</span></span> <span class="pl-e">aria-labelledby</span>=<span class="pl-s"><span class="pl-pds">"</span>color-label<span class="pl-pds">"</span></span>>
<<span class="pl-ent">label</span> <span class="pl-e">for</span>=<span class="pl-s"><span class="pl-pds">"</span>color-green<span class="pl-pds">"</span></span>>Green</<span class="pl-ent">label</span>>
<<span class="pl-ent">input</span> <span class="pl-e">type</span>=<span class="pl-s"><span class="pl-pds">"</span>checkbox<span class="pl-pds">"</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">"</span>Blue<span class="pl-pds">"</span></span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">"</span>colors<span class="pl-pds">"</span></span> <span class="pl-e">id</span>=<span class="pl-s"><span class="pl-pds">"</span>color-blue<span class="pl-pds">"</span></span> <span class="pl-e">aria-labelledby</span>=<span class="pl-s"><span class="pl-pds">"</span>color-label<span class="pl-pds">"</span></span>>
<<span class="pl-ent">label</span> <span class="pl-e">for</span>=<span class="pl-s"><span class="pl-pds">"</span>color-blue<span class="pl-pds">"</span></span>>Blue</<span class="pl-ent">label</span>>
</<span class="pl-ent">p</span>>
</<span class="pl-ent">form</span>></pre></div>
<p>You'll need to do that in JS for the name:</p>
<div class="highlight highlight-source-js"><pre><span class="pl-k">let</span> name_value <span class="pl-k">=</span> <span class="pl-c1">window</span>.<span class="pl-smi">localStorage</span>.<span class="pl-c1">getItem</span>( <span class="pl-s"><span class="pl-pds">'</span>my-form-name<span class="pl-pds">'</span></span> );
<span class="pl-en">console</span>.<span class="pl-c1">log</span>( name_value ); <span class="pl-c"><span class="pl-c">//</span> (string) the value of the field.</span></pre></div>
<p>For the same input, if you don't provide <code>id</code>, just replace <code>name</code> by <code>the-name</code>.</p>
<p>To get the checkboxes value(s), use:</p>
<div class="highlight highlight-source-js"><pre><span class="pl-k">let</span> checks <span class="pl-k">=</span> <span class="pl-c1">window</span>.<span class="pl-smi">localStorage</span>.<span class="pl-c1">getItem</span>( <span class="pl-s"><span class="pl-pds">'</span>my-form-colors<span class="pl-pds">'</span></span> );
<span class="pl-en">console</span>.<span class="pl-c1">log</span>( checks ); (array) the list <span class="pl-k">of</span> <span class="pl-en">id</span>(s) <span class="pl-k">of</span> checked <span class="pl-en">checkbox</span>(es).</pre></div>
<h2>
<a id="user-content-limitations" class="anchor" href="#limitations" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Limitations</h2>
<p>Don't forget this script is an helper to save user time. If saving datas is a big challenge for you business, you should save them on your server and not locally on the user computer.</p>
<h3>
<a id="user-content-ios" class="anchor" href="#ios" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>iOS</h3>
<p>On iOS since 5.1, Safari Mobile store localStorage datas in the cache directory which can be cleaned by the OS when memory space in full.</p>
<h2>
<a id="user-content-work-in-progress" class="anchor" href="#work-in-progress" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Work In Progress</h2>
<p>Next versions will be release with those future support.</p>
<h3>
<a id="user-content-select-multiple" class="anchor" href="#select-multiple" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Select multiple</h3>
<p>Select with attribute <code>multiple</code> is not tested and a priori not supported yet.</p>
<h3>
<a id="user-content-storageduration-parameter" class="anchor" href="#storageduration-parameter" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><code>storageDuration</code> parameter</h3>
<p>It's in the source code, but this parameter has no effect yet.</p>
<h3>
<a id="user-content-information-messages" class="anchor" href="#information-messages" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Information messages</h3>
<p>A bunch of messages to:</p>
<ul>
<li>warn users their browser just crashed</li>
<li>activate/deactivate save-mode directly by the user himself</li>
</ul>
<h3>
<a id="user-content-offline-support" class="anchor" href="#offline-support" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Offline support</h3>
<p>Detect during the process if the user is still online or offline. If not add the possibility to display a warning message. If they try to submit the form, tell them their data is saved in their browser and the form will be send again when online. (don't close the tab!)</p>
<h2>
<a id="user-content-browser-support" class="anchor" href="#browser-support" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Browser Support</h2>
<p>This is an estimated table of browser support:</p>
<table>
<thead>
<tr>
<th>Chrome</th>
<th>Firefox</th>
<th>Edge</th>
<th>Opera</th>
<th>Safari</th>
<th>IE</th>
</tr>
</thead>
<tbody>
<tr>
<td>41</td>
<td>44</td>
<td>12</td>
<td>17</td>
<td>10</td>
<td>11</td>
</tr>
</tbody>
</table>
<p>Mobile:</p>
<table>
<thead>
<tr>
<th>Android Webview</th>
<th>Chrome Android</th>
<th>Edge</th>
<th>Firefox Android</th>
<th>Opera Android</th>
<th>iOS Safari</th>
</tr>
</thead>
<tbody>
<tr>
<td>41</td>
<td>41</td>
<td>12</td>
<td>44</td>
<td>17</td>
<td>10</td>
</tr>
</tbody>
</table>
<h2>
<a id="user-content-humans-behind-the-code" class="anchor" href="#humans-behind-the-code" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Humans behind the code</h2>
<ul>
<li>
<strong>Geoffrey Crofte</strong>
<br>First idea and first release. Lead Dev.</li>
<li>
<strong>Stéphanie Walter</strong>
<br>First beta tester. UX Ideas.</li>
</ul>
</article>
</body>
</html>