-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.html
More file actions
1462 lines (1335 loc) · 68.5 KB
/
demo.html
File metadata and controls
1462 lines (1335 loc) · 68.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>Demo of prependFoldingArrowIcon jQuery plug-in</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script type="text/javascript" src="dist/jquery-folding-arrow-icon-min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
<script type="text/javascript" src="examples.js"></script>
<link type="text/css" rel="stylesheet" href="examples.css">
<link rel="stylesheet" type="text/css" href="dist/jquery-folding-arrow-icon.css">
<script type="text/javascript">
hljs.initHighlightingOnLoad();
$(function(){
$("#l1 > li, #l1 ul.folding-arrows > li").prependFoldingArrowIcon();
$("#chevron > li").prependFoldingArrowIcon({
closePath: false
});
$("#outline > li").prependFoldingArrowIcon({
viewboxMargin: 2
});
$("#custom-arrow > li").prependFoldingArrowIcon({
graph: [{element: "path", attributes: {"d": "M0,-9 L10,0 L0,10 M-10,0 L8,0"}}],
viewboxRadius: 10,
viewboxMargin: 3,
closePath: false
});
$("#custom-arrow-circle > li").prependFoldingArrowIcon({
graph: [{element: "circle", attributes: {"cx": "0", "cy": "0", "r":"20"}},
{element: "path", attributes:{"d": "M0,-9 L10,0 L0,10 M-10,0 L8,0"}}],
viewboxRadius: 20,
viewboxMargin: 2,
closePath: false
});
$("#plus-manual > li").prependFoldingArrowIcon({
graph: [{element: "line", attributes: {"x1": "-10", "y1": "0", "x2": "10", "y2":"0"}},
{element: "line", attributes: {"x1": "0", "y1": "-10", "x2": "0", "y2":"10"}}],
svgClass: "folding-arrow-icon my-plus",
viewboxRadius: 10,
viewboxMargin: 1
}).setupFoldingArrowIconTransformation({
svgClass: "folding-arrow-icon my-plus",
transformations: [{">g": "rotate(45)"}]
});
$("#plus-preset > li").prependFoldingArrowIcon({
preset: "plus"
}).setupFoldingArrowIconTransformation({
preset: "plus"
});
$("#plus-minus-preset > li").prependFoldingArrowIcon({
preset: "plus-minus"
}).setupFoldingArrowIconTransformation({
preset: "plus-minus"
});
$("#plus-circle > li").prependFoldingArrowIcon({
preset: $.fn.prependFoldingArrowIcon.copyOfPreset("plus")
.prependToGraph("circle", {"cx": "0", "cy": "0", "r": "17"}),
viewboxRadius: 17,
viewboxMargin: 3
}).setupFoldingArrowIconTransformation({
preset: "plus"
});
var myPlusMinusCirclePreset = $.fn.prependFoldingArrowIcon.copyOfPreset("plus-minus")
.prependToGraph("circle", {"cx": "0", "cy": "0", "r": "17"})
.prop("viewboxRadius", 17)
.prop("viewboxMargin", 3);
$("#plus-minus-circle > li").prependFoldingArrowIcon({
preset: myPlusMinusCirclePreset
}).setupFoldingArrowIconTransformation({
preset: myPlusMinusCirclePreset
});
$("#bullets li.arrow.default").prependFoldingArrowIcon().setupFoldingArrowIconTransformation();
$("#bullets li.arrow.chevron").prependFoldingArrowIcon({closePath: false}).setupFoldingArrowIconTransformation();
$("#bullets li.dash, #bullets ul.dashes li").prependFoldingArrowIcon({preset: "dash"});
$("#bullets li.disc, #bullets ul.discs li").prependFoldingArrowIcon({preset: "disc"});
$("ul.folding-arrows > li > a, ul.folding-arrows > li > svg.folding-arrow-icon:not(.static)").click(function(ev){
ev.preventDefault();
openOrCloseLi($(this).parent());
});
$("ul.folding-arrows > li:not(.showing) > ul").hide();
$("ul.folding-arrows > li").setupFoldingArrowIconTransformation({
titleShowing: "fold",
titleHidden: "show content"
})
function registerSectionClickHandler(section) {
section.click(function() {
openOrCloseSection(section)
}).children("a").first().click(function(ev) {
ev.preventDefault();
ev.stopPropagation();
openOrCloseSection(section);
});
}
registerSectionClickHandler(
$("#sec-prefix").prependFoldingArrowIcon({
closePath: false
}).setupFoldingArrowIconTransformation()
);
registerSectionClickHandler(
$("#sec-postfix").appendFoldingArrowIcon({
preset: "arrow-up-down",
closePath: false
}).setupFoldingArrowIconTransformation({
preset: "arrow-up-down"
})
);
registerSectionClickHandler(
$("#sec-al-right").appendFoldingArrowIcon({
preset: "arrow-up-down",
closePath: false,
separator: ""
}).setupFoldingArrowIconTransformation({
preset: "arrow-up-down"
})
);
var arrowUpDownInCircle = $.fn.prependFoldingArrowIcon.copyOfPreset("arrow-up-down")
.prependToGraph("circle", {"cx": "0", "cy": "0", "r": "10"})
.prop("viewboxRadius", 10)
.prop("viewboxMargin", 0)
.prop("closePath", false);
$("#sec-al-right-circle1, #sec-al-right-circle2").prependFoldingArrowIcon({
preset: arrowUpDownInCircle,
separator: ""
})
registerSectionClickHandler(
$("#sec-al-right-circle1").setupFoldingArrowIconTransformation({
preset: arrowUpDownInCircle
})
);
registerSectionClickHandler(
$("#sec-al-right-circle2").setupFoldingArrowIconTransformation({
transformations: [{"path": "scale(1 -1)"}]
})
);
$("h2.folding-plus.x").prependFoldingArrowIcon({
preset: "plus",
viewboxMargin: 3,
separator: ""
}).setupFoldingArrowIconTransformation({
preset: "plus"
})
registerSectionClickHandler($("h2.folding-plus.x:not(.altered)"));
registerSectionClickHandler(
$("h2.folding-plus.x.altered").setupFoldingArrowIconTransformation({
transformations: [{"line.v": "scale(1 0)"}]
})
);
registerSectionClickHandler(
$("h2.folding-plus.minus").prependFoldingArrowIcon({
preset: "plus-minus",
viewboxMargin: 3,
separator: ""
}).setupFoldingArrowIconTransformation({
preset: "plus-minus"
})
);
$("h2.sec").each(function() {
$(this).next().hide();
}).setupFoldingArrowIconTransformation({
titleHidden: "open section"
});
$("#burger").prependFoldingArrowIcon({
preset: "burger",
separator: ""
}).setupFoldingArrowIconTransformation({
preset: "burger"
}).click(function(ev) {
ev.preventDefault();
openOrClose($("#burger"));
$("#burger-content").slideToggle();
});
$("#burger-content").hide();
});
function openOrClose(jqr) {
return jqr.toggleClass("showing").transformFoldingArrowIcon();
}
function openOrCloseLi(li) {
openOrClose(li);
if (li.is(".showing"))
$("ul", li).slideDown(500);
else
$("ul", li).slideUp(500);
}
function openOrCloseSection(h) {
if (!h.is(".showing")) {
//collapse currently open section(s):
$("h2.sec.showing").each(function() {
openOrCloseSection($(this));
});
openOrClose(h);
h.next().slideDown(500);
} else {
openOrClose(h);
h.next().slideUp(500);
}
}
</script>
<style type="text/css">
#g1 .folding-arrow-icon path {
stroke: none;
fill: silver;
}
#g1b .folding-arrow-icon path {
stroke: none;
fill: #a00
}
#chevron .folding-arrow-icon path {
stroke: navy;
stroke-width: 1;
fill: none;
stroke-linecap: round;
}
#outline .folding-arrow-icon path {
stroke: navy;
stroke-width: 1;
fill: none;
}
#custom-arrow .folding-arrow-icon path {
stroke: green;
stroke-width: 2;
fill: none;
}
#custom-arrow-circle .folding-arrow-icon path, #custom-arrow-circle .folding-arrow-icon circle {
stroke: green;
stroke-width: 3;
fill: none;
}
.folding-arrow.showing > svg.folding-arrow-icon.my-plus > g {
transform: rotate(135deg);
}
.my-plus line {
stroke: navy;
stroke-width: 2;
}
#plus-preset .plus line, #plus-minus-preset .plus-minus line {
stroke: #555;
stroke-width: 3;
}
ul.plus-circle .folding-arrow-icon line, ul.plus-circle .folding-arrow-icon circle {
stroke: #555;
stroke-width: 4;
fill: none;
}
#bullets .default svg path,
#bullets .default svg circle {
stroke: none;
fill: silver;
}
#bullets .default svg.dash line {
stroke: silver;
stroke-width: 2px;
}
#bullets .chevron svg path,
#bullets .chevron svg line,
#bullets .chevron svg circle {
stroke: navy;
stroke.width: 1px;
fill: none;
}
h2.folding-arrow .folding-arrow-icon path {
stroke: navy;
stroke-width: 2;
fill: none;
}
h2.sec {
border: 1px solid silver;
background-color: #eee;
border-radius: 0.3em;
padding: 0.2em;
margin-top: 0;
}
h2.sec a, h2.sec a:link, h2.sec a:visited {
text-decoration: none;
color: #007;
}
h2.folding-arrow + div > :first-child {
margin-top: 0;
}
h2.folding-arrow + div > :last-child {
margin-bottom: 0;
}
h2.folding-arrow + div {
margin-bottom: 2em;
}
/*
Note: the margins above (no top margin of the h2 itself and no top margin
for the first child in the hideable content resp no bottom margin for
the content's last child are chosen in order to enable a smooth folding animation
by jQuery's show() and hide() methods. Margins in these places would cause "jumps"
at the start and end of the animation, as the top margin of an element gets usually
"merged" with the bottom margin of its next sibling, while during the animation they
add up.
*/
#sec-al-right-circle1 .folding-arrow-icon circle, #sec-al-right-circle2 .folding-arrow-icon circle {
stroke: none;
fill: #007;
}
#sec-al-right-circle1 .folding-arrow-icon path, #sec-al-right-circle2 .folding-arrow-icon path {
stroke: white;
}
#sec-al-right-circle2 .folding-arrow-icon > g {
transition: none;
transform: none;
}
#sec-al-right-circle2 .folding-arrow-icon path {
transition: transform 0.5s;
}
#sec-al-right-circle2.showing .folding-arrow-icon path {
transform: scale(1, -1);
}
h2.sec.folding-plus a:link, h2.sec.folding-plus a:visited {
color: #555;
}
h2.sec.folding-plus:hover a, h2.sec.folding-plus a:focus {
color: #33e;
}
h2.sec.folding-plus .folding-arrow-icon line {
stroke: #555;
stroke-width: 3;
stroke-linecap: round;
}
h2.sec.folding-plus:hover .folding-arrow-icon line {
stroke: #33e;
}
h2.sec.al-right .folding-arrow-icon {
float: right;
width: 1em;
height: 1em;
margin-top: 0.1em;
}
h2.folding-plus.x.altered .folding-arrow-icon.plus > g {
transform: none;
transition: none;
}
h2.folding-plus.x.altered .folding-arrow-icon.plus line.v {
transition: transform 0.7s;
}
h2.folding-plus.x.altered.showing .folding-arrow-icon.plus line.v {
transform: scale(1, 0);
}
#burger .burger-icon {
width: 40px;
height: 40px;
vertical-align: middle;
}
#burger-menu {
border-top: 1px solid silver;
border-bottom: 1px solid silver;
border-radius: 0.2em;
padding: 1em;
}
</style>
</head>
<body>
<h1>Demo of prependFoldingArrowIcon jQuery plug-in</h1>
<p><em>Please note: This plug-in concentrates on drawing the SVG icon, which may even
be animated with CSS transitions. The actual content-folding is not part of this plug-in.
The following examples add some very simple folding with jQuery's <code>slideDown()</code>
and <code>slideUp()</code> methods with a delay argument.</em> These slideDown() and slideUp()
mechanism actually needed some tricky CSS tweaks to really run smoothly (only applied
in the »Foldable Sections« examples below), please refer to the source code of this page
if interested.</p>
<h2>Foldable list items</h2>
<h3>Defaults</h3>
<p>Let's start the examples with the most common use-case: foldable sub-lists in list items.</p>
<p>For this example, we create a demo HTML list with the following markup:</p>
<pre><code class="language-html">
<ul id="l1" class="folding-arrows">
<li id="g1"><a href="#!">Test list item</a>
<br>
Second line
<ul>
<li>sub</li>
<li>list</li>
</ul>
</li>
<li id="g1b" class="showing">
<a href="#!">Test list item</a>
<br>
Second line
<ul class="folding-arrows">
<li>sub<br>still sub</li>
<li>list</li>
</ul>
</li>
</ul>
</code></pre>
<p>This is what it looks like – with the folding arrow icon plugin applied with default settings:</p>
<ul id="l1" class="folding-arrows">
<li id="g1"><a href="#!">Test list item</a>
<br>
Second line
<ul>
<li>sub</li>
<li>list</li>
</ul>
</li>
<li id="g1b" class="showing">
<a href="#!">Test list item</a>
<br>
Second line
<ul class="folding-arrows">
<li>sub<br>still sub</li>
<li>list</li>
</ul>
</li>
</ul>
<p>The examples above demonstrate the default shape of the folding arrow icon, being a closed
triangle pointing to the right resp. down. The javascript to include them is quite simple:</p>
<pre><code class="language-javascript">$("#l1 > li, #l1 ul.folding-arrows > li").prependFoldingArrowIcon();
</code></pre>
<p>This JavaScript alone is not enough, since the inserted SVG is unstyled, so you need
to add some CSS code to define the size and color theme:</p>
<p>This Library already comes with an included CSS file (<code>jquery-folding-arrow-icon.css</code>),
which defines a default size for the images and the transition for rotating the arrow when
the CSS class of the list item changes. Specifically for icons in unordered lists,
it also contains rules which align list items without bullets and with this SVG image
(inline inside the li's content) neatly with other normally bulleted list items
(see first sub list with default list bullets and compare its alignment to the second
sub list equipped with arrow icons).</p>
<p>But including that CSS file still isn't enough, since it does <em>not</em> define
the actual look (colors and line with) of the graphic. That, you' still have to define
on your own (otherwise it will default to a black triangle). This demo actually defines
two different color settings for the first and the second list item:</p>
<pre><code class="language-css">#g1 .folding-arrow-icon path {
stroke: none;
fill: silver;
}
#g1b .folding-arrow-icon path {
stroke: none;
fill: #a00
}
</code></pre>
<p>Now, you just have to add the class "showing" to a list item if its icon should be
transformed to a down-pointing arrow, removing the class transforms it back into a
right-pointing arrow. Actually, in the example above, the second list item has been
fitted with a "showing" class statically (see HTML markup shown above), which is why
it's already unfolded upon page load, while the first is initially folded.</p>
<p>Please note that this jQuery plug-in does <em>not</em> hide or show the actual
sub lists, but concentrates on just providing the animatable triangle icon. The
actual folding has to bee implemented separately (though I'm planning to release
a higher-level jQuery plug-in in the future, which will simplify showing or hiding sections
<em>and</em> adding a class like <code>showing</code>to a switch element in order
to display the folding state like – but not limited to – using this icon plug-in).</p>
<p>This example page uses the following JavaScript code (for the demo above as well
as the following ones) in order to show and hide sub-lists:</p>
<pre><code class="language-javascript">$(function() {
function openOrClose(jqr) {
return jqr.toggleClass("showing").transformFoldingArrowIcon();
}
function openOrCloseLi(li) {
openOrClose(li);
if (li.is(".showing"))
$("ul", li).slideDown(500);
else
$("ul", li).slideUp(500);
}
$("ul.folding-arrows > li > a, ul.folding-arrows > li > svg.folding-arrow-icon:not(.static)").click(function(){
ev.preventDefault();
openOrCloseLi($(this).parent());
});
$("ul.folding-arrows > li:not(.showing) > ul").hide();
});
</code></pre>
<p>Please note the calling of a further jQuery plug-in function provided by this library:
<code>transformFoldingArrowIcon()</code>. As long as your page is viewed with a browser
that supports transformations via CSS, this plug-in is not needed, since the loaded
default CSS already defines the rotation transformation along with a CSS transition.</p>
<p>The click handler is only applied to those SVGs of class <code>folding-arrow-icon</code>
which do not also have the class <code>static</code>. The latter is used by default to
denote icons for static, not foldable list items. The shape of these icons might
be a dash or disc (see examples for dash or disc presets further below) or some
custom-designe other icons like a diamond, square etc.</p>
<p>Unfortunately, the Microsoft browsers (Edge and Internet Explorer) do not support
CSS transformations for inline SVG, they require the transformations defined in
tag attributes inside the SVG code. The <code>transformFoldingArrowIcon()</code>
function adds or removes such a transformation attribute depending on the current
state (whether the element has or has not the class "showing"). If called without
parameters, the default transformation is used.</p>
<p>Please note: If both a transition attribute and a CSS transition are defined for the
same SVG element, the CSS transition is used and the attribute is ignored.</p>
<h3>Variations</h3>
<p>Click a variation list item in order to view the description and code samples.</p>
<ul id="outline" class="folding-arrows">
<li>
<a href="#!">Outline (closed path)</a>
<ul>
<li>This example differs from the default above mainly in the CSS formatting:
The arrow is not filled, but a stroke is defined:
<pre><code class="language-css">#outline .folding-arrow-icon path {
stroke: navy;
stroke-width: 1;
fill: none;
}</code></pre>
</li>
<li>Also, the JavaScript method gets passed an options object literal with
exactly one option: <code>viewboxMargin</code>, which defaults to 1,
is overridden to be 2. This increases the margin around the image inside
the SVG area a little, because due to the stroke with the triangle icon
would otherwise be slightly larger than the filled one without stroke, and
during the rotation transition, the edges of the triangle would exceed
the visible image area, i.e. be clipped:
<pre><code class="language-javascript">$("#outline > li").prependFoldingArrowIcon({
viewboxMargin: 2
});</code></pre>
</li>
</ul>
</li>
</ul>
<ul id="chevron" class="folding-arrows">
<li>
<a href="#!">Chevron (unclosed path)</a>
<ul>
<li>This example is nearly the same as the outline example before, with two differences:
<ol>
<li>The Javascript omits the larger <code>viewportMargin</code>, resulting
in a slightly larger graphic and accepting a slight clipping during the
rotation transition, which hardly is noticable in this case (with the closed
triangle, it would be easier to notice).</li>
<li>Instead, the JavaScript sets the <code>closePath</code> option to false.
The triangle arrow is in fact acutally defined as a the chevron path you
see here, but the option <code>closePath</code>, which defaults to true,
will cause this main path to be closed. This default behaviour is now turned
off, resulting in the “raw chevron path” to be drawn.
<pre><code class="language-javascript">$("#chevron > li").prependFoldingArrowIcon({
closePath: false
});</code></pre>
</li>
<li>Since the path now has to open line ends, we can define the style of those
via CSS. Here, rounded line caps have been chosen.
<pre><code class="language-css">#chevron .folding-arrow-icon path {
stroke: navy;
stroke-width: 1;
fill: none;
stroke-linecap: round;
}</code></pre></li>
</ol>
</ul>
</li>
</ul>
<ul id="custom-arrow" class="folding-arrows">
<li>
<a href="#!">Defining a custom SVG arrow icon</a>
<ul>
<li>Instead of using the default triangle icon, you may define your own SVG code for
drawing an arrow. The arrow icon above has been defined as follows:</li>
<li><pre><code class="language-javascript">$("#custom-arrow > li").prependFoldingArrowIcon({
graph: [{element: "path", attributes: {"d": "M0,-9 L10,0 L0,10 M-10,0 L8,0"}}],
viewboxRadius: 10,
viewboxMargin: 3,
closePath: false
});</code></pre></li>
<li>Description of the options:
<ul>
<li><code>graph</code> defines the main SVG code. You define an array of SVG elements.
Each element of the array is an object with two properties: <code>element</code>
defines the element/tag name of the SVG element, and <code>attributes</code>
is an object ob key/value pairs defining a list of attributes to insert into
that tag.<br>
The <code>graph</code> array above thus specifies the following SVG tag:
<pre><code class="language-svg"><path d="M0,-9 L10,0 L0,10 M-10,0 L8,0"/></code></pre>
</li>
<li>All elements of the <code>graph</code> are internally grouped into one
group element (<code>g</code>).</li>
<li>When defining the coordinate values for the path, please note that the
origin, i.e. the point (0, 0) is always centered in the generated SVG icon.
The <code>viewboxRadius</code> option defines the radius of the viewport,
i.e. the visible part of the coordinate system. Acutally the viewport is
a square, in this case (radius 10) the point (-10, -10) is the upper left corner
and (10, 10) the lower right corner.</li>
<li>While the <code>viewboxRadius</code> defines the size of the square area
into which the <code>graph</code> shoult fit, the option <code>viewboxMargin</code>
defines the width of a margin around that graph.<br>
Please note: In this example the path “touches the edges” of the 20x20 square,
but since the shape is not filled, but a stroke width is defined, the image
is actually a little larger. The <code>viewboxMargin</code> should therefore
be at least half the stroke-width!</li>
<li>Actually <code>viewboxRadius</code> and <code>viewboxMargin</code> are simply
added to define the top left corner and the size of the viewport.
The separation into two options instead of one
is simply for better readability/maintainability of the options.</li>
<li>The <code>closePath</code> option has already been introduced in an
earlier example. If set to true, a <code>z</code> will be appended to
every path attribute of the graph, which will add a connecting line
between the start point and the end point of the path. In this case,
that's not desirable, so it's turned off.</li>
</ul>
</li>
<li>Besides the Script code, we again need some CSS to format the styles of the
icon (no filling, but instead a green stroke):</li>
<li><pre><code class="language-css">#custom-arrow .folding-arrow-icon path {
stroke: green;
stroke-width: 2;
fill: none;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="custom-arrow-circle" class="folding-arrows">
<li>
<a href="#!">Adding a circle to the image</a>
<ul>
<li>This example is a simple variation of the previous one. The following modifications
have been made:
<ul>
<li>The path has been kept unchanged, but a second SVG element has been added
to the <code>graph</code> array: a circle around the center coordinate (0, 0)
with a radius of 20.</li>
<li>In order to include that circle into the visible part of the image (viewport),
the <code>viewportRadius</code> is set to the radius of the circle (20).<br>
The resulting image has doubled in size. Note that the actual size in the browser
is defined by CSS rules and, in this case, stays the same. The 40x40px SVG is simply
scaled to fit, so in this case the image gets scaled down, the arrow shrinks.</li>
<li>Since the actual image size shrinks by 50%, also the resulting stroke width would
be halved. In order to compensate that a litte, the stroke width gets increased via CSS,
in this case to 3, the stroke width is now three quarter compared to the
previous example.</li>
<li>The <code>viewboxMargin</code> should be at least half the stroke width, since
half of the stroke width is applied inside the logical line of the circle, the
other half outside (in the margin area). So we set it to 2.</li>
</ul>
</li>
<li><pre><code class="language-javascript">$("#custom-arrow-circle > li").prependFoldingArrowIcon({
graph: [{element: "circle", attributes: {"cx": "0", "cy": "0", "r":"20"}},
{element: "path", attributes:{"d": "M0,-9 L10,0 L0,10 M-10,0 L8,0"}}],
viewboxRadius: 20,
viewboxMargin: 2,
closePath: false
});</code></pre>
</li>
<li><pre><code class="language-css">#custom-arrow-circle .folding-arrow-icon path, circle {
stroke: green;
stroke-width: 3;
fill: none;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="plus-manual" class="folding-arrows">
<li>
<a href="#!">Custom non-circle-image with different transition</a>
<ul>
<li><strong>Please note: If you like this example, you don't have to copy it!</strong>
This demo is only to show you how to use the plug-in's options to create some image
and transition of your choice. The actual example of the plus icon with
a 45-degree-rotation transition is also available as a simple preset, see next example!
</li>
<li>Similarly to the previous two examples, this one uses the <code>graph</code> option
to define the SVG image, this time consisting of two lines forming a plus.
The <code>viewboxRadius</code> is set to the width resp. height of the horizontal resp.
vertical line.
</li>
<li>The previous examples all inherited the default transformation (rotation of 90°
to the right) when unfolding the list entry. Like explained above, this is defined in
two ways:
<ol>
<li>The included CSS file <code>jquery-folding-arrow-icon.css</code> defines
the transformation and a transition (animation) by the following rules:
<pre><code class="language-css">svg.folding-arrow-icon > g {
transition: transform 0.5s;
}
.folding-arrow.showing > svg.folding-arrow-icon > g {
transform: rotate(90deg);
}</code></pre></li>
<li>For compatibility with Microsoft Browsers, all these examples call the
<code>transformFoldingArrowIcon()</code> plug-in function, see the
<code>function openOrClose(jqr)</code> defined above. This
function adds or removes transformation attributes to resp. from
SVG node(s). The default action is to add a 90deg right rotation
transformation to the <code>g</code> node, the group holding
the entire graph defined by the <code>graph</code> option.
</li>
</ol>
<em>This</em> example however should <em>not</em> inherit this default
transformation, for obvious reasons: a plus sign rotated by 90° looks
identical to its unrotated form.<br>
So we want to override both of the mechanisms described above:
<ol>
<li>We use the <code>svgClass</code> option to assign a
second class name (<code>my-plus</code>) to the <code>svg</code> element.
Yet, by also keeping the default class name (<code>folding-arrow-icon</code>),
the default rules still apply. <br>
Then we add a more specific CSS rule to override just the transformation
definition for elements of our <code>my-plus</code> class, setting the
transition to 45 degrees.—Actually, to set this example apart from
the preset shown in the next example, let's vary the angle to 135°.
The result will look the same, but the transition (animation) looks
different, since the plus rotates further and faster.
</li>
<li>In order to override the transformation attribute definition used
by the <code>transformFoldingArrowIcon()</code> plug-in function,
we add a <code>setupFoldingArrowIconTransformation()</code> call to
the <code>prependFoldingArrowIcon()</code> call. Here we pass two
options:
<ul>
<li><code>svgClass</code> holds class name used for finding the CSS node inside the
list item on which the <code>tronsfromFoldingArrowIcon()</code> function
is called. This should normally math the <code>svgClass</code> option passed
to <code>prependFoldingArrowIcon()</code>.</li>
<li><code>transformations</code> holds an array of key-value-pairs,
each of which defines a node selector as key and a the value for the
<code>transformation</code> attribute which should be added to the
selected node upon unfolding.<br>
In this case we define that a rotation of 45 degrees is to be added
to the first <code>g</code> node in the CSS DOM, i.e. the group consisting
of the two crossed lines.
</li>
</ul>
</li>
</ol>
</li>
<li>So, the resulting code for this example looks like this:</li>
<li><pre><code class="language-javascript">$("#plus-manual > li").prependFoldingArrowIcon({
graph: [{element: "line", attributes: {"x1": "-10", "y1": "0", "x2": "10", "y2":"0"}},
{element: "line", attributes: {"x1": "0", "y1": "-10", "x2": "0", "y2":"10"}}],
svgClass: "folding-arrow-icon my-plus",
viewboxRadius: 10,
viewboxMargin: 1
}).setupFoldingArrowIconTransformation({
svgClass: "folding-arrow-icon my-plus",
transformations: [{">g": "rotate(45)"}]
});</code></pre></li>
<li><pre><code class="language-css">.folding-arrow.showing > svg.folding-arrow-icon.my-plus > g {
transform: rotate(135deg);
}
.my-plus line {
stroke: navy;
stroke-width: 2;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="plus-preset" class="folding-arrows">
<li>
<a href="#!">Plus-X-Preset</a>
<ul>
<li>This example is mostly identical to the previous one (except for different local
CSS styles), but its simpler to use since it uses a built-in preset to define
the plus and its rotation instead of defining it locally in the example itself.</li>
<li>The plug-in contains several presets. A preset can be easily loaded by simply
using the <code>preset</code> option with the preset name (as string value).</li>
<li>Since not only the SVG graph itself should apply a preset differing from the
default preset (triangle arrow to the right), but also the non-CSS transformation
for Microsoft browsers IE & Edge, you'll also have to call the
<code>setupFoldingArrowIconTransformation()</code> plug-in function with the
preset defining the transformation (usually simply the same preset name, except
if you want to combine a graphic from one preset with a transformation from another).</li>
<li>Please note: Forgetting the <code>setupFoldingArrowIconTransformation</code> won't
seem to do any bad – as long as you use a browser supporting CSS transformations for SVG.
(The default transformation and transition for this preset are defined in the bundled
file <code>jquery-folding-arrow-icon.css</code>.) But if the page is opened in a
Microsoft browser, which doesn't yet support CSS transformations, the inline transformations
defined by this plug-in function will become “alive”. And since the default transition
is a rotation by 90°, this won't have any visible effect on the plus icon!</li>
<li>If you can't or don't want to test your page in Internet Explorer or Edge,
you may test the inline transformation attribute in your browser's developer tools by
selecting the SVG and disabling the CSS transformation rule for its <code>g</code> node!</li>
<li><pre><code class="language-javascript">$("#plus-preset > li").prependFoldingArrowIcon({
preset: "plus"
}).setupFoldingArrowIconTransformation({
preset: "plus"
});</code></pre></li>
<li><pre><code class="language-css">#plus-preset .plus line {
stroke: #555;
stroke-width: 3;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="plus-minus-preset" class="folding-arrows">
<li>
<a href="#!">Plus-Minus-Preset</a>
<ul>
<li>This example is mostly identical to the previous one, but this preset
defines a different transformation: Instead of rotating the plus icon to
form an X, it scales the vertical bar down (with a CSS transition) to
zero height, so that only the horizontal bar remains, and thus the plus icon
gets transformed into a minus icon.</li>
<li><pre><code class="language-javascript">$("#plus-preset > li").prependFoldingArrowIcon({
preset: "plus-minus"
}).setupFoldingArrowIconTransformation({
preset: "plus-minus"
});</code></pre></li>
<li><pre><code class="language-css">#plus-minus-preset .plus-minus line {
stroke: #555;
stroke-width: 3;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="plus-circle" class="folding-arrows plus-circle">
<li>
<a href="#!">Combine preset with circle</a>
<ul>
<li>Further above, we already demonstrated how to create a graph with a circle around an arrow icon.
However, that graph had been created from scratch. This example is to demonstrate how to
extend the graph of an existing preset.</li>
<li>The function <code>$.fn.prependFoldingArrowIcon.copyOfPreset()</code> (not a jQuery plug-in,
but a static helper function published in the plug-ins namespace) takes the name of a preset
and returns an object of a special PresetCopy class. This object can always be used as
argument to the <code>preset</code> option instead of a preset name (string), but before that,
you may apply modifications to that preset-copy using its methods.<br>
The most important methods are <code>prependToGraph()</code> and <code>appendToGraph()</code>.
Remember that the graph is an array of SVG element definitions, and these methods may
define further SVG elements which are added to the graph array at its beginning resp. end.
They take two arguments: first the element name (tag name), second an object of key-value-pairs
defining the attributes to add to that tag.</li>
<li>In this case we prepend a circle to the graph. The original preset graph has a radius of 10px,
and for the circle we choose a radius of 17px.</li>
<li>Now, as already explained in the previous example, the <code>viewboxRadius</code> also has to
be enlarged (to 17), and in order to leave some room for the stroke of width 4, we have to
define a <code>viewboxMargin</code> of at least 2. For some more tolerance, we choose 3.</li>
<li>Note 1: In <em>this</em> example, we directly set these viewBox-options directly in the options object.
It's always possible to combine the <code>preset</code> option with "hard-coded" other options,
the latter then override the preset's options!</li>
<li>Note 2: For the <code>setupFoldingArrowIconTransformations()</code> call we simply use
the original preset, since our copy of the preset only overrides the preset's graph,
the inherited transformation properties haven't changed and are also applicable on the
changed graph (since the added circle does not have to be transformed).</li>
<li><pre><code class="language-javascript">$("#plus-circle > li").prependFoldingArrowIcon({
preset: $.fn.prependFoldingArrowIcon.copyOfPreset("plus")
.prependToGraph("circle", {"cx": "0", "cy": "0", "r": "17"}),
viewboxRadius: 17,
viewboxMargin: 3
}).setupFoldingArrowIconTransformation({
preset: "plus"
});</code></pre></li>
<li><pre><code class="language-css">ul.plus-circle .plus line, ul.plus-circle .plus circle {
stroke: #555;
stroke-width: 4;
fill: none;
}</code></pre></li>
</ul>
</li>
</ul>
<ul id="plus-minus-circle" class="folding-arrows plus-circle">
<li>
<a href="#!">Combine preset with circle</a>
<ul>
<li>This example differs from the previous one in two ways:
<ol>
<li>We copied another preset ("plus-minus" instead of "plus").</li>
<li>The main difference is: We don't override the viewbox Properties locally in
the plug-in call's options, but directly in the copied preset. That is more elegant,
since it provides a consistent new preset with its viewbox perfectly fitting its graph.
And this newly created preset may be saved to a variable in order to be re-used in
several function calls. (Here, we demonstrate that by passing it to both
plug-in calls.)
</li>
</ol>
</li>
<li><pre><code class="language-javascript">var myPlusMinusCirclePreset = $.fn.prependFoldingArrowIcon.copyOfPreset("plus-minus")
.prependToGraph("circle", {"cx": "0", "cy": "0", "r": "17"})
.prop("viewboxRadius", 17)
.prop("viewboxMargin", 3);
$("#plus-minus-circle > li").prependFoldingArrowIcon({
preset: myPlusMinusCirclePreset
}).setupFoldingArrowIconTransformation({
preset: myPlusMinusCirclePreset
});</code></pre></li>
<li>For styling, we use the very same CSS as in the previous example.</li>
</ul>
</li>
</ul>
<h3>Bullets for static (non-foldable) list items</h3>
<ul id="bullets" class="folding-arrows">
<li class="arrow default">
<a href="#!">Preset <code>dash</code> and non-folding list items</a>
<ul class="folding-arrows dashes">
<li>The initial example at the beginning of this demo page demonstrated the
combination of arrow-icons with default CSS list bullets.
Yet—if you have lists of which only some list items are foldable
and others are static—you might want to use custom CSS images for
static list items, too. These can be styled via CSS to perfectly
match the folding arrow icon style and provide a more homogeneous look
of the two kinds of bullets.</li>
<li>Two presets are pre-defined: a dash and a disc bullet. This example
shows the dash preset (see the following list item after this unfolded group).</li>
<li>Please note that the dash preset defines a dash not actually centered in the whole
of the square SVG area, but instead perfectly aligned with the default
triangle arrow icon, its left and aligned with the left edge of the right-pointing
triangle, and its right end aligned with the right vertex of the right-pointing
triangle. If, however, the triangle points downwards, the triangle is
no more aligned with the left end of the dash. (Of course, you may always
create your own dash icon via the <code>graph</code> option.)</li>
<li>This very first dash example demonstrates how to create a dash visually
matching a silver and filled triangle:
<pre><code class="language-javascript">$("#bullets li.arrow.default").prependFoldingArrowIcon().setupFoldingArrowIconTransformation();
$("#bullets li.dash, #bullets ul.dashes li").prependFoldingArrowIcon({preset: "dash"});</code></pre>
<p>The first line prepends the default arrow icon and its default fallback
transformation as demonstrated above already. The second line applies
the <code>dash</code> preset to the next list item (<code>li</code> of class <code>dash</code>)
and to every list item of this sub list (<code>ul</code> of class <code>dashes</code>
— and of class <code>folding-arrows</code> in order to inherit the styles
of the included CSS file which, among others, turn off the default list bullets).
Since these are static list items, no transformation is defined.</p>
</li>
<li>The following CSS styles are applied to define the looks of the list bullets
(class <code>default</code> denotes these first silver examples, while the later,
examples using thin blue strokes are denoted by class <code>chevron</code>):
<pre><code class="language-css">#bullets .default svg path,
#bullets .default svg circle {
stroke: none;
fill: silver;
}
#bullets .default svg.dash line {
stroke: silver;
stroke-width: 2px;