JavaScript
  Home arrow JavaScript arrow Page 4 - Using JavaScript Click Interceptions in an...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Using JavaScript Click Interceptions in an Image Gallery
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-11-12

    Table of Contents:
  • Using JavaScript Click Interceptions in an Image Gallery
  • Building the basic structure of an image gallery
  • Using click interception to modify existing behavior
  • Listing the full source code of the improved image gallery

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using JavaScript Click Interceptions in an Image Gallery - Listing the full source code of the improved image gallery


    (Page 4 of 4 )

    In consonance with the concepts I deployed in the section you just read, below I included the complete source code of this simple image gallery. As you saw before, it uses the click interception approach to improve its existing behavior.

    Here's the corresponding code sample:


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Example on building an image gallery using click interception</title>

    <script language="javascript" type="text/javascript">

    // define 'displayImage()' function

    function displayImages(){

    var lnkcont=document.getElementById('linkcontainer');

    if(!lnkcont){return};

    var links=lnkcont.getElementsByTagName('a');

    if(!links){return};

    for(var i=0;i<links.length;i++){

    // use click interception to display images on the same web page

    links[i].onclick=function(){

    var imgcont=document.getElementById('imgcontainer');

    if(!imgcont){return};

    // if there is an existing image, remove it from the container

    if(imgcont.firstChild){

    imgcont.removeChild(imgcont.firstChild);

    }

    var img=document.createElement('img');

    img.setAttribute('src',this.href);

    img.setAttribute('alt',this.title);

    imgcont.appendChild(img);

    return false;

    }

    }

    }

    // call 'displayImage()' function when web page is loaded

    window.onload=function(){

    if(document.getElementById&&document.
    getElementsByTagName&&document.createElement){

    displayImages();

    }

    }

    </script>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    h1{

    font: bold 18pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    a:link,a:visited{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #00f;

    }

    a:hover{

    color: #f90;

    }

    #linkcontainer{

    width: 300px;

    padding: 5px;

    background: #eee;

    }

    #imgcontainer{

    width: 300px;

    text-align: center;

    }

    </style>

    </head>

    <body>

    <h1>Example on building an image gallery using click interception</h1>

    <div id="linkcontainer">

    <ul>

    <li><a href="sampleimagea.gif" title="First sample image goes here">View first image</a></li>

    <li><a href="sampleimageb.gif" title="Second sample image goes here">View second image</a></li>

    <li><a href="sampleimagec.gif" title="Third sample image goes here">View third image</a></li>

    </ul>

    </div>

    <div id="imgcontainer"></div>

    </body>

    </html>


    Feel free to use all of the code samples shown in this article to improve your JavaScript click interception skills.

    Final thoughts

    In this second installment of the series, you hopefully learned how to utilize click interceptions to extend the existing functionality of a primitive image gallery. This example demonstrates how useful this approach can be when used in a real-word situation.

    In the next tutorial, I'm going to show you how to use click interceptions to improve the behavior of a database-driven web application. This topic will be very educational and give you some useful knowledge, so don't miss the next part!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this second chapter of the series, clicks interceptions are applied to extend...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT