forked from gdi-curriculum-review/gdi-jquery-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass3.html
541 lines (481 loc) · 18.8 KB
/
class3.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 3 ~ JavaScript/jQuery ~ Girl Develop It</title>
<meta name="description" content="This is the official Girl Develop It Core Intro JavaScript course. Material based on original material by Sara Chipps, Pamela Fox, Alexis Goldstein, Izzy Johnston and Leo Newball.
The course is meant to be taught in 4 two-hour sections. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/simple.css" id="theme">
<link rel="stylesheet" href="css/class.css">
<!-- For syntax highlighting -->
<!-- light editor<link rel="stylesheet" href="lib/css/light.css">-->
<!-- dark editor--><link rel="stylesheet" href="lib/css/dark.css">
<link rel="stylesheet" href="lib/css/zenburn.css">
<link rel="stylesheet" href="plugin/accessibility-helper/css/accessibility-helper.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href='css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="css/print/pdf.css" type="text/css" media="print">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening slide -->
<section>
<img src="images/gdi_logo_badge.png" alt="Girl Develop It" style="box-shadow: none;" width="200" height="200">
<h2>Introduction to JavaScript and jQuery</h2>
<h4>Class 3</h4>
</section>
<!-- Welcome-->
<section>
<h3>Welcome!</h3>
<div class="left-align">
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<p class ="green">Some "rules"</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Have fun</li>
</ul>
</div>
</section>
<!-- What is a library-->
<section>
<h3>What is a library?</h3>
<ul>
<li class="fragment">Software libraries hold functions (not books!)</li>
<li class="fragment">When you include a library, you can use all the functions in that library</li>
<li class="fragment">That means: <span class="pink">you get to take advantage of other people's experience!</li>
<li class="fragment">And... <span class ="blue">Save time!</span></li>
</ul>
</section>
<!-- What is jQuery-->
<section>
<h3>What is jQuery?</h3>
<p class="fragment">jQuery is a <span class="green">library</span> of JavaScript functions.</p>
<p class="fragment">It contains many functions to help simplify your programming, including:</p>
<ul>
<li class="fragment">HTML element selection & manipulation</li>
<li class="fragment">CSS manipulation</li>
<li class="fragment">HTML events</li>
<li class="fragment">JavaScript effects and animations</li>
</ul>
</section>
<section>
<h3>Why use jQuery?</h3>
<ul>
<li class="fragment">The most popular JavaScript library</li>
<li class="fragment">jQuery empowers you to "write less, do more."</li>
<li class="fragment">Great <a href="http://docs.jquery.com/" target="_blank">documentation and tutorials</a></li>
<li class="fragment">Used by over <a href="http://trends.builtwith.com/javascript/jQuery" target="_blank">53 million</a>(!) websites</li>
</ul>
</section>
<!-- <section>
<h3>jQuery: A Brief History</h3>
<ul>
<li class="fragment">jQuery was created by John Resig, a JavaScript tool developer at Mozilla.</li>
<li class="fragment">January 2006: John announced jQuery at BarCampNYC: BarCampNYC Wrap-up</li>
<li class="fragment">September 2007: A new user interface library is added to jQuery: jQuery UI: Interactions and Widgets</li>
<li class="fragment">September 2008: Microsoft and Nokia announce their support for jQuery</li>
<li class="fragment">December 2009: jQuery wins .Net Magazine's Award for Best Open Source Application</li>
</ul>
</section> -->
<!-- Including jquery-->
<section>
<h3>Including jQuery</h3>
Two ways to include jQuery on your page:
<div class="fragment">
Download the library, store it locally:
<pre><code contenteditable class="html">
<head>
<script src="jquery.js"></script>
</head>
</code></pre>
</div>
<div class="fragment">
Include the library from a <abbr title="Content Delivery Network">CDN</abbr>:
<pre><code contenteditable class="html">
<head>
<script src="https://code.jquery.com/jquery-latest.min.js">
</script>
</head>
</code></pre>
</div>
<div class="fragment">
Note: CDN-hosted code can change or be unavailable! It's always best to specify the exact version you want, <a href="https://css-tricks.com/snippets/jquery/fallback-for-cdn-hosted-jquery/" target="_blank">and provide a fallback</a>.
</div>
</section>
<!-- Selectors-->
<section>
<h3>jQuery Selectors</h3>
<p>Remember <span class="green">document.getElementById()</span> and <span class="green">document.getElementsByTagName()</span>? </p>
<p class="fragment"> jQuery selectors let you get elements by: </p>
<ul>
<li class="fragment">Element name (div, p)
<pre><code contenteditable class="javascript">
var $divs = $("div"); // All divs on page
</code></pre>
</li>
<li class="fragment">ID name (#mainpicture, #results)
<pre><code contenteditable class="javascript">
var $img = $("#mainpicture"); //img with id mainpicture
</code></pre>
</li>
<li class="fragment">Class name (.result, .picture)
<pre><code contenteditable class="javascript">
var $images = $(".picture"); //All images with class picture
</code></pre>
</li>
</ul>
<aside class="notes">
<p>Point out naming convention of $varName for jQuery objects</p>
</aside>
</section>
<!-- Actions-->
<section>
<h3>jQuery Actions</h3>
<div class="left-align">
<p class="fragment">jQuery has hundreds of actions that can be performed on any element</p>
<p class="fragment">All the actions are methods</p>
<p class="fragment">As methods they are called with dot notation</p>
</div>
<div class="fragment">
Action format
<pre><code contenteditable class="javascript">
$(selector).action();
</code></pre>
</div>
</section>
<!-- Attributes and css-->
<section>
<h3>Updating attributes and css</h3>
<div class="fragment">
<pre><code contenteditable class="html">
<img id="mainpicture" src="images/boring-image.png">
</code></pre>
<pre><code contenteditable class="javascript">
var $img = $('#mainpicture');
// Attribute Get/Set
$img.attr('src');
$img.attr('src', 'images/pink-logo.png');
// CSS Get/Set
$img.css('width');
$img.css('width', '200px');
</code></pre>
<img id="mainpicture" src="images/boring-image.png">
</div>
</section>
<!-- html values-->
<section>
<h3>Updating values and html</h3>
<pre><code contenteditable class="html">
<div id="results-slide-9">Boo!</div>
</code></pre>
<p>Get and set html value</p>
<pre><code contenteditable class="javascript">
var $results = $('#results-slide-9');
$results.html();
$results.html('New html!');
</code></pre>
<p><small>Try it!</small></p>
<div id="results-slide-9">Boo!</div>
</section>
<!-- Append and prepend-->
<section>
<h3>Append and Prepend</h3>
<pre><code contenteditable class="html">
<div id="results-slide-10">Boo!</div>
</code></pre>
<pre><code contenteditable class="javascript">
var $results = $('#results-slide-10');
// Append html
$results.append('Additional html');
// Prepend html
$results.prepend('Additional html (on top)');
</code></pre>
<p><small>Try it!</small></p>
<div id="results-slide-10">Boo!</div>
</section>
<section>
<h3>Creating new element</h3>
<div class="fragment">
<pre><code contenteditable class="javascript">
var $newDiv = $('<div></div>');
</code></pre>
</div>
<div class="fragment">
Seriously. That's it!
</div>
</section>
<!-- Exercise-->
<section>
<h3>Let's Develop It!</h3>
<p>Try to convert last week's DOM interaction into jQuery.</p>
<p>Don't forget to include jQuery in your HTML head!</p>
</section>
<!-- Document Ready-->
<section>
<h3>Document Ready</h3>
<div class="left-align">
<p>Webpages take time to load</p>
<p class="fragment">Almost always, you don't want the JavaScript to be called until the page is loaded</p>
</div>
<div class="fragment">
Document ready is a method called when the page is loaded
<pre><code contenteditable class="javascript">
$(document).ready(function(){
// your code here
});
</code></pre>
</div>
<div class="fragment left-align">
<span class="yellow">Note:</span> The function() inside is an "anonymous function". It has no name, but still performs like a function.
</div>
</section>
<!-- Document Ready-->
<section>
<h3>Where to Put Your JavaScript</h3>
<p>When you wrap your code with <code>$(document).ready(function(){});</code>, you can follow best practices and load your JavaScript at the end of your HTML document, right before the closing </body> tag.</p>
<p>This lets your content load quickly, and ensures the DOM is fully loaded before you start modifying it.</p>
<aside class="notes">
<p>Demo what happens if you try to access the DOM before it is ready!</p>
</aside>
</section>
<!-- HTML Events-->
<section>
<h3>HTML events</h3>
<p>Events occur on a webpage via user interaction</p>
<p class="fragment">Common Events:</p>
<ul>
<li class="fragment">mouseenter -- mouse goes inside an element</li>
<li class="fragment">mouseleave -- mouse leaves an element</li>
<li class="fragment">click -- mouse clicks an element</li>
<li class="fragment"><a href="http://api.jquery.com/category/events/" target="_blank">Other events</a></li>
</ul>
</section>
<section>
<h3>Handling events</h3>
<pre><code contenteditable class="javascript">
$(selector).on('mouseenter', function(){
//code when the mouse enters
})
</code></pre>
<div class="fragment">
<pre><code contenteditable class="javascript box">
$('.box').on('mouseenter', function(){
$(this).css('background-color', 'purple')
})
</code></pre>
</div>
<div class="fragment left-align">
<div>The <span class="green">$(this)</span> selector in jQuery refers to the element on whom the action was called.</div>
<div>Here <span class="green">$(this)</span> is the <span class="blue">$('.box')</span> that the mouse entered.
</div>
</section>
<section>
<h3>Handling event examples</h3>
<div class="fragment">
<pre><code contenteditable class="javascript box">
$('.box').on('mouseenter', function(){
$(this).css('background-color', 'purple')
})
</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class="javascript box">
$('.box').on('mouseleave', function(){
$(this).css('background-color', 'orange')
})
</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class="javascript box">
$('.box').on('click', function(){
$(this).css('background-color', 'green')
})
</code></pre>
</div>
</section>
<section>
<h3>Combining events</h3>
<p>If you want multiple events to happen on the same element, you can pass an object to the <code>on</code> method. We call this an <strong>event map</strong>.</p>
<div class="fragment">
<pre><code contenteditable class="javascript box">
$('.box').on({
click: function() {
$(this).css('background-color', 'green')
},
mouseenter: function() {
$(this).css('background-color', 'purple')
},
mouseleave: function(){
$(this).css('background-color', 'orange')
}
});
</code></pre>
</div>
</section>
<!-- Exercise-->
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Move your <script> tags to the end of your HTML file.</li>
<li>Add a div to your HTML that is 100px by 200px</li>
<li>Bind events to the div in your JavaScript file</li>
<li>Don't forget to surround your events with document ready!</li>
<li>Try to change size, color, or event the HTML inside the div</li>
<li>Bonus: change all the onclick events on your buttons to jQuery click events</li>
</ul>
</section>
<!-- HTML forms-->
<section>
<h3>HTML forms</h3>
<p>HTML Forms allow users to enter information</p>
<div class="fragment">
<pre><code contenteditable class="html">
<form id="about-me">
<input type="text" id="name" placeholder="Enter a name"/>
<label>Do you like popcorn?</label>
<label for="popcorn-yes">Yes</label>
<input type="radio" name="popcorn" id="popcorn-yes" value="yes"/>
<label for="popcorn-no">No </label>
<input type="radio" name="popcorn" id="popcorn-no" value="no"/>
<label for="dinosaur">Favorite Dinosaur</label>
<select id="dinosaur">
<option value="t-rex">Tyrannosaurus Rex</option>
<option value="tri">Triceratops</option>
<option value="stego">Stegosaurus</option>
<option value="other">Other</option>
</select>
<input type="submit" value="Go!"/>
</form>
</code></pre>
</div>
</section>
<section>
<h3>HTML forms</h3>
<p>HTML Forms allow users to enter information</p>
<div class="fragment">
<form id="about-me">
<input type="text" id="name" placeholder="Enter a name"/><br/>
<label>Do you like popcorn?</label><br/>
<label for="popcorn-yes">Yes</label>
<input type="radio" name="popcorn" id="popcorn-yes" value="yes"/>
<label for="popcorn-no">No </label>
<input type="radio" name="popcorn" id="popcorn-no" value="no"/>
<br>
<label for="dinosaur">Favorite Dinosaur</label><br/>
<select id="dinosaur">
<option value="t-rex">Tyrannosaurus Rex</option>
<option value="tri">Triceratops</option>
<option value="stego">Stegosaurus</option>
<option value="other">Other</option>
</select><br/>
<input type="submit" value="Go!"/>
</form>
</div>
</section>
<!-- JavaScript and HTML Forms-->
<section>
<h3>Values from Forms</h3>
<p>You can use JavaScript to get values from a form</p>
<div class="fragment">
<pre><code contenteditable class="javascript">
$('#name').val();
$('select#dinosaur').val();
$('input:radio[name="popcorn"]:checked').val();
</code></pre>
</div>
<div class="fragment">
Or set values of a form
<pre><code contenteditable class="javascript">
$('#name').val('Mitch');
$('select#dinosaur').val('stego');
$('input:radio[name="popcorn"][value="no"]').attr('checked',true);
</code></pre>
</div>
</section>
<section>
<h3>Values from Forms</h3>
<p>jQuery has an event for form submission</p>
<div class="fragment">
<pre><code contenteditable class="javascript">
$('#about-me').on('submit', function(event){
//code to execute after submission
event.preventDefault();
});
</code></pre>
You can use <span class="yellow">"event.preventDefault();"</span> to prevent the form trying to submit to a server.
</div>
</section>
<!-- Exercise-->
<section>
<h3>Let's Develop It</h3>
<ul>
<li>Choose one (or all!) of your functions made so far</li>
<li>i.e. lifetime supply, favorite things, or my friends</li>
<li>Create a form to send dynamic data to the function when you click the submit button</li>
<li>Don't forget to add parameters to your existing functions!</p>
<li>This is a little harder than all the other exercises.</li>
<li>Be creative!</li>
</ul>
</section>
<!-- -->
<section>
<h2>Questions?</h2>
<div style = "font-size:1200%; height:100%; margin-top:20%" class ="blue">?
<div class ="clear"></div></div>
</section>
</div>
<footer>
<div class="copyright">
Introduction to JavaScript/jQuery -- Girl Develop It Burlington --
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/accessibility-helper/js/accessibility-helper.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
<!-- To enable Dev Tools interactions with slide examples in the same window -->
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
</body>
</html>