Take Home Assignment 4
Take Home Assignment 4
Issues with a lot of the wording Number of Tickets: textfield, range or number are acceptable answers If you ever have issues please contact me! Always, always put some sort of comment at the top of your source code stating your name, date, and version, etc.
Test 1
Information for the test is posted on LION As outlined in your syllabus, it is worth 20% The test will be open book
Objectives
Applied 1. Use any of these plugins to enhance a web page: Lightbox, bxSlider, Cycle, or jLayout. 2. Given the specifications for a jQuery task for which there is a useful plugin, find and use the plugin to do the task. 3. Given the specifications for a jQuery plugin, create it. Knowledge 1. In general terms, explain what a plugin is. 2. In general terms, describe the process of finding and using a plugin. 3. Describe the API standards for creating a jQuery plugin in terms of implicit iteration, chaining, and defaults.
Introduction
jQuery plugins are JavaScript applications that extend the functionality of jQuery These plugins require the use of the core jQuery library Plugins are available for hundreds of web functions In general, if you can find a plugin for doing what you want, thats better than writing the jQuery code yourself
Check out some of the most useful plugins in Figure 11-2 of your textbook
Two Cautions
Make sure that you include a script element for jQuery and make sure that the script element for the plugin comes after it. Some plugins wont work with the latest version of jQuery. So if you have any problems with a plugin, check its documentation to see which version of jQuery it requires.
Structure of a Plugin
The plugin should be wrapped within an Immediately Invoked Function Expression (IIFE):
(function($) { / the plugin goes here })(jQuery);
If a plugin isnt coded this way, it can cause conflicts with other libraries and plugins that use the $ sign
General Structure
(function($){ $.fn.methodName = function() { this.each(function() { // the code for the plugin }); return this; } })(jQuery);
The each method is called for the object that the plugin is applied to, which is referred to by the this keyword If the object consists of more than one element, the plugin function is applied to each element
highlightMenu Plugin
The HTML for the menu
<ul id="vecta_menu"> <li><a href="index.html">Home</a></li> <li><a href="aboutus.html">About Us</a></li> <!-- the rest of the links for the menu --> </ul>
highlightMenu Plugin
(function($){ $.fn.highlightMenu = function() { return this.each(function() { var items = $("li a"); items.css('font-family', 'arial, helvetica, sans-serif') .css('font-weight', 'bold') .css('text-decoration', 'none') .css('background-color', '#dfe3e6') .css('color', '#cc1c0d') .css('width', '125px'); items.mouseover(function() { $(this).css('background-color', '#000') .css('color', '#fff'); }); items.mouseout(function() { $(this).css('background-color', '#dfe3e6') .css('color', '#cc1c0d'); }); }); } })(jQuery);