-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratch-v3.html
411 lines (275 loc) · 10.4 KB
/
scratch-v3.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
<!-- The following code will select all <p> tags and apply the css rules defined in the <css> tag. Note that the <css> tag is a child of the <select-all> tag, and that the <select-all> tag has a 'targets' attribute. This attribute tells the library to select all elements that match the selector in the 'targets' attribute. In this case, we're selecting all <p> tags. -->
<when event="load" media="(min-width:768px)">
<select-all targets="p">
<css>
<color>red</color>
<font-size>16px</font-size>
</css>
<attr>
<aria-hidden>true</aria-hidden>
</attr>
</select-all>
</when>
<select-all>
<targets select-all="p">
<prev>h2</prev>
</targets>
<css>
<color>red</color>
<font-size>16px</font-size>
</css>
<attr>
<aria-hidden>true</aria-hidden>
</attr>
</select-all>
<!--
this code will make all h3s that precede a p tag red with font-size 16px.
-->
<select-all>
<targets select-all="p">
<prev>h3</prev>
</targets>
<css>
<color>orange</color>
<font-style>italic</font-style>
</css>
</select-all>
<!--
The following code will select all elements with the class 'myClass' and apply the jQuery method 'addClass' with the value of 'newClass'. Note that the <add-class> tag is a child of the <select-all> tag, and that the <select-all> tag has a 'targets' attribute. This attribute tells the library to select all elements that match the selector in the 'targets' attribute. In this case, we're selecting all elements with the class 'myClass'.
-->
<select-all targets=".myClass">
<add-class>otherClass</add-class>
</select-all>
<if day="tuesday">
<else>
<select-all targets=".show-tuesday">
<hide></hide>
</select-all>
</else>
</if>
<!-- here's a more complex example of a notification bar built with Hijinx. -->
<!-- the actual markup -->
<div id="notification-bar">
This is a notification. <button id="close-button">Close</button>
</div>
<!-- Hijinx -->
<!-- when we click #close-button -->
<select-all targets="#close-button">
<on-click>
<!-- hide the notification bar -->
<select-all targets="#notification-bar">
<hide></hide>
</select-all>
<!-- set the value of 'notificationBar' to 'closed'-->
<store>
<notificationBar>closed</notificationBar>
</store>
</on-click>
</select-all>
<!-- If the value of 'notificationBar' is 'closed' -->
<if store="notificationBar" is value="closed">
<!-- hide the notification bar -->
<select-all targets="#notification-bar">
<hide></hide>
</select-all>
</if>
<!-- Setting -->
<!-- Here's an example that uses 'set' to define a jQuery object. elLinks is a collection of links found within .card elements (sets will run first), and we can use their values inside other operations, like wrapping .card elements in a link that references the href of the appropriate item in the collection. -->
<set name="elLinks">
<select-all targets=".card">
<find>a</find>
<attr>href</attr>
</select-all>
</set>
<select-all targets=".card">
<wrap>
<a href="[elLinks]"></a>
</wrap>
</select-all>
<!-- accessibility example: getting post titles, then adding a sr-only span to each link with its post's title. -->
<!-- create a group called postTitles, which are the texts of all the .post titles -->
<set name="postTitles">
<select-all targets=".post">
<find>.post-title</find>
<text></text>
</select-all>
</set>
<!-- append a span with the text of the appropriate postTitle to each post link -->
<select-all targets=".post a">
<append>
<span class="sr-only">about [postTitles]</span>
</append>
</select-all>
<!--
This will use this document's HTML syntax to add local navigation to a page
1. Look through all .prose elements and find all h2 elements. Get their text and store it, along with a url-friendly version of the text, in sets called 'localNavItemsText' and 'localNavItemsUrl'.
2. Create a <nav> element with the class 'local-nav' and append it to the .prose element. Then, for each item in the localNavItems set, append an <a> element with the text of the item and a href of '#item-url-friendly-text'.
3. Then, for each .prose element, find all h2 elements and wrap each of them in an <a> element with a href of '#item-url-friendly-text'.
-->
<!-- create a set called 'localNavItems' that contains the text of all h2 elements in .prose elements -->
<set name="localNavItemsText">
<select-all targets=".prose">
<find>h2</find>
<text></text>
</select-all>
</set>
<!-- create a set called 'localNavItemsUrl' that contains the url-friendly text of all h2 elements in .prose elements -->
<set name="localNavItemsUrl">
<select-all targets="[localNavItemsText]">
<!-- urlify is a custom method that converts text to a url-friendly format with a '#' at the beginning -->
<urlify></urlify>
</select-all>
</set>
<!-- This is optional, .local-nav can already be in the DOM -->
<select-all targets=".prose">
<append>
<nav class="local-nav"></nav>
</append>
</select-all>
<!-- for each item in the localNavItems set, append an <a> element with the text of the item and a href of '#item-url-friendly-text'. -->
<select-all targets=".local-nav">
<append>
<a href="[localNavItemsUrl]">[localNavItemsText]</a>
</append>
</select-all>
<!-- for each .prose element, find all h2 elements and wrap each of them in an <a> element with a href of '#item-url-friendly-text'. -->
<select-all targets=".prose h2">
<wrap>
<a href="[localNavItemsUrl]"></a>
</wrap>
</select-all>
<!-- This will use a custom <localnav> element to add local navigation to a page -->
<localnav targets=".prose" headings="h2, h3" destination=".local-nav"></localnav>
<!-- This will use a custom <localnav> element to add local navigation to a page with h3 headings -->
<localnav>
<targets>.prose</targets>
<headings>h2, h3</headings>
<destination>.local-nav</destination>
<scrollspy>true</scrollspy>
</localnav>
<!--
we can also use hijinx to perform greensock animations, first by establishing a timeline, then by adding tweens to that timeline, like from and to tweens.
for example, the following HTML syntax which passes 'to' properties as child tags of a <to> tag instead of as attributes
-->
<to>
<color>red</color>
<duration>1</duration>
</to>
<!-- we can wrap those timelines in a scrolltrigger, which will fire the timeline when the element is scrolled into view. For example, using our above example, we can wrap the timeline in a scrolltrigger (a tag which has its own child tag properties like <start> and <end>) like so: -->
<scrolltrigger name="fades" users=".fades-parent">
<start>top 50%</start>
<end>bottom 50%</end>
<scrub>true</scrub>
<animation>
<timeline>
<to targets="p">
<color>red</color>
<duration>1</duration>
<stagger>0.5</stagger>
</to>
<to targets="h2">
<color>blue</color>
<duration>1</duration>
<stagger>0.5</stagger>
</to>
</timeline>
</animation>
</scrolltrigger>
<!-- make p's red -->
<animation>
<on-scroll targets="section">
<start>top 50%</start>
<end>bottom 50%</end>
<scrub>true</scrub>
</on-scroll>
<timeline>
<to targets="p">
<color>red</color>
<duration>1</duration>
<stagger>0.5</stagger>
</to>
</timeline>
</animation>
<!-- we can also use GSAP's batch() method to animate a group of elements as they all collectively enter the viewport. Here's
the html for that, using a <batch> element and appropriate child tags for batch properties: -->
<batch>
<targets>section</targets>
<on-scroll>
<start>top 50%</start>
<end>bottom 50%</end>
<scrub>true</scrub>
</on-scroll>
<timeline>
<to targets="p">
<color>red</color>
<duration>1</duration>
<stagger>0.5</stagger>
</to>
</timeline>
<!-- Notes -->
<!--
-we'll want to perform an 'each' on the collection of elements that we're targeting.
-we want to use arriveJS to watch for new elements that match the selector.
-methods like insertBefore or insertAfter will need to be able to target elements that are not yet in the DOM, so we'll need to use arriveJS for that as well.
-we want to be able to add a class to something AND select that element with select-all
-consider skipping the select-all and allowing components (click handlers, animations) to be declared inside the HTML, e.g.
-->
<button>
<span>Click Me</span>
<on-click>
<!-- hide the notification bar -->
<select-all targets="#notification-bar">
<hide></hide>
</select-all>
<!-- set the value of 'notificationBar' to 'closed'-->
<store>
<notificationBar>closed</notificationBar>
</store>
</on-click>
</button>
<!-- or -->
<div>
<p>Headline goes here!</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Culpa delectus nemo nostrum est, autem aut, non
enim temporibus, vel omnis rem ipsum alias perferendis et sunt ratione reprehenderit natus.</p>
<scrolltrigger>fades</scrolltrigger>
</div>
<!--
-general lifecycle
1.
2. creating new elements
3. adding attributes
4.
5.
-->
<radio-group>
</radio-group>
<input-text>
</input-text>
<input-range id="" slider="true" persist="true">
</input-range>
<input-button-group>
</input-button-group>
{{hero-inner}} : `
`
Mobius section panel:
{{hero-outer}}
{{hero-inner}}
{{/hero-outer}}
Part panel:
name = {{hero-outer}}
content = <div>jkl;</div>
{{myDiv}} : '<div></div>',
{{myDiv}} : '<div></div>',
<!--- {{mypart}} --->
<div>mypartcontent</div>
<!--- {{myotherpart}} --->
<div>myotherpartcontent</div>
<!--- {{mypart}} --->
<div>mypartcontent</div>
<!--- {{myotherpart}} --->
<div>myotherpartcontent</div>
<!--- {{mypart}} --->
<div>mypartcontent</div>
<!--- {{myotherpart}} --->
<div>myotherpartcontent</div>