250 likes | 354 Views
Writing your first jQuery plugin. Slides + Code. Presentation http://www.slidesix.com Code https://github.com/cfaddict/cfobjective2011 Blog Post http://www.danvega.org/blog. About Me. Programmer Senior Web Developer STERIS Adobe Community Professional (ACP)
E N D
Slides + Code • Presentation • http://www.slidesix.com • Code • https://github.com/cfaddict/cfobjective2011 • Blog Post • http://www.danvega.org/blog
About Me • Programmer • Senior Web Developer STERIS • Adobe Community Professional (ACP) • Manager Cleveland Adobe User Group • Writer / Teacher / Presenter • Cleveland Sports Fan • Runner / Exercise / Poker / Travel
Agenda • What you should know • Performance Tips & Tricks • Building blocks of jQuery Plugins • BlogSlider Plugin Walkthrough • Wrap-up & FAQ
Why jQuery • cfObjective 2011 • JavaScript • Coding is fun! • jQuery • jQuery is easy to use • Plugin Architecture
Performance Tips & Tricks • Why performance • Best practices • More Work = Slower Response • Faster != Better
Latest Version • ALWAYS use the latest version of jQuery core • Performance improvements and bug fixes are usually made between each version • 1.6.0 – Changes to the Attributes Module • What about Google CDN?
Why Google CDN • Cached version • Size of library. • Reduces bandwidth used by your server. • Geographically close response.
Selectors • Fastest to slowest are • ID Selectors (“#navigation”) • Element Selectors (“form”) • Class Selectors (“.navigation”) • Pseudo & Attribute Selectors (“:hidden”) • Bonus Question
Caching var parents = $(‘.parents’); var children = $(‘.parents’).find(‘.child’); //bad • Cache ALWAYS!!! • Each $(“query”) searches the DOM and returns a new collection
Chaining • Comparable to caching • Almost all jQuery methods return a jQuery object and support chaining • Less code, easy to write and it is just darn fun!
Event Delegation • Understanding bind( ), live( ) and delegate( ) • Each technique progressively gives you a little more control and flexibility. • At its core event delegation is all about letting events bubble up the DOM tree to a parent element.
Limit Direct DOM Manipulation • The basic idea here is to create exactly what you need in memory, and then update the DOM. This is not a jQuery best practice, but a must for efficient JavaScript. • GOOD - Updated the DOM 1x • BAD - Update the DOM on each iteration
What is a jQuery Plugin • Extension of jQuery • Modular Code • Markup (HTML) • Look & Feel (CSS) • Functionality (JavaScript) • The Good, the bad and the ugly • Plugin Myths
JavaScript Recap • Classes • Properties • Methods • Constructors • Prototype
Getting Started • What is your plugin going to do? • How will the developer use it? • Naming Conventions • jquery.stripes.js / jquery.stripes.min.js • The base plugin • Improving the base plugin
Flexible Plugins • Configurable plugins • Default settings • $.extend(); • Local vs Global
Adding Functionality to your plugin • Namespace • Adding methods to your plugin • Events
Resources • Performance • Addy Osmani http://vimeo.com/18846584 • Plugins/Authoring • jQuery http://docs.jquery.com/Plugins/Authoring • BlogSlider Plugin • http://www.github.com/cfaddict/blogslider • Ninjas • http://dougneiner.com • http://www.bennadel.com
Contact Information email: danvega@gmail.com twitter: @cfaddict web: http://www.danvega.org