-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
executable file
·600 lines (578 loc) · 20.5 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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>femtoJS - Really small JavaScript (ES6) library for DOM
manipulation.</title>
<link rel="stylesheet" href="lib/style.css">
<link href="lib/prism.css" rel="stylesheet" />
<script src="lib/prism.js"></script>
<script src="lib/docJS.js"></script>
<script src="src/femtoJS.min.js"></script>
<script>
window.addEventListener(
'load',
function() {
const docOrder = [
'$', '$.fragment', 'on', 'off', 'css', 'html', 'before',
'after', 'first', 'last', 'insertBefore', 'insertAfter',
'insertFirst', 'insertLast', 'append', 'prepend',
'text', 'addClass', 'toggleClass', 'removeClass',
'empty', 'attr', 'getAttr', 'removeAttr', 'parent',
'offset', 'sel'
]
// LoganDark: I'm so sorry
const docs = {
$: {
argOrder: ['target'],
argTypes: { target: 'string | HTMLElement | Array' },
desc: 'This is the gateway to femtoJS. This' +
' function returns a femtoJS object' +
' which all of the following methods' +
' can be called on.',
example: function example() {
const femtoJS = $('body')
// this is a femtoJS object storing the `body` tag
}
},
'$.fragment': {
argOrder: [],
argTypes: {},
desc: 'Returns <code>$(document.create' +
'DocumentFragment())</code>. Not all' +
' methods may be available on this' +
' object. Currently, it\'s very' +
' difficult to get this object into the' +
' DOM, even if you manage to do your' +
' work correctly.',
example: function example() {
const frag = $.fragment()
frag.append(
$('<div>').css('background-color: green;')
)
$('body').sel()[0].appendChild(frag.sel()[0])
// this hack is needed to get it into the DOM
// since femtoJS's methods don't use appendChild
// but instead insertAdjacentElement
// which doesn't like DocumentFragments
}
},
on: {
argOrder: ['event', 'callback'],
argTypes: {
event: 'string',
callback: 'function'
},
desc: 'Subscribes to the event' +
' <code>event</code> for all objects in' +
' the selection, using' +
' <code>callback</code> as the event' +
' handler.',
example: function example() {
$('body').on('load', function callback() {
console.log('I\'m loaded!')
// this gets logged when the page loads,
// obviously
})
}
},
off: {
argOrder: ['event', 'callback'],
argTypes: {
event: 'string',
callback: 'function'
},
desc: 'Unsubscribes to the event' +
' <code>event</code> for all objects in' +
' the selection that are using' +
' <code>callback</code> as the event' +
' handler.',
example: function example() {
function callback() {
console.log('I\'m loaded!')
// this never gets logged!
}
const body = $('body')
// subscribe but then unsubscribe, it never gets
// called
body.on('load', callback)
body.off('load', callback)
}
},
css: {
argOrder: ['css'],
argTypes: { css: 'string' },
desc: 'Adds CSS to the elements. This' +
' basically appends <code>css</code> to' +
' their <code>style</code> attributes.',
example: function example() {
$('body').css('background-color: green;')
// the body's background color is now green
}
},
html: {
argOrder: ['innerhtml'],
argTypes: { innerhtml: 'string' },
desc: 'Sets the InnerHTML of an element to' +
' the argument <code>innerhtml</code>.',
example: function example() {
$('body').html('You\'ve Been Hacked!' +
' Please Contact Microsoft For' +
' Support At This Number:' +
' 1-XXX-XXX-XXXX' +
' Your Computer Is At Risk!')
// real virus
}
},
before: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'If <code>content</code> is a' +
' <code>string</code>, append that HTML' +
' before the start of the elements. If' +
' it\'s a <code>HTMLElement</code>,' +
' append that element before the start' +
' of the elements. If it\'s a' +
' <code>femtoJS</code> object, append' +
' everything in its selection before' +
' the start of the elements.' +
' <code>string</code> is recommended' +
' if you have more than one element in' +
' this object\'s selection.',
example: function example() {
$('body').before('<p>Hi!</p>')
// creates a paragraph BEFORE the body element
// the paragraph is not the first element in the
// body, but actually comes before it, like:
// ...
// </head>
// <p>Hi!</p>
// <body>
// ...
}
},
after: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'If <code>content</code> is a' +
' <code>string</code>, append that HTML' +
' after the end of the elements. If' +
' it\'s a <code>HTMLElement</code>,' +
' append that element after the end of' +
' the elements. If it\'s a' +
' <code>femtoJS</code> object, append' +
' everything in its selection after the' +
' end of the elements.' +
' <code>string</code> is recommended' +
' if you have more than one element in' +
' this object\'s selection.',
example: function example() {
$('body').after('<p>Hi!</p>')
// creates a paragraph AFTER the body element
// the paragraph is not the last element in the
// body, but actually comes after it, like:
// ...
// </body>
// <p>Hi!</p>
// </html>
}
},
first: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'If <code>content</code> is a' +
' <code>string</code>, append that HTML' +
' to the beginning of the elements. If' +
' it\'s a <code>HTMLElement</code>,' +
' append that element to the beginning' +
' of the elements. If it\'s a' +
' <code>femtoJS</code> object, append' +
' everything in its selection to the' +
' beginning of the elements.' +
' <code>string</code> is recommended' +
' if you have more than one element in' +
' this object\'s selection.',
example: function example() {
$('body').first('<p>Hi!</p>')
// prepends a paragraph to the body element
// the paragraph is now the first element in the
// body, like:
// ...
// <body>
// <p>Hi!</p>
// ...
}
},
last: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'If <code>content</code> is a' +
' <code>string</code>, append that HTML' +
' to the end of the elements. If' +
' it\'s a <code>HTMLElement</code>,' +
' append that element to the end of the' +
' elements. If it\'s a' +
' <code>femtoJS</code> object, append' +
' everything in its selection to the' +
' end of the elements.' +
' <code>string</code> is recommended' +
' if you have more than one element in' +
' this object\'s selection.',
example: function example() {
$('body').last('<p>Hi!</p>')
// appends a paragraph to the body element
// the paragraph is now the last element in the
// body, like:
// ...
// <p>Hi!</p>
// </body>
// </html>
}
},
insertBefore: {
argOrder: ['content'],
argTypes: { content: 'HTMLElement | femtoJS' },
desc: 'Move all objects in the selection to' +
' right before the start of' +
' the <code>HTMLElement</code> or the' +
' first object in the' +
' <code>femtoJS</code> object\'s' +
' selection.',
example: function example() {
$('<p>').text('Hi!').insertBefore($('body'))
// creates a paragraph BEFORE the body element
// the paragraph is not the first element in the
// body, but actually comes before it, like:
// ...
// </head>
// <p>Hi!</p>
// <body>
// ...
}
},
insertAfter: {
argOrder: ['content'],
argTypes: { content: 'HTMLElement | femtoJS' },
desc: 'Move all objects in the selection to' +
' right after the start of' +
' the <code>HTMLElement</code> or the' +
' first object in the' +
' <code>femtoJS</code> object\'s' +
' selection.',
example: function example() {
$('<p>').text('Hi!').insertAfter($('body'))
// creates a paragraph AFTER the body element
// the paragraph is not the last element in the
// body, but actually comes after it, like:
// ...
// </body>
// <p>Hi!</p>
// </html>
}
},
insertFirst: {
argOrder: ['content'],
argTypes: { content: 'HTMLElement | femtoJS' },
desc: 'Move all objects in the selection to' +
' the beginning of' +
' the <code>HTMLElement</code> or the' +
' first object in the' +
' <code>femtoJS</code> object\'s' +
' selection.',
example: function example() {
$('<p>').text('Hi!').insertFirst($('body'))
// prepends a paragraph to the body element
// the paragraph is now the first element in the
// body, like:
// ...
// <body>
// <p>Hi!</p>
// ...
}
},
insertLast: {
argOrder: ['content'],
argTypes: { content: 'HTMLElement | femtoJS' },
desc: 'Move all objects in the selection to' +
' the end of' +
' the <code>HTMLElement</code> or the' +
' first object in the' +
' <code>femtoJS</code> object\'s' +
' selection.',
example: function example() {
$('<p>').text('Hi!').insertLast($('body'))
// appends a paragraph to the body element
// the paragraph is now the last element in the
// body, like:
// ...
// <p>Hi!</p>
// </body>
// </html>
}
},
append: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'Identical to <code>last</code>.'
},
prepend: {
argOrder: ['content'],
argTypes: {
content: 'string | HTMLElement | femtoJS'
},
desc: 'Identical to <code>first</code>.'
},
text: {
argOrder: ['text'],
argTypes: { text: 'string' },
desc: 'Changes the <code>innerText</code> of' +
' the selected elements to' +
' <code>text</code>.',
example: function example() {
$('body').text('Hello, world!')
// the body now contains "Hello, world!"
}
},
addClass: {
argOrder: ['class'],
argTypes: { class: 'string' },
desc: 'Adds the class <code>class</code> to' +
' all selected elements.',
example: function example() {
$('body').addClass('js-enabled')
// the body element now has the `js-enabled`
// class
}
},
toggleClass: {
argOrder: ['class'],
argTypes: { class: 'string' },
desc: 'Toggles the class <code>class</code>' +
' on all selected elements.',
example: function example() {
$('input[type="checkbox"]')
.toggleClass('selected')
// probably bad but who knows? maybe someone out
// there thinks accessibility can take a hike
// and uses CSS classes for checkboxes
// ...
// they can also take a hike, by the way
// and never come back!
}
},
removeClass: {
argOrder: ['class'],
argTypes: { class: 'string' },
desc: 'Removes the class <code>class</code>' +
' from all selected elements.',
example: function example() {
$('body').addClass('js-disabled')
// the body element no longer has the
// `js-disabled` class
}
},
empty: {
argOrder: [],
desc: 'Empties all selected elements,' +
' removing all children.',
example: function example() {
$('body').empty()
// the page is now blank (unless you have stuff
// in the head, or your CSS is doing something
// weird). you happy?
}
},
attr: {
argOrder: ['key', 'value'],
argTypes: {
key: 'string',
value: 'any'
},
desc: 'Sets the attribute <code>key</code> to' +
' <code>value</code>.',
example: function example() {
$('<a>').attr('href', 'https://www.google.com')
.attr('target', '_blank')
.insertLast($('body'))
// creates a link that opens a new tab to Google
// and appends it to the body
}
},
getAttr: {
argOrder: ['key'],
argTypes: { key: 'string' },
desc: 'Returns the content of attribute' +
' <code>key</code> on the first' +
' selected element.',
example: function example() {
console.log($('body').getAttr('data-kdfhkk'))
// this makes sense to me
}
},
removeAttr: {
argOrder: ['key'],
argTypes: { key: 'string' },
desc: 'Removes the attribute <code>key</code>' +
' from all selected elements.',
example: function example() {
console.log($('body').removeAttr('data-kdfhkk'))
// nevermind, get rid of it, nobody needs this
}
},
parent: {
argOrder: [],
desc: 'Replaces every element in the current' +
' selection with its parent element.',
example: function example() {
$('body').parent()
// <html> element, unless your page has a weird,
// weird structure, in which case... what?
}
},
offset: {
argOrder: [],
desc: 'Returns the' +
' <code>getBoundingClientRect</code>' +
' of the first element in the selection.',
example: function example() {
// I gotta be honest, I don't know what use this
// has, so I don't have any example, but you get
// the idea I hope
}
},
sel: {
argOrder: [],
desc: 'Returns the current selection in its' +
' entirety.',
example: function example() {
$('div').sel() // returns all div elements
}
}
}
const sidebar = $('#sidebar')
const links = $('<ul>')
.attr('id', 'links')
.insertLast(sidebar)
const funcs = $('#funcs')
for (let key of docOrder) {
const doc = docs[key]
let anchor = 'jump-to-' + key
let signature = key + '(' + doc.argOrder.join(', ')
+ ')'
if (key.charAt(0) !== '$') {
signature = '.' + signature
}
links.append(
$('<li>')
.append($('<a>')
.text(signature)
.attr('href', '#' + anchor))
)
const argTable = $('<table>')
.addClass('argTable')
.append(
$('<tr>')
.append($('<th>').text('Argument'))
.append($('<th>').text('Type'))
)
for (let arg of doc.argOrder) {
argTable.append(
$('<tr>')
.append($('<td>').text(arg))
.append($('<td>').append(
$('<code>')
.addClass('language-js')
.text(doc.argTypes[arg]))
)
)
}
const container = $('<div>')
.addClass('l')
.attr('id', anchor)
funcs.append(
container
.append($('<h3>').text(signature))
.append(argTable)
.append($('<p>')
.html(doc.desc.replace(
/<code>/g,
'<code class="language-js">'
)))
)
if ('example' in doc) {
let lines = doc.example.toString().split('\n')
let funcIndent = lines[lines.length - 1].length - 1
for (let i = 1; i < lines.length; i++) {
lines[i] = lines[i].substr(funcIndent)
}
let code = $('<code>').text(lines.join('\n'))
code.html(code.sel()[0].innerHTML.replace(
/<br\s*\/?>/g,
'\n'
))
container.append(
$('<pre>')
.addClass('language-js')
.append(code)
)
}
if (doc.argOrder.length === 0) {
argTable.remove()
}
}
Prism.highlightAll()
}
)
</script>
</head>
<body>
<div id="sidebar">
<h3>femtoJS Docs</h3>
<p>Quick navigation:</p>
</div>
<div id="intro">
<h1><a href="https://github.com/vladocar/femtoJS"><img
style="vertical-align:middle;width:128px;height:128px"
src="logo/femtoJS-logo.png" /><span> femtoJS</span></a></h1>
<h3>Really small JavaScript (ES6) library for DOM manipulation.</h3>
<p>So, what is femtoJS? femtoJS is a JavaScript library for basic
DOM manipulation. It has a jQuery-inspired syntax and supports
chaining.</p>
<p>femtoJS is about <b>100 lines</b> of code in size, and the
entire library weighs in at just under 0.9kB compressed and
gzipped.</p>
<p>Because FemtoJS is so small and simple, you can add or remove
methods directly in the library, meaning it's very customizable.
All methods are unrelated, so removing one will not affect any
others in any way.</p>
<p>This library is designed to be personalized to meet your needs.
It's easy to modify the code to add new methods or change
existing ones.</p>
<p>Here are some code examples:</p>
<pre><code class="language-js">$('.someClass').css('background-color: green;').html('Hello World');</code></pre>
<pre><code class="language-js">$('a').on('click', function() {
$('#someDiv').css('background-color: green; color: #fff;');
})</code></pre>
<p>It works in ES6-supporting browsers. For Internet Explorer -56346
support, see <a
href="https://github.com/vladocar/nanoJS">NanoJS</a>.
</p>
<h2 class="l" style="text-decoration: underline"><a
href="https://github.com/vladocar/femtoJS">
<img src="github.svg" style="width:32px;height:32px" />
Download on Github</a></h2>
<h3> Here is the list of all the methods:</h3>
<div id="funcs"></div>
</div>
</body>
</html>