-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
407 lines (318 loc) · 14.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>FrenchDipJS</title>
<meta name="description" content="A flexible, light-weight module for creating custom components">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="57x57" href="demo/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="demo/favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="demo/favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="demo/favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="demo/favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="demo/favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="demo/favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="demo/favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="demo/favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="demo/favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="demo/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="demo/favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="demo/favicon/favicon-16x16.png">
<link rel="manifest" href="demo/favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="demo/favicon/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Arimo:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<!-- HighlightJS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/styles/monokai.min.css">
<link rel="stylesheet" href="demo/styles/app.css">
</head>
<body>
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 ol-xs-12" style="padding: 0;">
<h1 class="display-4 hidden-sm-down">FrenchDipJS</h1>
<h1 class="display-1 hidden-md-up hidden-xs-down">FrenchDipJS</h1>
<h1 class="hidden-sm-up">FrenchDipJS</h1>
<p class="lead">A flexible, light-weight module for creating custom components</p>
<p>
<a class="btn btn-primary-outline btn-sm"
href="https://github.com/nominalaeon/french-dip/archive/develop.zip"
role="button">Download</a>
<a class="btn btn-primary btn-sm"
href="https://github.com/nominalaeon/french-dip"
role="button">View on Github</a>
</p>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-xs-12" style="padding: 0; overflow-x: auto;">
<p class="lead">Not every project needs the full arsenal of a front-end framework.</p>
<h2 id="what">Why FrenchDip</h2>
<p class="hidden-xs-down"><i>Performance</i> can suffer from loading all of those unused bits of JavaScript.<br/>
<i>Development</i> can slow from steep learning curves.</p>
<p>A project that<br/>
- has little dynamic content to display <i>OR</i><br/>
- has a back-end templating solution <span class="hidden-sm-down">(PHP, JavaServer Pages, ASP.NET, etc.)</span><br/>
may be biting off more front-end framework than it will ever need to chew.</p>
<p>Chances are a front-end framework is being loaded simply to offer means to add custom functionality. This is where FrenchDipJS shines like a freshly baked baguette.</p>
<h2 id="what">What FrenchDip</h2>
<p>FrenchDip is a component wrapper that ties JavaScript classes defined in your project to instances of assigned DOM elements. This allows you to basically build your own framework.</p>
<h2 id="how">How FrenchDip</h2>
<div class="container" style="padding: 0;">
<div class="row" style="padding: 0;">
<div class="example col-xs-12">
<p>Displays two different numbers</p>
<div class="your-class-name"
data-frenchdip="YourClass"></div>
<div class="your-class-name"
data-frenchdip="YourClass"></div>
</div>
<div class="col-md-6 col-xs-12" style="padding: 0; overflow-x: auto;">
<p><b>HTML</b><br/>
Use the "data-frenchdip" attribute to request the JavaScript Class that needs to be invoked for an element.</p>
<pre><code class="html"><p>Displays two different numbers</p>
<div class="your-class-name"
data-frenchdip="YourClass"></div>
<div class="your-class-name"
data-frenchdip="YourClass"></div></code></pre>
</div>
<div class="col-md-6 col-xs-12" style="padding-right: 0; overflow-x: auto;">
<p><b>JavaScript</b><br/>
Create a JavaScript Class and register it with FrenchDip, provide the Class itself and then its name as a string.</p>
<pre><code class="javascript">function YourClass() {
// this.root - node tied to an instance
// this.options - node's data-attr values
this.root.innerHTML = Math.random();
}
FrenchDip.register(YourClass, 'YourClass');
</code></pre>
</div>
<p>FrenchDipJS collects registered DOM elements, forEach's through them, and invokes a new instance of the requested Class for each one.</p>
<p><b>If the name property is set on a registered component, the string form isn’t required as a second argument for FrenchDip.register(YourClass). If the name property is not set, FrenchDip requires the name as a string FrenchDip.register(YourClass, 'YourClass').</b></p>
</div>
</div>
<h2 id="usage">Install</h2>
<p>Manual install <a href="https://github.com/nominalaeon/french-dip/archive/develop.zip">from GitHub</a></p>
<p>Bower install: <code class="comment">bower install french-dip --save</code></p>
<h2 id="setup">Setup</h2>
<p>Be sure FrenchDip loads before your app's JavaScript, otherwise it can get read in anywhere in your document. Head, body, below the footer, it's all good.</p>
<pre><code class="html"><!-- French Dip -->
<script src="french-dip/french-dip.js"></script>
<!-- App JS -->
<script src="scripts/app.js"></script></code></pre>
</div>
</div>
</div>
<!--====================================
= Usage Examples =
=====================================-->
<div class="demo-wrapper container">
<h2 id="usage-examples">Usage Examples</h2>
<!-- vanilla JavaScript -->
<h3>Examples with vanilla JavaScript</h3>
<div class="row">
<div class="demo demo--js media col-lg-6 col-xs-12"
data-frenchdip="DemoJS"
data-heading="nananana Batman"
data-new-src="demo/images/batman.png"
data-interval="3000">
<div class="media-left">
<img src="demo/images/bruce-wayne.png"/>
</div>
<div class="media-body">
<p><b class="heading media-heading">Bruce Wayne</b></p>
<p><small>...for 3 seconds anyway</small></p>
<pre><code><div class="demo--js"
data-frenchdip="DemoJS"
data-heading="nananana Batman"
data-new-src="batman.png"
data-interval="3000">
<img src="bruce-wayne.png"/>
<p class="heading">Bruce Wayne</p>
</div></code></pre>
</div>
</div>
<div class="demo demo--js media col-lg-6 col-xs-12"
data-frenchdip="DemoJS"
data-heading="Batman Beyond"
data-new-src="demo/images/batman-beyond.png">
<div class="media-left">
<img src="demo/images/bruce-wayne.png"/>
</div>
<div class="media-body">
<p><b class="heading media-heading">Bruce Wayne</b></p>
<p><small>Changes once</small></p>
<pre><code><div class="demo--js"
data-frenchdip="DemoJS"
data-heading="Batman Beyond"
data-new-src="batman-beyond.png">
<img src="bruce-wayne.png"/>
<p class="heading">Bruce Wayne</p>
</div></code></pre>
</div>
</div>
</div>
<div class="row">
<div class="demo demo--code col-xs-12">
<pre><code>/** JavaScript Class pattern */
function DemoJS() {
var heading = this.root.querySelectorAll('h4')[0],
img = this.root.querySelectorAll('img')[0],
newHead = this.options.heading,
newSrc = this.options.newSrc,
oldHead, oldSrc;
if (this.options.interval) {
runInterval(this.options.interval);
} else {
runTimeout();
}
function runInterval(interval) {
setInterval(swapAssets, interval);
}
function runTimeout() {
setTimeout(swapAssets, 1000);
}
function swapAssets() {
oldHead = heading.innerHTML;
oldSrc = img.getAttribute('src');
heading.innerHTML = newHead;
img.setAttribute('src', newSrc);
newHead = oldHead;
newSrc = oldSrc;
}
}
/** Register Class with FrenchDipJS */
FrenchDip.register(DemoJS, 'DemoJS');</code></pre>
</div>
</div>
<!-- ES2015 -->
<h3>Examples with ES2015</h3>
<div class="row">
<div class="demo demo--es62015 media col-lg-6 col-xs-12"
data-frenchdip="DemoES2015"
data-heading="Batman"
data-new-src="demo/images/batman.png">
<div class="media-left">
<img src="demo/images/bruce-wayne.png"/>
</div>
<div class="media-body">
<p><b class="heading media-heading">Bruce Wayne</b></p>
<p><small>Changes once</small></p>
<pre><code><div class="demo--es62015"
data-frenchdip="DemoES2015"
data-heading="Batman"
data-new-src="batman.png">
<img src="bruce-wayne.png"/>
<p class="heading">Bruce Wayne</p>
</div></code></pre>
</div>
</div>
<div class="demo demo--es62015 media col-lg-6 col-xs-12"
data-frenchdip="DemoES2015"
data-heading="Batman"
data-new-src="demo/images/fireproof.png">
<div class="media-left">
<img src="demo/images/bruce-wayne.png"/>
</div>
<div class="media-body">
<p><b class="heading media-heading">Bruce Wayne</b></p>
<p><small>Changes once</small></p>
<pre><code><div class="demo--es62015"
data-frenchdip="DemoES2015"
data-heading="Batman"
data-new-src="fireproof.png">
<img src="bruce-wayne.png"/>
<p class="heading">Bruce Wayne</p>
</div></code></pre>
</div>
</div>
</div>
<div class="row">
<div class="demo demo--code col-xs-12">
<pre><code>/** ES2015 Class */
class DemoES2015 {
constructor() {
this.heading = this.root.querySelectorAll('.heading')[0];
this.img = this.root.querySelectorAll('img')[0];
this.options = this.options;
setTimeout(() => {
this.swapAssets();
}, 1000);
}
swapAssets() {
this.heading.innerHTML = this.options.heading;
this.img.setAttribute('src', this.options.newSrc);
}
}
/** Register Class with FrenchDipJS */
FrenchDip.register(DemoES2015, 'DemoES2015');</code></pre>
</div>
</div>
<!-- jQuery -->
<h3>Examples with jQuery</h3>
<div class="row">
<div class="demo demo--clickable demo--jquery media col-lg-6 col-xs-12"
data-frenchdip="DemoJQ"
data-new-src="demo/images/batman.png">
<div class="media-left">
<img src="demo/images/bruce-wayne.png"/>
</div>
<div class="media-body">
<p><b class="heading media-heading">Bruce Wayne</b></p>
<p><small>For a dark knight, click here!</small></p>
<pre><code><div class="demo--jquery"
data-frenchdip="DemoJQ"
data-new-src="demo/images/batman.png">
<img src="bruce-wayne.png"/>
<p class="heading">Bruce Wayne</p>
</div></code></pre>
</div>
</div>
</div>
<div class="row">
<div class="demo demo--code col-xs-12">
<pre><code>/** JQuery */
var DemoJQ = DemoJQ;
$.extend(DemoJQ.prototype, {
heading: 'Batman via $.onClick'
});
/** Register Class with FrenchDipJS */
FrenchDip.register(DemoJQ, 'DemoJQ'); // Register DemoJQ Class with FrenchDip
function DemoJQ() {
this.$root = $(this.root);
this.$heading = $(this.$root.find('.heading').get(0));
this.$img = $(this.$root.find('img').get(0));
this.$root.on('click', $.proxy(swapAssets, this));
}
function swapAssets() {
this.$heading.html(this.heading);
this.$img.attr('src', this.options.newSrc);
this.$root.off();
}</code></pre>
</div>
</div>
</div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.0.0.js"
integrity="sha256-jrPLZ+8vDxt2FnE1zvZXCkCcebI/C8Dt5xyaQBjxQIo="
crossorigin="anonymous"
type="text/javascript" charset="utf-8"></script>
<!-- HighlightJS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/highlight.min.js"
type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
hljs.initHighlightingOnLoad();
</script>
<!-- French Dip -->
<script src="french-dip.min.js" type="text/javascript" charset="utf-8"></script>
<!-- App Components -->
<script src="demo/scripts/demo.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>