At the Forge - jQuery Plugins
Another common task people want to do in JavaScript is produce menus, including hierarchical menus. Indeed, if I think back several years, menus probably are one of the things for which my clients have most commonly asked. One of the best-known methods for creating menus with CSS is known as Suckerfish, because of the sample data that was used to show the technique.
There are many jQuery-based menu libraries, but one I've grown to enjoy is called Superfish, because it adds functionality to the Suckerfish style of menu. It handles submenus, adds shadows and even tries to be intelligent about when you plan to open the menu and when your mouse is passing by, using a separate plugin known as hoverIntent.
To use Superfish, you need to download and install the plugin. Then, you need to create a menu using a combination of <ul>, <li> and <a> tags. If you need a secondary hierarchy of menus, you can create one with a nested <ul> in an <li> tag. In each <a> tag, the href identifies which div on a page should be displayed when that menu item is clicked on, hiding all of the other divs by default.
You undoubtedly will want to start off with the Superfish CSS file that comes with the plugin. You always can modify it to suit your needs. There are large numbers of definitions, and I've never been able to build the CSS file from scratch. Instead, I've modified the existing one, changing it to suit my needs.
As always in jQuery, you use the plugin by attaching it to an element of the HTML page. Instead of using the element's ID, as you did with DataTable, here you attach it to the <ul> tag with a class of sf-menu:
<script type="text/javascript">
$(document).ready(function () {
jQuery('ul.sf-menu').superfish();
});
</script>
If there were more than one <ul> with that class, Superfish would create menus on all of them. Remember, the jQuery object can return any number of page elements: zero, one or a large number. The full HTML for the example is shown in Listing 2.
Listing 2. menu.html
<html>
<head>
<title>Testing menus</title>
<link rel="stylesheet" type="text/css" media="screen"
href="superfish.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="superfish.js"></script>
<script type="text/javascript">
$(document).ready(function () {
jQuery('ul.sf-menu').superfish();
});
</script>
</head>
<body>
<h1>Testing menus</h1>
<div>
<ul class="sf-menu sf-navbar">
<li>
<a href="">Account</a>
<ul>
<li><a id="checking-menu" href="#checking-div">Checking</a>
</li>
<li><a id="savings-menu" href="#savings-div">Savings</a>
</li>
<li><a id="credit-card-menu" href="#credit-card-div">
Credit card
</a>
</li>
</ul>
</li>
<li><a id="profile-menu" href="#profile-div">Profile</a>
</li>
<li><a id="help-menu" href="#help-div">Help</a>
</li>
</ul>
</div>
</body>
</html>
Plugins are the secret to jQuery's success, and there are so many plugins for jQuery, it's impossible to describe them all here. But, as you can see from these two examples, using the plugin often requires very little effort. Once you get the hang of it, downloading, installing and using plugins becomes second nature. I've found it can be useful to create a simple, small HTML file with dummy data and use a jQuery plugin with that, just to understand the basics of how to use a plugin.
There are times when plugins clash with one another, in that they're both trying to rewrite the HTML, sometimes in conflicting ways. For example, I recently used DataTable along with with a jQuery tab widget, and it took me a while until I could ensure that everything was visible on the page. As jQuery plugins become increasingly sophisticated, we might have to worry about this more and more.
For now, however, jQuery plugins are a fun and easy way to spruce up your Web application. Next month, I'll explain how to design your own plugin, delving a bit deeper into jQuery's plumbing and understanding how jQuery takes advantage of JavaScript's quirks to give us an extensible platform for client-side programs.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Web Development News
Developer Poll
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- seo services in india
5 min 23 sec ago - For KDE install kio-mtp
6 min 5 sec ago - Evernote is much more...
2 hours 6 min ago - Reply to comment | Linux Journal
10 hours 51 min ago - Dynamic DNS
11 hours 25 min ago - Reply to comment | Linux Journal
12 hours 24 min ago - Reply to comment | Linux Journal
13 hours 14 min ago - Not free anymore
17 hours 16 min ago - Great
21 hours 3 min ago - Reply to comment | Linux Journal
21 hours 11 min ago








Comments
Previous Article on jQuery
The previous article on jQuery is available here - Last month Linux Journal
http://www.linuxjournal.com/article/10335
errtheblog.com/posts/73-the-j
errtheblog.com/posts/73-the-jskinny-on-jquery is a broken link, download something that can't be open