120 likes | 225 Views
Extending a Website with jQuery. Dawn Pedersen. What is JavaScript?. JavaScript is the basis for both jQuery and Spry applications JavaScript is referred to as a client-side scripting language It does not need to be parsed by the server like PHP and ASP do (these are server-side scripts)
E N D
Extending a Website with jQuery Dawn Pedersen
What is JavaScript? • JavaScript is the basis for both jQuery and Spry applications • JavaScript is referred to as a client-side scripting language • It does not need to be parsed by the server like PHP and ASP do (these are server-side scripts) • It is interpreted and rendered by the browser (the client) after the page is loaded • JavaScript is not the same as Java, which is a server-side programming language.
JavaScript Caveats • Because it is run on the client end, it is subject to all the quirks of various browsers (just like CSS) • JavaScript should not be used for mission-critical functionality, because the user can turn it off • JavaScript should degrade elegantly (if users turn it off, the page will still work)
JavaScript Script Locations • Like CSS, JavaScript can be placed • inline with content on the page • in the head of the page (internal) • in an external file ending with .js • Like CSS, external files are preferred • to keep our markup clean • to have access to the script from any page
What is jQuery? • jQuery is a method of using a JavaScript library which is already scripted for you. • jQuery scripts can do all kinds of fancy things on your site. • You simply: • download the library you want • put files in the right places • add links to the scripts in your markup • make a few changes to your existing markup
Lightbox Intro • Lightbox is a set of JavaScript scripts—a jQueryplugin—that will allow you to have images (or other content) open with an animation in an overlay window. • It provides a nice interface for viewing images.
Lightbox Exercise • Download and extract the Lightbox .zip file from the Lightbox2 website: http://www.huddletogether.com/projects/lightbox2/ • I will provide some directions on the next slides, but you can also get them from the website.
Lightbox Exercise • Start by downloading our starter gallery: http://blulob.com/ai/mm2203/docs/gallery.zip. • Extract this file to your Desktop. • Create a new folder in this site called “js”. • Grab a few files from the extracted Lightbox folder: • Move the 3 .js files into your gallery’s “js” folder. • Move the lightbox.css file into your gallery’s “css” folder. • Move the image files into your gallery’s “images” folder. • We’re done with the Lightbox folder. Future steps will refer to your gallery site folder only.
Lightbox Exercise • In index.html, add links to the three .js files within your <head> element: • <script type="text/javascript" src="js/prototype.js"></script> • <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> • <script type="text/javascript" src="js/lightbox.js"></script> • Add the link to the CSS file in the <head> element: • <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> Be sure the paths are correct to those files. • If you have another CSS file to load be sure it comes after the lightbox.css file, so that any CSS you have written will override the styles for Lightbox.
Lightbox Exercise • To enable the Lightbox, add some markup to the <a> tags on index.html: • Add the rel="lightbox" attribute. • Putting [group name] will put the photos in a group so that you can click next or previous to scroll through them. • Adding a title="caption name" attribute will display a caption below the picture. That’s it. Assuming your links to the support files are correct, it should work. Test it!
More on jQuery • If Lightbox or other jQueryplugins are not working, it can often be attributed to a conflict with other JavaScript being run on the page. • There are a number of other scripts available that do much the same as Lightbox, built with different libraries, or with slightly different functionality. • A whole catalog of jQueryplugins can be downloaded from http://plugins.jquery.com/. Take a few minutes and check some of the demos out.
What is Spry? • Spry is Dreamweaver’s version of JavaScript libraries. • Spry effects alter the look of a page element—or of the whole page itself—when a particular event occurs.