advanced jquery
DESCRIPTION
Advanced Jquery session in Horizons Software http://harouny.wordpress.com/TRANSCRIPT
![Page 1: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/1.jpg)
Advanced JQuery
Prepared by: Ahmed EL-Harouny
Senior Software Engineer
![Page 2: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/2.jpg)
1. Handling Events1. Binding To Events2. Event Object3. Binding Shortcuts4. Manually Trigger Events5. Keyboard Events6. Unbind Events7. The Live() function
2. Ajax1. load() – the simplest2. jQuery.ajax() – the giant3. Json and Jsonp4. Twitter demo!
3. Build a plugin Demo
Agenda
![Page 3: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/3.jpg)
Handling EventsBinding to events
Bind() function: attach a handler to an event for the elements.
Multiple Handlers
When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.
![Page 4: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/4.jpg)
Handling EventsEvent Object
event object: an object that contains information and functionality related to the current event is passed to all event handlers:
![Page 5: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/5.jpg)
Handling EventsBinding ShortcutsMost DOM events exists as functions for short• click()• change()• mousedown(), mouseenter(), mouseleave(), mousemove() …etc• ready()• scroll()
![Page 6: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/6.jpg)
Handling EventsManually Trigger Events
Shortcut functions can also be used for triggering events:
trigger() function: Execute all handlers and behaviors attached to the matched elements for the given event type.
![Page 7: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/7.jpg)
Handling EventsKeyboard Events
keyup(): The keyup event is sent to an element when the user releases a key on the keyboard.
keydown (): The keydown event is sent to an element when the user first presses a key on the keyboard.
Note: keyboard events are only triggered on elements that have focus.
![Page 8: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/8.jpg)
Handling EventsUnbind Eventsunbind() function: Remove a previously-attached event handler from the elements.
![Page 9: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/9.jpg)
Handling EventsThe Live() functionlive() function: Attach an event handler for all elements which match the current selector, now and in the future.
Note: #thirdBtn don’t exist on the page yet.
![Page 10: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/10.jpg)
Ajaxload() – the simplest
load() function: Load data from the server and place the returned HTML into the matched element.
Also takes those optional parameters:[, data] [, complete(responseText, textStatus, XMLHttpRequest)]
![Page 11: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/11.jpg)
AjaxjQuery.ajax() – the giant
jQuery.ajax() function: Perform an asynchronous HTTP (Ajax) request.Reference: http://api.jquery.com/jQuery.ajax/
![Page 12: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/12.jpg)
JsonJavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange.
Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages.
Json and Jsonp
![Page 13: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/13.jpg)
Json and Jsonp (continued)Jason Format:
![Page 14: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/14.jpg)
JsonpJSONP or "JSON with padding" is a complement to the base JSON data format. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the same origin policy.
Json and Jsonp (continued)
![Page 15: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/15.jpg)
Json and Jsonp (continued)
Demo
![Page 16: Advanced Jquery](https://reader033.vdocuments.us/reader033/viewer/2022061210/54907f8cb4795942548b4736/html5/thumbnails/16.jpg)
Build a plugin Demo
Demo
http://harouny.wordpress.com/2012/06/06/make-your-first-jquery-plugin-in-2-minutes/