-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.html
431 lines (379 loc) · 11.7 KB
/
jquery.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Prototype ⇔ jQuery - To and from JavaScript libraries</title>
<meta name="generator" content="Slide Show (S9) 2.0.1 on Ruby 1.9.2 (2011-07-09) [i386-mingw32]">
<meta name="author" content="Your Name Here" >
<!-- helper/macro that lets you add (CSS3) gradient using headers
see http://slideshow.rubyforge.org/themes.html
-->
<!-- S6 style sheet links -->
<link rel="stylesheet" href="jquery.css" media="projection" id="styleProjection">
<link rel="stylesheet" href="s6/screen.css" media="screen" id="styleScreen">
<link rel="stylesheet" href="s6/print.css" media="print">
<!-- S6 JS -->
<script src="s6/jquery.js"></script>
<script src="s6/jquery.slideshow.js"></script>
<script>
$(document).ready( function() {
Slideshow.init();
} );
</script>
<!-- Better Browser Banner for Microsoft Internet Explorer (IE) -->
<!--[if IE]>
<script src="s6/jquery.microsoft.js"></script>
<![endif]-->
</head>
<body>
<div class="layout">
<div id="header"></div>
<div id="footer">
<h1>Your Footer Here</h1>
<h2>Your Subfooter Here</h2>
</div>
</div>
<div class="presentation">
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Prototype ⇔ jQuery</h1>
<p class="center">To and from JavaScript libraries by <a href="http://remysharp.com">Remy Sharp</a><sup class="footnote" id="fnr1"><a href="#fn1">1</a></sup></p>
<p class="footnote" id="fn1"><a href="#fnr1"><sup>1</sup></a> Adapted S6 Version from <a href="http://www.slideshare.net/remy.sharp/prototype-jquery-going-from-one-to-the-other">Original PDF Slide Deck</a></p>
<!-- begin help -->
<div class='help projection'>
<p><strong>Slide Show Keyboard Controls (Help)</strong></p>
<table>
<tr>
<td> Action </td>
<td> Key </td>
</tr>
<tr>
<td> Go to next slide </td>
<td> Space Bar, Right Arrow, Down Arrow, Page Down, Click Heading </td>
</tr>
<tr>
<td> Go to previous slide </td>
<td> Left Arrow, Up Arrow, Page Up </td>
</tr>
<tr>
<td> Toggle between slideshow and outline view (Ø) </td>
<td> T </td>
</tr>
<tr>
<td> Show/hide slide controls (Ø « ») </td>
<td> C, Move mouse to bottom right corner </td>
</tr>
<tr>
<td> Zoom in, zoom out, zoom reset (100%) </td>
<td> Control<code>+</code>Plus, Control<code>+</code>Minus, Control<code>+</code><code>0</code> </td>
</tr>
</table>
</div>
<!-- end help -->
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Why Prototype?</h1>
<ul>
<li>Extends the DOM and core JavaScript objects</li>
<li>An arsenal of utility functions</li>
</ul>
<p class="right smaller">Based on Prototype 1.5.1 & 1.6</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Why jQuery</h1>
<ul>
<li>Centred around chaining and binding methods to objects and elements</li>
<li>Totally encapsulated</li>
<li>Aims to be exceptionally easy to develop with</li>
</ul>
<p class="right smaller">Based on jQuery 1.2.1</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Differences in Native Support</h1>
<!-- begin left {} -->
<table width='100%'><tr><td width='50%' markdown='block' style='vertical-align: top;'>
<p>Prototype has:</p>
<ul>
<li>Class creation</li>
<li>Try.these</li>
<li>Position, Range</li>
</ul>
</td>
<!-- end left -->
<!-- begin right {} -->
<td width='50%' markdown='block' style='vertical-align: top;'>
<p>jQuery has:</p>
<ul>
<li>No Conflict (<code>$</code>)</li>
<li>Effects</li>
</ul>
</td></tr></table>
<!-- end right -->
<p class="smaller">Non-exhaustive list, and in most case, the
functionality can be implemented with plugins.</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1 class="fullscreen">Syntax Comparison</h1>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Dollar Variable</h1>
<ul>
<li>Prototype uses <code>$</code> for id based selection</li>
<li>jQuery <code>$</code> = CSS based selector (= <code>$$</code> in Prototype)</li>
</ul>
<p class="smaller">Note that Prototype will return element objects or arrays of
elements for most methods. jQuery will usually return a jQuery
object (which looks like an array in Firebug).</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1><code>$</code> Example</h1>
<p>Prototype</p>
<pre class='code'>
$('speech1').show();
</pre>
<p>jQuery</p>
<pre class='code'>
$('#speech1').show();
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>CSS Based Selectors</h1>
<ul>
<li>Prototype – <code>$$</code></li>
</ul>
<p>To narrow down it’s context use
<code>Element.getElementsBySelector(selector)</code>
(or <code>Element.select(selector)</code> in 1.6)</p>
<ul>
<li>jQuery – <code>$</code></li>
</ul>
<p>Virtually all of jQuery’s DOM selection is done using CSS 1-3</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Selector Examples</h1>
<p>Prototype</p>
<pre class='code'>
$$('.dialog').invoke('show');
$('final-speech').getElementsBySelector('DIV.final-dialog').each(Element.hide);
// 1.6
$('final-speech').select('DIV.final-dialog').invoke('hide');
</pre>
<p>jQuery</p>
<pre class='code'>
$('.dialog').show();
$('#final-speech DIV.final-dialog').hide();
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>DOM Ready Event</h1>
<ul>
<li>Prototype – uses Event object</li>
<li>jQuery – uses two types of syntax, both meaning the same thing</li>
</ul>
<p class="smaller">jQuery uses different methods to execute the ready function when
the DOM is ready, using specific methods for Internet Explorer
and for Safari<sup class="footnote" id="fnr1"><a href="#fn1">1</a></sup></p>
<p class="footnote" id="fn1"><a href="#fnr1"><sup>1</sup></a> <a href="http://dean.edwards.name/weblog/2006/06/again/"><code>window.onload</code> again</a>, <a href="http://blog.outofhanwell.com/2006/06/08/the-windowonload-problem-revisited/">The <code>window.onload</code> Problem Revisited</a></p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Ready Example</h1>
<p>Prototype</p>
<pre class='code'>
Event.observe(window,'load',function(){});
</pre>
<p>Prototype 1.6</p>
<pre class='code'>
document.observe('contentloaded',function{});
</pre>
<p>jQuery</p>
<pre class='code'>
$(document).ready(function(){});
// or
$(function(){});
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Iteration</h1>
<p>Prototype – current active element, and
position is passed in to callback function.</p>
<pre class='code'>
[el1, el2].each(fn(el, i))
</pre>
<p>jQuery – current element position passed
in to callback function, and binds the
function to current active element (i.e. this
is set to the active element).</p>
<pre class='code'>
$([el1, el2]).each(fn(i))
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>DOM Walking</h1>
<p>Prototype – up, down, next & previous</p>
<p>jQuery – parent/s, children, next, prev (& nextAll, prevAll)</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>DOM Manipulation</h1>
<p>Prototype – Insertion class: After, Before, Bottom, Top, update (1.6 will add: <code>Element.insert</code>)</p>
<p>jQuery – after, before, append, prepend & html</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Element Classes</h1>
<p>Prototype – <code>addClassName</code>, <code>removeClassName</code>, <code>toggleClassName</code>, <code>hasClassName</code></p>
<p>jQuery – <code>addClass</code>, <code>removeClass</code>, <code>toggleClass</code>, is (for class matching)</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Events</h1>
<p>Prototype – Event class: <code>observe</code>, <code>stopObserving</code>
(Prototype 1.6 will support <code>Element.observe</code>)</p>
<p>jQuery – <code>bind</code>, <code>unbind</code> (also supports shortcuts: <code>.click</code>, <code>.dblclick</code>, <code>.mouse*</code>, <code>.ready</code>,
<code>.focus</code>, <code>.blur</code>)</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Bubbling</h1>
<p>Prototype – <code>Event.stop()</code></p>
<p>jQuery – return false or <code>event.stopPropagation()</code> (event is passed in
to the callback)</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Ajax</h1>
<p>Prototype</p>
<pre class='code'>
new Ajax.Request(url[, options])
</pre>
<p>jQuery</p>
<pre class='code'>
$.ajax(options) // url included in options
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Ajax – Method Comparison</h1>
<table id="ajax">
<tr>
<th>Prototype </th>
<th></th>
<th>jQuery </th>
</tr>
<tr>
<td> <code>onCreate</code> </td>
<td> ⇔ </td>
<td> <code>beforeSend</code> </td>
</tr>
<tr>
<td> <code>onSuccess</code> </td>
<td> ⇔ </td>
<td> <code>success</code> </td>
</tr>
<tr>
<td> <code>onException</code> </td>
<td> ⇔ </td>
<td> <code>error</code> </td>
</tr>
<tr>
<td> <code>onComplete</code> </td>
<td> ⇔ </td>
<td> <code>complete</code> </td>
</tr>
</table>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Ajax Examples</h1>
<p>Prototype</p>
<pre class='code'>
new Ajax.Request('/profile', {
method: 'post',
parameters:$H({'action':'check_username','username':$F('username')}),
onSuccess: function (j) {
// do stuff with response
}
});
</pre>
<p>jQuery</p>
<pre class='code'>
$.ajax({ url: '/profile',
data: {'action':'check_username','username': $('#username').val()},
type: 'post',
success: function (json) {
// do stuff with response
}
});
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Plugins / Extensions</h1>
<p>Prototype</p>
<pre class='code'>
Element.addMethods({myPlugin : function(element, args) { return element; }});
</pre>
<p>jQuery</p>
<pre class='code'>
jQuery.fn.myPlugin = function (args) { return this; };
</pre>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Browser Detection</h1>
<p>Prototype – <code>Prototype.Browser.IE</code>, <code>.Webkit</code>, etc.</p>
<p>jQuery – <code>jQuery.browser.msie</code>, <code>.safari</code>, etc.</p>
</div>
<div class='slide '>
<!-- _S9SLIDE_ -->
<h1>Resources</h1>
<table id="resources">
<tr>
<th></th>
<th>Prototype </th>
<th>jQuery </th>
</tr>
<tr>
<td> API </td>
<td> <a href="http://prototypejs.org/api"><code>prototypejs.org/api</code></a> </td>
<td> <a href="http://docs.jquery.com/Core"><code>docs.jquery.com/Core</code></a> </td>
</tr>
<tr>
<td> Tutorials </td>
<td> <a href="http://prototypejs.org/learn"><code>prototypejs.org/learn</code></a> </td>
<td> <a href="http://docs.jquery.com/Tutorials"><code>docs.jquery.com/Tutorials</code></a> </td>
</tr>
<tr>
<td> Effects </td>
<td> <a href="http://script.aculo.us"><code>script.aculo.us</code></a> </td>
<td> <a href="http://docs.jquery.com/Effects"><code>docs.jquery.com/Effects</code></a> </td>
</tr>
</table>
<!-- begin google-analytics {:code=>"UA-397343-10"} -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-397343-10']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- end google-analytics -->
</div>
</div><!-- presentation -->
</body>
</html>