-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
390 lines (331 loc) · 11.8 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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="https://unpkg.com/imbue-js"></script>
<title>Imbue.js</title>
<style>
* {
font-family: "Roboto", sans-serif;
line-height: 1.2em;
font-size: 1em;
}
.pre {
white-space: pre;
}
.comment {
color: #695CF9;
}
ul li {
line-height: 1.4em;
font-size: 1.1em;
}
p {
font-size: 1.2em;
}
.center {
margin: 0 auto;
text-align: center;
}
.dark {
background: #131228;
color: white;
}
.purple {
background: #695cf9;
color: white;
}
.box {
border-radius: 8px;
margin: 0 auto;
max-width: 90%;
width: 900px;
}
.shadow {
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
0 1px 2px rgba(0, 0, 0, 0.24);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
0 1px 2px rgba(0, 0, 0, 0.24);
-ms-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
0 1px 2px rgba(0, 0, 0, 0.24);
-o-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
0 1px 2px rgba(0, 0, 0, 0.24);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
-webkit-transition: all 0.25s ease-in-out;
-moz-transition: all 0.25s ease-in-out;
-ms-transition: all 0.25s ease-in-out;
-o-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
}
.p-10 {
padding: 10px;
}
p code,
li code {
padding: 3px;
border-radius: 8px;
font-size: .9em;
}
.pre code {
padding: 3px;
border-radius: 8px;
font-family: monospace;
font-size: 15px;
line-height: 1.2;
page-break-inside: avoid;
background: #131228;
border: 1px solid #695CF9;
border-left: 3px solid #695CF9;
color: white;
margin-bottom: 1.6em;
max-width: 100%;
overflow: auto;
padding: 1em 1.5em;
display: block;
word-wrap: break-word;
}
.purple code {
background-color: #131228;
}
h2 {
margin-bottom: 5px;
margin-top: 25px;
margin-left: 0;
padding-left: 0;
font-size: 3em;
}
hr {
background-color: #282654;
border: 0;
height: 2px;
border-radius: 100%;
}
h3 {
margin-bottom: 5px;
margin-top: 25px;
margin-left: 0;
padding-left: 0;
font-size: 1.5em;
}
a {
text-decoration: none;
color: white;
}
</style>
</head>
<body>
<br />
<p class="center">
<img height="75" src="https://github.com/ghosts/imbue-js/blob/master/logo.png?raw=true" alt="Imbue logo" />
<br /><br />
<small class="box dark p-10" style="line-height: 1em; margin-top:0 auto;margin-bottom: 0 auto;padding-top:15px;">
<a target="_blank" href="https://github.com/Ghosts/Imbue-js" title="Imbue Repo">
<svg aria-hidden="true" class="octicon octicon-mark-github" height="24" version="1.1" viewBox="0 0 16 16"
width="24">
<path fill-rule="evenodd" fill="#ffffff"
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">
</path>
</svg>
<b>Version 1.0.12</b>
➡
</a>
</small>
</p>
<br />
<div class="box">
<h2 id="examples">Download & CDN</h2>
</div>
<div class="box dark p-10 shadow">
<p>
CDN:
<span class="pre"><code>http://unpkg.com/@ghosts/imbue-js</code></span>
</p>
<p>
NPM:
<span class="pre"><code>npm i @ghosts/imbue-js</code></span>
</p>
<small>Imbue is loaded on this page, feel free to explore the methods in the developer console.</small>
<br /> <br />
</div>
<br />
<div class="box">
<h2 id="examples">Background</h2>
</div>
<div class="box purple p-10 shadow">
<p>
Imbue was designed to replace some of the core features of jQuery, and
provide a limited set of useful shortcuts and extensions on top of the
standard NodeList, HTMLElement, HTMLDocument, and Array prototypes.
</p>
<p>Some useful notes about Imbue:</p>
<ul>
<li>
In most cases if a call fails or nothing is found,
<code>undefined</code> is returned (similar to standard JS for
selection)
</li>
<li>
Imbue extends standard elements and is therefore interoperable with
many other frameworks
</li>
<li>
Methods and properties of Imbue often rename or call very simple
native JS functions, nothing too fancy here
</li>
<li>
Due to use of the IntersectionObserver API Imbue is <b>not</b> compatible with IE. But it's also 2019, so why
would it be? Imbue will work flawlessly on all modern browsers (and slightly not-so modern)
</li>
<li>Speed should be essentially on par with vanilla JS</li>
<li>
Imbue is <strong>not</strong> a framework, it will not completely
replace something like jQuery, but it most likely can replace a
majority of use-cases
</li>
</ul>
<p>
The main focus of Imbue is to augment standard JavaScript to make it
easier to use in regards to DOM manipulation, and provide added
functions as shorthands for standard calls. One easy example that
illustrates this is the call for <code>document.whenReady()</code>,
similar to <code>$( document ).ready()</code>. If you mainly use jQuery
for selectors, setting styles, and some helper functions, Imbue can
replace it with a much smaller footprint and faster runtimes. An added
benefit is that Imbue is closer to native JavaScript than jQuery,
meaning less to learn. For instance,
<code>document.getElement()</code> in Imbue is very similar to
<code>document.getElementById()</code> in native JavaScript. All Imbue
functions are added to element objects, original JavaScript methods are
preserved for the DOM and can be used interchangeably and alongside the
added Imbue methods.
</p>
<p>
<em>NOTE: this is a work in progress at the moment, contibutions
appreciated!</em>
</p>
</div>
<div class="box">
<h2 id="examples">Methods & Properties</h2>
</div>
<div class="box dark p-10 shadow">
<h3 id="htmldocument">HTMLDocument</h3>
<p>
<span class="pre"><code>document.getElement("p") <span class="comment">// returns first p elements</span></code></span>
</p>
<p>
<span class="pre"><code>document.getElements("p") <span class="comment">// returns all p elements</span></code></span>
</p>
<p>
<span class="pre"><code>document.getElement("p", context) <span class="comment">// optionally provide context (default is document)</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>document.whenReady(function() { <span class="comment">// code here </span>}); <span class="comment">// ran when document is ready</span></code></span>
</p>
<p>
<span class="pre"><code>document.whenReady(() => { <span class="comment">// code here </span>});</code></span>
</p>
<h3 id="htmlelement">HTMLElement</h3>
<p>
Using "element" as example (usually something retrieved from an above
"get" function)
</p>
<hr />
<p>
<span class="pre"><code>element.whenVisible(() => alert("Now Visible!")) <span class="comment">// Provided callback runs once each time the element is visible.</span></code></span>
</p>
<p>
<span class="pre"><code>element.whenHidden(() => alert("Now Hidden!"))<span class="comment">// Provided callback runs once each time the element is hidden.</span></code></span>
</p>
<hr/>
<p>
<span class="pre"><code>element.onHover(() => alert("Being Hovered!")) <span class="comment">// Provided callback runs once each time the element is visible.</span></code></span>
</p>
<p>
<span class="pre"><code>element.onClick(() => alert("Just Clicked!")) <span class="comment">// Provided callback runs once each time the element is visible.</span></code></span>
</p>
<p>
<span class="pre"><code>element.onEvent("eventName", () => alert("Event happened!")) <span class="comment">// Generic for any event needed</span></code></span>
</p>
<hr/>
<p>
<span class="pre"><code>element.removeClass("classToRemove")</code></span>
</p>
<p>
<span class="pre"><code>element.setClassList("this will be the class list")</code></span>
</p>
<p>
<span class="pre"><code>element.toggleClass("nightMode")</code></span>
</p>
<p>
<span class="pre"><code>element.hasClass("nightMode") <span class="comment">// returns true or false</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>element.getStyles()</code></span>
</p>
<p>
<span class="pre"><code>element.setStyles({"background-color" : "red"})</code></span>
</p>
<p>
<span class="pre"><code>element.removeStyles(["background-color", "color"])</code></span>
</p>
<p>
<span class="pre"><code>element.removeStyle("background-color")</code></span>
</p>
<p>
<span class="pre"><code>element.getWidth() <span class="comment">// Retruns computed width of element</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>element.getParent() <span class="comment">// same as parentNode</span></code></span>
</p>
<p>
<span class="pre"><code>element.getSiblings() <span class="comment">// retrieve array of sibling nodes</span></code></span>
</p>
<p>
<span class="pre"><code>element.getChildren() <span class="comment">// same as childNodes</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>element.getSelectedNode() <span class="comment">// retrieves first selected checkbox/selected element</span></code></span>
</p>
<p>
<span class="pre"><code>element.getSelectedNodes() <span class="comment">// retrieves all selected checkbox/selected elements</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>element.getData("id") <span class="comment">// gives value of data-id attribute</span></code></span>
</p>
<p>
<span class="pre"><code>element.removeData("id") <span class="comment">// removes data-id attribute</span></code></span>
</p>
<p>
<span class="pre"><code>element.setData("id", 5) <span class="comment">// sets data-id=5</span></code></span>
</p>
<hr />
<p>
<span class="pre"><code>element.hideElement() <span class="comment">// hide element</span></code></span>
</p>
<p>
<span class="pre"><code>element.showElement() <span class="comment">// show element</span></code></span>
</p>
<hr />
<h3 id="nodelist">NodeList</h3>
<p>
Better documentation on this coming soon. For the most part, NodeList calls are the same as HTMLElement but with a plural form.
</p>
<h3 id="ajax">AJAX</h3>
<p>
<span class="pre"><code>AJAX({
type: "",
url: "/",
success: function() {},
error: function() {},
contentType: "",
dataType: "",
data: data
});<span class="comment">// contentType, dataType, and type will all default to GET & JSON</span></code></span>
</p>
</div>
</body>
</html>