To and from JavaScript libraries by Remy Sharp1
1 Adapted S6 Version from Original PDF Slide Deck
Slide Show Keyboard Controls (Help)
Action | Key |
Go to next slide | Space Bar, Right Arrow, Down Arrow, Page Down, Click Heading |
Go to previous slide | Left Arrow, Up Arrow, Page Up |
Toggle between slideshow and outline view (Ø) | T |
Show/hide slide controls (Ø « ») | C, Move mouse to bottom right corner |
Zoom in, zoom out, zoom reset (100%) | Control+ Plus, Control+ Minus, Control+ 0 |
Based on Prototype 1.5.1 & 1.6
Based on jQuery 1.2.1
Prototype has:
|
jQuery has:
|
Non-exhaustive list, and in most case, the functionality can be implemented with plugins.
$
for id based selection$
= CSS based selector (= $$
in Prototype)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).
$
ExamplePrototype
$('speech1').show();
jQuery
$('#speech1').show();
$$
To narrow down it’s context use
Element.getElementsBySelector(selector)
(or Element.select(selector)
in 1.6)
$
Virtually all of jQuery’s DOM selection is done using CSS 1-3
Prototype
$$('.dialog').invoke('show'); $('final-speech').getElementsBySelector('DIV.final-dialog').each(Element.hide); // 1.6 $('final-speech').select('DIV.final-dialog').invoke('hide');
jQuery
$('.dialog').show(); $('#final-speech DIV.final-dialog').hide();
jQuery uses different methods to execute the ready function when the DOM is ready, using specific methods for Internet Explorer and for Safari1
Prototype
Event.observe(window,'load',function(){});
Prototype 1.6
document.observe('contentloaded',function{});
jQuery
$(document).ready(function(){}); // or $(function(){});
Prototype – current active element, and position is passed in to callback function.
[el1, el2].each(fn(el, i))
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).
$([el1, el2]).each(fn(i))
Prototype – up, down, next & previous
jQuery – parent/s, children, next, prev (& nextAll, prevAll)
Prototype – Insertion class: After, Before, Bottom, Top, update (1.6 will add: Element.insert
)
jQuery – after, before, append, prepend & html
Prototype – addClassName
, removeClassName
, toggleClassName
, hasClassName
jQuery – addClass
, removeClass
, toggleClass
, is (for class matching)
Prototype – Event class: observe
, stopObserving
(Prototype 1.6 will support Element.observe
)
jQuery – bind
, unbind
(also supports shortcuts: .click
, .dblclick
, .mouse*
, .ready
,
.focus
, .blur
)
Prototype – Event.stop()
jQuery – return false or event.stopPropagation()
(event is passed in
to the callback)
Prototype
new Ajax.Request(url[, options])
jQuery
$.ajax(options) // url included in options
Prototype | jQuery | |
---|---|---|
onCreate |
⇔ | beforeSend |
onSuccess |
⇔ | success |
onException |
⇔ | error |
onComplete |
⇔ | complete |
Prototype
new Ajax.Request('/profile', { method: 'post', parameters:$H({'action':'check_username','username':$F('username')}), onSuccess: function (j) { // do stuff with response } });
jQuery
$.ajax({ url: '/profile', data: {'action':'check_username','username': $('#username').val()}, type: 'post', success: function (json) { // do stuff with response } });
Prototype
Element.addMethods({myPlugin : function(element, args) { return element; }});
jQuery
jQuery.fn.myPlugin = function (args) { return this; };
Prototype – Prototype.Browser.IE
, .Webkit
, etc.
jQuery – jQuery.browser.msie
, .safari
, etc.
Prototype | jQuery | |
---|---|---|
API | prototypejs.org/api |
docs.jquery.com/Core |
Tutorials | prototypejs.org/learn |
docs.jquery.com/Tutorials |
Effects | script.aculo.us |
docs.jquery.com/Effects |