Book Image

jQuery Plugin Development Beginner's Guide

By : Giulio Bai
Book Image

jQuery Plugin Development Beginner's Guide

By: Giulio Bai

Overview of this book

<p>jQuery is the most famous JavaScript library. If you use jQuery a lot, it can be a good idea to start packaging your code into plugins. A jQuery plugin is simply a way to put your code into a package, which makes it easier to maintain your code and use across different projects. While basic scripting is relatively straightforward, writing plugins can leave people scratching their heads.<br /><br />With this exhaustive guide in hand, you can start building your own plugins in a matter of minutes! This book takes you beyond the basics of jQuery and enables you to take full advantage of jQuery's powerful plugin architecture to deliver highly interactive content to your website viewers.<br /><br />This book contains all the information you need to successfully author your very own jQuery plugin with a particular focus on the practical aspect of design and development. <br /><br />This book will also cover some details of real life plugins and explain their functioning to gain a better understanding of the overall concept of plugin development and jQuery plugin architecture.<br /><br />Different topics regarding plugin development are discussed, and you will learn how to develop many types of add-ons, ranging from media plugins (such as slideshows, video and audio controls, and so on) to various utilities (image pre-loading, handling cookies) and use and applications of jQuery effects and animations (sliding, fading, combined animations) to eventually demonstrate how all of these plugins can be merged and give birth to a new, more complex, and multipurpose script that comes in handy in a lot of situations.</p>
Table of Contents (20 chapters)
jQuery 1.4 Plugin Development
Credits
About the Author
About the Reviewers
Preface

Preface

jQuery is the most famous JavaScript library. If you use jQuery a lot, it may be a good idea to start packaging your code into plugins. A jQuery plugin is simply a way to put your code into a package, which makes it easier to maintain your code and use it across different projects. Although basic scripting is relatively straightforward, writing plugins can leave people scratching their heads.

With this exhaustive guide in hand, you can start building your own plugins in a matter of minutes! This book takes you beyond the basics of jQuery and enables you to take full advantage of jQuery's powerful plugin architecture to deliver highly interactive content to your website viewers.

This book contains all the information you need to successfully author your very own jQuery plugin with a particular focus on the practical aspect of design and development.

This book will also cover some details of real-life plugins and explain their functioning to gain a better understanding of the overall concept of plugin development and jQuery plugin architecture.

Different topics regarding plugin development are discussed, and you will learn how to develop many types of add-ons, ranging from media plugins (such as slideshows, video and audio controls, and so on) to various utilities (image pre-loading, handling cookies). You will also learn the use and applications of jQuery effects and animations (sliding, fading, and combined animations) to eventually demonstrate how all of these plugins can be merged and give birth to a new, more complex, and multipurpose script that comes in handy in a lot of situations.

What this book covers

Chapter 1, What is jQuery About?, covers what jQuery is and why we should use and prefer it over other libraries. Some basic concepts, as well as some history, are covered in this chapter that acts as an introduction to the real topic of the book.

Chapter 2, Plugins Basics, is our first real approach to jQuery plugins. It provides an in-depth description of jQuery's own plugin architecture, providing some examples and sample applications for some of the most popular plugins.

Chapter 3, Our First jQuery Plugin, as its name suggests, is about creating our first, working, and fantastic jQuery plugin! Step-by-step instructions are provided in order to guide even very beginners to the successful realization of their first plugin.

Chapter 4, Media Plugins: Images Plugins, discusses how images play a big role in today's Internet. Since we don't want to be left out, nor behind, in this chapter, we do our best to create a jQuery plugin that is very easy to use, customize, and at the same time, very effective and good looking. Besides, a gallery-like plugin will certainly enhance the user experience of our web pages!

Chapter 5, Media Plugins: Audio Plugins, shows us how, after images, sounds too can be used in a variety of different ways to hold the visitor's attention. Not only will we learn how to develop a jQuery-based audio player plugin, but we will also analyze the advantages and disadvantages of the HTML5 audio tag, compared to JavaScript solutions.

Chapter 6, Media Plugins: Video Plugins, presents a detailed guide to the creation of a video player plugin, and also offers some hints on how to better display video objects on a web page with the aid of JavaScript and/or HTML code.

Chapter 7, Form Plugins, shows a handful of different, but all extremely useful, plugins we can develop in order to improve our forms and offer an enhanced user experience on our website. A number of jQuery plugins are coded, step-by-step, and discussed to better understand what to use, how to use it, and in what circumstances.

Chapter 8, User Interface Plugins, offers many plugin examples and explains how the developer should tackle the problem, in such a way that the final result can be easily modified and integrated into an organized project.

Chapter 9, User Interface Plugins: Tooltip Plugins, explains that to get a fully working tooltip plugin, a series of preliminary steps is required. These include understanding mouse movement and events, positioning through CSS rules, and, last but not least, interaction with jQuery code to actually show and hide the tooltip element at our will.

Chapter 10, User Interface Plugins: Menu and Navigation Plugins, discusses how developing menu and navigation plugins with some additional effects to enhance their appearance and user experience is rather simple. The principles are explained in this chapter, as well as a number of different approaches that we might want to use to obtain a menu plugin.

Chapter 11, Animation Plugins, discusses how fun-to-activate and nice-to-look-at animation plugins play one of the most important roles when it comes to user interaction. Be it a moving image or a bouncing shape, they are always worth the time spent coding them and actually amuse the visitor. We will learn how to make things move, bounce, fade in and away—nothing more, nothing less.

Chapter 12, Utility Plugins, shows how creating utility plugins (which can be easily used thanks to jQuery's own internal structure and which allow for a very effective integration) is a big plus. If we need some kind of function or method to take care of some repetitive task, we could speed up the process with just a few lines of code.

Chapter 13, Top jQuery Plugins, is a selection of the top 10 plugins. It briefly shows how they are customized on a website, their uses, their advantages and disadvantages, as well as provides a basic documentation that readers can easily use and refer to when (and if) they decide to mess with any of the plugins discussed in this chapter.

Appendix A, Tools, reference, and final recommendations, contains some useful jQuery-related links and offline resources for further reference.

Who this book is for

This book is for anyone who wants to have a better understanding of the dynamics of jQuery when plugins come into play, as well as for those who are willing to push jQuery to its limits and develop awesome plugins to use on their websites. A little background information about JavaScript and jQuery cannot harm anyone, but even very beginners can have a chance to be introduced to the wonderful world of jQuery.

Conventions

In this book, you will find several headings appearing frequently.

To give clear instructions on how to complete a procedure or task, we use:

Time for action — heading

  1. 1. Action 1

  2. 2. Action 2

  3. 3. Action 3

Instructions often need some extra explanation so that they make sense, so they are followed with:

What just happened?

This heading explains the working of tasks or instructions that you have just completed.

You will also find some other learning aids in the book, including:

Pop quiz

These are short multiple choice questions intended to help you test your own understanding.

Have a go hero — heading

These set practical challenges and give you ideas for experimenting with what you have learned.

You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

jQuery.fn.txtHover = function() {
return this.each(function() {
jQuery(this).hover(function() {
jQuery(this).text("Mouse hovered");
});
});
};

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "To enable the Web Inspector, open Preferences, go to the Advanced tab, and select the Show develop menu in the menu bar item".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.